Skip to content

Commit 326eb2d

Browse files
authored
Add label and annotation support for ResourceClaims (#111)
1 parent 2b7b9e3 commit 326eb2d

File tree

5 files changed

+50
-0
lines changed

5 files changed

+50
-0
lines changed

helm/crds/resourceproviders.yaml

+12
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,18 @@ spec:
236236
fields to specific numeric ranges.
237237
type: object
238238
x-kubernetes-preserve-unknown-fields: true
239+
resourceClaimAnnotations:
240+
description: >-
241+
Annotations to apply to ResourceClaim.
242+
type: object
243+
additionalProperties:
244+
type: string
245+
resourceClaimLabels:
246+
description: >-
247+
Labels to apply to ResourceClaim.
248+
type: object
249+
additionalProperties:
250+
type: string
239251
resourceName:
240252
description: >-
241253
Name to apply to resource list entry when resources list is generated.

helm/templates/crds/resourceproviders.yaml

+12
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,18 @@ spec:
237237
fields to specific numeric ranges.
238238
type: object
239239
x-kubernetes-preserve-unknown-fields: true
240+
resourceClaimAnnotations:
241+
description: >-
242+
Annotations to apply to ResourceClaim.
243+
type: object
244+
additionalProperties:
245+
type: string
246+
resourceClaimLabels:
247+
description: >-
248+
Labels to apply to ResourceClaim.
249+
type: object
250+
additionalProperties:
251+
type: string
240252
resourceName:
241253
description: >-
242254
Name to apply to resource list entry when resources list is generated.

operator/resourceclaim.py

+12
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,18 @@ async def manage(self, logger) -> None:
725725
else:
726726
raise
727727

728+
metadata_patch = {}
729+
for key, value in resource_provider.resource_claim_annotations.items():
730+
if self.annotations.get(key) != value:
731+
metadata_patch.setdefault('annotations', {})[key] = value
732+
for key, value in resource_provider.resource_claim_labels.items():
733+
if self.labels.get(key) != value:
734+
metadata_patch.setdefault('labels', {})[key] = value
735+
if metadata_patch:
736+
await self.merge_patch({
737+
"metadata": metadata_patch,
738+
})
739+
728740
if resource_provider.approval_required:
729741
if not 'approval' in self.status:
730742
await self.merge_patch_status({

operator/resourceprovider.py

+8
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,14 @@ def parameter_defaults(self) -> Mapping:
269269
if parameter.default_value != None
270270
}
271271

272+
@property
273+
def resource_claim_annotations(self) -> Mapping:
274+
return self.spec.get('resourceClaimAnnotations', {})
275+
276+
@property
277+
def resource_claim_labels(self) -> Mapping:
278+
return self.spec.get('resourceClaimLabels', {})
279+
272280
@property
273281
def resource_name(self):
274282
return self.spec.get('resourceName', self.name)

test/roles/poolboy_test_simple/tasks/test-parameters-01.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@
4444
type: integer
4545
default: 0
4646
minimum: 0
47+
resourceClaimAnnotations:
48+
test-annotation: test-annotation-value
49+
resourceClaimLabels:
50+
test-label: test-label-value
4751
template:
4852
definition:
4953
spec:
@@ -100,6 +104,8 @@
100104
assert:
101105
that:
102106
- __state.status.resources[0].state.metadata.name == resource_claim_test_parameters_01_a_resource_name
107+
- __state.metadata.annotations['test-annotation'] == 'test-annotation-value'
108+
- __state.metadata.labels['test-label'] == 'test-label-value'
103109

104110
- name: Verify creation of ResourceClaimTest test-parameters-01-a
105111
kubernetes.core.k8s_info:

0 commit comments

Comments
 (0)