-
Notifications
You must be signed in to change notification settings - Fork 325
fix: detect manual changes on CRDs and CRs with three-way-merge #923
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
Changes from 1 commit
115630c
6610be9
a460e71
efb7e0a
a59ce03
5d14d97
f5b13c2
2ff4b31
1076d7d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Refactor cleanMetadataForPatch to call deleteStatusAndTidyMetadata to avoid code duplication and ensure consistent metadata handling - Add TestCreatePatchForCRD test case to cover the CRD type branch (apiextv1.CustomResourceDefinition path) Signed-off-by: yxxhero <aiopsclub@163.com>
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -244,33 +244,10 @@ func isPatchEmpty(patch []byte) bool { | |
| } | ||
|
|
||
| func cleanMetadataForPatch(data []byte) ([]byte, error) { | ||
| var objMap map[string]interface{} | ||
| if err := json.Unmarshal(data, &objMap); err != nil { | ||
| objMap, err := deleteStatusAndTidyMetadata(data) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| delete(objMap, "status") | ||
|
|
||
| if metadata, ok := objMap["metadata"].(map[string]interface{}); ok { | ||
| delete(metadata, "managedFields") | ||
| delete(metadata, "generation") | ||
| delete(metadata, "creationTimestamp") | ||
| delete(metadata, "resourceVersion") | ||
| delete(metadata, "uid") | ||
|
|
||
| // Remove helm-related and k8s annotations that shouldn't be compared | ||
| if a := metadata["annotations"]; a != nil { | ||
| annotations := a.(map[string]interface{}) | ||
| delete(annotations, "meta.helm.sh/release-name") | ||
| delete(annotations, "meta.helm.sh/release-namespace") | ||
| delete(annotations, "deployment.kubernetes.io/revision") | ||
|
|
||
| if len(annotations) == 0 { | ||
| delete(metadata, "annotations") | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return json.Marshal(objMap) | ||
| } | ||
|
Comment on lines
+252
to
+261
|
||
|
|
||
|
|
||