jlandowner / helm-chartsnap Goto Github PK
View Code? Open in Web Editor NEWSnapshot testing tool for Helm charts
License: MIT License
Snapshot testing tool for Helm charts
License: MIT License
Hi,
I am writing to request a feature enhancement in your chartsnap plugin. Specifically, I would like the system to generate a warning when the indexing of YAML files is incorrect. For example, this example:
apiVersion: apps/v1
kind: Deployment
metadata:
name: test
spec:
replicas: 1
spec:
imagePullSecrets:
- name: {{ .Values.imagePullSecrets }}
Currently, when there is an issue with the indexing of these files, it can lead to unexpected behavior in our application, which is difficult to debug due to the lack of explicit warnings or error messages.
Implementing this feature would greatly improve our ability to identify and resolve issues more efficiently, thereby improving the overall robustness of our application.
I look forward to your positive response. Because this approach, we could resolve a lot of issues in our debugging.
Thank you for all your help.
Best regards,
Sofía
First of all, thank you so much for this amazing tool.
I'm creating this issue due since several days I'm facing this issue
WARN: failed to recognize a resource. snapshot as Unknown:
---
object:
apiVersion: helm-chartsnap.jlandowner.dev/v1alpha1
kind: Unknown
raw: |
coalesce.go:286: warning: cannot overwrite table with non table for certificate-exporter.hostPathsExporter.securityContext (map[capabilities:map[drop:[ALL]] readOnlyRootFilesystem:true runAsGroup:0 runAsUser:0])
coalesce.go:286: warning: cannot overwrite table with non table for certificate-exporter.secretsExporter.securityContext (map[capabilities:map[drop:[ALL]] readOnlyRootFilesystem:true runAsGroup:65534 runAsUser:65534])
I don't know but maybe could be related with the array section
this is my values.yaml:
certificate-exporter:
exposePerCertificateErrorMetrics: true
exposeRelativeMetrics: true
secretsExporter:
securityContext: []
hostPathsExporter:
securityContext: []
My helm version is 3.14.2
Support to run cmd without args such as chartsnap -f values.yaml
by using the values file like:
testSpec:
chart: cilium
additionalArgs: |
--repo https://helm.cilium.io
--namespace kube-system
...
@jlandowner thanks for this amazing tool!
I was looking for exactly something like this, because I work in a project with multiple different developers, which all have different levels of experiences with helm and how to write and modify helm charts.
I'm just wondering, if it's somehow possible to also integrate a validator tool to validate the generated yaml code against the kubernetes api. Did you or someone else already thought about something like that? It would be really easy, if the snapshots would be stored as plain yaml files.
I have a use case in which I would like to test multiple test values files located in a single directory (let's say, named tests
). For every values file, my Helm chart generates Kubernetes Secrets with dynamically generated data. Secrets are always named the same. Now, to make my tests pass, I need to separately add the same testSpec.dynamicFields
to every test values file which is redundant. I would like to be able to define global dynamicFields
-like rules that would be used when generating snapshots for every values file in my tests
directory.
It's possible to set a global dynamic fields configuration that is used for every values file. Dynamic fields configuration is used to replace all dynamically generated content with ###DYNAMIC_FIELD###
constant when the rule matches an object's field.
Sample command:
helm chartsnap -c <chart> -f <directory-with-test-values-files> --dynamic-fields-config=./exclude-secrets-data.yaml
Sample config file (exclude-secrets-data.yaml
):
dynamicFields:
- apiVersion: v1
kind: Secret
name: chartsnap-postgresql
jsonPath:
- /data/postgres-password
Alternatively, this could be a config file used by the tool, e.g. .chartsnap.yaml
in which the global configuration would be defined (I believe there could be more global settings to tune than just dynamicFields
in the future).
Option 1
dynamicFields:
- apiVersion: v1
kind: Secret
name: cosmo-auth-env
jsonPath:
- /data/COOKIE_HASHKEY
- /data/COOKIE_BLOCKKEY
- /data/COOKIE_HASHKEY
- /data/COOKIE_SESSION_NAME
base64: true
value: '###DYNAMIC_FIELD###' # Add
Option 2
dynamicFields:
- apiVersion: v1
kind: Secret
name: cosmo-auth-env
jsonPath: # Support both string and struct array
- path: /data/COOKIE_HASHKEY # Change as path property
value: '###COOKIE_HASHKEY###'
- path: /data/COOKIE_BLOCKKEY
value: '###COOKIE_BLOCKKEY###' # This option can set values on each path.
Hello again,
today I wanted to integrate helm-chartsnap into another project where I discovered an edge case that I'm not sure how to handle.
Let's imagine we have a template that contains the following:
testValue: {{ required "testValue is required" .Values.testValue }}
and a values.yaml
that contains the following:
testValue:
Executing helm template and also helm chartsnap -c .
would now result in the following "error" message:
Error: execution error at (<TEMPLATE_PATH>.yaml:1:3): testValue is required
The question now is, how should I handle this? I don't want to put a default value in the values.yaml
because there is no "default" value as the value always depends on the environment the helm chart will applied to.
One idea would be to provide a separate "default" values.yaml
file just for chartsnap. But this feels somehow ugly for me. Also I would need to provide testValue
in each of my test values.yaml
files which is very repetitive.
Another idea would be to somehow provide these kind of values within the .chartsnap.yaml
, but I guess that's not supported at the moment, right?
After #110 chartsnap can take a error output snapshot with success exitcode. But also it unintentionally takes a error snapshot that chart is not found.
It should take only helm's rendering output(including rendering error) and it should exit with errors excluding rendering error.
Hi,
I would like to use dynamicFields with kyes which has '/' characters.
Part of the templated yaml:
spec:
template:
metadata:
annotations:
checksum/values: 30da9af9da506b1fc3aa378d47e2d916f1d62e0e30dda84b25e855053233fd33
This is the .chartignore
dynamicFields:
- apiVersion: apps/v1
kind: Deployment
name: cosmo-auth-env
jsonPath:
- /spec/template/metadata/annotaions/checksum/values
I got the following error:
chart=. values=test/test.yaml err=failed to replace json path: failed to replace json path: failed to patch JSON6902: replace operation does not apply: doc is missing path: /spec/template/metadata/annotaions/checksum/values: missing value:
I tried the following escape segments:
/spec/template/metadata/annotaions/"checksum/values"
/spec/template/metadata/annotaions/'checksum/values'
/spec/template/metadata/annotaions/checksum%2Fvalues
None of the worked for me.
How can I escape the / in the key character?
Thank you for your help!
My default values for my chart do not produce any manifests. I have templates in there but they are all guarded by if statements.
helm chartsnap -c charts/project -u
RUNS Snapshot testing chart=charts/project values=
FAIL chart=charts/ace-project values= err=failed to encode manifests: failed to close encoder: yaml: expected STREAM-START
time=2024-04-09T14:12:24.545-04:00 level=ERROR msg="failed to get snapshot chart=charts/project values=: failed to encode manifests: failed to close encoder: yaml: expected STREAM-START"
Error: plugin "chartsnap" exited with error
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.