From afeee9f7d53e771ea14eea7d8e0ec812bc190692 Mon Sep 17 00:00:00 2001 From: Matej Feder Date: Thu, 16 Jan 2025 15:55:04 +0100 Subject: [PATCH] Fix image properties propagation Signed-off-by: Matej Feder --- .../openstacknodeimagerelease_types.go | 54 ++++++++++++++++++- ...k.x-k8s.io_openstacknodeimagereleases.yaml | 7 +++ 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/api/v1alpha1/openstacknodeimagerelease_types.go b/api/v1alpha1/openstacknodeimagerelease_types.go index 1756fe30..4b4a2078 100644 --- a/api/v1alpha1/openstacknodeimagerelease_types.go +++ b/api/v1alpha1/openstacknodeimagerelease_types.go @@ -42,7 +42,59 @@ 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 + 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 + 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 + DiskFormat string `json:"disk_format,omitempty"` + + // MinDisk is the amount of disk space in + // GB that is required to boot the image. + //nolint:tagliatelle + MinDisk int `json:"min_disk,omitempty"` + + // MinRAM is the amount of RAM in MB that + // is required to boot the image. + //nolint:tagliatelle + 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 { diff --git a/config/crd/bases/infrastructure.clusterstack.x-k8s.io_openstacknodeimagereleases.yaml b/config/crd/bases/infrastructure.clusterstack.x-k8s.io_openstacknodeimagereleases.yaml index e7e24989..dc9e9e65 100644 --- a/config/crd/bases/infrastructure.clusterstack.x-k8s.io_openstacknodeimagereleases.yaml +++ b/config/crd/bases/infrastructure.clusterstack.x-k8s.io_openstacknodeimagereleases.yaml @@ -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