Skip to content

Commit 70be251

Browse files
authored
Merge pull request #19 from itaysk/removeapply
remove kubectl apply tracking annotation
2 parents 10b26e6 + 0f72aa9 commit 70be251

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

cmd/neat.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,14 @@ func Neat(in string) (string, error) {
7070
}
7171

7272
func neatMetadata(in string) (string, error) {
73+
var err error
74+
in, err = sjson.Delete(in, `metadata.annotations.kubectl\.kubernetes\.io/last-applied-configuration`)
75+
if err != nil {
76+
return in, fmt.Errorf("error deleting last-applied-configuration : %v", err)
77+
}
7378
// TODO: prettify this. gjson's @pretty is ok but setRaw the pretty code gives unwanted result
7479
newMeta := gjson.Get(in, "{metadata.name,metadata.namespace,metadata.labels,metadata.annotations}")
75-
in, err := sjson.Set(in, "metadata", newMeta.Value())
80+
in, err = sjson.Set(in, "metadata", newMeta.Value())
7681
if err != nil {
7782
return in, fmt.Errorf("error setting new metadata : %v", err)
7883
}

cmd/neat_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,28 @@ func TestNeatMetadata(t *testing.T) {
5252
}
5353
}`,
5454
},
55+
{
56+
title: "annotations with apply",
57+
data: `{
58+
"metadata": {
59+
"name": "test",
60+
"namespace": "testns",
61+
"annotations": {
62+
"my-annotation": "is here",
63+
"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"authentication.istio.io/v1alpha1\",\"kind\":\"Policy\",\"metadata\":{\"annotations\":{},\"name\":\"default\",\"namespace\":\"one\"},\"spec\":{\"peers\":[{\"mtls\":{}}]}}\n"
64+
}
65+
}
66+
}`,
67+
expect: `{
68+
"metadata": {
69+
"name": "test",
70+
"namespace": "testns",
71+
"annotations": {
72+
"my-annotation": "is here"
73+
}
74+
}
75+
}`,
76+
},
5577
}
5678
for _, c := range cases {
5779
resJSON, err := neatMetadata(c.data)

0 commit comments

Comments
 (0)