Skip to content

Commit

Permalink
ImageFilter to ImageParam
Browse files Browse the repository at this point in the history
  • Loading branch information
mdbooth committed Mar 28, 2024
1 parent 5d30363 commit 9ad02ed
Show file tree
Hide file tree
Showing 47 changed files with 507 additions and 241 deletions.
16 changes: 7 additions & 9 deletions api/v1alpha5/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,13 +356,13 @@ func Convert_v1alpha5_OpenStackMachineSpec_To_v1beta1_OpenStackMachineSpec(in *O
out.ServerGroup = &infrav1.ServerGroupFilter{}
}

imageFilter := infrav1.ImageFilter{}
imageParam := infrav1.ImageParam{}
if in.ImageUUID != "" {
imageFilter.ID = &in.ImageUUID
imageParam.ID = &in.ImageUUID
} else if in.Image != "" { // Only add name when ID is not set, in v1beta1 it's not possible to set both.
imageFilter.Name = &in.Image
imageParam.Filter = &infrav1.ImageFilter{Name: &in.Image}
}
out.Image = imageFilter
out.Image = imageParam

if in.IdentityRef != nil {
out.IdentityRef = &infrav1.OpenStackIdentityReference{Name: in.IdentityRef.Name}
Expand Down Expand Up @@ -686,12 +686,10 @@ func Convert_v1beta1_OpenStackMachineSpec_To_v1alpha5_OpenStackMachineSpec(in *i
out.ServerGroupID = in.ServerGroup.ID
}

if in.Image.Name != nil && *in.Image.Name != "" {
out.Image = *in.Image.Name
}

if in.Image.ID != nil && *in.Image.ID != "" {
if in.Image.ID != nil {
out.ImageUUID = *in.Image.ID
} else if in.Image.Filter != nil && in.Image.Filter.Name != nil {
out.Image = *in.Image.Filter.Name
}

if in.IdentityRef != nil {
Expand Down
4 changes: 2 additions & 2 deletions api/v1alpha5/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 7 additions & 9 deletions api/v1alpha6/openstackmachine_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,13 +272,13 @@ func Convert_v1alpha6_OpenStackMachineSpec_To_v1beta1_OpenStackMachineSpec(in *O
out.ServerGroup = nil
}

imageFilter := infrav1.ImageFilter{}
imageParam := infrav1.ImageParam{}
if in.ImageUUID != "" {
imageFilter.ID = &in.ImageUUID
imageParam.ID = &in.ImageUUID
} else if in.Image != "" { // Only add name when ID is not set, in v1beta1 it's not possible to set both.
imageFilter.Name = &in.Image
imageParam.Filter = &infrav1.ImageFilter{Name: &in.Image}
}
out.Image = imageFilter
out.Image = imageParam

if len(in.ServerMetadata) > 0 {
serverMetadata := make([]infrav1.ServerMetadata, 0, len(in.ServerMetadata))
Expand Down Expand Up @@ -320,12 +320,10 @@ func Convert_v1beta1_OpenStackMachineSpec_To_v1alpha6_OpenStackMachineSpec(in *i
out.ServerGroupID = in.ServerGroup.ID
}

if in.Image.Name != nil && *in.Image.Name != "" {
out.Image = *in.Image.Name
}

if in.Image.ID != nil && *in.Image.ID != "" {
if in.Image.ID != nil {
out.ImageUUID = *in.Image.ID
} else if in.Image.Filter != nil && in.Image.Filter.Name != nil {
out.Image = *in.Image.Filter.Name
}

if len(in.ServerMetadata) > 0 {
Expand Down
4 changes: 2 additions & 2 deletions api/v1alpha6/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 7 additions & 9 deletions api/v1alpha7/openstackmachine_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,13 @@ func Convert_v1alpha7_OpenStackMachineSpec_To_v1beta1_OpenStackMachineSpec(in *O
out.ServerGroup = nil
}

imageFilter := infrav1.ImageFilter{}
imageParam := infrav1.ImageParam{}
if in.ImageUUID != "" {
imageFilter.ID = &in.ImageUUID
imageParam.ID = &in.ImageUUID
} else if in.Image != "" { // Only add name when ID is not set, in v1beta1 it's not possible to set both.
imageFilter.Name = &in.Image
imageParam.Filter = &infrav1.ImageFilter{Name: &in.Image}
}
out.Image = imageFilter
out.Image = imageParam

if len(in.ServerMetadata) > 0 {
serverMetadata := make([]infrav1.ServerMetadata, 0, len(in.ServerMetadata))
Expand Down Expand Up @@ -215,12 +215,10 @@ func Convert_v1beta1_OpenStackMachineSpec_To_v1alpha7_OpenStackMachineSpec(in *i
out.ServerGroupID = in.ServerGroup.ID
}

if in.Image.Name != nil && *in.Image.Name != "" {
out.Image = *in.Image.Name
}

if in.Image.ID != nil && *in.Image.ID != "" {
if in.Image.ID != nil {
out.ImageUUID = *in.Image.ID
} else if in.Image.Filter != nil && in.Image.Filter.Name != nil {
out.Image = *in.Image.Filter.Name
}

if len(in.ServerMetadata) > 0 {
Expand Down
4 changes: 2 additions & 2 deletions api/v1alpha7/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/v1beta1/openstackmachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type OpenStackMachineSpec struct {
// The image to use for your server instance.
// If the rootVolume is specified, this will be used when creating the root volume.
// +required
Image ImageFilter `json:"image"`
Image ImageParam `json:"image"`

// The ssh key to inject in the instance
SSHKeyName string `json:"sshKeyName,omitempty"`
Expand Down
28 changes: 24 additions & 4 deletions api/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,42 @@ type OpenStackMachineTemplateResource struct {
Spec OpenStackMachineSpec `json:"spec"`
}

// ImageFilter describes the data needed to identify which image to use. If ID is provided it is required that all other fields are unset.
// +kubebuilder:validation:XValidation:rule="(has(self.id) && !has(self.name) && !has(self.tags)) || !has(self.id)",message="when ID is set you cannot set other options"
type ImageFilter struct {
// The ID of the desired image. If ID is provided, the other filters cannot be provided. Must be in UUID format.
// ImageParam describes a glance image. It can be specified by ID or filter.
// +kubebuilder:validation:MaxProperties:=1
// +kubebuilder:validation:MinProperties:=1
type ImageParam struct {
// ID is the uuid of the image. ID will not be validated before use.
// +kubebuilder:validation:Format:=uuid
// +optional
ID optional.String `json:"id,omitempty"`

// Filter describes a query for an image. If specified, the combination
// of name and tags must return a single matching image or an error will
// be raised.
// +optional
Filter *ImageFilter `json:"filter,omitempty"`
}

// ImageFilter describes a query for an image.
// +kubebuilder:validation:MinProperties:=1
type ImageFilter struct {
// The name of the desired image. If specified, the combination of name and tags must return a single matching image or an error will be raised.
// +optional
Name optional.String `json:"name,omitempty"`

// The tags associated with the desired image. If specified, the combination of name and tags must return a single matching image or an error will be raised.
// +listType=set
// +optional
Tags []string `json:"tags,omitempty"`
}

func (f *ImageFilter) IsZero() bool {
if f == nil {
return true
}
return f.Name == nil && len(f.Tags) == 0
}

type ExternalRouterIPParam struct {
// The FixedIP in the corresponding subnet
FixedIP string `json:"fixedIP,omitempty"`
Expand Down
30 changes: 25 additions & 5 deletions api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9ad02ed

Please sign in to comment.