Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Fatih Türken <[email protected]>
  • Loading branch information
turkenf committed Sep 12, 2024
1 parent 6fd8e14 commit dff19a8
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions cmd/cleanupexamples/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,30 @@ import (
"sigs.k8s.io/yaml"
)

// removeAnnotations removes specific annotations from a Kubernetes
// filterAnnotations removes specific annotations from a Kubernetes
// unstructured object. It looks for annotations with prefixes
// "upjet.upbound.io/" and "uptest.upbound.io/" and removes
// them if they are present.
func removeAnnotations(u *unstructured.Unstructured) {
func filterAnnotations(u *unstructured.Unstructured) {
annotations := u.GetAnnotations()
if annotations != nil {
annotationsToRemove := []string{
"upjet.upbound.io/",
"uptest.upbound.io/",
}
annotationsToRemove := []string{
"upjet.upbound.io/",
"uptest.upbound.io/",
}

for key := range annotations {
for _, prefix := range annotationsToRemove {
if strings.HasPrefix(key, prefix) {
delete(annotations, key)
break
}
for key := range annotations {
for _, prefix := range annotationsToRemove {
if strings.HasPrefix(key, prefix) {
delete(annotations, key)
break
}
}
}

if len(annotations) == 0 {
u.SetAnnotations(nil)
} else {
u.SetAnnotations(annotations)
}
if len(annotations) == 0 {
u.SetAnnotations(nil)
} else {
u.SetAnnotations(annotations)
}
}

Expand Down Expand Up @@ -84,7 +82,7 @@ func processYAML(yamlData []byte) ([]byte, error) {
}

// Remove specific annotations from the decoded Kubernetes object.
removeAnnotations(u)
filterAnnotations(u)

modifiedYAML, err := yaml.Marshal(u.Object)
if err != nil {
Expand Down

0 comments on commit dff19a8

Please sign in to comment.