openkruise / kruise

Automated management of large-scale applications on Kubernetes (incubating project under CNCF)
https://openkruise.io
Other
4.64k stars 764 forks source link

[feature request] Sidecarset Pod Metadata support Array merge. #1332

Closed jzeng4 closed 12 months ago

jzeng4 commented 1 year ago

What would you like to be added: Currently, pod annotation injection supports the followings:

For MergePatchJson, it only allows to merge non-array annotations. For array annotations, it will did overwrite.

What we need is to merge the annotation array if the annotations have the same key. For example:

Why is this needed:

jzeng4 commented 1 year ago

If this feature makes sense, we can commit a PR for this feature.

jzeng4 commented 1 year ago

@FillZpp could you prioritize this ticket? thank you!

furykerry commented 1 year ago

@jzeng4 maybe your merge behavior can be satisfied with json patch. it may look like this. ` apiVersion: apps.kruise.io/v1alpha1 kind: SidecarSet spec: containers: ... patchPodMetadata:

`

zmberg commented 1 year ago

@jzeng4 maybe your merge behavior can be satisfied with json patch. it may look like this. ` apiVersion: apps.kruise.io/v1alpha1 kind: SidecarSet spec: containers: ... patchPodMetadata:

  • annotations:

    • linkedin.com/applications: '[ { "op": "add", "path": "/-", "value": "{ "product":"foo2"}"} , "op": "add", "path": "/-", "value": "{ "product":"bar2"} } ]' patchPolicy: PatchJson

`

@furykerry @jzeng4 Currently sidecarSet controller will call the merge json function when upgrade sidecar in-place, so the above PatchJson will result in repeated element.

If PatchJson is only effective in webhook, the method is ok. So we can skip the jsonPatch in controller. Related Docs:

  1. https://datatracker.ietf.org/doc/html/rfc6902
  2. https://github.com/evanphx/json-patch

Related Code: https://github.com/openkruise/kruise/blob/master/pkg/control/sidecarcontrol/util.go#L451

@jzeng4 Can you submit the feature?

jzeng4 commented 1 year ago

sure. will work on that.

furykerry commented 1 year ago

sure. will work on that.

plz submit a KEP doc to describe the user case and other technical detail before diving into implementation, my concern includes:

  1. if multiple sidecarsets include patch metadata fields, what is the expected behavior, how to ensure the patch sequence
  2. if the patch metadata field is changed, does it affects existing pods?
stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.