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

Error: json: cannot unmarshal string into Go struct field Kustomization.patches of type types.Patch #1373

Closed
luisdavim opened this issue Jul 19, 2019 · 18 comments
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.

Comments

@luisdavim
Copy link

This was working file with v3.0.0, I've updated to v3.0.3 and I'm getting the error:

Error: json: cannot unmarshal string into Go struct field Kustomization.patches of type types.Patch

This is the kustomization file:

# Adds namespace to all resources.
namespace: marquis-system

# Value of this field is prepended to the
# names of all resources, e.g. a deployment named
# "wordpress" becomes "alices-wordpress".
# Note that it should also match with the prefix (text before '-') of the namespace
# field above.
namePrefix: marquis-

# Labels to add to all resources and selectors.
#commonLabels:
#  someName: someValue

# Each entry in this list must resolve to an existing
# resource definition in YAML.  These are the resource
# files that kustomize reads, modifies and emits as a
# YAML string, with resources separated by document
# markers ("---").
resources:
- ./rbac/rbac_role.yaml
- ./rbac/rbac_role_binding.yaml
- ./manager/manager.yaml
- ./rbac/auth_proxy_service.yaml
- ./rbac/auth_proxy_role.yaml
- ./rbac/auth_proxy_role_binding.yaml

patches:
- manager_image_patch.yaml
  # Protect the /metrics endpoint by putting it behind auth.
  # Only one of manager_auth_proxy_patch.yaml and
  # manager_prometheus_metrics_patch.yaml should be enabled.
- manager_auth_proxy_patch.yaml
  # If you want your controller-manager to expose the /metrics
  # endpoint w/o any authn/z, uncomment the following line and
  # comment manager_auth_proxy_patch.yaml.
  # Only one of manager_auth_proxy_patch.yaml and
  # manager_prometheus_metrics_patch.yaml should be enabled.
#- manager_prometheus_metrics_patch.yaml
@jbrette
Copy link
Contributor

jbrette commented Jul 19, 2019

"patches:" was obsolete. You are supposed to use "patchesStrategicMerge:" instead.

Since "patches:" is used for more extended patching.

@luisdavim
Copy link
Author

thanks, I guess that was it. I think the readme should be updated.

@functicons
Copy link

+1, I hit the same error. My yaml files were generated by kubebuilder, they worked with Kustomize v2, but upgrading Kustomize to v3.0.3 breaks it.

@jbrette
Copy link
Contributor

jbrette commented Jul 19, 2019

Interesting...Was looking at the log. patches has been deprecated last year v1.0.9.

I guess we will have to check if kubebuilder needs to be updated. Meanwhile the easiest workaround is
replaced patches: by patchesStrategicMerge:

Krenair added a commit to Krenair/verify-metadata-controller that referenced this issue Jul 22, 2019
This was probably fine when Chris wrote it in February, but since then the
newest release of Kustomization has broken things:
kubernetes-sigs/kustomize#1373
russellb added a commit to russellb/cluster-api-provider-baremetal that referenced this issue Jul 22, 2019
Change "patches" to "patchesStrategicMerge".  The use of "patches" has
been deprecated since v1.0.9:

https://github.com/kubernetes-sigs/kustomize/blob/v1.0.9/pkg/types/kustomization.go#L129

With kustomize v3, this fails with a message similar to the one seen
in this issue:

kubernetes-sigs/kustomize#1373

This change should not result in any change in behavior, but makes
this kustomization.yaml no longer use a deprecated field.
@jbrette
Copy link
Contributor

jbrette commented Jul 22, 2019

@functicons Created a PR in kubebuilder

@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.

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 Oct 21, 2019
@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

@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 Nov 20, 2019
@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
Copy link
Contributor

@fejta-bot: Closing this issue.

In response to this:

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

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@jmichalek132
Copy link

Hi since patches is obsolete, this example should be removed or updated.

@leoskyrocker
Copy link

I think "patches" means something else - not obsolete as of today.
It is used for patching multiple objects at once via the same patch file.

@jmichalek132
Copy link

jmichalek132 commented Apr 15, 2020

Okay so the use of "patches" above is not working because it's missing target? And with target specified it's still working/valid use?

@jgriff
Copy link

jgriff commented Apr 23, 2020

I think the problem is kubectl uses a much older version of kustomize. It appears the "multiple patching" support was added in v3.1.0 of kustomize (based on when examples/patchMultipleObjects.md was added in this commit).

Works in kustomize 3.5.4

❯ kustomize version
{Version:3.5.4 GitCommit:3af514fa9f85430f0c1557c4a0291e62112ab026 BuildDate:2020-01-17T14:23:25+00:00 GoOs:darwin GoArch:amd64}

overlays/my-overlay/kustomization.yaml

patches:
  - patch: |
      apiVersion: apps/v1
      kind: Deployment
      metadata:
        name: does-not-matter
      spec:
        template:
          spec:
            priorityClassName: my-priority-class
    target:
      kind: Deployment

This works:

kustomize build overlays/my-overlay

But not in kubectl (1.18) with kustomize (2.0.3)

❯ kubectl version
Client Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.1", GitCommit:"7879fc12a63337efff607952a323df90cdc7a335", GitTreeState:"clean", BuildDate:"2020-04-10T21:53:51Z", GoVersion:"go1.14.2", Compiler:"gc", Platform:"darwin/amd64"}

Currently the only way to know which version of kustomize is used in kubectl is to consult the README, which currently states its using v2.0.3.

So this does not work:

❯ kubectl kustomize overlays/my-overlay
Error: AccumulateTarget: couldn't make target for {redacted}: cannot unmarshal object into Go struct field Kustomization.patchesStrategicMerge of type patch.StrategicMerge

@leoskyrocker
Copy link

Yep that’s right

@manishtanwar19
Copy link

As opposed to pointed out in other comments, patches should be used only, as patchesStrategicMerge field was deprecated in v5.0.0.

The change that worked for me while using patches: only, was:

 patches:
- ./patch-deployment.yaml
- ./patch-hpa.yaml
 patches:
- path: ./patch-deployment.yaml
- path: ./patch-hpa.yaml

Adding path: in patches.

@Stef16Robbe
Copy link

Stef16Robbe commented Sep 1, 2023

As opposed to pointed out in other comments, patches should be used only, as patchesStrategicMerge field was deprecated in v5.0.0.

The change that worked for me while using patches: only, was:

 patches:
- ./patch-deployment.yaml
- ./patch-hpa.yaml
 patches:
- path: ./patch-deployment.yaml
- path: ./patch-hpa.yaml

Adding path: in patches.

This can be automatically done by running kustomize edit fix.

@CameronHudson8
Copy link

CameronHudson8 commented Dec 19, 2023

I had loads of kustomization.yaml files to convert, and this is what I used to find and update all of them.

grep -rl 'patchesStrategicMerge' \
    | grep -v '\.git' \
    | xargs -I'{}' yq -i '.patches = (.patchesStrategicMerge | map({ "path": . })) | del(.patchesStrategicMerge)' {}

@martinwunderlich-celonis

Just came across this issue and had the same problem. It was due to a very complex env var value with several levels of escaping. I was able to fix by moving this env var from the literals in the configMapGenerator to an external env file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.
Projects
None yet
Development

No branches or pull requests