lensapp / lens

Lens - The way the world runs Kubernetes
https://k8slens.dev/
MIT License
22.53k stars 1.47k forks source link

Resource with YAML binary data can't be created #4865

Open panuhorsmalahti opened 2 years ago

panuhorsmalahti commented 2 years ago

Describe the bug If a resource is created that uses yaml binary encoding, an error is displayed: error: error validating "/private/var/folders/_j/ztr5t9y90jq_jpsz1s2ytvk40000gp/T/c2e945a68a4e9610d06d3dc88eb2e662/resource.yaml": error validating data: ValidationError(Pod.spec.containers[0].image): invalid type for io.k8s.api.core.v1.Container.image: got "map", expected "string"; if you choose to ignore these errors, turn validation off with --validate=false.

The same resource can be created with kubectl apply using Lens terminal.

To Reproduce Steps to reproduce the behavior:

  1. Open a 'Create resource' terminal in Lens
  2. Paste the following:
    apiVersion: v1
    kind: Pod
    metadata:
    name: static-web
    labels:
    role: myrole
    spec:
    containers:
    - name: web
      image: !!binary bmdpbng=
      ports:
        - name: web
          containerPort: 80
          protocol: TCP

Expected behavior Resource is created.

Actual behavior Error notification is displayed.

Environment (please complete the following information):

Additional context I was using a Lens DevCluster.

panuhorsmalahti commented 2 years ago

I suspect the bug is that in Lens the YAML is converted to JSON/POJO, where the binary is converted as an array of numbers, but with kubectl apply it's using Go's unmarshaling library, which does it differently. I noticed that online YAML -> JSON converters convert !!binary to number array instead of string.