Skip to content

Commit

Permalink
Don't allow wrapping Policy kinds
Browse files Browse the repository at this point in the history
Signed-off-by: Dale Haiducek <[email protected]>
  • Loading branch information
dhaiducek authored and openshift-merge-robot committed Apr 12, 2023
1 parent bca63f4 commit 1761673
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
13 changes: 10 additions & 3 deletions internal/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,16 @@ func isPolicyTypeManifest(manifest map[string]interface{}) (bool, error) {
return false, errors.New("invalid or not found kind")
}

isPolicy := strings.HasPrefix(apiVersion, "policy.open-cluster-management.io") &&
kind != "Policy" &&
strings.HasSuffix(kind, "Policy")
// Don't allow generation for root Policies
isOcmAPI := strings.HasPrefix(apiVersion, "policy.open-cluster-management.io")
if isOcmAPI && kind == "Policy" {
return false, errors.New("providing a root Policy kind is not supported by the generator; " +
"the manifest should be applied to the hub cluster directly")
}

// Identify OCM Policies
isPolicy := isOcmAPI && kind != "Policy" && strings.HasSuffix(kind, "Policy")


if isPolicy {
// metadata.name is required on policy manifests
Expand Down
3 changes: 2 additions & 1 deletion internal/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,8 @@ func TestIsPolicyTypeManifest(t *testing.T) {
},
},
wantVal: false,
wantErr: "",
wantErr: "providing a root Policy kind is not supported by the generator; " +
"the manifest should be applied to the cluster directly",
},
"valid PlacementRule": {
manifest: map[string]interface{}{
Expand Down

0 comments on commit 1761673

Please sign in to comment.