diff --git a/api/v1/constructors.go b/api/v1/constructors.go index 30a3ef34..3a013782 100644 --- a/api/v1/constructors.go +++ b/api/v1/constructors.go @@ -787,7 +787,13 @@ func NewHostProfileSpec(host v1info.HostInfo) (*HostProfileSpec, error) { // Fill-in the basic attributes spec.Personality = &host.Personality - subfunctions := strings.Split(host.SubFunctions, ",") + subfunctionStrings := strings.Split(host.SubFunctions, ",") + subfunctions := make([]SubFunction, 0) + if len(subfunctionStrings) > 0 { + for _, subfunctionString := range subfunctionStrings { + subfunctions = append(subfunctions, SubFunctionFromString(subfunctionString)) + } + } spec.SubFunctions = subfunctions spec.AdministrativeState = &host.AdministrativeState if host.BootMAC != zeroMAC { diff --git a/api/v1/hostprofile_types.go b/api/v1/hostprofile_types.go index c931a336..d46eb6c0 100644 --- a/api/v1/hostprofile_types.go +++ b/api/v1/hostprofile_types.go @@ -668,6 +668,13 @@ func (in RouteInfo) IsKeyEqual(x RouteInfo) bool { return false } +// +kubebuilder:validation:Enum=controller;worker;storage;lowlatency +type SubFunction string + +func SubFunctionFromString(s string) SubFunction { + return SubFunction(s) +} + // +deepequal-gen:ignore-nil-fields=true type ProfileBaseAttributes struct { // Personality defines the role to be assigned to the host @@ -680,11 +687,10 @@ type ProfileBaseAttributes struct { // +optional AdministrativeState *string `json:"administrativeState,omitempty"` - // SubFunctionList defines the set of subfunctions to be provisioned on the + // SubFunctions defines the set of subfunctions to be provisioned on the // node at time of initial provisioning. - // +kubebuilder:validation:Enum=controller;worker;storage;lowlatency // +optional - SubFunctions StringList `json:"subfunctions,omitempty"` + SubFunctions []SubFunction `json:"subfunctions,omitempty"` // Location defines the physical location of the host in the data centre. // +optional @@ -881,12 +887,6 @@ type HostProfileSpec struct { Routes RouteList `json:"routes,omitempty"` } -// HostProfileStatus defines the observed state of HostProfile -type HostProfileStatus struct { - // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster - // Important: Run "make" to regenerate code after modifying this file -} - // HasWorkerSubfunction is a utility function that returns true if a profile // is configured to require the compute subfunction. func (in *HostProfileSpec) HasWorkerSubFunction() bool { @@ -917,8 +917,7 @@ type HostProfile struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` - Spec HostProfileSpec `json:"spec,omitempty"` - Status HostProfileStatus `json:"status,omitempty"` + Spec HostProfileSpec `json:"spec,omitempty"` } // +kubebuilder:object:root=true diff --git a/api/v1/zz_generated.deepcopy.go b/api/v1/zz_generated.deepcopy.go index a8ba29fe..7d5e3c93 100644 --- a/api/v1/zz_generated.deepcopy.go +++ b/api/v1/zz_generated.deepcopy.go @@ -637,7 +637,6 @@ func (in *HostProfile) DeepCopyInto(out *HostProfile) { out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) in.Spec.DeepCopyInto(&out.Spec) - out.Status = in.Status } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new HostProfile. @@ -752,21 +751,6 @@ func (in *HostProfileSpec) DeepCopy() *HostProfileSpec { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *HostProfileStatus) DeepCopyInto(out *HostProfileStatus) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new HostProfileStatus. -func (in *HostProfileStatus) DeepCopy() *HostProfileStatus { - if in == nil { - return nil - } - out := new(HostProfileStatus) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *HostSpec) DeepCopyInto(out *HostSpec) { *out = *in @@ -1392,7 +1376,7 @@ func (in *ProfileBaseAttributes) DeepCopyInto(out *ProfileBaseAttributes) { } if in.SubFunctions != nil { in, out := &in.SubFunctions, &out.SubFunctions - *out = make(StringList, len(*in)) + *out = make([]SubFunction, len(*in)) copy(*out, *in) } if in.Location != nil { diff --git a/api/v1/zz_generated.deepequal.go b/api/v1/zz_generated.deepequal.go index d8048b37..c4d68c62 100644 --- a/api/v1/zz_generated.deepequal.go +++ b/api/v1/zz_generated.deepequal.go @@ -745,16 +745,6 @@ func (in *HostProfileSpec) DeepEqual(other *HostProfileSpec) bool { return true } -// DeepEqual is an autogenerated deepequal function, deeply comparing the -// receiver with other. in must be non-nil. -func (in *HostProfileStatus) DeepEqual(other *HostProfileStatus) bool { - if other == nil { - return false - } - - return true -} - // DeepEqual is an autogenerated deepequal function, deeply comparing the // receiver with other. in must be non-nil. func (in *HostSpec) DeepEqual(other *HostSpec) bool { @@ -1476,15 +1466,8 @@ func (in *ProfileBaseAttributes) DeepEqual(other *ProfileBaseAttributes) bool { if len(*in) != len(*other) { return false } else { - for _, inElement := range *in { - found := false - for _, otherElement := range *other { - if inElement == otherElement { - found = true - break - } - } - if !found { + for i, inElement := range *in { + if inElement != (*other)[i] { return false } } diff --git a/config/crd/bases/starlingx.windriver.com_hostprofiles.yaml b/config/crd/bases/starlingx.windriver.com_hostprofiles.yaml index 446875af..ba478de0 100644 --- a/config/crd/bases/starlingx.windriver.com_hostprofiles.yaml +++ b/config/crd/bases/starlingx.windriver.com_hostprofiles.yaml @@ -891,20 +891,17 @@ spec: type: array type: object subfunctions: - description: SubFunctionList defines the set of subfunctions to be - provisioned on the node at time of initial provisioning. - enum: - - controller - - worker - - storage - - lowlatency + description: SubFunctions defines the set of subfunctions to be provisioned + on the node at time of initial provisioning. items: + enum: + - controller + - worker + - storage + - lowlatency type: string type: array type: object - status: - description: HostProfileStatus defines the observed state of HostProfile - type: object type: object served: true storage: true diff --git a/config/crd/bases/starlingx.windriver.com_hosts.yaml b/config/crd/bases/starlingx.windriver.com_hosts.yaml index feff558d..90575648 100644 --- a/config/crd/bases/starlingx.windriver.com_hosts.yaml +++ b/config/crd/bases/starlingx.windriver.com_hosts.yaml @@ -975,14 +975,14 @@ spec: type: array type: object subfunctions: - description: SubFunctionList defines the set of subfunctions to - be provisioned on the node at time of initial provisioning. - enum: - - controller - - worker - - storage - - lowlatency + description: SubFunctions defines the set of subfunctions to be + provisioned on the node at time of initial provisioning. items: + enum: + - controller + - worker + - storage + - lowlatency type: string type: array type: object diff --git a/controllers/host/host_controller.go b/controllers/host/host_controller.go index 60b5321b..c3e0bdb4 100644 --- a/controllers/host/host_controller.go +++ b/controllers/host/host_controller.go @@ -259,10 +259,14 @@ func (r *HostReconciler) UpdateRequired(instance *starlingxv1.Host, profile *sta } if profile.SubFunctions != nil { + profileSubFunctions := make([]string, 0) + for _, single := range profile.SubFunctions { + profileSubFunctions = append(profileSubFunctions, string(single)) + } subfunctions := strings.Split(h.SubFunctions, ",") - if utils.ListChanged(profile.SubFunctions, subfunctions) { + if utils.ListChanged(profileSubFunctions, subfunctions) { result = true - subfunctions := strings.Join(profile.SubFunctions, ",") + subfunctions := strings.Join(profileSubFunctions, ",") opts.SubFunctions = &subfunctions } }