Skip to content

Commit ab183b5

Browse files
Add aggregate metadata (#274)
This change adds aggregate metadata to the type kvmv1.Aggregate struct, and passes it in the aggregates controller.
1 parent 0c09786 commit ab183b5

File tree

6 files changed

+49
-7
lines changed

6 files changed

+49
-7
lines changed

api/v1/hypervisor_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@ type Aggregate struct {
206206

207207
// UUID is the unique identifier of the aggregate.
208208
UUID string `json:"uuid"`
209+
210+
// Metadata is the metadata of the aggregate as key-value pairs.
211+
// +kubebuilder:validation:Optional
212+
Metadata map[string]string `json:"metadata,omitempty"`
209213
}
210214

211215
type HyperVisorUpdateStatus struct {

api/v1/zz_generated.deepcopy.go

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

applyconfigurations/api/v1/aggregate.go

Lines changed: 17 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

charts/openstack-hypervisor-operator/crds/kvm.cloud.sap_hypervisors.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,12 @@ spec:
229229
description: Aggregate represents an OpenStack aggregate with its
230230
name and UUID.
231231
properties:
232+
metadata:
233+
additionalProperties:
234+
type: string
235+
description: Metadata is the metadata of the aggregate as key-value
236+
pairs.
237+
type: object
232238
name:
233239
description: Name is the name of the aggregate.
234240
type: string

internal/openstack/aggregates.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,9 @@ func ApplyAggregates(ctx context.Context, serviceClient *gophercloud.ServiceClie
127127
for _, name := range desiredAggregates {
128128
agg := aggregateMap[name] // exists as per "Verify all desired aggregates exist" check
129129
result = append(result, kvmv1.Aggregate{
130-
Name: agg.Name,
131-
UUID: agg.UUID,
130+
Name: agg.Name,
131+
UUID: agg.UUID,
132+
Metadata: agg.Metadata,
132133
})
133134
}
134135

internal/openstack/aggregates_test.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ var _ = Describe("ApplyAggregates", func() {
3838
"deleted": false,
3939
"id": 1,
4040
"uuid": "uuid-agg1",
41-
"hosts": ["test-host"]
41+
"hosts": ["test-host"],
42+
"metadata": {"key1": "value1", "key2": "value2"}
4243
},
4344
{
4445
"name": "agg2",
@@ -54,7 +55,8 @@ var _ = Describe("ApplyAggregates", func() {
5455
"deleted": false,
5556
"id": 3,
5657
"uuid": "uuid-agg3",
57-
"hosts": []
58+
"hosts": [],
59+
"metadata": {}
5860
}
5961
]
6062
}`
@@ -119,12 +121,17 @@ var _ = Describe("ApplyAggregates", func() {
119121
// Check we have the right aggregates by name and UUID
120122
names := make([]string, len(aggregates))
121123
uuids := make([]string, len(aggregates))
124+
metadata := make([]map[string]string, len(aggregates))
122125
for i, agg := range aggregates {
123126
names[i] = agg.Name
124127
uuids[i] = agg.UUID
128+
metadata[i] = agg.Metadata
125129
}
126130
Expect(names).To(ConsistOf("agg1", "agg2", "agg3"))
127131
Expect(uuids).To(ConsistOf("uuid-agg1", "uuid-agg2", "uuid-agg3"))
132+
Expect(metadata[0]).To(Equal(map[string]string{"key1": "value1", "key2": "value2"})) // agg1 metadata should be preserved
133+
Expect(metadata[1]).To(BeNil()) // agg2 has no metadata field, should be nil
134+
Expect(metadata[2]).To(BeEmpty()) // agg3 has empty metadata, should be preserved
128135
})
129136
})
130137

0 commit comments

Comments
 (0)