Skip to content

Commit 4210174

Browse files
JustinKuliopenshift-merge-robot
authored andcommitted
Enhance crd-sync to add labels and annotations
The previous update to the Policy CRD which added the "deletion-orphan" annotation would not be persisted through the "crd-sync.sh" script. Now, that script adds the annotation. The script also adds the "policy-type" annotation to the v1beta1 CRD for ConfigurationPolicy, since that was missing. It is easier to add it here rather than update the kustomization in the other repo, since it never creates the v1beta1 crd in that repo's scripts. Refs: - https://issues.redhat.com/browse/ACM-5326 Signed-off-by: Justin Kulikauskas <[email protected]>
1 parent 7058b6b commit 4210174

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

build/crd-sync.sh

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,31 @@ done
2929
cp deploy/crds/policy.open-cluster-management.io_policies.yaml ../policy-crd-v1beta1.yaml
3030
)
3131

32-
addLabelsExpression='.metadata.labels += {"addon.open-cluster-management.io/hosted-manifest-location": "hosting"}'
32+
addLocationLabel='.metadata.labels += {"addon.open-cluster-management.io/hosted-manifest-location": "hosting"}'
33+
addTemplateLabel='.metadata.labels += {"policy.open-cluster-management.io/policy-type": "template"}'
34+
35+
# This annotation must *only* be added on the hub cluster. On others, we want the CRD removed.
36+
# This kind of condition is not valid YAML on its own, so it has to be hacked in.
37+
addTempAnnotation='.metadata.annotations += {"SEDTARGET": "SEDTARGET"}'
38+
replaceAnnotation='s/SEDTARGET: SEDTARGET/{{ if .Values.onMulticlusterHub }}"addon.open-cluster-management.io\/deletion-orphan": ""{{ end }}/g'
3339

3440
cat > pkg/addon/configpolicy/manifests/managedclusterchart/templates/policy.open-cluster-management.io_configurationpolicies_crd.yaml << EOF
3541
# Copyright Contributors to the Open Cluster Management project
3642
3743
{{- if semverCompare "< 1.16.0" .Capabilities.KubeVersion.Version }}
38-
$(yq e "$addLabelsExpression" .go/config-policy-crd-v1beta1.yaml)
44+
$(yq e "$addLocationLabel | $addTemplateLabel" .go/config-policy-crd-v1beta1.yaml)
3945
{{ else }}
40-
$(yq e "$addLabelsExpression" .go/config-policy-crd-v1.yaml)
46+
$(yq e "$addLocationLabel" .go/config-policy-crd-v1.yaml)
4147
{{- end }}
4248
EOF
4349

4450
cat > pkg/addon/policyframework/manifests/managedclusterchart/templates/policy.open-cluster-management.io_policies_crd.yaml << EOF
4551
# Copyright Contributors to the Open Cluster Management project
4652
4753
{{- if semverCompare "< 1.16.0" .Capabilities.KubeVersion.Version }}
48-
$(yq e "$addLabelsExpression" .go/policy-crd-v1beta1.yaml)
54+
$(yq e "$addTempAnnotation | $addLocationLabel" .go/policy-crd-v1beta1.yaml | sed -E "$replaceAnnotation")
4955
{{ else }}
50-
$(yq e "$addLabelsExpression" .go/policy-crd-v1.yaml)
56+
$(yq e "$addTempAnnotation | $addLocationLabel" .go/policy-crd-v1.yaml | sed -E "$replaceAnnotation")
5157
{{- end }}
5258
EOF
5359

pkg/addon/configpolicy/manifests/managedclusterchart/templates/policy.open-cluster-management.io_configurationpolicies_crd.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ metadata:
1212
name: configurationpolicies.policy.open-cluster-management.io
1313
labels:
1414
addon.open-cluster-management.io/hosted-manifest-location: hosting
15+
policy.open-cluster-management.io/policy-type: template
1516
spec:
1617
additionalPrinterColumns:
1718
- JSONPath: .status.compliant

pkg/addon/policyframework/manifests/managedclusterchart/templates/policy.open-cluster-management.io_policies_crd.yaml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ kind: CustomResourceDefinition
88
metadata:
99
annotations:
1010
controller-gen.kubebuilder.io/version: v0.6.1
11-
{{- if .Values.onMulticlusterHub }}
12-
"addon.open-cluster-management.io/deletion-orphan": ""
13-
{{- end }}
11+
{{ if .Values.onMulticlusterHub }}"addon.open-cluster-management.io/deletion-orphan": ""{{ end }}
1412
creationTimestamp: null
1513
name: policies.policy.open-cluster-management.io
1614
labels:
@@ -240,9 +238,7 @@ kind: CustomResourceDefinition
240238
metadata:
241239
annotations:
242240
controller-gen.kubebuilder.io/version: v0.6.1
243-
{{- if .Values.onMulticlusterHub }}
244-
"addon.open-cluster-management.io/deletion-orphan": ""
245-
{{- end }}
241+
{{ if .Values.onMulticlusterHub }}"addon.open-cluster-management.io/deletion-orphan": ""{{ end }}
246242
creationTimestamp: null
247243
name: policies.policy.open-cluster-management.io
248244
labels:

0 commit comments

Comments
 (0)