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

Better error message when patch is the wrong type? #5113

Open
roy-work opened this issue Mar 29, 2023 · 3 comments
Open

Better error message when patch is the wrong type? #5113

roy-work opened this issue Mar 29, 2023 · 3 comments
Labels
kind/bug Categorizes issue or PR as related to a bug. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one.

Comments

@roy-work
Copy link

What happened?

If I attempt the supplied patch, kustomize errors.

What did you expect to happen?

The patch is applied, or, if not, a usable diagnostic as to what is wrong with the input given.

How can we reproduce it (as minimally and precisely as possible)?

# kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
  - argocd.yaml
patchesJson6902:
  - target:
      group: rbac.authorization.k8s.io
      version: v1
      kind: ClusterRole
      name: argocd-server
    patch:
      - op: add
        path: "/rules/3/verbs/2"
        value: "update"
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  labels:
    app.kubernetes.io/component: server
    app.kubernetes.io/name: argocd-server
    app.kubernetes.io/part-of: argocd
  name: argocd-server
rules:
- apiGroups:
  - '*'
  resources:
  - '*'
  verbs:
  - delete
  - get
  - patch
- apiGroups:
  - ""
  resources:
  - events
  verbs:
  - list
- apiGroups:
  - ""
  resources:
  - pods
  - pods/log
  verbs:
  - get
- apiGroups:
  - argoproj.io
  resources:
  - applications
  verbs:
  - get
  - list
  - watch

Expected output

#[rest same as before]
- apiGroups:
  - argoproj.io
  resources:
  - applications
  verbs:
  - get
  - list
  - update
  - watch

Actual output

» kustomize build .
Error: invalid Kustomization: json: cannot unmarshal array into Go struct field Patch.patchesJson6902.patch of type string

Kustomize version

v5.0.1

Operating system

MacOS

@roy-work roy-work added the kind/bug Categorizes issue or PR as related to a bug. label Mar 29, 2023
@k8s-ci-robot k8s-ci-robot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Mar 29, 2023
@roy-work
Copy link
Author

Okay, this is partial user-error, but a.) this is really hard to see and b.) the error message could be loads more helpful in pointing me in the right direction here.

This:

    patch:

needs to be,

    patch: |

Kustomize requires the entire JSON patch to be double-encoded …

@roy-work roy-work changed the title Cannot add to array? Better error message when patch is the wrong type? Mar 29, 2023
@koba1t
Copy link
Member

koba1t commented Apr 5, 2023

I think patchesJson6902.[].patch requires the format of yaml string in multi-line literal is a reasonable reason.
Because I think patchesJson6902.[].patch is just converted for Yaml format of json6902.
https://kubectl.docs.kubernetes.io/references/kustomize/kustomization/patchesjson6902/

But I agree your opinion with be a better error message.
/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 Apr 5, 2023
@k8s-triage-robot
Copy link

This issue has not been updated in over 1 year, and should be re-triaged.

You can:

  • Confirm that this issue is still relevant with /triage accepted (org members only)
  • 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 Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one.
Projects
None yet
Development

No branches or pull requests

4 participants