Skip to content

Commit

Permalink
Add label and annotation support for ResourceClaims (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkupferer authored Jun 13, 2024
1 parent 2b7b9e3 commit 326eb2d
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 0 deletions.
12 changes: 12 additions & 0 deletions helm/crds/resourceproviders.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 12 additions & 0 deletions helm/templates/crds/resourceproviders.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 12 additions & 0 deletions operator/resourceclaim.py
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
8 changes: 8 additions & 0 deletions operator/resourceprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions test/roles/poolboy_test_simple/tasks/test-parameters-01.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 326eb2d

Please sign in to comment.