Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions pkg/syncutil/parser/syncannotationreader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
22 changes: 11 additions & 11 deletions pkg/syncutil/parser/syncannotationreader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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\"]}]]\"",
},
},
},
Expand All @@ -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\"]}]]\"",
},
},
},
Expand Down Expand Up @@ -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\"]}]]\"",
},
},
},
Expand All @@ -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\"]}]]\"",
},
},
},
Expand All @@ -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{},
Expand All @@ -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\"]}]]\"",
},
},
},
Expand Down