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

kubectl / kubernetes not 100% compatible with YAML 1.2 #34146

Open
chrishiestand opened this issue Oct 5, 2016 · 70 comments
Open

kubectl / kubernetes not 100% compatible with YAML 1.2 #34146

chrishiestand opened this issue Oct 5, 2016 · 70 comments
Assignees
Labels
area/kubectl lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/cli Categorizes an issue or PR as relevant to SIG CLI. triage/accepted Indicates an issue or PR is ready to be actively worked on.

Comments

@chrishiestand
Copy link
Contributor

Is this a request for help? (If yes, you should use our troubleshooting guide and community support channels, see http://kubernetes.io/docs/troubleshooting/.): No

What keywords did you search in Kubernetes issues before filing this one? (If you have found any duplicates, you should instead reply there.): is:issue yaml in:title version


Is this a BUG REPORT or FEATURE REQUEST? (choose one): Bug Report

Kubernetes version (use kubectl version): v1.3.7 (seems to be the same on master)

What happened: I tried to apply a yaml file with kubectl --context=minikube apply -f ./etc/deployment.yaml and got a validation error. However the yaml is valid 1.2.

The error is:
error validating "./etc/deployment.yaml": error validating data: expected type string, for field spec.template.spec.containers[2].command[6], got bool; if you choose to ignore these errors, turn validation off with --validate=false

What you expected to happen: kubectl should apply the deployment file

How to reproduce it (as minimally and precisely as possible):

Try to apply this object file:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: redis
spec:
  replicas: 1
  selector:
    matchLabels:
      name: redis
  template:
    metadata:
      labels:
        name: redis
    spec:
      containers:
        -
          name: redis
          image: 'redis:3.2'
          command:
            - redis-server
            - '--appendonly'
            - no

Anything else do we need to know:

The "no" is the source of confusion for the program. In previous YAML versions this should be translated to be a boolean value, but in the current, 1.2, it should be a string "no". kubectl is using the older standard and translating this as a bool.

It is not so simple for me as to quote the "no" value like 'no' - this object file is the output of another library which uses the 1.2 standard. We need to be aware that of course people will use various libraries to consume and produce yaml.

I believe the problem can be traced from this https://github.com/ghodss/yaml to this source library here: https://github.com/cloudfoundry-incubator/candiedyaml/blob/master/resolver.go#L42

Should kubernetes only support YAML 1.2? It seems to me that we'd want to deprecate previous yaml support since YAML is not backwards compatible. YAML spec versions at: http://yaml.org/ - I have noticed that several of the online yaml validators also seem to get this "wrong".

@jingxu97
Copy link
Contributor

jingxu97 commented Oct 8, 2016

@saad-ali, @caesarxuchao is this related to something we discovered on kubectl version issue

@caesarxuchao
Copy link
Member

@kubernetes/kubectl

@ghodss
Copy link
Contributor

ghodss commented Oct 10, 2016

As you've pointed out, Kubernetes uses ghodss/yaml which is just a wrapper for candiedyaml. candiedyaml's README states that it's a "YAML 1.1 parser with support for YAML 1.2 features" ... I would recommend filing an issue with candiedyaml if you think that the behavior should be different.

Alternatively, ghodss/yaml used to be a wrapper around go-yaml, but we switched it to candiedyaml due to licensing concerns. It seems, however, that those concerns were recently addressed and go-yaml changed its license, so if you find that go-yaml has better behavior we could consider switching back.

@fraenkel
Copy link
Contributor

go-yaml has the same issues, but I would recommend you still switch back due to compatibility issues. Kube is using an older version of your code which relies on go-yaml.

@pwittrock
Copy link
Member

@fabianofranz Would you be able to own this or find it an owner?

@pwittrock pwittrock added the priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. label Oct 18, 2016
@fabianofranz
Copy link
Contributor

@pwittrock on it. ;)

Before anything else I'll submit a PR to ghodss/yaml to switch back to go-yaml since it seems more reliable and it's now licensed as Apache 2.0 (go-yaml/yaml#160 (comment) and go-yaml/yaml@e4d366f).

@pwittrock
Copy link
Member

SGTM.

@fabianofranz
Copy link
Contributor

fabianofranz commented Oct 24, 2016

The YAML 1.2 spec became, as one of the biggest changes, more restrictive about what's supported as booleans, mostly now only recommending true and false (no longer using on/off and yes/no as booleans, but just regular strings).

I opened a go-yaml issue about this, but I'm not sure a fix is going to happen since go-yaml wants to claim to "support most of YAML 1.1 and 1.2", so they will most likely want to keep supporting the specs disjunction instead of becoming more restrictive and leaving 1.1 out.

If we really want to fix this, I mostly see two options: we either a) fully move to 1.2, everywhere (and find a library that does it according to the spec); or b) try to extend go-yaml by proposing more flexibility to choose how to handle the differences between 1.1 and 1.2. In case of b), for example, have a UnmarshallingStrategy structure that would be passed to Unmarshal which carry flags that would affect the unmarshalling behavior, case by case. For example, StrictYAML12Booleans would specifically make booleans strict to the 1.2 spec. In kube that would be global, meaning booleans would always be strict to 1.2, but trying to keep 1.1 and 1.2 disjunction support for everything else as of now.

Thoughts?

@chrishiestand
Copy link
Contributor Author

In my limited experience it's usually better to fully support standard(s) for maximum interoperability and less user surprises. From a distance, I'd guess that supporting a disjointed set of standards adds confusion and technical debt to a community. And piling on to standards confusion just because other projects do it doesn't seem right. But this may not reflect the reasons for the current disjointed support.

There might be another option because YAML 1.2 and 1.1 allow version directives like so:

%YAML 1.2
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: redis
spec:
  replicas: 1
  selector:
    matchLabels:
      name: redis
  template:
    metadata:
      labels:
        name: redis
    spec:
      containers:
        -
          name: redis
          image: 'redis:3.2'
          command:
            - redis-server
            - '--appendonly'
            - no

currently kubectl apply -f redis-above.yaml returns: yaml: found incompatible YAML document

The downside of requiring directives for boolean handling are that we'd still need to find a compatible library and I generally don't see yaml libraries including them in output, so we'd probably need to add version directive printing support to libraries/tools that are missing the option. The upside is that it is 100% standards compliant.

@fraenkel
Copy link
Contributor

If go-yaml exposes an Encoder/Decoder, one could set an option to enable "strict" YAML 1.2 parsing. Booleans are just one change in YAML 1.2, there are others.

There is also a separate issue opened on allowing longer lines to be emitted which could be made possible as well.

@0xmichalis
Copy link
Contributor

/sig cli
/sig api-machinery

@k8s-ci-robot k8s-ci-robot added sig/cli Categorizes an issue or PR as relevant to SIG CLI. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. labels Jun 24, 2017
@k8s-github-robot k8s-github-robot removed the needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. label Jun 24, 2017
@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

Prevent issues from auto-closing with an /lifecycle frozen comment.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or @fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Dec 30, 2017
@fejta-bot
Copy link

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle rotten
/remove-lifecycle stale

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Jan 29, 2018
@fejta-bot
Copy link

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close

@k8s-ci-robot k8s-ci-robot removed the triage/accepted Indicates an issue or PR is ready to be actively worked on. label Jun 7, 2023
@jiahuif
Copy link
Member

jiahuif commented Jun 8, 2023

/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Jun 8, 2023
@helayoty helayoty added this to SIG CLI Oct 2, 2023
@github-project-automation github-project-automation bot moved this to Needs Triage in SIG CLI Oct 2, 2023
@helayoty helayoty moved this from Needs Triage to Backlog in SIG CLI Oct 2, 2023
stefreak added a commit to garden-io/garden that referenced this issue Oct 4, 2023
See also kubernetes/kubernetes#34146
(Kubernetes manifest files are still using yaml 1.1)
stefreak added a commit to garden-io/garden that referenced this issue Oct 4, 2023
See also kubernetes/kubernetes#34146
(Kubernetes manifest files are still using yaml 1.1)
github-merge-queue bot pushed a commit to garden-io/garden that referenced this issue Oct 5, 2023
See also kubernetes/kubernetes#34146
(Kubernetes manifest files are still using yaml 1.1)
github-merge-queue bot pushed a commit to garden-io/garden that referenced this issue Oct 5, 2023
See also kubernetes/kubernetes#34146
(Kubernetes manifest files are still using yaml 1.1)
github-merge-queue bot pushed a commit to garden-io/garden that referenced this issue Oct 5, 2023
See also kubernetes/kubernetes#34146
(Kubernetes manifest files are still using yaml 1.1)
@k8s-triage-robot
Copy link

This issue is labeled with priority/important-soon but has not been updated in over 90 days, and should be re-triaged.
Important-soon issues must be staffed and worked on either currently, or very soon, ideally in time for the next release.

You can:

  • Confirm that this issue is still relevant with /triage accepted (org members only)
  • Deprioritize it with /priority important-longterm or /priority backlog
  • Close this issue with /close

For more details on the triage process, see https://www.kubernetes.dev/docs/guide/issue-triage/

/remove-triage accepted

@k8s-ci-robot k8s-ci-robot added needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. and removed triage/accepted Indicates an issue or PR is ready to be actively worked on. labels Jan 19, 2024
@sftim
Copy link
Contributor

sftim commented Jan 19, 2024

I wonder if this still merits the important-soon priority. I'm going to take initiative here:
/remove-priority important-soon
/priority important-longterm
/triage accepted

@k8s-ci-robot k8s-ci-robot added priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Jan 19, 2024
MasonM added a commit to MasonM/argo-workflows that referenced this issue Oct 13, 2024
[js-yaml](https://www.npmjs.com/package/js-yaml) has had no releases in
over 3 years. Also, the fact it only supports YAML 1.2 is leading to
bugs, since Kubernetes uses YAML 1.1 (see
kubernetes/kubernetes#34146).

This switches over to [yaml](https://www.npmjs.com/package/yaml), which
had a release last month, is [licensed under
ISC](https://github.com/eemeli/yaml/blob/main/LICENSE), and supports
YAML 1.1. I also added test cases for the parsing/stringifying code.

Signed-off-by: Mason Malone <[email protected]>
MasonM added a commit to MasonM/argo-workflows that referenced this issue Oct 13, 2024
[js-yaml](https://www.npmjs.com/package/js-yaml) has had no releases in
over 3 years. Also, the fact it only supports YAML 1.2 is leading to
bugs, since Kubernetes uses YAML 1.1 (see
kubernetes/kubernetes#34146).

This switches over to [yaml](https://www.npmjs.com/package/yaml), which
had a release last month, is [licensed under
ISC](https://github.com/eemeli/yaml/blob/main/LICENSE), and supports
YAML 1.1. I also added test cases for the parsing/stringifying code.

Signed-off-by: Mason Malone <[email protected]>
MasonM added a commit to MasonM/argo-workflows that referenced this issue Oct 13, 2024
[js-yaml](https://www.npmjs.com/package/js-yaml) has had no releases in
over 3 years. Also, the fact it only supports YAML 1.2 is leading to
bugs, since Kubernetes uses YAML 1.1 (see
kubernetes/kubernetes#34146).

This switches over to [yaml](https://www.npmjs.com/package/yaml), which
had a release last month, is [licensed under
ISC](https://github.com/eemeli/yaml/blob/main/LICENSE), and supports
YAML 1.1. I also added test cases for the parsing/stringifying code.

Signed-off-by: Mason Malone <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/kubectl lifecycle/frozen Indicates that an issue or PR should not be auto-closed due to staleness. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/cli Categorizes an issue or PR as relevant to SIG CLI. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
Status: Backlog
Development

No branches or pull requests