Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add comment support when parsing YAML files #602

Open
fredgate opened this issue Aug 17, 2021 · 3 comments
Open

Add comment support when parsing YAML files #602

fredgate opened this issue Aug 17, 2021 · 3 comments
Labels
enhancement New feature or request

Comments

@fredgate
Copy link

I have a Helm chart that I test for Kubernetes API deprecations using deprek8ion policies.

Here is the command and output I have :

helm template my-chart-1.0.0.tgz | conftest test -o json -
[
        {
                "filename": "",
                "namespace": "main",
                "successes": 71,
                "warnings": [
                        {
                                "msg": "Ingress/my-ingress: API networking.k8s.io/v1beta1 for Ingress is deprecated from Kubernetes 1.19, use networking.k8s.io/v1 instead."
                        }
                ]
        }
]

In the result, the filename is missing.

My chart I have one file by resource (one file for deployment, another file for service, yet another file for ingress...), but the helm template command render one output with a multi document YAML like that

...

---
# Source: my-chart/templates/service.yaml
apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
...

---
# Source: my-chart/templates/ingress.yaml
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: my-ingress
spec:
...

Each resource is prefixed with a comment indicating the file containing the resource definition. But this information is not reported in conftest output.
How to proceed ?

@jalseth
Copy link
Member

jalseth commented Aug 25, 2021

Hi @fredgate. This comment in the Helm output is a Helm-specific thing, and is not a part of the YAML specification so it is not parsed by conftest. I will take a look into what can be done here to make this clearer in the output when testing helm files.

@jalseth jalseth added the enhancement New feature or request label Aug 25, 2021
@jalseth
Copy link
Member

jalseth commented Sep 13, 2021

@fredgate The YAML package we use [1] does not return us any comments, so adding this would be a significant refactor. Time allowing we may still add this, but I wanted to let you know it probably won't be soon. That said, I'd welcome a PR if you have the time!

[1] https://pkg.go.dev/github.com/ghodss/yaml

@jpreese jpreese changed the title Missing filename when testing Helm chart Add comment support when parsing YAML files Jan 6, 2022
@eliasscosta
Copy link

I have an identical issue. I want to test yamls where they have fields and these fields have values as a template standards:

name: #@ data.values.metadata.name

This kind of value is a standard from ytt templates.

When I generated the test I got a null value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants