Skip to content

Commit

Permalink
Merge pull request #47 from Kshatrix/templates
Browse files Browse the repository at this point in the history
Set template type and providers in template spec
  • Loading branch information
Kshatrix authored Jun 21, 2024
2 parents 3352d18 + e9ae6bd commit 646128d
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 11 deletions.
9 changes: 8 additions & 1 deletion api/v1alpha1/template_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ type TemplateSpec struct {
// Helm holds a reference to a Helm chart representing the HMC template
// +kubebuilder:validation:Required
Helm HelmSpec `json:"helm"`
// Type specifies the type of the provided template.
// Should be set if not present in the Helm chart metadata.
// +kubebuilder:validation:Enum=deployment;provider;core
Type TemplateType `json:"type,omitempty"`
// Providers represent required/exposed CAPI providers depending on the template type.
// Should be set if not present in the Helm chart metadata.
Providers Providers `json:"providers,omitempty"`
}

// +kubebuilder:validation:XValidation:rule="(has(self.chartName) && !has(self.chartRef)) || (!has(self.chartName) && has(self.chartRef))", message="either chartName or chartRef must be set"
Expand Down Expand Up @@ -96,7 +103,7 @@ type TemplateStatus struct {
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;provider;core
Type string `json:"type,omitempty"`
Type TemplateType `json:"type,omitempty"`
// Providers represent required/exposed CAPI providers depending on the template type.
Providers Providers `json:"providers,omitempty"`
// ObservedGeneration is the last observed generation.
Expand Down
1 change: 1 addition & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions config/crd/bases/hmc.mirantis.com_templates.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,39 @@ spec:
- message: either chartName or chartRef must be set
rule: (has(self.chartName) && !has(self.chartRef)) || (!has(self.chartName)
&& has(self.chartRef))
providers:
description: |-
Providers represent required/exposed CAPI providers depending on the template type.
Should be set if not present in the Helm chart metadata.
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.
Should be set if not present in the Helm chart metadata.
enum:
- deployment
- provider
- core
type: string
required:
- helm
type: object
Expand Down
33 changes: 23 additions & 10 deletions internal/controller/template_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,19 +150,32 @@ func (r *TemplateReconciler) parseChartMetadata(template *hmc.Template, chart *c
default:
return errNoProviderType
}
infraProviders := chart.Metadata.Annotations[hmc.ChartAnnotationInfraProviders]
bootstrapProviders := chart.Metadata.Annotations[hmc.ChartAnnotationBootstrapProviders]
cpProviders := chart.Metadata.Annotations[hmc.ChartAnnotationControlPlaneProviders]
template.Status.Type = hmc.TemplateType(templateType)

template.Status.Type = templateType
if infraProviders != "" {
template.Status.Providers.InfrastructureProviders = strings.Split(infraProviders, ",")
// the value in spec has higher priority
if len(template.Spec.Providers.InfrastructureProviders) > 0 {
template.Status.Providers.InfrastructureProviders = template.Spec.Providers.InfrastructureProviders
} else {
infraProviders := chart.Metadata.Annotations[hmc.ChartAnnotationInfraProviders]
if infraProviders != "" {
template.Status.Providers.InfrastructureProviders = strings.Split(infraProviders, ",")
}
}
if bootstrapProviders != "" {
template.Status.Providers.BootstrapProviders = strings.Split(bootstrapProviders, ",")
if len(template.Spec.Providers.BootstrapProviders) > 0 {
template.Status.Providers.BootstrapProviders = template.Spec.Providers.BootstrapProviders
} else {
bootstrapProviders := chart.Metadata.Annotations[hmc.ChartAnnotationBootstrapProviders]
if bootstrapProviders != "" {
template.Status.Providers.BootstrapProviders = strings.Split(bootstrapProviders, ",")
}
}
if cpProviders != "" {
template.Status.Providers.ControlPlaneProviders = strings.Split(cpProviders, ",")
if len(template.Spec.Providers.ControlPlaneProviders) > 0 {
template.Status.Providers.ControlPlaneProviders = template.Spec.Providers.ControlPlaneProviders
} else {
cpProviders := chart.Metadata.Annotations[hmc.ChartAnnotationControlPlaneProviders]
if cpProviders != "" {
template.Status.Providers.InfrastructureProviders = strings.Split(cpProviders, ",")
}
}
return nil
}
Expand Down
32 changes: 32 additions & 0 deletions templates/hmc/templates/template-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,38 @@ spec:
- message: either chartName or chartRef must be set
rule: (has(self.chartName) && !has(self.chartRef)) || (!has(self.chartName)
&& has(self.chartRef))
providers:
description: |-
Providers represent required/exposed CAPI providers depending on the template type.
Should be set if not present in the Helm chart metadata.
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.
Should be set if not present in the Helm chart metadata.
enum:
- deployment
- provider
- core
type: string
required:
- helm
type: object
Expand Down

0 comments on commit 646128d

Please sign in to comment.