Skip to content

Commit

Permalink
prefer kubectl pristine over qbec, fixes splunk#232
Browse files Browse the repository at this point in the history
When both pristine exists, most problably last apply operation was done
via kubectl, thus it contains more actual data than qbec pristine.
  • Loading branch information
kvaps committed Apr 8, 2021
1 parent 5799263 commit 0e974bd
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/remote/pristine.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func (f fallbackPristine) getPristine(annotations map[string]string, orig *unstr
}

func getPristineVersion(obj *unstructured.Unstructured, includeFallback bool) (*unstructured.Unstructured, string) {
pristineReaders := []pristineReader{qbecPristine{}, kubectlPristine{}}
pristineReaders := []pristineReader{kubectlPristine{}, qbecPristine{}}
if includeFallback {
pristineReaders = append(pristineReaders, fallbackPristine{})
}
Expand Down
9 changes: 9 additions & 0 deletions internal/remote/pristine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,15 @@ func testPristineReader(t *testing.T, useFallback bool) {
a.Equal("", obj.GetAnnotations()[model.QbecNames.PristineAnnotation])
},
},
{
file: "both-applied.yaml",
asserter: func(t *testing.T, obj *unstructured.Unstructured, source string) {
a := assert.New(t)
a.Equal("kubectl annotation", source)
a.NotNil(obj)
a.NotEqual("", obj.GetAnnotations()[kubectlLastConfig])
},
},
{
name: "qbec-bad.yaml",
file: "qbec-applied.yaml",
Expand Down
19 changes: 19 additions & 0 deletions internal/remote/testdata/pristine/both-applied.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: v1
data:
data-1: value-1
data-2: value-4
kind: ConfigMap
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"v1","data":{"data-1":"value-1","data-2":"value-4"},"kind":"ConfigMap","metadata":{"annotations":{"qbec.io/component":"cm"},"labels":{"qbec.io/application":"test","qbec.io/environment":"default"},"name":"test-configmap","namespace":"istio-test"}}
qbec.io/component: cm
qbec.io/last-applied: H4sIAAAAAAAA/1SOsU7FMAxFdz7jzgnoIaaszKzsfqmLLBI7tG6Xqv+OUmilN1m+9/jIG6jJJ0+zmCJhvSFgICek7Zjx1lMqC8eziq9X9IY94Ft0QMK76ShfH9QQUNnptJCqObmYzn39uXN+FnvJVpspqyMh1+4pdOfywFBrRfJxiwTn2RGuknWVybT+KQYeaSnePUqV//GYj6cqNez70y8AAAD//wEAAP//CtqlhewAAAA=
creationTimestamp: "2021-04-08T15:05:47Z"
labels:
qbec.io/application: test
qbec.io/environment: default
name: test-configmap
namespace: istio-test
resourceVersion: "679364782"
uid: d0724aac-42e5-4c58-8b17-d66d40aa178a

0 comments on commit 0e974bd

Please sign in to comment.