From 27f0c689c7f470219307d3f9bc857c1ff7bc5e92 Mon Sep 17 00:00:00 2001 From: eromanova Date: Fri, 7 Jun 2024 16:20:17 +0400 Subject: [PATCH] Add new parameters to Management spec and status HMC-23 --- api/v1alpha1/management_types.go | 62 +++++++++++++++++-- api/v1alpha1/template_types.go | 3 + api/v1alpha1/zz_generated.deepcopy.go | 53 +++++++++++++++- charts/hmc/templates/management-crd.yaml | 44 +++++++++++-- .../bases/hmc.mirantis.com_managements.yaml | 45 ++++++++++++-- 5 files changed, 193 insertions(+), 14 deletions(-) diff --git a/api/v1alpha1/management_types.go b/api/v1alpha1/management_types.go index f8fb17c97..d5885bdb9 100644 --- a/api/v1alpha1/management_types.go +++ b/api/v1alpha1/management_types.go @@ -17,7 +17,14 @@ limitations under the License. package v1alpha1 import ( + apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/yaml" +) + +const ( + ManagementName = "hmc" + ManagementNamespace = "hmc-system" ) // EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! @@ -28,14 +35,61 @@ type ManagementSpec struct { // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster // Important: Run "make" to regenerate code after modifying this file - // Foo is an example field of Management. Edit management_types.go to remove/update - Foo string `json:"foo,omitempty"` + // Components is the list of supported management components + Components []Component `json:"components,omitempty"` +} + +// Component represents HMC management component +type Component struct { + // Template is the name of the Template associated with this component + Template string `json:"template"` + // Config allows to provide parameters for management component customization. + // If no Config provided, the field will be populated with the default + // values for the template. + // +optional + Config *apiextensionsv1.JSON `json:"config,omitempty"` +} + +func (in *Component) HelmValues() (values map[string]interface{}, err error) { + if in.Config != nil { + err = yaml.Unmarshal(in.Config.Raw, &values) + } + return values, err +} + +func (m ManagementSpec) SetDefaults() { + // TODO: Uncomment when Templates will be ready + /* + m.Components = []Component{ + { + Template: "cluster-api", + }, + { + Template: "k0smotron", + }, + { + Template: "cluster-api-provider-aws", + }, + } + */ } // ManagementStatus defines the observed state of Management type ManagementStatus struct { - // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster - // Important: Run "make" to regenerate code after modifying this file + // ObservedGeneration is the last observed generation. + // +optional + ObservedGeneration int64 `json:"observedGeneration,omitempty"` + + // Components contains the map with the status of Management components installation + Components map[string]ComponentStatus `json:"components,omitempty"` +} + +// ComponentStatus is the status of Management component installation +type ComponentStatus struct { + // Success represents if a component installation was successful + Success bool `json:"success,omitempty"` + // Error stores as error message in case of failed installation + Error string `json:"error,omitempty"` } //+kubebuilder:object:root=true diff --git a/api/v1alpha1/template_types.go b/api/v1alpha1/template_types.go index 92cdac7bb..b4e7d884d 100644 --- a/api/v1alpha1/template_types.go +++ b/api/v1alpha1/template_types.go @@ -24,6 +24,9 @@ import ( ) const ( + // TemplatesNamespace is the namespace where all management and provider Templates are located + TemplatesNamespace = "hmc-system" + // TemplateKind is the string representation of a Template. TemplateKind = "Template" // DeploymentKind is the string representation of a Deployment. diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 8e7ea7745..26d557b48 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -115,6 +115,41 @@ func (in *AWSProviderStatus) DeepCopy() *AWSProviderStatus { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Component) DeepCopyInto(out *Component) { + *out = *in + if in.Config != nil { + in, out := &in.Config, &out.Config + *out = new(v1.JSON) + (*in).DeepCopyInto(*out) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Component. +func (in *Component) DeepCopy() *Component { + if in == nil { + return nil + } + out := new(Component) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ComponentStatus) DeepCopyInto(out *ComponentStatus) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ComponentStatus. +func (in *ComponentStatus) DeepCopy() *ComponentStatus { + if in == nil { + return nil + } + out := new(ComponentStatus) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Deployment) DeepCopyInto(out *Deployment) { *out = *in @@ -235,8 +270,8 @@ func (in *Management) DeepCopyInto(out *Management) { *out = *in out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - out.Spec = in.Spec - out.Status = in.Status + in.Spec.DeepCopyInto(&out.Spec) + in.Status.DeepCopyInto(&out.Status) } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Management. @@ -292,6 +327,13 @@ func (in *ManagementList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ManagementSpec) DeepCopyInto(out *ManagementSpec) { *out = *in + if in.Components != nil { + in, out := &in.Components, &out.Components + *out = make([]Component, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ManagementSpec. @@ -307,6 +349,13 @@ func (in *ManagementSpec) DeepCopy() *ManagementSpec { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ManagementStatus) DeepCopyInto(out *ManagementStatus) { *out = *in + if in.Components != nil { + in, out := &in.Components, &out.Components + *out = make(map[string]ComponentStatus, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ManagementStatus. diff --git a/charts/hmc/templates/management-crd.yaml b/charts/hmc/templates/management-crd.yaml index 28b3017ec..f5c064a11 100644 --- a/charts/hmc/templates/management-crd.yaml +++ b/charts/hmc/templates/management-crd.yaml @@ -40,13 +40,49 @@ spec: spec: description: ManagementSpec defines the desired state of Management properties: - foo: - description: Foo is an example field of Management. Edit management_types.go - to remove/update - type: string + components: + description: Components is the list of supported management components + items: + description: Component represents HMC management component + properties: + config: + description: |- + Config allows to provide parameters for management component customization. + If no Config provided, the field will be populated with the default + values for the template. + x-kubernetes-preserve-unknown-fields: true + template: + description: Template is the name of the Template associated with + this component + type: string + required: + - template + type: object + type: array type: object status: description: ManagementStatus defines the observed state of Management + properties: + components: + additionalProperties: + description: ComponentStatus is the status of Management component + installation + properties: + error: + description: Error stores as error message in case of failed installation + type: string + success: + description: Success represents if a component installation was + successful + type: boolean + type: object + description: Components contains the map with the status of Management + components installation + type: object + observedGeneration: + description: ObservedGeneration is the last observed generation. + format: int64 + type: integer type: object type: object served: true diff --git a/config/crd/bases/hmc.mirantis.com_managements.yaml b/config/crd/bases/hmc.mirantis.com_managements.yaml index 11fdbc665..f8e5aa073 100644 --- a/config/crd/bases/hmc.mirantis.com_managements.yaml +++ b/config/crd/bases/hmc.mirantis.com_managements.yaml @@ -39,13 +39,50 @@ spec: spec: description: ManagementSpec defines the desired state of Management properties: - foo: - description: Foo is an example field of Management. Edit management_types.go - to remove/update - type: string + components: + description: Components is the list of supported management components + items: + description: Component represents HMC management component + properties: + config: + description: |- + Config allows to provide parameters for management component customization. + If no Config provided, the field will be populated with the default + values for the template. + x-kubernetes-preserve-unknown-fields: true + template: + description: Template is the name of the Template associated + with this component + type: string + required: + - template + type: object + type: array type: object status: description: ManagementStatus defines the observed state of Management + properties: + components: + additionalProperties: + description: ComponentStatus is the status of Management component + installation + properties: + error: + description: Error stores as error message in case of failed + installation + type: string + success: + description: Success represents if a component installation + was successful + type: boolean + type: object + description: Components contains the map with the status of Management + components installation + type: object + observedGeneration: + description: ObservedGeneration is the last observed generation. + format: int64 + type: integer type: object type: object served: true