Skip to content

Commit

Permalink
🐛 Fix image properties propagation (#224)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
matofeder authored Jan 17, 2025
1 parent f048fa7 commit 56aa0f4
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 4 deletions.
52 changes: 51 additions & 1 deletion api/v1alpha1/openstacknodeimagerelease_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,57 @@ type OpenStackNodeImage struct {
}

// CreateOpts represents options used to create an image.
type CreateOpts images.CreateOpts
// TODO: Reimplement logic to import `images.CreateOpts` from Gophercloud with a `Properties` override.
// The current `images.CreateOpts` defines `json:"-"` for the `Properties` field, making it unsuitable
// for proper unmarshalling required for `CreateOpts` used in Kubernetes resources
// and `nodeimagerelease.yaml`.
// One solution is to create a new struct specifically for unmarshalling
// that embeds `images.CreateOpts` and redefines the `Properties` field to allow proper handling.
type CreateOpts struct {
// Name is the name of the new image.
Name string `json:"name" required:"true"`

// Id is the the image ID.
ID string `json:"id,omitempty"`

// Visibility defines who can see/use the image.
Visibility *images.ImageVisibility `json:"visibility,omitempty"`

// Hidden is whether the image is listed in default image list or not.
//nolint:tagliatelle // Allow snake_case JSON tags
Hidden *bool `json:"os_hidden,omitempty"`

// Tags is a set of image tags.
Tags []string `json:"tags,omitempty"`

// ContainerFormat is the format of the
// container. Valid values are ami, ari, aki, bare, and ovf.
//nolint:tagliatelle // Allow snake_case JSON tags
ContainerFormat string `json:"container_format,omitempty"`

// DiskFormat is the format of the disk. If set,
// valid values are ami, ari, aki, vhd, vmdk, raw, qcow2, vdi,
// and iso.
//nolint:tagliatelle // Allow snake_case JSON tags
DiskFormat string `json:"disk_format,omitempty"`

// MinDisk is the amount of disk space in
// GB that is required to boot the image.
//nolint:tagliatelle // Allow snake_case JSON tags
MinDisk int `json:"min_disk,omitempty"`

// MinRAM is the amount of RAM in MB that
// is required to boot the image.
//nolint:tagliatelle // Allow snake_case JSON tags
MinRAM int `json:"min_ram,omitempty"`

// protected is whether the image is not deletable.
Protected *bool `json:"protected,omitempty"`

// properties is a set of properties, if any, that
// are associated with the image.
Properties map[string]string `json:"properties,omitempty"`
}

// OpenStackNodeImageReleaseStatus defines the observed state of OpenStackNodeImageRelease.
type OpenStackNodeImageReleaseStatus struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ spec:
description: Hidden is whether the image is listed in default
image list or not.
type: boolean
properties:
additionalProperties:
type: string
description: |-
properties is a set of properties, if any, that
are associated with the image.
type: object
protected:
description: protected is whether the image is not deletable.
type: boolean
Expand Down
11 changes: 8 additions & 3 deletions internal/controller/openstacknodeimagerelease_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,9 @@ func HandleImageCreationSuccessfully(t *testing.T) { //nolint: gocritic
"id": "test_id",
"name": "test_image",
"disk_format": "qcow2",
"container_format": "bare"
"container_format": "bare",
"architecture": "x86_64",
"hw_disk_bus": "scsi"
}`)

w.Header().Add("Content-Type", "application/json")
Expand All @@ -433,7 +435,9 @@ func HandleImageCreationSuccessfully(t *testing.T) { //nolint: gocritic
"disk_format": "qcow2",
"visibility": "shared",
"min_disk": 0,
"id": "test_id"
"id": "test_id",
"architecture": "x86_64",
"hw_disk_bus": "scsi"
}`)
})
}
Expand All @@ -449,6 +453,7 @@ func TestCreateImage(t *testing.T) {
Name: "test_image",
DiskFormat: "qcow2",
ContainerFormat: "bare",
Properties: map[string]string{"architecture": "x86_64", "hw_disk_bus": "scsi"},
}

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

assert.NoError(t, err)
Expand Down

0 comments on commit 56aa0f4

Please sign in to comment.