feat: annotate applied manifests with parent placement name#464
feat: annotate applied manifests with parent placement name#464
Conversation
Co-authored-by: ryanzhang-oss <59209500+ryanzhang-oss@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Propagates placement identity from Work objects down to the applied resources on member clusters by annotating each applied manifest with the parent placement name (kubernetes-fleet.io/parent-CRP), improving traceability without impacting drift detection/hashing.
Changes:
- Pass placement name (from
Worklabelfleetv1beta1.PlacementTrackingLabel) into the apply call path. - Annotate the sanitized manifest copy with the placement name before applying.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| pkg/controllers/workapplier/process.go | Passes the placement tracking label value from the Work into apply() as a new argument. |
| pkg/controllers/workapplier/apply.go | Adds a placementName parameter to apply() and sets the placement tracking annotation on the manifest being applied. |
| // Add an annotation that identifies which placement placed this object, so that | ||
| // it is visible on the member cluster. | ||
| if placementName != "" { | ||
| annotations := manifestObjCopy.GetAnnotations() | ||
| if annotations == nil { | ||
| annotations = map[string]string{} | ||
| } | ||
| annotations[fleetv1beta1.PlacementTrackingLabel] = placementName | ||
| manifestObjCopy.SetAnnotations(annotations) | ||
| } |
There was a problem hiding this comment.
New behavior (propagating the Work placement tracking label onto applied objects as an annotation) is introduced here, but there is no unit test covering it. Since this package already has unit tests in apply_test.go, please add a focused test to verify: (1) when placementName is non-empty, the annotation key fleetv1beta1.PlacementTrackingLabel is set on the sanitized manifest copy; and (2) when placementName is empty, no annotation is added/modified. Consider extracting the annotation injection into a small helper to make it easy to unit test without requiring dynamic client interactions.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Applied manifest objects on member clusters had no indication of which placement placed them. The
PlacementTrackingLabel(kubernetes-fleet.io/parent-CRP) already exists onWorkobjects — this change propagates it as an annotation onto each applied manifest object.Changes
apply.go: AddedplacementName stringparameter toapply(); aftersanitizeManifestObject, setskubernetes-fleet.io/parent-CRPannotation onmanifestObjCopywhen the placement name is non-emptyprocess.go: Updated theapply()call to passwork.GetLabels()[fleetv1beta1.PlacementTrackingLabel]Notes
PlacementTrackingLabelconstant as the annotation key — same semantic, separate mapdiscardFieldsIrrelevantInComparisonFrom(allkubernetes-fleet.io/keys are excluded from comparison), so it does not affect drift detection or manifest hashingOriginal prompt
Created from VS Code.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.