From 758eb922b4d51db83419b5a1a4957b2c7f4af2e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20L=C3=B6nnegren?= Date: Wed, 1 Nov 2023 14:32:25 +0100 Subject: [PATCH] Add DeviceSelector types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fredrik Lönnegren --- api/v1beta1/types.go | 30 ++++++++++++ api/v1beta1/zz_generated.deepcopy.go | 48 +++++++++++++++++++ charts/crds/templates/crds.yaml | 16 +++++++ ...mental.cattle.io_machineregistrations.yaml | 24 ++++++++++ 4 files changed, 118 insertions(+) diff --git a/api/v1beta1/types.go b/api/v1beta1/types.go index 21ecb3111..c1df0985c 100644 --- a/api/v1beta1/types.go +++ b/api/v1beta1/types.go @@ -26,6 +26,8 @@ type Install struct { // +optional Device string `json:"device,omitempty" yaml:"device,omitempty"` // +optional + DeviceSelector DeviceSelector `json:"device-selector,omitempty" yaml:"device-selector,omitempty"` + // +optional NoFormat bool `json:"no-format,omitempty" yaml:"no-format,omitempty"` // +optional ConfigURLs []string `json:"config-urls,omitempty" yaml:"config-urls,omitempty"` @@ -120,3 +122,31 @@ type Config struct { // +optional CloudConfig map[string]runtime.RawExtension `json:"cloud-config,omitempty" yaml:"cloud-config,omitempty"` } + +type DeviceSelector []DeviceSelectorRequirement + +type DeviceSelectorRequirement struct { + // +required + // +kubebuilder:validation:Required + // +kubebuilder:validation:Enum=Name;Size + Key DeviceSelectorKey `json:"key"` + // +required + // +kubebuilder:validation:Required + // +kubebuilder:validation:Enum=In;NotIn;Gt;Lt + Operator DeviceSelectorOperator `json:"operator"` + // +optional + Values []string `json:"values,omitempty"` +} + +type DeviceSelectorKey string +type DeviceSelectorOperator string + +const ( + DeviceSelectorOpIn DeviceSelectorOperator = "In" + DeviceSelectorOpNotIn DeviceSelectorOperator = "NotIn" + DeviceSelectorOpGt DeviceSelectorOperator = "Gt" + DeviceSelectorOpLt DeviceSelectorOperator = "Lt" + + DeviceSelectorKeyName DeviceSelectorKey = "Name" + DeviceSelectorKeySize DeviceSelectorKey = "Size" +) diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go index 71c62eaa6..5a5f53ce3 100644 --- a/api/v1beta1/zz_generated.deepcopy.go +++ b/api/v1beta1/zz_generated.deepcopy.go @@ -120,6 +120,47 @@ func (in *ContainerImage) DeepCopy() *ContainerImage { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in DeviceSelector) DeepCopyInto(out *DeviceSelector) { + { + in := &in + *out = make(DeviceSelector, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DeviceSelector. +func (in DeviceSelector) DeepCopy() DeviceSelector { + if in == nil { + return nil + } + out := new(DeviceSelector) + in.DeepCopyInto(out) + return *out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DeviceSelectorRequirement) DeepCopyInto(out *DeviceSelectorRequirement) { + *out = *in + if in.Values != nil { + in, out := &in.Values, &out.Values + *out = make([]string, len(*in)) + copy(*out, *in) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DeviceSelectorRequirement. +func (in *DeviceSelectorRequirement) DeepCopy() *DeviceSelectorRequirement { + if in == nil { + return nil + } + out := new(DeviceSelectorRequirement) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Elemental) DeepCopyInto(out *Elemental) { *out = *in @@ -173,6 +214,13 @@ func (in *ImageCommons) DeepCopy() *ImageCommons { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Install) DeepCopyInto(out *Install) { *out = *in + if in.DeviceSelector != nil { + in, out := &in.DeviceSelector, &out.DeviceSelector + *out = make(DeviceSelector, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } if in.ConfigURLs != nil { in, out := &in.ConfigURLs, &out.ConfigURLs *out = make([]string, len(*in)) diff --git a/charts/crds/templates/crds.yaml b/charts/crds/templates/crds.yaml index b644aba75..ba13a53dc 100644 --- a/charts/crds/templates/crds.yaml +++ b/charts/crds/templates/crds.yaml @@ -669,6 +669,22 @@ spec: type: boolean device: type: string + device-selector: + items: + properties: + key: + type: string + operator: + type: string + values: + items: + type: string + type: array + required: + - key + - operator + type: object + type: array disable-boot-entry: type: boolean eject-cd: diff --git a/config/crd/bases/elemental.cattle.io_machineregistrations.yaml b/config/crd/bases/elemental.cattle.io_machineregistrations.yaml index 0896bccc6..75c0f1787 100644 --- a/config/crd/bases/elemental.cattle.io_machineregistrations.yaml +++ b/config/crd/bases/elemental.cattle.io_machineregistrations.yaml @@ -53,6 +53,30 @@ spec: type: boolean device: type: string + device-selector: + items: + properties: + key: + enum: + - Name + - Size + type: string + operator: + enum: + - In + - NotIn + - Gt + - Lt + type: string + values: + items: + type: string + type: array + required: + - key + - operator + type: object + type: array disable-boot-entry: type: boolean eject-cd: