Skip to content

Commit 1761673

Browse files
dhaiducekopenshift-merge-robot
authored andcommitted
Don't allow wrapping Policy kinds
Signed-off-by: Dale Haiducek <[email protected]>
1 parent bca63f4 commit 1761673

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

internal/utils.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,16 @@ func isPolicyTypeManifest(manifest map[string]interface{}) (bool, error) {
295295
return false, errors.New("invalid or not found kind")
296296
}
297297

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

302309
if isPolicy {
303310
// metadata.name is required on policy manifests

internal/utils_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,8 @@ func TestIsPolicyTypeManifest(t *testing.T) {
628628
},
629629
},
630630
wantVal: false,
631-
wantErr: "",
631+
wantErr: "providing a root Policy kind is not supported by the generator; " +
632+
"the manifest should be applied to the cluster directly",
632633
},
633634
"valid PlacementRule": {
634635
manifest: map[string]interface{}{

0 commit comments

Comments
 (0)