pkg icon indicating copy to clipboard operation
pkg copied to clipboard

`patch.Helper` doesn't work with secrets and configmaps

Open errordeveloper opened this issue 2 years ago • 4 comments
trafficstars

I was using patcher in a project and discovered the hard way that it doesn't actually patch secrets.

The reason behind that is to do with this logic: https://github.com/fluxcd/pkg/blob/a04ccbfc5bc8348e31131978140640f0b1363d18/runtime/patch/patch.go#L239-L242

So it very deliberately checks spec field, which is something secrets and configmaps don't have.

errordeveloper avatar Jun 15 '23 14:06 errordeveloper

Of course, there are more examples of resources that don't have spec.

errordeveloper avatar Jun 15 '23 15:06 errordeveloper

I suggest you use ssa.apply to patch Kubernetes native resources, the patcher is for custom resources which subscribe to the spec/status standard.

stefanprodan avatar Jun 15 '23 15:06 stefanprodan

@stefanprodan maybe that should be made more explicit in the docs?

errordeveloper avatar Jun 15 '23 15:06 errordeveloper

Yes for sure, patcher is for controllers to set finalizers and status conditions, we use it as such in Flux, and we should clearly state it’s purpose in docs.

stefanprodan avatar Jun 15 '23 16:06 stefanprodan