Skip to content

Commit 56aa0f4

Browse files
authored
🐛 Fix image properties propagation (#224)
* Fix image properties propagation Signed-off-by: Matej Feder <[email protected]> * Update unittests Signed-off-by: Matej Feder <[email protected]> --------- Signed-off-by: Matej Feder <[email protected]>
1 parent f048fa7 commit 56aa0f4

File tree

3 files changed

+66
-4
lines changed

3 files changed

+66
-4
lines changed

api/v1alpha1/openstacknodeimagerelease_types.go

+51-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,57 @@ type OpenStackNodeImage struct {
4242
}
4343

4444
// CreateOpts represents options used to create an image.
45-
type CreateOpts images.CreateOpts
45+
// TODO: Reimplement logic to import `images.CreateOpts` from Gophercloud with a `Properties` override.
46+
// The current `images.CreateOpts` defines `json:"-"` for the `Properties` field, making it unsuitable
47+
// for proper unmarshalling required for `CreateOpts` used in Kubernetes resources
48+
// and `nodeimagerelease.yaml`.
49+
// One solution is to create a new struct specifically for unmarshalling
50+
// that embeds `images.CreateOpts` and redefines the `Properties` field to allow proper handling.
51+
type CreateOpts struct {
52+
// Name is the name of the new image.
53+
Name string `json:"name" required:"true"`
54+
55+
// Id is the the image ID.
56+
ID string `json:"id,omitempty"`
57+
58+
// Visibility defines who can see/use the image.
59+
Visibility *images.ImageVisibility `json:"visibility,omitempty"`
60+
61+
// Hidden is whether the image is listed in default image list or not.
62+
//nolint:tagliatelle // Allow snake_case JSON tags
63+
Hidden *bool `json:"os_hidden,omitempty"`
64+
65+
// Tags is a set of image tags.
66+
Tags []string `json:"tags,omitempty"`
67+
68+
// ContainerFormat is the format of the
69+
// container. Valid values are ami, ari, aki, bare, and ovf.
70+
//nolint:tagliatelle // Allow snake_case JSON tags
71+
ContainerFormat string `json:"container_format,omitempty"`
72+
73+
// DiskFormat is the format of the disk. If set,
74+
// valid values are ami, ari, aki, vhd, vmdk, raw, qcow2, vdi,
75+
// and iso.
76+
//nolint:tagliatelle // Allow snake_case JSON tags
77+
DiskFormat string `json:"disk_format,omitempty"`
78+
79+
// MinDisk is the amount of disk space in
80+
// GB that is required to boot the image.
81+
//nolint:tagliatelle // Allow snake_case JSON tags
82+
MinDisk int `json:"min_disk,omitempty"`
83+
84+
// MinRAM is the amount of RAM in MB that
85+
// is required to boot the image.
86+
//nolint:tagliatelle // Allow snake_case JSON tags
87+
MinRAM int `json:"min_ram,omitempty"`
88+
89+
// protected is whether the image is not deletable.
90+
Protected *bool `json:"protected,omitempty"`
91+
92+
// properties is a set of properties, if any, that
93+
// are associated with the image.
94+
Properties map[string]string `json:"properties,omitempty"`
95+
}
4696

4797
// OpenStackNodeImageReleaseStatus defines the observed state of OpenStackNodeImageRelease.
4898
type OpenStackNodeImageReleaseStatus struct {

config/crd/bases/infrastructure.clusterstack.x-k8s.io_openstacknodeimagereleases.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ spec:
114114
description: Hidden is whether the image is listed in default
115115
image list or not.
116116
type: boolean
117+
properties:
118+
additionalProperties:
119+
type: string
120+
description: |-
121+
properties is a set of properties, if any, that
122+
are associated with the image.
123+
type: object
117124
protected:
118125
description: protected is whether the image is not deletable.
119126
type: boolean

internal/controller/openstacknodeimagerelease_controller_test.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,9 @@ func HandleImageCreationSuccessfully(t *testing.T) { //nolint: gocritic
421421
"id": "test_id",
422422
"name": "test_image",
423423
"disk_format": "qcow2",
424-
"container_format": "bare"
424+
"container_format": "bare",
425+
"architecture": "x86_64",
426+
"hw_disk_bus": "scsi"
425427
}`)
426428

427429
w.Header().Add("Content-Type", "application/json")
@@ -433,7 +435,9 @@ func HandleImageCreationSuccessfully(t *testing.T) { //nolint: gocritic
433435
"disk_format": "qcow2",
434436
"visibility": "shared",
435437
"min_disk": 0,
436-
"id": "test_id"
438+
"id": "test_id",
439+
"architecture": "x86_64",
440+
"hw_disk_bus": "scsi"
437441
}`)
438442
})
439443
}
@@ -449,6 +453,7 @@ func TestCreateImage(t *testing.T) {
449453
Name: "test_image",
450454
DiskFormat: "qcow2",
451455
ContainerFormat: "bare",
456+
Properties: map[string]string{"architecture": "x86_64", "hw_disk_bus": "scsi"},
452457
}
453458

454459
fakeClient := fakeclient.ServiceClient()
@@ -462,7 +467,7 @@ func TestCreateImage(t *testing.T) {
462467
ContainerFormat: "bare",
463468
DiskFormat: "qcow2",
464469
Visibility: "shared",
465-
Properties: map[string]interface{}{},
470+
Properties: map[string]any{"architecture": "x86_64", "hw_disk_bus": "scsi"},
466471
}
467472

468473
assert.NoError(t, err)

0 commit comments

Comments
 (0)