diff --git a/api/v1alpha1/template_types.go b/api/v1alpha1/template_types.go index 4fe530887..92cdac7bb 100644 --- a/api/v1alpha1/template_types.go +++ b/api/v1alpha1/template_types.go @@ -31,10 +31,12 @@ const ( // ChartAnnotationType is an annotation containing the type of Template. ChartAnnotationType = "hmc.mirantis.com/type" - // ChartAnnotationInfraProvider is an annotation containing the CAPI provider associated with Template. - ChartAnnotationInfraProvider = "hmc.mirantis.com/infrastructure-provider" - // ChartAnnotationBootstrapProvider is an annotation containing the k8s distribution associated with Template. - ChartAnnotationBootstrapProvider = "hmc.mirantis.com/bootstrap-provider" + // ChartAnnotationInfraProviders is an annotation containing the CAPI infrastructure providers associated with Template. + ChartAnnotationInfraProviders = "hmc.mirantis.com/infrastructure-providers" + // ChartAnnotationBootstrapProviders is an annotation containing the CAPI bootstrap providers associated with Template. + ChartAnnotationBootstrapProviders = "hmc.mirantis.com/bootstrap-providers" + // ChartAnnotationControlPlaneProviders is an annotation containing the CAPI control plane providers associated with Template. + ChartAnnotationControlPlaneProviders = "hmc.mirantis.com/control-plane-providers" ) // TemplateType specifies the type of template packaged as a helm chart. @@ -44,10 +46,8 @@ type TemplateType string const ( // TemplateTypeDeployment is the type used for creating HMC Deployment objects TemplateTypeDeployment TemplateType = "deployment" - // TemplateTypeInfraProvider is the type used for adding CAPI infrastructure providers in the HMC Management object - TemplateTypeInfraProvider TemplateType = "infrastructure-provider" - // TemplateTypeBootstrapProvider is the type used for adding CAPI bootstrap providers in the HMC Management object - TemplateTypeBootstrapProvider TemplateType = "bootstrap-provider" + // TemplateTypeProvider is the type used for adding CAPI providers in the HMC Management object. + TemplateTypeProvider TemplateType = "provider" // TemplateTypeManagement is the type used for HMC management components TemplateTypeManagement TemplateType = "management" ) @@ -78,7 +78,7 @@ type HelmSpec struct { // TemplateStatus defines the observed state of Template type TemplateStatus struct { TemplateValidationStatus `json:",inline"` - // Descriptions contains information about the template. + // Description contains information about the template. // +optional Description string `json:"description,omitempty"` // Config demonstrates available parameters for template customization, @@ -90,14 +90,17 @@ type TemplateStatus struct { // +optional ChartRef *helmcontrollerv2.CrossNamespaceSourceReference `json:"chartRef,omitempty"` // Type specifies the type of the provided template, as discovered from the Helm chart metadata. - // +kubebuilder:validation:Enum=deployment;infrastructure-provider;bootstrap-provider;management + // +kubebuilder:validation:Enum=deployment;provider;management Type string `json:"type,omitempty"` - // InfrastructureProvider specifies a CAPI infrastructure provider associated with the template. + // InfrastructureProviders specifies CAPI infrastructure providers associated with the template. // +optional - InfrastructureProvider string `json:"infrastructureProvider,omitempty"` - // BootstrapProvider specifies a CAPI bootstrap provider associated with the template. + InfrastructureProviders []string `json:"infrastructureProviders,omitempty"` + // BootstrapProviders specifies CAPI bootstrap providers associated with the template. // +optional - BootstrapProvider string `json:"bootstrapProvider,omitempty"` + BootstrapProviders []string `json:"bootstrapProviders,omitempty"` + // ControlPlaneProviders specifies CAPI control plane providers associated with the template. + // +optional + ControlPlaneProviders []string `json:"controlPlaneProviders,omitempty"` // ObservedGeneration is the last observed generation. // +optional ObservedGeneration int64 `json:"observedGeneration,omitempty"` diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 6aa312a7e..8e7ea7745 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -408,6 +408,21 @@ 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) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TemplateStatus. diff --git a/charts/hmc/Chart.yaml b/charts/hmc/Chart.yaml index c599819ec..2f1e7f753 100644 --- a/charts/hmc/Chart.yaml +++ b/charts/hmc/Chart.yaml @@ -19,3 +19,5 @@ version: 0.1.0 # follow Semantic Versioning. They should reflect the version the application is using. # It is recommended to use it with quotes. appVersion: "0.1.0" +annotations: + hmc.mirantis.com/type: management diff --git a/charts/hmc/templates/template-crd.yaml b/charts/hmc/templates/template-crd.yaml index ccd1e9709..05872e0b9 100644 --- a/charts/hmc/templates/template-crd.yaml +++ b/charts/hmc/templates/template-crd.yaml @@ -93,10 +93,12 @@ spec: status: description: TemplateStatus defines the observed state of Template properties: - bootstrapProvider: - description: BootstrapProvider specifies a CAPI bootstrap provider associated + bootstrapProviders: + description: BootstrapProviders specifies CAPI bootstrap providers associated with the template. - type: string + items: + type: string + type: array chartRef: description: |- ChartRef is a reference to a source controller resource containing the @@ -132,13 +134,21 @@ 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: Descriptions contains information about the template. - type: string - infrastructureProvider: - description: InfrastructureProvider specifies a CAPI infrastructure - provider associated with the template. + 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 @@ -148,8 +158,7 @@ spec: from the Helm chart metadata. enum: - deployment - - infrastructure-provider - - bootstrap-provider + - provider - management type: string valid: diff --git a/config/crd/bases/hmc.mirantis.com_templates.yaml b/config/crd/bases/hmc.mirantis.com_templates.yaml index 45ebfe452..1b8e21016 100644 --- a/config/crd/bases/hmc.mirantis.com_templates.yaml +++ b/config/crd/bases/hmc.mirantis.com_templates.yaml @@ -92,10 +92,12 @@ spec: status: description: TemplateStatus defines the observed state of Template properties: - bootstrapProvider: - description: BootstrapProvider specifies a CAPI bootstrap provider + bootstrapProviders: + description: BootstrapProviders specifies CAPI bootstrap providers associated with the template. - type: string + items: + type: string + type: array chartRef: description: |- ChartRef is a reference to a source controller resource containing the @@ -131,13 +133,21 @@ 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: Descriptions contains information about the template. - type: string - infrastructureProvider: - description: InfrastructureProvider specifies a CAPI infrastructure - provider associated with the template. + 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 @@ -147,8 +157,7 @@ spec: discovered from the Helm chart metadata. enum: - deployment - - infrastructure-provider - - bootstrap-provider + - provider - management type: string valid: diff --git a/internal/controller/template_controller.go b/internal/controller/template_controller.go index 5fd6abe19..404179300 100644 --- a/internal/controller/template_controller.go +++ b/internal/controller/template_controller.go @@ -20,6 +20,7 @@ import ( "context" "encoding/json" "fmt" + "strings" "time" v2 "github.com/fluxcd/helm-controller/api/v2" @@ -45,10 +46,8 @@ const ( ) var ( - errNoInfraProvider = fmt.Errorf("no infra provider specified: %s chart annotation must not be empty", hmc.ChartAnnotationInfraProvider) - errNoBootstrapProvider = fmt.Errorf("no bootstrap provider specified: %s chart annotation must not be empty", hmc.ChartAnnotationBootstrapProvider) - errNoProviderType = fmt.Errorf("template type is not supported: %s chart annotation must be one of [%s/%s/%s]", - hmc.ChartAnnotationType, hmc.TemplateTypeDeployment, hmc.ChartAnnotationInfraProvider, hmc.ChartAnnotationBootstrapProvider) + errNoProviderType = fmt.Errorf("template type is not supported: %s chart annotation must be one of [%s/%s]", + hmc.ChartAnnotationType, hmc.TemplateTypeDeployment, hmc.TemplateTypeProvider) ) // TemplateReconciler reconciles a Template object @@ -152,32 +151,25 @@ func (r *TemplateReconciler) parseChartMetadata(template *hmc.Template, chart *c return fmt.Errorf("chart metadata is empty") } templateType := chart.Metadata.Annotations[hmc.ChartAnnotationType] - infraProvider := chart.Metadata.Annotations[hmc.ChartAnnotationInfraProvider] - bootstrapProvider := chart.Metadata.Annotations[hmc.ChartAnnotationBootstrapProvider] - switch hmc.TemplateType(templateType) { - case hmc.TemplateTypeDeployment: - if infraProvider == "" { - return errNoInfraProvider - } - if bootstrapProvider == "" { - return errNoBootstrapProvider - } - case hmc.TemplateTypeInfraProvider: - if infraProvider == "" { - return errNoInfraProvider - } - case hmc.TemplateTypeBootstrapProvider: - if bootstrapProvider == "" { - return errNoBootstrapProvider - } - case hmc.TemplateTypeManagement: + case hmc.TemplateTypeDeployment, hmc.TemplateTypeProvider, hmc.TemplateTypeManagement: default: return errNoProviderType } + infraProviders := chart.Metadata.Annotations[hmc.ChartAnnotationInfraProviders] + bootstrapProviders := chart.Metadata.Annotations[hmc.ChartAnnotationBootstrapProviders] + cpProviders := chart.Metadata.Annotations[hmc.ChartAnnotationControlPlaneProviders] + template.Status.Type = templateType - template.Status.InfrastructureProvider = infraProvider - template.Status.BootstrapProvider = bootstrapProvider + if infraProviders != "" { + template.Status.InfrastructureProviders = strings.Split(infraProviders, ",") + } + if bootstrapProviders != "" { + template.Status.BootstrapProviders = strings.Split(bootstrapProviders, ",") + } + if cpProviders != "" { + template.Status.ControlPlaneProviders = strings.Split(cpProviders, ",") + } return nil } diff --git a/templates/aws-hosted-cp/Chart.yaml b/templates/aws-hosted-cp/Chart.yaml index d071652c3..625d2d57f 100644 --- a/templates/aws-hosted-cp/Chart.yaml +++ b/templates/aws-hosted-cp/Chart.yaml @@ -13,3 +13,8 @@ version: 0.1.0 # follow Semantic Versioning. They should reflect the version the application is using. # It is recommended to use it with quotes. appVersion: "0.1.0" +annotations: + hmc.mirantis.com/type: deployment + hmc.mirantis.com/infrastructure-providers: aws + hmc.mirantis.com/controlplane-providers: k0smotron + hmc.mirantis.com/bootstrap-providers: k0s diff --git a/templates/aws-standalone-cp/Chart.yaml b/templates/aws-standalone-cp/Chart.yaml index 44cdd3f36..360a23c2f 100644 --- a/templates/aws-standalone-cp/Chart.yaml +++ b/templates/aws-standalone-cp/Chart.yaml @@ -12,3 +12,8 @@ version: 0.1.0 # follow Semantic Versioning. They should reflect the version the application is using. # It is recommended to use it with quotes. appVersion: "0.1.0" +annotations: + hmc.mirantis.com/type: deployment + hmc.mirantis.com/infrastructure-providers: aws + hmc.mirantis.com/controlplane-providers: k0s + hmc.mirantis.com/bootstrap-providers: k0s