From b7baafa991ac29836324229a2e5b0cbc1fd9a100 Mon Sep 17 00:00:00 2001 From: juliankatz Date: Thu, 8 Jun 2023 13:58:24 -0700 Subject: [PATCH] fix: make sync data annotation camelCase Fixes #2820 Signed-off-by: juliankatz --- pkg/syncutil/parser/syncannotationreader.go | 9 ++++---- .../parser/syncannotationreader_test.go | 22 +++++++++---------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/pkg/syncutil/parser/syncannotationreader.go b/pkg/syncutil/parser/syncannotationreader.go index ae22dac98d8..ba15cf3423c 100644 --- a/pkg/syncutil/parser/syncannotationreader.go +++ b/pkg/syncutil/parser/syncannotationreader.go @@ -10,7 +10,7 @@ import ( // syncAnnotationName is the name of the annotation that stores // GVKS that are required to be synced. -const SyncAnnotationName = "metadata.gatekeeper.sh/requires-sync-data" +const SyncAnnotationName = "metadata.gatekeeper.sh/requiresSyncData" // SyncRequirements contains a list of ANDed requirements, each of which // contains an expanded set of equivalent (ORed) GVKs. @@ -57,7 +57,8 @@ func ReadSyncRequirements(t *templates.ConstraintTemplate) (SyncRequirements, er return SyncRequirements{}, nil } -// Takes a compactGVKSet and expands it into a GVKEquivalenceSet. +// ExpandCompactEquivalenceSet takes a compactGVKSet and expands it into a +// GVKEquivalenceSet. func ExpandCompactEquivalenceSet(compactEquivalenceSet CompactGVKEquivalenceSet) GVKEquivalenceSet { equivalenceSet := GVKEquivalenceSet{} for _, group := range compactEquivalenceSet.Groups { @@ -70,8 +71,8 @@ func ExpandCompactEquivalenceSet(compactEquivalenceSet CompactGVKEquivalenceSet) return equivalenceSet } -// Takes a CompactSyncRequirements (the json form provided in the template -// annotation) and expands it into a SyncRequirements. +// ExpandCompactRequirements takes a CompactSyncRequirements (the json form +// provided in the template annotation) and expands it into a SyncRequirements. func ExpandCompactRequirements(compactSyncRequirements CompactSyncRequirements) (SyncRequirements, error) { syncRequirements := SyncRequirements{} for _, compactRequirement := range compactSyncRequirements { diff --git a/pkg/syncutil/parser/syncannotationreader_test.go b/pkg/syncutil/parser/syncannotationreader_test.go index aa26b076eaa..a82a3b79eac 100644 --- a/pkg/syncutil/parser/syncannotationreader_test.go +++ b/pkg/syncutil/parser/syncannotationreader_test.go @@ -20,7 +20,7 @@ func TestReadSyncRequirements(t *testing.T) { template: &templates.ConstraintTemplate{ ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{ - "metadata.gatekeeper.sh/requires-sync-data": "\n\"[[{\"groups\": [\"group1\"], \"versions\": [\"version1\"], \"kinds\": [\"kind1\"]}]]\"", + "metadata.gatekeeper.sh/requiresSyncData": "\n\"[[{\"groups\": [\"group1\"], \"versions\": [\"version1\"], \"kinds\": [\"kind1\"]}]]\"", }, }, }, @@ -39,7 +39,7 @@ func TestReadSyncRequirements(t *testing.T) { template: &templates.ConstraintTemplate{ ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{ - "metadata.gatekeeper.sh/requires-sync-data": "\n\"[[{\"groups\": [\"group1\", \"group2\"], \"versions\": [\"version1\", \"version2\"], \"kinds\": [\"kind1\", \"kind2\"]}]]\"", + "metadata.gatekeeper.sh/requiresSyncData": "\n\"[[{\"groups\": [\"group1\", \"group2\"], \"versions\": [\"version1\", \"version2\"], \"kinds\": [\"kind1\", \"kind2\"]}]]\"", }, }, }, @@ -93,7 +93,7 @@ func TestReadSyncRequirements(t *testing.T) { template: &templates.ConstraintTemplate{ ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{ - "metadata.gatekeeper.sh/requires-sync-data": "\n\"[[{\"groups\": [\"group1\"], \"versions\": [\"version1\"], \"kinds\": [\"kind1\"]}, {\"groups\": [\"group2\"], \"versions\": [\"version2\"], \"kinds\": [\"kind2\"]}]]\"", + "metadata.gatekeeper.sh/requiresSyncData": "\n\"[[{\"groups\": [\"group1\"], \"versions\": [\"version1\"], \"kinds\": [\"kind1\"]}, {\"groups\": [\"group2\"], \"versions\": [\"version2\"], \"kinds\": [\"kind2\"]}]]\"", }, }, }, @@ -117,7 +117,7 @@ func TestReadSyncRequirements(t *testing.T) { template: &templates.ConstraintTemplate{ ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{ - "metadata.gatekeeper.sh/requires-sync-data": "\n\"[[{\"groups\": [\"group1\"], \"versions\": [\"version1\"], \"kinds\": [\"kind1\"]}], [{\"groups\": [\"group2\"], \"versions\": [\"version2\"], \"kinds\": [\"kind2\"]}]]\"", + "metadata.gatekeeper.sh/requiresSyncData": "\n\"[[{\"groups\": [\"group1\"], \"versions\": [\"version1\"], \"kinds\": [\"kind1\"]}], [{\"groups\": [\"group2\"], \"versions\": [\"version2\"], \"kinds\": [\"kind2\"]}]]\"", }, }, }, @@ -139,7 +139,7 @@ func TestReadSyncRequirements(t *testing.T) { }, }, { - name: "test with no requires-sync-data annotation", + name: "test with no requiresSyncData annotation", template: &templates.ConstraintTemplate{ ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{}, @@ -148,33 +148,33 @@ func TestReadSyncRequirements(t *testing.T) { want: SyncRequirements{}, }, { - name: "test with empty requires-sync-data annotation", + name: "test with empty requiresSyncData annotation", template: &templates.ConstraintTemplate{ ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{ - "metadata.gatekeeper.sh/requires-sync-data": "", + "metadata.gatekeeper.sh/requiresSyncData": "", }, }, }, wantErr: true, }, { - name: "test with invalid requires-sync-data annotation", + name: "test with invalid requiresSyncData annotation", template: &templates.ConstraintTemplate{ ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{ - "metadata.gatekeeper.sh/requires-sync-data": "invalid", + "metadata.gatekeeper.sh/requiresSyncData": "invalid", }, }, }, wantErr: true, }, { - name: "test with requires-sync-data annotation with invalid keys", + name: "test with requiresSyncData annotation with invalid keys", template: &templates.ConstraintTemplate{ ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{ - "metadata.gatekeeper.sh/requires-sync-data": "\n\"[[{\"group\": [\"group1\"], \"version\": [\"version1\"], \"kind\": [\"kind1\"]}]]\"", + "metadata.gatekeeper.sh/requiresSyncData": "\n\"[[{\"group\": [\"group1\"], \"version\": [\"version1\"], \"kind\": [\"kind1\"]}]]\"", }, }, },