diff --git a/helm/crds/resourceproviders.yaml b/helm/crds/resourceproviders.yaml index 38e1c0b..52d9801 100644 --- a/helm/crds/resourceproviders.yaml +++ b/helm/crds/resourceproviders.yaml @@ -236,6 +236,18 @@ spec: fields to specific numeric ranges. type: object x-kubernetes-preserve-unknown-fields: true + resourceClaimAnnotations: + description: >- + Annotations to apply to ResourceClaim. + type: object + additionalProperties: + type: string + resourceClaimLabels: + description: >- + Labels to apply to ResourceClaim. + type: object + additionalProperties: + type: string resourceName: description: >- Name to apply to resource list entry when resources list is generated. diff --git a/helm/templates/crds/resourceproviders.yaml b/helm/templates/crds/resourceproviders.yaml index fe6b3ec..ecd17dd 100644 --- a/helm/templates/crds/resourceproviders.yaml +++ b/helm/templates/crds/resourceproviders.yaml @@ -237,6 +237,18 @@ spec: fields to specific numeric ranges. type: object x-kubernetes-preserve-unknown-fields: true + resourceClaimAnnotations: + description: >- + Annotations to apply to ResourceClaim. + type: object + additionalProperties: + type: string + resourceClaimLabels: + description: >- + Labels to apply to ResourceClaim. + type: object + additionalProperties: + type: string resourceName: description: >- Name to apply to resource list entry when resources list is generated. diff --git a/operator/resourceclaim.py b/operator/resourceclaim.py index 76fb70e..caa373a 100644 --- a/operator/resourceclaim.py +++ b/operator/resourceclaim.py @@ -725,6 +725,18 @@ async def manage(self, logger) -> None: else: raise + metadata_patch = {} + for key, value in resource_provider.resource_claim_annotations.items(): + if self.annotations.get(key) != value: + metadata_patch.setdefault('annotations', {})[key] = value + for key, value in resource_provider.resource_claim_labels.items(): + if self.labels.get(key) != value: + metadata_patch.setdefault('labels', {})[key] = value + if metadata_patch: + await self.merge_patch({ + "metadata": metadata_patch, + }) + if resource_provider.approval_required: if not 'approval' in self.status: await self.merge_patch_status({ diff --git a/operator/resourceprovider.py b/operator/resourceprovider.py index 9e4aa97..319fd40 100644 --- a/operator/resourceprovider.py +++ b/operator/resourceprovider.py @@ -269,6 +269,14 @@ def parameter_defaults(self) -> Mapping: if parameter.default_value != None } + @property + def resource_claim_annotations(self) -> Mapping: + return self.spec.get('resourceClaimAnnotations', {}) + + @property + def resource_claim_labels(self) -> Mapping: + return self.spec.get('resourceClaimLabels', {}) + @property def resource_name(self): return self.spec.get('resourceName', self.name) diff --git a/test/roles/poolboy_test_simple/tasks/test-parameters-01.yaml b/test/roles/poolboy_test_simple/tasks/test-parameters-01.yaml index 54bd81f..e669111 100644 --- a/test/roles/poolboy_test_simple/tasks/test-parameters-01.yaml +++ b/test/roles/poolboy_test_simple/tasks/test-parameters-01.yaml @@ -44,6 +44,10 @@ type: integer default: 0 minimum: 0 + resourceClaimAnnotations: + test-annotation: test-annotation-value + resourceClaimLabels: + test-label: test-label-value template: definition: spec: @@ -100,6 +104,8 @@ assert: that: - __state.status.resources[0].state.metadata.name == resource_claim_test_parameters_01_a_resource_name + - __state.metadata.annotations['test-annotation'] == 'test-annotation-value' + - __state.metadata.labels['test-label'] == 'test-label-value' - name: Verify creation of ResourceClaimTest test-parameters-01-a kubernetes.core.k8s_info: