Skip to content

Commit

Permalink
chore: same status annotation name for data and policies
Browse files Browse the repository at this point in the history
Signed-off-by: Ievgenii Shepeliuk <[email protected]>
  • Loading branch information
eshepelyuk committed Jun 15, 2022
1 parent af4f65e commit eb518c1
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
10 changes: 4 additions & 6 deletions pkg/configmap/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ import (

const (
statusAnnotationKey = "openpolicyagent.org/kube-mgmt-status"
<<<<<<< HEAD
retriesAnnotationKey = "openpolicyagent.org/kube-mgmt-retries"
=======
>>>>>>> c80123be (chore: same status annotation name for data and policies)

// Special namespace in Kubernetes federation that holds scheduling policies.
// commented because staticcheck: 'const kubeFederationSchedulingPolicy is unused (U1000)'
Expand Down Expand Up @@ -271,18 +274,13 @@ func (s *Sync) syncRemove(cm *v1.ConfigMap, isPolicy bool) {

func (s *Sync) setAnnotations(cm *v1.ConfigMap, st status, retries int) {
bs, err := json.Marshal(st)

statusAnnotationKey := policyStatusAnnotationKey
if !isPolicy {
statusAnnotationKey = dataStatusAnnotationKey
}
if err != nil {
logrus.Errorf("Failed to serialize %v for %v/%v: %v", statusAnnotationKey, cm.Namespace, cm.Name, err)
return
}
annotation := string(bs)
if cm.Annotations != nil {
if existing, ok := cm.Annotations[policyStatusAnnotationKey]; ok {
if existing, ok := cm.Annotations[statusAnnotationKey]; ok {
if existing == annotation {
// If the annotation did not change, do not write it.
// (issue https://github.com/open-policy-agent/kube-mgmt/issues/90)
Expand Down
6 changes: 6 additions & 0 deletions test/e2e/default/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@ ${OPA}/data/example/include/allow | jq -e '.result==true'

${OPA}/data/default | jq -e '.result|keys==["data-include"]'
${OPA}/data/default/data-include | jq -e '.result["include.json"].inKey=="inValue"'

kubectl get cm -l openpolicyagent.org/policy=rego -ojson | \
jq -e '.items[].metadata.annotations["openpolicyagent.org/kube-mgmt-status"]|fromjson|.status=="ok"'

kubectl get cm -l openpolicyagent.org/data=opa -ojson | \
jq -e '.items[].metadata.annotations["openpolicyagent.org/kube-mgmt-status"]|fromjson|.status=="ok"'
4 changes: 2 additions & 2 deletions test/e2e/fixture-labels.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ data:
include.rego: |
package example.include
allow := true
---
---
kind: ConfigMap
metadata:
name: policy-exclude
Expand All @@ -33,7 +33,7 @@ apiVersion: v1
data:
include.json: |
{"inKey": "inValue"}
---
---
kind: ConfigMap
metadata:
name: data-exclude
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/fixture.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ data:
include.rego: |
package example.include
allow := true
---
---
kind: ConfigMap
metadata:
name: policy-exclude
Expand All @@ -33,7 +33,7 @@ apiVersion: v1
data:
include.json: |
{"inKey": "inValue"}
---
---
kind: ConfigMap
metadata:
name: data-exclude
Expand Down
6 changes: 6 additions & 0 deletions test/e2e/labels/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ ${OPA}/data/example/include/allow | jq -e '.result==true'

${OPA}/data/default | jq -e '.result|keys==["data-include"]'
${OPA}/data/default/data-include | jq -e '.result["include.json"].inKey=="inValue"'

kubectl get cm -l qweqwe/policy=111 -ojson | \
jq -e '.items[].metadata.annotations["openpolicyagent.org/kube-mgmt-status"]|fromjson|.status=="ok"'

kubectl get cm -l asdasd/data=222 -ojson | \
jq -e '.items[].metadata.annotations["openpolicyagent.org/kube-mgmt-status"]|fromjson|.status=="ok"'

0 comments on commit eb518c1

Please sign in to comment.