diff --git a/api/v1alpha1/common.go b/api/v1alpha1/common.go new file mode 100644 index 000000000..df62c0a17 --- /dev/null +++ b/api/v1alpha1/common.go @@ -0,0 +1,27 @@ +/* +Copyright 2024. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1alpha1 + +// Providers is a structure holding different types of CAPI providers +type Providers struct { + // InfrastructureProviders is the list of CAPI infrastructure providers + InfrastructureProviders []string `json:"infrastructure,omitempty"` + // BootstrapProviders is the list of CAPI bootstrap providers + BootstrapProviders []string `json:"bootstrap,omitempty"` + // ControlPlaneProviders is the list of CAPI control plane providers + ControlPlaneProviders []string `json:"controlPlane,omitempty"` +} diff --git a/api/v1alpha1/deployment_types.go b/api/v1alpha1/deployment_types.go index 74ffe1a07..e9917896e 100644 --- a/api/v1alpha1/deployment_types.go +++ b/api/v1alpha1/deployment_types.go @@ -47,6 +47,10 @@ type DeploymentStatus struct { //+kubebuilder:object:root=true //+kubebuilder:subresource:status +// +kubebuilder:resource:shortName=hmc-deploy;deploy +// +kubebuilder:printcolumn:name="valid",type="boolean",JSONPath=".status.valid",description="Valid",priority=0 +// +kubebuilder:printcolumn:name="validationError",type="string",JSONPath=".status.validationError",description="Validation Error",priority=1 +// +kubebuilder:printcolumn:name="dryRun",type="string",JSONPath=".spec.dryRun",description="Dry Run",priority=1 // Deployment is the Schema for the deployments API type Deployment struct { diff --git a/api/v1alpha1/management_types.go b/api/v1alpha1/management_types.go index 60796f4a8..9640a59d1 100644 --- a/api/v1alpha1/management_types.go +++ b/api/v1alpha1/management_types.go @@ -80,7 +80,7 @@ type ManagementStatus struct { // +optional ObservedGeneration int64 `json:"observedGeneration,omitempty"` // Providers is the list of discovered supported providers - Providers ProvidersStatus `json:"providers,omitempty"` + Providers Providers `json:"providers,omitempty"` // Components contains the map with the status of Management components installation Components map[string]ComponentStatus `json:"components,omitempty"` } @@ -93,18 +93,9 @@ type ComponentStatus struct { Error string `json:"error,omitempty"` } -// ProvidersStatus is the list of discovered supported providers -type ProvidersStatus struct { - // InfrastructureProviders is the list of discovered infrastructure providers - InfrastructureProviders []string `json:"infrastructure,omitempty"` - // BootstrapProviders is the list of discovered bootstrap providers - BootstrapProviders []string `json:"bootstrap,omitempty"` - // ControlPlaneProviders is the list of discovered control plane providers - ControlPlaneProviders []string `json:"controlPlane,omitempty"` -} - //+kubebuilder:object:root=true //+kubebuilder:subresource:status +// +kubebuilder:resource:shortName=hmc-mgmt;mgmt // Management is the Schema for the managements API type Management struct { diff --git a/api/v1alpha1/template_types.go b/api/v1alpha1/template_types.go index 57a6c7c82..fa8833533 100644 --- a/api/v1alpha1/template_types.go +++ b/api/v1alpha1/template_types.go @@ -97,15 +97,8 @@ type TemplateStatus struct { // Type specifies the type of the provided template, as discovered from the Helm chart metadata. // +kubebuilder:validation:Enum=deployment;provider;core Type string `json:"type,omitempty"` - // InfrastructureProviders specifies CAPI infrastructure providers associated with the template. - // +optional - InfrastructureProviders []string `json:"infrastructureProviders,omitempty"` - // BootstrapProviders specifies CAPI bootstrap providers associated with the template. - // +optional - BootstrapProviders []string `json:"bootstrapProviders,omitempty"` - // ControlPlaneProviders specifies CAPI control plane providers associated with the template. - // +optional - ControlPlaneProviders []string `json:"controlPlaneProviders,omitempty"` + // Providers represent required/exposed CAPI providers depending on the template type. + Providers Providers `json:"providers,omitempty"` // ObservedGeneration is the last observed generation. // +optional ObservedGeneration int64 `json:"observedGeneration,omitempty"` @@ -121,6 +114,11 @@ type TemplateValidationStatus struct { //+kubebuilder:object:root=true //+kubebuilder:subresource:status +// +kubebuilder:resource:shortName=hmc-tmpl;tmpl +// +kubebuilder:printcolumn:name="type",type="string",JSONPath=".status.type",description="Type",priority=0 +// +kubebuilder:printcolumn:name="valid",type="boolean",JSONPath=".status.valid",description="Valid",priority=0 +// +kubebuilder:printcolumn:name="validationError",type="string",JSONPath=".status.validationError",description="Validation Error",priority=1 +// +kubebuilder:printcolumn:name="description",type="string",JSONPath=".status.description",description="Description",priority=1 // Template is the Schema for the templates API type Template struct { diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index ca1001810..69710a79e 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -370,7 +370,7 @@ func (in *ManagementStatus) DeepCopy() *ManagementStatus { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ProvidersStatus) DeepCopyInto(out *ProvidersStatus) { +func (in *Providers) DeepCopyInto(out *Providers) { *out = *in if in.InfrastructureProviders != nil { in, out := &in.InfrastructureProviders, &out.InfrastructureProviders @@ -389,12 +389,12 @@ func (in *ProvidersStatus) DeepCopyInto(out *ProvidersStatus) { } } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ProvidersStatus. -func (in *ProvidersStatus) DeepCopy() *ProvidersStatus { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Providers. +func (in *Providers) DeepCopy() *Providers { if in == nil { return nil } - out := new(ProvidersStatus) + out := new(Providers) in.DeepCopyInto(out) return out } @@ -488,21 +488,7 @@ func (in *TemplateStatus) DeepCopyInto(out *TemplateStatus) { *out = new(v2.CrossNamespaceSourceReference) **out = **in } - if in.InfrastructureProviders != nil { - in, out := &in.InfrastructureProviders, &out.InfrastructureProviders - *out = make([]string, len(*in)) - copy(*out, *in) - } - if in.BootstrapProviders != nil { - in, out := &in.BootstrapProviders, &out.BootstrapProviders - *out = make([]string, len(*in)) - copy(*out, *in) - } - if in.ControlPlaneProviders != nil { - in, out := &in.ControlPlaneProviders, &out.ControlPlaneProviders - *out = make([]string, len(*in)) - copy(*out, *in) - } + in.Providers.DeepCopyInto(&out.Providers) } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TemplateStatus. diff --git a/config/crd/bases/hmc.mirantis.com_deployments.yaml b/config/crd/bases/hmc.mirantis.com_deployments.yaml index 9000a9970..6c5654bb8 100644 --- a/config/crd/bases/hmc.mirantis.com_deployments.yaml +++ b/config/crd/bases/hmc.mirantis.com_deployments.yaml @@ -11,10 +11,28 @@ spec: kind: Deployment listKind: DeploymentList plural: deployments + shortNames: + - hmc-deploy + - deploy singular: deployment scope: Namespaced versions: - - name: v1alpha1 + - additionalPrinterColumns: + - description: Valid + jsonPath: .status.valid + name: valid + type: boolean + - description: Validation Error + jsonPath: .status.validationError + name: validationError + priority: 1 + type: string + - description: Dry Run + jsonPath: .spec.dryRun + name: dryRun + priority: 1 + type: string + name: v1alpha1 schema: openAPIV3Schema: description: Deployment is the Schema for the deployments API diff --git a/config/crd/bases/hmc.mirantis.com_managements.yaml b/config/crd/bases/hmc.mirantis.com_managements.yaml index 5f8a3e1b6..aa11c42fb 100644 --- a/config/crd/bases/hmc.mirantis.com_managements.yaml +++ b/config/crd/bases/hmc.mirantis.com_managements.yaml @@ -11,6 +11,9 @@ spec: kind: Management listKind: ManagementList plural: managements + shortNames: + - hmc-mgmt + - mgmt singular: management scope: Namespaced versions: @@ -87,20 +90,20 @@ spec: description: Providers is the list of discovered supported providers properties: bootstrap: - description: BootstrapProviders is the list of discovered bootstrap + description: BootstrapProviders is the list of CAPI bootstrap providers items: type: string type: array controlPlane: - description: ControlPlaneProviders is the list of discovered control + description: ControlPlaneProviders is the list of CAPI control plane providers items: type: string type: array infrastructure: - description: InfrastructureProviders is the list of discovered - infrastructure providers + description: InfrastructureProviders is the list of CAPI infrastructure + providers items: type: string type: array diff --git a/config/crd/bases/hmc.mirantis.com_templates.yaml b/config/crd/bases/hmc.mirantis.com_templates.yaml index eb222cb7f..76ece9ad8 100644 --- a/config/crd/bases/hmc.mirantis.com_templates.yaml +++ b/config/crd/bases/hmc.mirantis.com_templates.yaml @@ -11,10 +11,32 @@ spec: kind: Template listKind: TemplateList plural: templates + shortNames: + - hmc-tmpl + - tmpl singular: template scope: Namespaced versions: - - name: v1alpha1 + - additionalPrinterColumns: + - description: Type + jsonPath: .status.type + name: type + type: string + - description: Valid + jsonPath: .status.valid + name: valid + type: boolean + - description: Validation Error + jsonPath: .status.validationError + name: validationError + priority: 1 + type: string + - description: Description + jsonPath: .status.description + name: description + priority: 1 + type: string + name: v1alpha1 schema: openAPIV3Schema: description: Template is the Schema for the templates API @@ -92,12 +114,6 @@ spec: status: description: TemplateStatus defines the observed state of Template properties: - bootstrapProviders: - description: BootstrapProviders specifies CAPI bootstrap providers - associated with the template. - items: - type: string - type: array chartRef: description: |- ChartRef is a reference to a source controller resource containing the @@ -133,25 +149,36 @@ spec: Config demonstrates available parameters for template customization, that can be used when creating Deployment objects. x-kubernetes-preserve-unknown-fields: true - controlPlaneProviders: - description: ControlPlaneProviders specifies CAPI control plane providers - associated with the template. - items: - type: string - type: array description: description: Description contains information about the template. type: string - infrastructureProviders: - description: InfrastructureProviders specifies CAPI infrastructure - providers associated with the template. - items: - type: string - type: array observedGeneration: description: ObservedGeneration is the last observed generation. format: int64 type: integer + providers: + description: Providers represent required/exposed CAPI providers depending + on the template type. + properties: + bootstrap: + description: BootstrapProviders is the list of CAPI bootstrap + providers + items: + type: string + type: array + controlPlane: + description: ControlPlaneProviders is the list of CAPI control + plane providers + items: + type: string + type: array + infrastructure: + description: InfrastructureProviders is the list of CAPI infrastructure + providers + items: + type: string + type: array + type: object type: description: Type specifies the type of the provided template, as discovered from the Helm chart metadata. diff --git a/config/samples/hmc.mirantis.com_v1alpha1_deployment.yaml b/config/samples/hmc.mirantis.com_v1alpha1_deployment.yaml index ba60b2aef..ff740d605 100644 --- a/config/samples/hmc.mirantis.com_v1alpha1_deployment.yaml +++ b/config/samples/hmc.mirantis.com_v1alpha1_deployment.yaml @@ -6,4 +6,4 @@ metadata: app.kubernetes.io/managed-by: kustomize name: deployment-sample spec: - # TODO(user): Add fields here + template: aws-standalone-cp diff --git a/internal/controller/management_controller.go b/internal/controller/management_controller.go index c5c47f191..773c50b1c 100644 --- a/internal/controller/management_controller.go +++ b/internal/controller/management_controller.go @@ -61,7 +61,7 @@ func (r *ManagementReconciler) Reconcile(ctx context.Context, req ctrl.Request) } var errs error - detectedProviders := hmc.ProvidersStatus{} + detectedProviders := hmc.Providers{} detectedComponents := make(map[string]hmc.ComponentStatus) for _, component := range management.Spec.Components { @@ -119,7 +119,7 @@ func (r *ManagementReconciler) Reconcile(ctx context.Context, req ctrl.Request) func updateComponentsStatus( components map[string]hmc.ComponentStatus, - providers *hmc.ProvidersStatus, + providers *hmc.Providers, componentName string, templateStatus hmc.TemplateStatus, err string) { @@ -130,9 +130,9 @@ func updateComponentsStatus( } if err == "" { - providers.InfrastructureProviders = append(providers.InfrastructureProviders, templateStatus.InfrastructureProviders...) - providers.BootstrapProviders = append(providers.BootstrapProviders, templateStatus.BootstrapProviders...) - providers.ControlPlaneProviders = append(providers.ControlPlaneProviders, templateStatus.ControlPlaneProviders...) + providers.InfrastructureProviders = append(providers.InfrastructureProviders, templateStatus.Providers.InfrastructureProviders...) + providers.BootstrapProviders = append(providers.BootstrapProviders, templateStatus.Providers.BootstrapProviders...) + providers.ControlPlaneProviders = append(providers.ControlPlaneProviders, templateStatus.Providers.ControlPlaneProviders...) } } diff --git a/internal/controller/template_controller.go b/internal/controller/template_controller.go index b7877cd37..ba2bf1e5b 100644 --- a/internal/controller/template_controller.go +++ b/internal/controller/template_controller.go @@ -162,13 +162,13 @@ func (r *TemplateReconciler) parseChartMetadata(template *hmc.Template, chart *c template.Status.Type = templateType if infraProviders != "" { - template.Status.InfrastructureProviders = strings.Split(infraProviders, ",") + template.Status.Providers.InfrastructureProviders = strings.Split(infraProviders, ",") } if bootstrapProviders != "" { - template.Status.BootstrapProviders = strings.Split(bootstrapProviders, ",") + template.Status.Providers.BootstrapProviders = strings.Split(bootstrapProviders, ",") } if cpProviders != "" { - template.Status.ControlPlaneProviders = strings.Split(cpProviders, ",") + template.Status.Providers.ControlPlaneProviders = strings.Split(cpProviders, ",") } return nil } diff --git a/templates/hmc/templates/deployment-crd.yaml b/templates/hmc/templates/deployment-crd.yaml index 6e39bb2be..9a8711960 100644 --- a/templates/hmc/templates/deployment-crd.yaml +++ b/templates/hmc/templates/deployment-crd.yaml @@ -12,10 +12,28 @@ spec: kind: Deployment listKind: DeploymentList plural: deployments + shortNames: + - hmc-deploy + - deploy singular: deployment scope: Namespaced versions: - - name: v1alpha1 + - additionalPrinterColumns: + - description: Valid + jsonPath: .status.valid + name: valid + type: boolean + - description: Validation Error + jsonPath: .status.validationError + name: validationError + priority: 1 + type: string + - description: Dry Run + jsonPath: .spec.dryRun + name: dryRun + priority: 1 + type: string + name: v1alpha1 schema: openAPIV3Schema: description: Deployment is the Schema for the deployments API diff --git a/templates/hmc/templates/management-crd.yaml b/templates/hmc/templates/management-crd.yaml index a5deadc0a..9027ea6b0 100644 --- a/templates/hmc/templates/management-crd.yaml +++ b/templates/hmc/templates/management-crd.yaml @@ -12,6 +12,9 @@ spec: kind: Management listKind: ManagementList plural: managements + shortNames: + - hmc-mgmt + - mgmt singular: management scope: Namespaced versions: @@ -87,19 +90,18 @@ spec: description: Providers is the list of discovered supported providers properties: bootstrap: - description: BootstrapProviders is the list of discovered bootstrap - providers + description: BootstrapProviders is the list of CAPI bootstrap providers items: type: string type: array controlPlane: - description: ControlPlaneProviders is the list of discovered control - plane providers + description: ControlPlaneProviders is the list of CAPI control plane + providers items: type: string type: array infrastructure: - description: InfrastructureProviders is the list of discovered infrastructure + description: InfrastructureProviders is the list of CAPI infrastructure providers items: type: string diff --git a/templates/hmc/templates/template-crd.yaml b/templates/hmc/templates/template-crd.yaml index 4a8acc1be..5cc2bbfbd 100644 --- a/templates/hmc/templates/template-crd.yaml +++ b/templates/hmc/templates/template-crd.yaml @@ -12,10 +12,32 @@ spec: kind: Template listKind: TemplateList plural: templates + shortNames: + - hmc-tmpl + - tmpl singular: template scope: Namespaced versions: - - name: v1alpha1 + - additionalPrinterColumns: + - description: Type + jsonPath: .status.type + name: type + type: string + - description: Valid + jsonPath: .status.valid + name: valid + type: boolean + - description: Validation Error + jsonPath: .status.validationError + name: validationError + priority: 1 + type: string + - description: Description + jsonPath: .status.description + name: description + priority: 1 + type: string + name: v1alpha1 schema: openAPIV3Schema: description: Template is the Schema for the templates API @@ -93,12 +115,6 @@ spec: status: description: TemplateStatus defines the observed state of Template properties: - bootstrapProviders: - description: BootstrapProviders specifies CAPI bootstrap providers associated - with the template. - items: - type: string - type: array chartRef: description: |- ChartRef is a reference to a source controller resource containing the @@ -134,25 +150,35 @@ spec: Config demonstrates available parameters for template customization, that can be used when creating Deployment objects. x-kubernetes-preserve-unknown-fields: true - controlPlaneProviders: - description: ControlPlaneProviders specifies CAPI control plane providers - associated with the template. - items: - type: string - type: array description: description: Description contains information about the template. type: string - infrastructureProviders: - description: InfrastructureProviders specifies CAPI infrastructure providers - associated with the template. - items: - type: string - type: array observedGeneration: description: ObservedGeneration is the last observed generation. format: int64 type: integer + providers: + description: Providers represent required/exposed CAPI providers depending + on the template type. + properties: + bootstrap: + description: BootstrapProviders is the list of CAPI bootstrap providers + items: + type: string + type: array + controlPlane: + description: ControlPlaneProviders is the list of CAPI control plane + providers + items: + type: string + type: array + infrastructure: + description: InfrastructureProviders is the list of CAPI infrastructure + providers + items: + type: string + type: array + type: object type: description: Type specifies the type of the provided template, as discovered from the Helm chart metadata.