diff --git a/Makefile b/Makefile index 3e52526af..396c640ce 100644 --- a/Makefile +++ b/Makefile @@ -55,7 +55,7 @@ help: ## Display this help. .PHONY: manifests manifests: controller-gen ## Generate CustomResourceDefinition objects. - $(CONTROLLER_GEN) crd paths="./..." output:crd:artifacts:config=templates/hmc/templates/crds + $(CONTROLLER_GEN) crd paths="./..." output:crd:artifacts:config=$(PROVIDER_TEMPLATES_DIR)/hmc/templates/crds .PHONY: generate generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations. @@ -63,9 +63,9 @@ generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and .PHONY: set-hmc-version set-hmc-version: yq - $(YQ) eval '.version = "$(VERSION)"' -i templates/hmc/Chart.yaml - $(YQ) eval '.version = "$(VERSION)"' -i templates/hmc-templates/Chart.yaml - $(YQ) eval '.image.tag = "$(VERSION)"' -i templates/hmc/values.yaml + $(YQ) eval '.version = "$(VERSION)"' -i $(PROVIDER_TEMPLATES_DIR)/hmc/Chart.yaml + $(YQ) eval '.version = "$(VERSION)"' -i $(PROVIDER_TEMPLATES_DIR)/hmc-templates/Chart.yaml + $(YQ) eval '.image.tag = "$(VERSION)"' -i $(PROVIDER_TEMPLATES_DIR)/hmc/values.yaml .PHONY: hmc-chart-release hmc-chart-release: set-hmc-version templates-generate ## Generate hmc helm chart @@ -74,7 +74,7 @@ hmc-chart-release: set-hmc-version templates-generate ## Generate hmc helm chart hmc-dist-release: $(HELM) $(YQ) @mkdir -p dist @printf "apiVersion: v1\nkind: Namespace\nmetadata:\n name: $(NAMESPACE)\n" > dist/install.yaml - $(HELM) template -n $(NAMESPACE) hmc templates/hmc >> dist/install.yaml + $(HELM) template -n $(NAMESPACE) hmc $(PROVIDER_TEMPLATES_DIR)/hmc >> dist/install.yaml $(YQ) eval -i '.metadata.namespace = "hmc-system"' dist/install.yaml $(YQ) eval -i '.metadata.annotations."meta.helm.sh/release-name" = "hmc"' dist/install.yaml $(YQ) eval -i '.metadata.annotations."meta.helm.sh/release-namespace" = "hmc-system"' dist/install.yaml @@ -123,23 +123,27 @@ add-license: addlicense ##@ Build TEMPLATES_DIR := templates +PROVIDER_TEMPLATES_DIR := $(TEMPLATES_DIR)/provider CHARTS_PACKAGE_DIR ?= $(LOCALBIN)/charts $(CHARTS_PACKAGE_DIR): | $(LOCALBIN) rm -rf $(CHARTS_PACKAGE_DIR) mkdir -p $(CHARTS_PACKAGE_DIR) -CHARTS = $(patsubst $(TEMPLATES_DIR)/%,%,$(wildcard $(TEMPLATES_DIR)/*)) +TEMPLATE_FOLDERS = $(patsubst $(TEMPLATES_DIR)/%,%,$(wildcard $(TEMPLATES_DIR)/*)) .PHONY: helm-package -helm-package: helm - @make $(patsubst %,package-chart-%,$(CHARTS)) +helm-package: $(CHARTS_PACKAGE_DIR) helm + @make $(patsubst %,package-%-templates,$(TEMPLATE_FOLDERS)) + +package-%-templates: + @make TEMPLATES_SUBDIR=$(TEMPLATES_DIR)/$* $(patsubst %,package-chart-%,$(shell ls $(TEMPLATES_DIR)/$*)) lint-chart-%: - $(HELM) dependency update $(TEMPLATES_DIR)/$* - $(HELM) lint --strict $(TEMPLATES_DIR)/$* + $(HELM) dependency update $(TEMPLATES_SUBDIR)/$* + $(HELM) lint --strict $(TEMPLATES_SUBDIR)/$* -package-chart-%: $(CHARTS_PACKAGE_DIR) lint-chart-% - $(HELM) package --destination $(CHARTS_PACKAGE_DIR) $(TEMPLATES_DIR)/$* +package-chart-%: lint-chart-% + $(HELM) package --destination $(CHARTS_PACKAGE_DIR) $(TEMPLATES_SUBDIR)/$* LD_FLAGS?= -s -w LD_FLAGS += -X github.com/Mirantis/hmc/internal/build.Version=$(VERSION) @@ -232,7 +236,7 @@ registry-undeploy: .PHONY: hmc-deploy hmc-deploy: helm - $(HELM) upgrade --values $(HMC_VALUES) --reuse-values --install --create-namespace hmc templates/hmc -n $(NAMESPACE) + $(HELM) upgrade --values $(HMC_VALUES) --reuse-values --install --create-namespace hmc $(PROVIDER_TEMPLATES_DIR)/hmc -n $(NAMESPACE) .PHONY: dev-deploy dev-deploy: ## Deploy HMC helm chart to the K8s cluster specified in ~/.kube/config. @@ -279,7 +283,7 @@ dev-push: docker-build helm-push .PHONY: dev-templates dev-templates: templates-generate - $(KUBECTL) -n $(NAMESPACE) apply -f templates/hmc-templates/files/templates + $(KUBECTL) -n $(NAMESPACE) apply -f $(PROVIDER_TEMPLATES_DIR)/hmc-templates/files/templates .PHONY: dev-aws-creds dev-aws-creds: yq diff --git a/api/v1alpha1/clustertemplate_types.go b/api/v1alpha1/clustertemplate_types.go new file mode 100644 index 000000000..390cd64d5 --- /dev/null +++ b/api/v1alpha1/clustertemplate_types.go @@ -0,0 +1,62 @@ +// 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 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// +kubebuilder:object:root=true +// +kubebuilder:subresource:status +// +kubebuilder:resource:shortName=clustertmpl +// +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 + +// ClusterTemplate is the Schema for the cluster templates API +type ClusterTemplate struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec ClusterTemplateSpec `json:"spec,omitempty"` + Status ClusterTemplateStatus `json:"status,omitempty"` +} + +// +kubebuilder:object:root=true + +// ClusterTemplateList contains a list of ClusterTemplate +type ClusterTemplateList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []ClusterTemplate `json:"items"` +} + +// ClusterTemplateSpec defines the desired state of ClusterTemplate +type ClusterTemplateSpec struct { + TemplateSpecMixin `json:",inline"` +} + +// ClusterTemplateStatus defines the observed state of ClusterTemplate +type ClusterTemplateStatus struct { + TemplateStatusMixin `json:",inline"` +} + +func (t *ClusterTemplate) GetSpec() *TemplateSpecMixin { + return &t.Spec.TemplateSpecMixin +} + +func (t *ClusterTemplate) GetStatus() *TemplateStatusMixin { + return &t.Status.TemplateStatusMixin +} diff --git a/api/v1alpha1/providertemplate_types.go b/api/v1alpha1/providertemplate_types.go new file mode 100644 index 000000000..ef909e1a2 --- /dev/null +++ b/api/v1alpha1/providertemplate_types.go @@ -0,0 +1,62 @@ +// 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 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// +kubebuilder:object:root=true +// +kubebuilder:subresource:status +// +kubebuilder:resource:shortName=providertmpl,scope=Cluster +// +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 + +// ProviderTemplate is the Schema for the provider templates API +type ProviderTemplate struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec ProviderTemplateSpec `json:"spec,omitempty"` + Status ProviderTemplateStatus `json:"status,omitempty"` +} + +// +kubebuilder:object:root=true + +// ProviderTemplateList contains a list of ProviderTemplate +type ProviderTemplateList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []ProviderTemplate `json:"items"` +} + +// ProviderTemplateSpec defines the desired state of ProviderTemplate +type ProviderTemplateSpec struct { + TemplateSpecMixin `json:",inline"` +} + +// ProviderTemplateStatus defines the observed state of ProviderTemplate +type ProviderTemplateStatus struct { + TemplateStatusMixin `json:",inline"` +} + +func (t *ProviderTemplate) GetSpec() *TemplateSpecMixin { + return &t.Spec.TemplateSpecMixin +} + +func (t *ProviderTemplate) GetStatus() *TemplateStatusMixin { + return &t.Status.TemplateStatusMixin +} diff --git a/api/v1alpha1/servicetemplate_types.go b/api/v1alpha1/servicetemplate_types.go new file mode 100644 index 000000000..4c5dc0cc2 --- /dev/null +++ b/api/v1alpha1/servicetemplate_types.go @@ -0,0 +1,62 @@ +// 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 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// +kubebuilder:object:root=true +// +kubebuilder:subresource:status +// +kubebuilder:resource:shortName=svctmpl +// +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 + +// ServiceTemplate is the Schema for the service templates API +type ServiceTemplate struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec ServiceTemplateSpec `json:"spec,omitempty"` + Status ServiceTemplateStatus `json:"status,omitempty"` +} + +// +kubebuilder:object:root=true + +// ServiceTemplateList contains a list of ServiceTemplate +type ServiceTemplateList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []ServiceTemplate `json:"items"` +} + +// ServiceTemplateSpec defines the desired state of ServiceTemplate +type ServiceTemplateSpec struct { + TemplateSpecMixin `json:",inline"` +} + +// ServiceTemplateStatus defines the observed state of ServiceTemplate +type ServiceTemplateStatus struct { + TemplateStatusMixin `json:",inline"` +} + +func (t *ServiceTemplate) GetSpec() *TemplateSpecMixin { + return &t.Spec.TemplateSpecMixin +} + +func (t *ServiceTemplate) GetStatus() *TemplateStatusMixin { + return &t.Status.TemplateStatusMixin +} diff --git a/api/v1alpha1/template_types.go b/api/v1alpha1/template_types.go index 529d3e939..67ad60060 100644 --- a/api/v1alpha1/template_types.go +++ b/api/v1alpha1/template_types.go @@ -15,20 +15,11 @@ package v1alpha1 import ( - apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - helmcontrollerv2 "github.com/fluxcd/helm-controller/api/v2" + apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" ) const ( - // ManagementKind is the string representation of a Management. - ManagementKind = "Management" - // TemplateKind is the string representation of a Template. - TemplateKind = "Template" - - // ChartAnnotationType is an annotation containing the type of Template. - ChartAnnotationType = "hmc.mirantis.com/type" // 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. @@ -37,28 +28,11 @@ const ( ChartAnnotationControlPlaneProviders = "hmc.mirantis.com/control-plane-providers" ) -// TemplateType specifies the type of template packaged as a helm chart. -// Should be provided in the chart Annotations. -type TemplateType string - -const ( - // TemplateTypeDeployment is the type used for creating HMC ManagedCluster objects - TemplateTypeDeployment TemplateType = "deployment" - // TemplateTypeProvider is the type used for adding CAPI providers in the HMC Management object. - TemplateTypeProvider TemplateType = "provider" - // TemplateTypeCore is the type used for HMC and CAPI core components - TemplateTypeCore TemplateType = "core" -) - -// TemplateSpec defines the desired state of Template -type TemplateSpec struct { +// TemplateSpecMixin is a Template configuration common for all Template types +type TemplateSpecMixin 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"` @@ -80,8 +54,8 @@ type HelmSpec struct { ChartRef *helmcontrollerv2.CrossNamespaceSourceReference `json:"chartRef,omitempty"` } -// TemplateStatus defines the observed state of Template -type TemplateStatus struct { +// TemplateStatusMixin defines the observed state of Template common for all Template types +type TemplateStatusMixin struct { TemplateValidationStatus `json:",inline"` // Description contains information about the template. // +optional @@ -94,9 +68,6 @@ type TemplateStatus struct { // Helm chart representing the template. // +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;provider;core - 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. @@ -112,32 +83,8 @@ type TemplateValidationStatus struct { ValidationError string `json:"validationError,omitempty"` } -//+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 { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - - Spec TemplateSpec `json:"spec,omitempty"` - Status TemplateStatus `json:"status,omitempty"` -} - -//+kubebuilder:object:root=true - -// TemplateList contains a list of Template -type TemplateList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata,omitempty"` - Items []Template `json:"items"` -} - func init() { - SchemeBuilder.Register(&Template{}, &TemplateList{}) + SchemeBuilder.Register(&ClusterTemplate{}, &ClusterTemplateList{}) + SchemeBuilder.Register(&ServiceTemplate{}, &ServiceTemplateList{}) + SchemeBuilder.Register(&ProviderTemplate{}, &ProviderTemplateList{}) } diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 27106101f..ff5d2092a 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -25,6 +25,97 @@ import ( runtime "k8s.io/apimachinery/pkg/runtime" ) +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ClusterTemplate) DeepCopyInto(out *ClusterTemplate) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + in.Status.DeepCopyInto(&out.Status) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterTemplate. +func (in *ClusterTemplate) DeepCopy() *ClusterTemplate { + if in == nil { + return nil + } + out := new(ClusterTemplate) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ClusterTemplate) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ClusterTemplateList) DeepCopyInto(out *ClusterTemplateList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]ClusterTemplate, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterTemplateList. +func (in *ClusterTemplateList) DeepCopy() *ClusterTemplateList { + if in == nil { + return nil + } + out := new(ClusterTemplateList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ClusterTemplateList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ClusterTemplateSpec) DeepCopyInto(out *ClusterTemplateSpec) { + *out = *in + in.TemplateSpecMixin.DeepCopyInto(&out.TemplateSpecMixin) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterTemplateSpec. +func (in *ClusterTemplateSpec) DeepCopy() *ClusterTemplateSpec { + if in == nil { + return nil + } + out := new(ClusterTemplateSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ClusterTemplateStatus) DeepCopyInto(out *ClusterTemplateStatus) { + *out = *in + in.TemplateStatusMixin.DeepCopyInto(&out.TemplateStatusMixin) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterTemplateStatus. +func (in *ClusterTemplateStatus) DeepCopy() *ClusterTemplateStatus { + if in == nil { + return nil + } + out := new(ClusterTemplateStatus) + in.DeepCopyInto(out) + 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 @@ -307,6 +398,97 @@ func (in *ManagementStatus) DeepCopy() *ManagementStatus { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ProviderTemplate) DeepCopyInto(out *ProviderTemplate) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + in.Status.DeepCopyInto(&out.Status) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ProviderTemplate. +func (in *ProviderTemplate) DeepCopy() *ProviderTemplate { + if in == nil { + return nil + } + out := new(ProviderTemplate) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ProviderTemplate) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ProviderTemplateList) DeepCopyInto(out *ProviderTemplateList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]ProviderTemplate, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ProviderTemplateList. +func (in *ProviderTemplateList) DeepCopy() *ProviderTemplateList { + if in == nil { + return nil + } + out := new(ProviderTemplateList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ProviderTemplateList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ProviderTemplateSpec) DeepCopyInto(out *ProviderTemplateSpec) { + *out = *in + in.TemplateSpecMixin.DeepCopyInto(&out.TemplateSpecMixin) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ProviderTemplateSpec. +func (in *ProviderTemplateSpec) DeepCopy() *ProviderTemplateSpec { + if in == nil { + return nil + } + out := new(ProviderTemplateSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ProviderTemplateStatus) DeepCopyInto(out *ProviderTemplateStatus) { + *out = *in + in.TemplateStatusMixin.DeepCopyInto(&out.TemplateStatusMixin) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ProviderTemplateStatus. +func (in *ProviderTemplateStatus) DeepCopy() *ProviderTemplateStatus { + if in == nil { + return nil + } + out := new(ProviderTemplateStatus) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Providers) DeepCopyInto(out *Providers) { *out = *in @@ -338,7 +520,7 @@ func (in *Providers) DeepCopy() *Providers { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Template) DeepCopyInto(out *Template) { +func (in *ServiceTemplate) DeepCopyInto(out *ServiceTemplate) { *out = *in out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) @@ -346,18 +528,18 @@ func (in *Template) DeepCopyInto(out *Template) { in.Status.DeepCopyInto(&out.Status) } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Template. -func (in *Template) DeepCopy() *Template { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ServiceTemplate. +func (in *ServiceTemplate) DeepCopy() *ServiceTemplate { if in == nil { return nil } - out := new(Template) + out := new(ServiceTemplate) in.DeepCopyInto(out) return out } // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *Template) DeepCopyObject() runtime.Object { +func (in *ServiceTemplate) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c } @@ -365,31 +547,31 @@ func (in *Template) DeepCopyObject() runtime.Object { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *TemplateList) DeepCopyInto(out *TemplateList) { +func (in *ServiceTemplateList) DeepCopyInto(out *ServiceTemplateList) { *out = *in out.TypeMeta = in.TypeMeta in.ListMeta.DeepCopyInto(&out.ListMeta) if in.Items != nil { in, out := &in.Items, &out.Items - *out = make([]Template, len(*in)) + *out = make([]ServiceTemplate, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } } } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TemplateList. -func (in *TemplateList) DeepCopy() *TemplateList { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ServiceTemplateList. +func (in *ServiceTemplateList) DeepCopy() *ServiceTemplateList { if in == nil { return nil } - out := new(TemplateList) + out := new(ServiceTemplateList) in.DeepCopyInto(out) return out } // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *TemplateList) DeepCopyObject() runtime.Object { +func (in *ServiceTemplateList) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c } @@ -397,24 +579,56 @@ func (in *TemplateList) DeepCopyObject() runtime.Object { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *TemplateSpec) DeepCopyInto(out *TemplateSpec) { +func (in *ServiceTemplateSpec) DeepCopyInto(out *ServiceTemplateSpec) { + *out = *in + in.TemplateSpecMixin.DeepCopyInto(&out.TemplateSpecMixin) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ServiceTemplateSpec. +func (in *ServiceTemplateSpec) DeepCopy() *ServiceTemplateSpec { + if in == nil { + return nil + } + out := new(ServiceTemplateSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ServiceTemplateStatus) DeepCopyInto(out *ServiceTemplateStatus) { + *out = *in + in.TemplateStatusMixin.DeepCopyInto(&out.TemplateStatusMixin) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ServiceTemplateStatus. +func (in *ServiceTemplateStatus) DeepCopy() *ServiceTemplateStatus { + if in == nil { + return nil + } + out := new(ServiceTemplateStatus) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TemplateSpecMixin) DeepCopyInto(out *TemplateSpecMixin) { *out = *in in.Helm.DeepCopyInto(&out.Helm) in.Providers.DeepCopyInto(&out.Providers) } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TemplateSpec. -func (in *TemplateSpec) DeepCopy() *TemplateSpec { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TemplateSpecMixin. +func (in *TemplateSpecMixin) DeepCopy() *TemplateSpecMixin { if in == nil { return nil } - out := new(TemplateSpec) + out := new(TemplateSpecMixin) in.DeepCopyInto(out) return out } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *TemplateStatus) DeepCopyInto(out *TemplateStatus) { +func (in *TemplateStatusMixin) DeepCopyInto(out *TemplateStatusMixin) { *out = *in out.TemplateValidationStatus = in.TemplateValidationStatus if in.Config != nil { @@ -430,12 +644,12 @@ func (in *TemplateStatus) DeepCopyInto(out *TemplateStatus) { in.Providers.DeepCopyInto(&out.Providers) } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TemplateStatus. -func (in *TemplateStatus) DeepCopy() *TemplateStatus { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TemplateStatusMixin. +func (in *TemplateStatusMixin) DeepCopy() *TemplateStatusMixin { if in == nil { return nil } - out := new(TemplateStatus) + out := new(TemplateStatusMixin) in.DeepCopyInto(out) return out } diff --git a/cmd/main.go b/cmd/main.go index b155b2cb1..81504348d 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -171,11 +171,34 @@ func main() { currentNamespace := utils.CurrentNamespace() - if err = (&controller.TemplateReconciler{ - Client: mgr.GetClient(), - Scheme: mgr.GetScheme(), + if err = (&controller.ClusterTemplateReconciler{ + TemplateReconciler: controller.TemplateReconciler{ + Client: mgr.GetClient(), + Scheme: mgr.GetScheme(), + SystemNamespace: currentNamespace, + }, + }).SetupWithManager(mgr); err != nil { + setupLog.Error(err, "unable to create controller", "controller", "ClusterTemplate") + os.Exit(1) + } + if err = (&controller.ServiceTemplateReconciler{ + TemplateReconciler: controller.TemplateReconciler{ + Client: mgr.GetClient(), + Scheme: mgr.GetScheme(), + SystemNamespace: currentNamespace, + }, }).SetupWithManager(mgr); err != nil { - setupLog.Error(err, "unable to create controller", "controller", "Template") + setupLog.Error(err, "unable to create controller", "controller", "ServiceTemplate") + os.Exit(1) + } + if err = (&controller.ProviderTemplateReconciler{ + TemplateReconciler: controller.TemplateReconciler{ + Client: mgr.GetClient(), + Scheme: mgr.GetScheme(), + SystemNamespace: currentNamespace, + }, + }).SetupWithManager(mgr); err != nil { + setupLog.Error(err, "unable to create controller", "controller", "ProviderTemplate") os.Exit(1) } if err = (&controller.ManagedClusterReconciler{ @@ -245,8 +268,16 @@ func main() { setupLog.Error(err, "unable to create webhook", "webhook", "Management") os.Exit(1) } - if err := (&hmcwebhook.TemplateValidator{}).SetupWebhookWithManager(mgr); err != nil { - setupLog.Error(err, "unable to create webhook", "webhook", "Template") + if err := (&hmcwebhook.ClusterTemplateValidator{}).SetupWebhookWithManager(mgr); err != nil { + setupLog.Error(err, "unable to create webhook", "webhook", "ClusterTemplate") + os.Exit(1) + } + if err := (&hmcwebhook.ServiceTemplateValidator{}).SetupWebhookWithManager(mgr); err != nil { + setupLog.Error(err, "unable to create webhook", "webhook", "ServiceTemplate") + os.Exit(1) + } + if err := (&hmcwebhook.ProviderTemplateValidator{}).SetupWebhookWithManager(mgr); err != nil { + setupLog.Error(err, "unable to create webhook", "webhook", "ProviderTemplate") os.Exit(1) } } diff --git a/hack/templates.sh b/hack/templates.sh index a17a222ee..c23f6da30 100755 --- a/hack/templates.sh +++ b/hack/templates.sh @@ -19,22 +19,26 @@ set -eu # Directory containing HMC templates TEMPLATES_DIR=${TEMPLATES_DIR:-templates} # Output directory for the generated Template manifests -TEMPLATES_OUTPUT_DIR=${TEMPLATES_OUTPUT_DIR:-templates/hmc-templates/files/templates} +TEMPLATES_OUTPUT_DIR=${TEMPLATES_OUTPUT_DIR:-templates/provider/hmc-templates/files/templates} # The name of the HMC templates helm chart HMC_TEMPLATES_CHART_NAME='hmc-templates' mkdir -p $TEMPLATES_OUTPUT_DIR -rm $TEMPLATES_OUTPUT_DIR/*.yaml +rm -f $TEMPLATES_OUTPUT_DIR/*.yaml -for chart in $TEMPLATES_DIR/*; do - if [ -d "$chart" ]; then - name=$(grep '^name:' $chart/Chart.yaml | awk '{print $2}') - if [ "$name" = "$HMC_TEMPLATES_CHART_NAME" ]; then continue; fi - version=$(grep '^version:' $chart/Chart.yaml | awk '{print $2}') +for type in "$TEMPLATES_DIR"/*; do + kind="$(echo "${type#*/}Template" | awk '{$1=toupper(substr($1,0,1))substr($1,2)}1')" + for chart in "$type"/*; do + if [ -d "$chart" ]; then + name=$(grep '^name:' $chart/Chart.yaml | awk '{print $2}') + if [ "$name" = "$HMC_TEMPLATES_CHART_NAME" ]; then continue; fi + version=$(grep '^version:' $chart/Chart.yaml | awk '{print $2}') - cat < $TEMPLATES_OUTPUT_DIR/$name.yaml + cat < $TEMPLATES_OUTPUT_DIR/$name.yaml apiVersion: hmc.mirantis.com/v1alpha1 -kind: Template +kind: $kind +EOF + cat <> $TEMPLATES_OUTPUT_DIR/$name.yaml metadata: name: $name spec: @@ -43,6 +47,7 @@ spec: chartVersion: $version EOF - echo "Generated $TEMPLATES_OUTPUT_DIR/$name.yaml" - fi + echo "Generated $TEMPLATES_OUTPUT_DIR/$name.yaml" + fi + done done diff --git a/internal/controller/managedcluster_controller.go b/internal/controller/managedcluster_controller.go index d7e2561e6..5f3c5ea03 100644 --- a/internal/controller/managedcluster_controller.go +++ b/internal/controller/managedcluster_controller.go @@ -167,7 +167,7 @@ func (r *ManagedClusterReconciler) Update(ctx context.Context, l logr.Logger, ma err = errors.Join(err, r.updateStatus(ctx, managedCluster)) }() - template := &hmc.Template{} + template := &hmc.ClusterTemplate{} templateRef := types.NamespacedName{Name: managedCluster.Spec.Template, Namespace: r.SystemNamespace} if err := r.Get(ctx, templateRef, template); err != nil { l.Error(err, "Failed to get Template") @@ -183,17 +183,6 @@ func (r *ManagedClusterReconciler) Update(ctx context.Context, l logr.Logger, ma }) return ctrl.Result{}, err } - templateType := template.Status.Type - if templateType != hmc.TemplateTypeDeployment { - errMsg := "only templates of 'managedCluster' type are supported" - apimeta.SetStatusCondition(managedCluster.GetConditions(), metav1.Condition{ - Type: hmc.TemplateReadyCondition, - Status: metav1.ConditionFalse, - Reason: hmc.FailedReason, - Message: errMsg, - }) - return ctrl.Result{}, errors.New(errMsg) - } if !template.Status.Valid { errMsg := "provided template is not marked as valid" apimeta.SetStatusCondition(managedCluster.GetConditions(), metav1.Condition{ diff --git a/internal/controller/managedcluster_controller_test.go b/internal/controller/managedcluster_controller_test.go index edd2625d4..525237158 100644 --- a/internal/controller/managedcluster_controller_test.go +++ b/internal/controller/managedcluster_controller_test.go @@ -45,7 +45,7 @@ var _ = Describe("ManagedCluster Controller", func() { Namespace: "default", } managedCluster := &hmc.ManagedCluster{} - template := &hmc.Template{} + template := &hmc.ClusterTemplate{} management := &hmc.Management{} namespace := &v1.Namespace{} @@ -64,30 +64,32 @@ var _ = Describe("ManagedCluster Controller", func() { By("creating the custom resource for the Kind Template") err = k8sClient.Get(ctx, typeNamespacedName, template) if err != nil && errors.IsNotFound(err) { - template = &hmc.Template{ + template = &hmc.ClusterTemplate{ ObjectMeta: metav1.ObjectMeta{ Name: templateName, Namespace: utils.DefaultSystemNamespace, }, - Spec: hmc.TemplateSpec{ - Helm: hmc.HelmSpec{ - ChartRef: &hcv2.CrossNamespaceSourceReference{ - Kind: "HelmChart", - Name: "ref-test", - Namespace: "default", + Spec: hmc.ClusterTemplateSpec{ + TemplateSpecMixin: hmc.TemplateSpecMixin{ + Helm: hmc.HelmSpec{ + ChartRef: &hcv2.CrossNamespaceSourceReference{ + Kind: "HelmChart", + Name: "ref-test", + Namespace: "default", + }, }, }, - Type: hmc.TemplateTypeDeployment, }, } Expect(k8sClient.Create(ctx, template)).To(Succeed()) - template.Status = hmc.TemplateStatus{ - Type: hmc.TemplateTypeDeployment, - TemplateValidationStatus: hmc.TemplateValidationStatus{ - Valid: true, - }, - Config: &apiextensionsv1.JSON{ - Raw: []byte(`{"foo":"bar"}`), + template.Status = hmc.ClusterTemplateStatus{ + TemplateStatusMixin: hmc.TemplateStatusMixin{ + TemplateValidationStatus: hmc.TemplateValidationStatus{ + Valid: true, + }, + Config: &apiextensionsv1.JSON{ + Raw: []byte(`{"foo":"bar"}`), + }, }, } Expect(k8sClient.Status().Update(ctx, template)).To(Succeed()) diff --git a/internal/controller/management_controller.go b/internal/controller/management_controller.go index a86be05c6..a13893104 100644 --- a/internal/controller/management_controller.go +++ b/internal/controller/management_controller.go @@ -100,19 +100,18 @@ func (r *ManagementReconciler) Update(ctx context.Context, management *hmc.Manag components := wrappedComponents(management) for _, component := range components { - template := &hmc.Template{} + template := &hmc.ProviderTemplate{} err := r.Get(ctx, types.NamespacedName{ - Namespace: r.SystemNamespace, - Name: component.Template, + Name: component.Template, }, template) if err != nil { - errMsg := fmt.Sprintf("Failed to get Template %s/%s: %s", r.SystemNamespace, component.Template, err) + errMsg := fmt.Sprintf("Failed to get ProviderTemplate %s: %s", component.Template, err) updateComponentsStatus(detectedComponents, &detectedProviders, component.Template, template.Status, errMsg) errs = errors.Join(errs, errors.New(errMsg)) continue } if !template.Status.Valid { - errMsg := fmt.Sprintf("Template %s/%s is not marked as valid", r.SystemNamespace, component.Template) + errMsg := fmt.Sprintf("Template %s is not marked as valid", component.Template) updateComponentsStatus(detectedComponents, &detectedProviders, component.Template, template.Status, errMsg) errs = errors.Join(errs, errors.New(errMsg)) continue @@ -283,7 +282,7 @@ func updateComponentsStatus( components map[string]hmc.ComponentStatus, providers *hmc.Providers, componentName string, - templateStatus hmc.TemplateStatus, + templateStatus hmc.ProviderTemplateStatus, err string, ) { components[componentName] = hmc.ComponentStatus{ diff --git a/internal/controller/suite_test.go b/internal/controller/suite_test.go index 691cf93de..f389a60a5 100644 --- a/internal/controller/suite_test.go +++ b/internal/controller/suite_test.go @@ -76,12 +76,14 @@ var _ = BeforeSuite(func() { ctx, cancel = context.WithCancel(context.TODO()) - validatingWebhooks, mutatingWebhooks, err := loadWebhooks(filepath.Join("..", "..", "templates", "hmc", "templates", "webhooks.yaml")) + validatingWebhooks, mutatingWebhooks, err := loadWebhooks( + filepath.Join("..", "..", "templates", "provider", "hmc", "templates", "webhooks.yaml"), + ) Expect(err).NotTo(HaveOccurred()) testEnv = &envtest.Environment{ CRDDirectoryPaths: []string{ - filepath.Join("..", "..", "templates", "hmc", "templates", "crds"), + filepath.Join("..", "..", "templates", "provider", "hmc", "templates", "crds"), filepath.Join("..", "..", "bin", "crd")}, ErrorIfCRDPathMissing: true, @@ -139,7 +141,13 @@ var _ = BeforeSuite(func() { err = (&hmcwebhook.ManagementValidator{}).SetupWebhookWithManager(mgr) Expect(err).NotTo(HaveOccurred()) - err = (&hmcwebhook.TemplateValidator{}).SetupWebhookWithManager(mgr) + err = (&hmcwebhook.ClusterTemplateValidator{}).SetupWebhookWithManager(mgr) + Expect(err).NotTo(HaveOccurred()) + + err = (&hmcwebhook.ServiceTemplateValidator{}).SetupWebhookWithManager(mgr) + Expect(err).NotTo(HaveOccurred()) + + err = (&hmcwebhook.ProviderTemplateValidator{}).SetupWebhookWithManager(mgr) Expect(err).NotTo(HaveOccurred()) go func() { diff --git a/internal/controller/template_controller.go b/internal/controller/template_controller.go index eb0ffe0c4..ed16218ed 100644 --- a/internal/controller/template_controller.go +++ b/internal/controller/template_controller.go @@ -43,43 +43,100 @@ const ( defaultReconcileInterval = 10 * time.Minute ) -var ( - errNoProviderType = fmt.Errorf("template type is not supported: %s chart annotation must be one of [%s/%s/%s]", - hmc.ChartAnnotationType, hmc.TemplateTypeDeployment, hmc.TemplateTypeProvider, hmc.TemplateTypeCore) -) - // TemplateReconciler reconciles a Template object type TemplateReconciler struct { client.Client Scheme *runtime.Scheme + SystemNamespace string downloadHelmChartFunc func(context.Context, *sourcev1.Artifact) (*chart.Chart, error) } -func (r *TemplateReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { - l := log.FromContext(ctx).WithValues("TemplateController", req.NamespacedName) - l.Info("Reconciling Template") +type ClusterTemplateReconciler struct { + TemplateReconciler +} + +type ServiceTemplateReconciler struct { + TemplateReconciler +} + +type ProviderTemplateReconciler struct { + TemplateReconciler +} - template := &hmc.Template{} - if err := r.Get(ctx, req.NamespacedName, template); err != nil { +func (r *ClusterTemplateReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { + l := log.FromContext(ctx).WithValues("ClusterTemplateController", req.NamespacedName) + l.Info("Reconciling ClusterTemplate") + + clusterTemplate := &hmc.ClusterTemplate{} + err := r.Get(ctx, req.NamespacedName, clusterTemplate) + if err != nil { if apierrors.IsNotFound(err) { - l.Info("Template not found, ignoring since object must be deleted") + l.Info("ClusterTemplate not found, ignoring since object must be deleted") return ctrl.Result{}, nil } - l.Error(err, "Failed to get Template") + l.Error(err, "Failed to get ClusterTemplate") return ctrl.Result{}, err } + return r.ReconcileTemplate(ctx, clusterTemplate) +} - var hcChart *sourcev1.HelmChart +func (r *ServiceTemplateReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { + l := log.FromContext(ctx).WithValues("ServiceTemplateReconciler", req.NamespacedName) + l.Info("Reconciling ServiceTemplate") + + serviceTemplate := &hmc.ServiceTemplate{} + err := r.Get(ctx, req.NamespacedName, serviceTemplate) + if err != nil { + if apierrors.IsNotFound(err) { + l.Info("ServiceTemplate not found, ignoring since object must be deleted") + return ctrl.Result{}, nil + } + l.Error(err, "Failed to get ServiceTemplate") + return ctrl.Result{}, err + } + return r.ReconcileTemplate(ctx, serviceTemplate) +} + +func (r *ProviderTemplateReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { + l := log.FromContext(ctx).WithValues("ProviderTemplateReconciler", req.NamespacedName) + l.Info("Reconciling ProviderTemplate") + + providerTemplate := &hmc.ProviderTemplate{} + err := r.Get(ctx, req.NamespacedName, providerTemplate) + if err != nil { + if apierrors.IsNotFound(err) { + l.Info("ProviderTemplate not found, ignoring since object must be deleted") + return ctrl.Result{}, nil + } + l.Error(err, "Failed to get ProviderTemplate") + return ctrl.Result{}, err + } + return r.ReconcileTemplate(ctx, providerTemplate) +} + +// Template is the interface defining a list of methods to interact with templates +type Template interface { + client.Object + GetSpec() *hmc.TemplateSpecMixin + GetStatus() *hmc.TemplateStatusMixin +} + +func (r *TemplateReconciler) ReconcileTemplate(ctx context.Context, template Template) (ctrl.Result, error) { + l := log.FromContext(ctx) + + spec := template.GetSpec() + status := template.GetStatus() var err error - if template.Spec.Helm.ChartRef != nil { - hcChart, err = r.getHelmChartFromChartRef(ctx, template.Spec.Helm.ChartRef) + var hcChart *sourcev1.HelmChart + if spec.Helm.ChartRef != nil { + hcChart, err = r.getHelmChartFromChartRef(ctx, spec.Helm.ChartRef) if err != nil { - l.Error(err, "failed to get artifact from chartRef", "kind", template.Spec.Helm.ChartRef.Kind, "namespace", template.Spec.Helm.ChartRef.Namespace, "name", template.Spec.Helm.ChartRef.Name) + l.Error(err, "failed to get artifact from chartRef", "kind", spec.Helm.ChartRef.Kind, "namespace", spec.Helm.ChartRef.Namespace, "name", spec.Helm.ChartRef.Name) return ctrl.Result{}, err } } else { - if template.Spec.Helm.ChartName == "" { - err = fmt.Errorf("neither chartName nor chartRef is set") + if spec.Helm.ChartName == "" { + err := fmt.Errorf("neither chartName nor chartRef is set") l.Error(err, "invalid helm chart reference") return ctrl.Result{}, err } @@ -95,7 +152,8 @@ func (r *TemplateReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c l.Error(err, "could not get the helm chart") return ctrl.Result{}, err } - template.Status.ChartRef = &v2.CrossNamespaceSourceReference{ + + status.ChartRef = &v2.CrossNamespaceSourceReference{ Kind: sourcev1.HelmChartKind, Name: hcChart.Name, Namespace: hcChart.Namespace, @@ -134,7 +192,7 @@ func (r *TemplateReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c return ctrl.Result{}, err } - template.Status.Description = helmChart.Metadata.Description + status.Description = helmChart.Metadata.Description rawValues, err := json.Marshal(helmChart.Values) if err != nil { l.Error(err, "Failed to parse Helm chart values") @@ -142,75 +200,74 @@ func (r *TemplateReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c _ = r.updateStatus(ctx, template, err.Error()) return ctrl.Result{}, err } - template.Status.Config = &apiextensionsv1.JSON{Raw: rawValues} + status.Config = &apiextensionsv1.JSON{Raw: rawValues} l.Info("Chart validation completed successfully") return ctrl.Result{}, r.updateStatus(ctx, template, "") } -func (r *TemplateReconciler) parseChartMetadata(template *hmc.Template, chart *chart.Chart) error { +func (r *TemplateReconciler) parseChartMetadata(template Template, chart *chart.Chart) error { if chart.Metadata == nil { return fmt.Errorf("chart metadata is empty") } - // the value in spec has higher priority - templateType := template.Spec.Type - if templateType == "" { - templateType = hmc.TemplateType(chart.Metadata.Annotations[hmc.ChartAnnotationType]) - switch templateType { - case hmc.TemplateTypeDeployment, hmc.TemplateTypeProvider, hmc.TemplateTypeCore: - default: - return errNoProviderType - } - } - template.Status.Type = templateType + spec := template.GetSpec() + status := template.GetStatus() // the value in spec has higher priority - if len(template.Spec.Providers.InfrastructureProviders) > 0 { - template.Status.Providers.InfrastructureProviders = template.Spec.Providers.InfrastructureProviders + if len(spec.Providers.InfrastructureProviders) > 0 { + status.Providers.InfrastructureProviders = spec.Providers.InfrastructureProviders } else { infraProviders := chart.Metadata.Annotations[hmc.ChartAnnotationInfraProviders] if infraProviders != "" { - template.Status.Providers.InfrastructureProviders = strings.Split(infraProviders, ",") + status.Providers.InfrastructureProviders = strings.Split(infraProviders, ",") } } - if len(template.Spec.Providers.BootstrapProviders) > 0 { - template.Status.Providers.BootstrapProviders = template.Spec.Providers.BootstrapProviders + if len(spec.Providers.BootstrapProviders) > 0 { + status.Providers.BootstrapProviders = spec.Providers.BootstrapProviders } else { bootstrapProviders := chart.Metadata.Annotations[hmc.ChartAnnotationBootstrapProviders] if bootstrapProviders != "" { - template.Status.Providers.BootstrapProviders = strings.Split(bootstrapProviders, ",") + status.Providers.BootstrapProviders = strings.Split(bootstrapProviders, ",") } } - if len(template.Spec.Providers.ControlPlaneProviders) > 0 { - template.Status.Providers.ControlPlaneProviders = template.Spec.Providers.ControlPlaneProviders + if len(spec.Providers.ControlPlaneProviders) > 0 { + status.Providers.ControlPlaneProviders = spec.Providers.ControlPlaneProviders } else { cpProviders := chart.Metadata.Annotations[hmc.ChartAnnotationControlPlaneProviders] if cpProviders != "" { - template.Status.Providers.ControlPlaneProviders = strings.Split(cpProviders, ",") + status.Providers.ControlPlaneProviders = strings.Split(cpProviders, ",") } } return nil } -func (r *TemplateReconciler) updateStatus(ctx context.Context, template *hmc.Template, validationError string) error { - template.Status.ObservedGeneration = template.Generation - template.Status.ValidationError = validationError - template.Status.Valid = validationError == "" - if err := r.Status().Update(ctx, template); err != nil { - return fmt.Errorf("failed to update status for template %s/%s: %w", template.Namespace, template.Name, err) +func (r *TemplateReconciler) updateStatus(ctx context.Context, template Template, validationError string) error { + status := template.GetStatus() + status.ObservedGeneration = template.GetGeneration() + status.ValidationError = validationError + status.Valid = validationError == "" + err := r.Status().Update(ctx, template) + if err != nil { + return fmt.Errorf("failed to update status for template %s/%s: %w", template.GetNamespace(), template.GetName(), err) } return nil } -func (r *TemplateReconciler) reconcileHelmChart(ctx context.Context, template *hmc.Template) (*sourcev1.HelmChart, error) { - if template.Spec.Helm.ChartRef != nil { +func (r *TemplateReconciler) reconcileHelmChart(ctx context.Context, template Template) (*sourcev1.HelmChart, error) { + spec := template.GetSpec() + if spec.Helm.ChartRef != nil { // HelmChart is not managed by the controller return nil, nil } + + namespace := template.GetNamespace() + if namespace == "" { + namespace = r.SystemNamespace + } helmChart := &sourcev1.HelmChart{ ObjectMeta: metav1.ObjectMeta{ - Name: template.Name, - Namespace: template.Namespace, + Name: template.GetName(), + Namespace: namespace, }, } @@ -222,14 +279,14 @@ func (r *TemplateReconciler) reconcileHelmChart(ctx context.Context, template *h helmChart.OwnerReferences = []metav1.OwnerReference{ { APIVersion: hmc.GroupVersion.String(), - Kind: hmc.TemplateKind, - Name: template.Name, - UID: template.UID, + Kind: template.GetObjectKind().GroupVersionKind().Kind, + Name: template.GetName(), + UID: template.GetUID(), }, } helmChart.Spec = sourcev1.HelmChartSpec{ - Chart: template.Spec.Helm.ChartName, - Version: template.Spec.Helm.ChartVersion, + Chart: spec.Helm.ChartName, + Version: spec.Helm.ChartVersion, SourceRef: sourcev1.LocalHelmChartSourceReference{ Kind: sourcev1.HelmRepositoryKind, Name: defaultRepoName, @@ -260,8 +317,22 @@ func (r *TemplateReconciler) getHelmChartFromChartRef(ctx context.Context, chart } // SetupWithManager sets up the controller with the Manager. -func (r *TemplateReconciler) SetupWithManager(mgr ctrl.Manager) error { +func (r *ClusterTemplateReconciler) SetupWithManager(mgr ctrl.Manager) error { + return ctrl.NewControllerManagedBy(mgr). + For(&hmc.ClusterTemplate{}). + Complete(r) +} + +// SetupWithManager sets up the controller with the Manager. +func (r *ServiceTemplateReconciler) SetupWithManager(mgr ctrl.Manager) error { + return ctrl.NewControllerManagedBy(mgr). + For(&hmc.ServiceTemplate{}). + Complete(r) +} + +// SetupWithManager sets up the controller with the Manager. +func (r *ProviderTemplateReconciler) SetupWithManager(mgr ctrl.Manager) error { return ctrl.NewControllerManagedBy(mgr). - For(&hmc.Template{}). + For(&hmc.ProviderTemplate{}). Complete(r) } diff --git a/internal/controller/template_controller_test.go b/internal/controller/template_controller_test.go index ac86ed55d..8433e192c 100644 --- a/internal/controller/template_controller_test.go +++ b/internal/controller/template_controller_test.go @@ -54,10 +54,22 @@ var _ = Describe("Template Controller", func() { Name: resourceName, Namespace: "default", // TODO(user):Modify as needed } - template := &hmcmirantiscomv1alpha1.Template{} + clusterTemplate := &hmcmirantiscomv1alpha1.ClusterTemplate{} + serviceTemplate := &hmcmirantiscomv1alpha1.ServiceTemplate{} + providerTemplate := &hmcmirantiscomv1alpha1.ProviderTemplate{} helmRepo := &sourcev1.HelmRepository{} helmChart := &sourcev1.HelmChart{} + templateSpec := hmcmirantiscomv1alpha1.TemplateSpecMixin{ + Helm: hmcmirantiscomv1alpha1.HelmSpec{ + ChartRef: &v2.CrossNamespaceSourceReference{ + Kind: "HelmChart", + Name: helmChartName, + Namespace: helmRepoNamespace, + }, + }, + } + BeforeEach(func() { By("creating helm repository") err := k8sClient.Get(ctx, types.NamespacedName{Name: helmRepoName, Namespace: helmRepoNamespace}, helmRepo) @@ -100,25 +112,39 @@ var _ = Describe("Template Controller", func() { } Expect(k8sClient.Status().Update(ctx, helmChart)).Should(Succeed()) - By("creating the custom resource for the Kind Template") - err = k8sClient.Get(ctx, typeNamespacedName, template) + By("creating the custom resource for the Kind ClusterTemplate") + err = k8sClient.Get(ctx, typeNamespacedName, clusterTemplate) if err != nil && errors.IsNotFound(err) { - resource := &hmcmirantiscomv1alpha1.Template{ + resource := &hmcmirantiscomv1alpha1.ClusterTemplate{ ObjectMeta: metav1.ObjectMeta{ Name: resourceName, Namespace: "default", }, - Spec: hmcmirantiscomv1alpha1.TemplateSpec{ - Helm: hmcmirantiscomv1alpha1.HelmSpec{ - ChartRef: &v2.CrossNamespaceSourceReference{ - Kind: "HelmChart", - Name: helmChartName, - Namespace: helmRepoNamespace, - }, - }, - Type: hmcmirantiscomv1alpha1.TemplateTypeDeployment, + Spec: hmcmirantiscomv1alpha1.ClusterTemplateSpec{TemplateSpecMixin: templateSpec}, + } + Expect(k8sClient.Create(ctx, resource)).To(Succeed()) + } + By("creating the custom resource for the Kind ServiceTemplate") + err = k8sClient.Get(ctx, typeNamespacedName, serviceTemplate) + if err != nil && errors.IsNotFound(err) { + resource := &hmcmirantiscomv1alpha1.ServiceTemplate{ + ObjectMeta: metav1.ObjectMeta{ + Name: resourceName, + Namespace: "default", + }, + Spec: hmcmirantiscomv1alpha1.ServiceTemplateSpec{TemplateSpecMixin: templateSpec}, + } + Expect(k8sClient.Create(ctx, resource)).To(Succeed()) + } + By("creating the custom resource for the Kind ProviderTemplate") + err = k8sClient.Get(ctx, typeNamespacedName, providerTemplate) + if err != nil && errors.IsNotFound(err) { + resource := &hmcmirantiscomv1alpha1.ProviderTemplate{ + ObjectMeta: metav1.ObjectMeta{ + Name: resourceName, + Namespace: "default", }, - // TODO(user): Specify other spec details if needed. + Spec: hmcmirantiscomv1alpha1.ProviderTemplateSpec{TemplateSpecMixin: templateSpec}, } Expect(k8sClient.Create(ctx, resource)).To(Succeed()) } @@ -126,24 +152,46 @@ var _ = Describe("Template Controller", func() { AfterEach(func() { // TODO(user): Cleanup logic after each test, like removing the resource instance. - resource := &hmcmirantiscomv1alpha1.Template{} - err := k8sClient.Get(ctx, typeNamespacedName, resource) + clusterTemplateResource := &hmcmirantiscomv1alpha1.ClusterTemplate{} + err := k8sClient.Get(ctx, typeNamespacedName, clusterTemplateResource) + Expect(err).NotTo(HaveOccurred()) + + By("Cleanup the specific resource instance ClusterTemplate") + Expect(k8sClient.Delete(ctx, clusterTemplateResource)).To(Succeed()) + + serviceTemplateResource := &hmcmirantiscomv1alpha1.ServiceTemplate{} + err = k8sClient.Get(ctx, typeNamespacedName, serviceTemplateResource) + Expect(err).NotTo(HaveOccurred()) + + By("Cleanup the specific resource instance ServiceTemplate") + Expect(k8sClient.Delete(ctx, serviceTemplateResource)).To(Succeed()) + + providerTemplateResource := &hmcmirantiscomv1alpha1.ProviderTemplate{} + err = k8sClient.Get(ctx, typeNamespacedName, providerTemplateResource) Expect(err).NotTo(HaveOccurred()) - By("Cleanup the specific resource instance Template") - Expect(k8sClient.Delete(ctx, resource)).To(Succeed()) + By("Cleanup the specific resource instance ClusterTemplate") + Expect(k8sClient.Delete(ctx, providerTemplateResource)).To(Succeed()) }) It("should successfully reconcile the resource", func() { - By("Reconciling the created resource") - controllerReconciler := &TemplateReconciler{ + templateReconciler := TemplateReconciler{ Client: k8sClient, Scheme: k8sClient.Scheme(), downloadHelmChartFunc: fakeDownloadHelmChartFunc, } + By("Reconciling the ClusterTemplate resource") + clusterTemplateReconciler := &ClusterTemplateReconciler{TemplateReconciler: templateReconciler} + _, err := clusterTemplateReconciler.Reconcile(ctx, reconcile.Request{NamespacedName: typeNamespacedName}) + Expect(err).NotTo(HaveOccurred()) + + By("Reconciling the ServiceTemplate resource") + serviceTemplateReconciler := &ServiceTemplateReconciler{TemplateReconciler: templateReconciler} + _, err = serviceTemplateReconciler.Reconcile(ctx, reconcile.Request{NamespacedName: typeNamespacedName}) + Expect(err).NotTo(HaveOccurred()) - _, err := controllerReconciler.Reconcile(ctx, reconcile.Request{ - NamespacedName: typeNamespacedName, - }) + By("Reconciling the ProviderTemplate resource") + providerTemplateReconciler := &ProviderTemplateReconciler{TemplateReconciler: templateReconciler} + _, err = providerTemplateReconciler.Reconcile(ctx, reconcile.Request{NamespacedName: typeNamespacedName}) Expect(err).NotTo(HaveOccurred()) // TODO(user): Add more specific assertions depending on your controller's reconciliation logic. // Example: If you expect a certain status condition after reconciliation, verify it here. diff --git a/internal/telemetry/tracker.go b/internal/telemetry/tracker.go index 2935c2fb3..fbabb12b3 100644 --- a/internal/telemetry/tracker.go +++ b/internal/telemetry/tracker.go @@ -69,8 +69,8 @@ func (t *Tracker) trackManagedClusterHeartbeat(ctx context.Context) error { return err } - templates := make(map[string]v1alpha1.Template) - templatesList := &v1alpha1.TemplateList{} + templates := make(map[string]v1alpha1.ClusterTemplate) + templatesList := &v1alpha1.ClusterTemplateList{} err = t.List(ctx, templatesList, crclient.InNamespace(t.SystemNamespace)) if err != nil { return err diff --git a/internal/webhook/managedcluster_webhook.go b/internal/webhook/managedcluster_webhook.go index bb2b8a26b..b92387ce4 100644 --- a/internal/webhook/managedcluster_webhook.go +++ b/internal/webhook/managedcluster_webhook.go @@ -121,8 +121,8 @@ func (v *ManagedClusterValidator) Default(ctx context.Context, obj runtime.Objec return nil } -func (v *ManagedClusterValidator) getManagedClusterTemplate(ctx context.Context, templateName string) (*v1alpha1.Template, error) { - template := &v1alpha1.Template{} +func (v *ManagedClusterValidator) getManagedClusterTemplate(ctx context.Context, templateName string) (*v1alpha1.ClusterTemplate, error) { + template := &v1alpha1.ClusterTemplate{} templateRef := types.NamespacedName{Name: templateName, Namespace: v.SystemNamespace} if err := v.Get(ctx, templateRef, template); err != nil { return nil, err @@ -130,10 +130,7 @@ func (v *ManagedClusterValidator) getManagedClusterTemplate(ctx context.Context, return template, nil } -func (v *ManagedClusterValidator) isTemplateValid(ctx context.Context, template *v1alpha1.Template) error { - if template.Status.Type != v1alpha1.TemplateTypeDeployment { - return fmt.Errorf("the template should be of the deployment type. Current: %s", template.Status.Type) - } +func (v *ManagedClusterValidator) isTemplateValid(ctx context.Context, template *v1alpha1.ClusterTemplate) error { if !template.Status.Valid { return fmt.Errorf("the template is not valid: %s", template.Status.ValidationError) } @@ -144,7 +141,7 @@ func (v *ManagedClusterValidator) isTemplateValid(ctx context.Context, template return nil } -func (v *ManagedClusterValidator) verifyProviders(ctx context.Context, template *v1alpha1.Template) error { +func (v *ManagedClusterValidator) verifyProviders(ctx context.Context, template *v1alpha1.ClusterTemplate) error { requiredProviders := template.Status.Providers management := &v1alpha1.Management{} managementRef := types.NamespacedName{Name: v1alpha1.ManagementName} diff --git a/internal/webhook/managedcluster_webhook_test.go b/internal/webhook/managedcluster_webhook_test.go index c17dadaf9..c1080333e 100644 --- a/internal/webhook/managedcluster_webhook_test.go +++ b/internal/webhook/managedcluster_webhook_test.go @@ -53,37 +53,27 @@ var ( { name: "should fail if the template is unset", managedCluster: managedcluster.NewManagedCluster(), - err: "the ManagedCluster is invalid: templates.hmc.mirantis.com \"\" not found", + err: "the ManagedCluster is invalid: clustertemplates.hmc.mirantis.com \"\" not found", }, { - name: "should fail if the template is not found in hmc-system namespace", + name: "should fail if the cluster template is not found in hmc-system namespace", managedCluster: managedcluster.NewManagedCluster(managedcluster.WithTemplate(testTemplateName)), existingObjects: []runtime.Object{ mgmt, - template.NewTemplate( + template.NewClusterTemplate( template.WithName(testTemplateName), template.WithNamespace("default"), ), }, - err: fmt.Sprintf("the ManagedCluster is invalid: templates.hmc.mirantis.com \"%s\" not found", testTemplateName), + err: fmt.Sprintf("the ManagedCluster is invalid: clustertemplates.hmc.mirantis.com \"%s\" not found", testTemplateName), }, { - name: "should fail if the template was found but is invalid (type is unset)", + name: "should fail if the cluster template was found but is invalid (some validation error)", managedCluster: managedcluster.NewManagedCluster(managedcluster.WithTemplate(testTemplateName)), existingObjects: []runtime.Object{ mgmt, - template.NewTemplate(template.WithName(testTemplateName)), - }, - err: "the ManagedCluster is invalid: the template should be of the deployment type. Current: ", - }, - { - name: "should fail if the template was found but is invalid (some validation error)", - managedCluster: managedcluster.NewManagedCluster(managedcluster.WithTemplate(testTemplateName)), - existingObjects: []runtime.Object{ - mgmt, - template.NewTemplate( + template.NewClusterTemplate( template.WithName(testTemplateName), - template.WithTypeStatus(v1alpha1.TemplateTypeDeployment), template.WithValidationStatus(v1alpha1.TemplateValidationStatus{ Valid: false, ValidationError: "validation error example", @@ -102,9 +92,8 @@ var ( BootstrapProviders: []string{"k0s"}, }), ), - template.NewTemplate( + template.NewClusterTemplate( template.WithName(testTemplateName), - template.WithTypeStatus(v1alpha1.TemplateTypeDeployment), template.WithProvidersStatus(v1alpha1.Providers{ InfrastructureProviders: []string{"azure"}, BootstrapProviders: []string{"k0s"}, @@ -120,9 +109,8 @@ var ( managedCluster: managedcluster.NewManagedCluster(managedcluster.WithTemplate(testTemplateName)), existingObjects: []runtime.Object{ mgmt, - template.NewTemplate( + template.NewClusterTemplate( template.WithName(testTemplateName), - template.WithTypeStatus(v1alpha1.TemplateTypeDeployment), template.WithProvidersStatus(v1alpha1.Providers{ InfrastructureProviders: []string{"aws"}, BootstrapProviders: []string{"k0s"}, @@ -212,9 +200,8 @@ func TestManagedClusterDefault(t *testing.T) { output: managedcluster.NewManagedCluster(managedcluster.WithTemplate(testTemplateName)), existingObjects: []runtime.Object{ mgmt, - template.NewTemplate( + template.NewClusterTemplate( template.WithName(testTemplateName), - template.WithTypeStatus(v1alpha1.TemplateTypeDeployment), template.WithValidationStatus(v1alpha1.TemplateValidationStatus{ Valid: false, ValidationError: "validation error example", @@ -229,9 +216,8 @@ func TestManagedClusterDefault(t *testing.T) { output: managedcluster.NewManagedCluster(managedcluster.WithTemplate(testTemplateName)), existingObjects: []runtime.Object{ mgmt, - template.NewTemplate( + template.NewClusterTemplate( template.WithName(testTemplateName), - template.WithTypeStatus(v1alpha1.TemplateTypeDeployment), template.WithValidationStatus(v1alpha1.TemplateValidationStatus{Valid: true}), ), }, @@ -246,9 +232,8 @@ func TestManagedClusterDefault(t *testing.T) { ), existingObjects: []runtime.Object{ mgmt, - template.NewTemplate( + template.NewClusterTemplate( template.WithName(testTemplateName), - template.WithTypeStatus(v1alpha1.TemplateTypeDeployment), template.WithValidationStatus(v1alpha1.TemplateValidationStatus{Valid: true}), template.WithConfigStatus(managedClusterConfig), ), diff --git a/internal/webhook/template_webhook.go b/internal/webhook/template_webhook.go index 421641ae2..ab51d9308 100644 --- a/internal/webhook/template_webhook.go +++ b/internal/webhook/template_webhook.go @@ -17,48 +17,125 @@ package webhook // nolint:dupl import ( "context" - "github.com/Mirantis/hmc/api/v1alpha1" "k8s.io/apimachinery/pkg/runtime" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/webhook" "sigs.k8s.io/controller-runtime/pkg/webhook/admission" + + "github.com/Mirantis/hmc/api/v1alpha1" +) + +type ClusterTemplateValidator struct { + client.Client +} + +func (in *ClusterTemplateValidator) SetupWebhookWithManager(mgr ctrl.Manager) error { + in.Client = mgr.GetClient() + return ctrl.NewWebhookManagedBy(mgr). + For(&v1alpha1.ClusterTemplate{}). + WithValidator(in). + WithDefaulter(in). + Complete() +} + +var ( + _ webhook.CustomValidator = &ClusterTemplateValidator{} + _ webhook.CustomDefaulter = &ClusterTemplateValidator{} ) -type TemplateValidator struct { +// ValidateCreate implements webhook.Validator so a webhook will be registered for the type. +func (*ClusterTemplateValidator) ValidateCreate(_ context.Context, _ runtime.Object) (admission.Warnings, error) { + return nil, nil +} + +// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type. +func (*ClusterTemplateValidator) ValidateUpdate(_ context.Context, _ runtime.Object, _ runtime.Object) (admission.Warnings, error) { + return nil, nil +} + +// ValidateDelete implements webhook.Validator so a webhook will be registered for the type. +func (*ClusterTemplateValidator) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) { + return nil, nil +} + +// Default implements webhook.Defaulter so a webhook will be registered for the type. +func (*ClusterTemplateValidator) Default(_ context.Context, _ runtime.Object) error { + return nil +} + +type ServiceTemplateValidator struct { + client.Client +} + +func (in *ServiceTemplateValidator) SetupWebhookWithManager(mgr ctrl.Manager) error { + in.Client = mgr.GetClient() + return ctrl.NewWebhookManagedBy(mgr). + For(&v1alpha1.ServiceTemplate{}). + WithValidator(in). + WithDefaulter(in). + Complete() +} + +var ( + _ webhook.CustomValidator = &ServiceTemplateValidator{} + _ webhook.CustomDefaulter = &ServiceTemplateValidator{} +) + +// ValidateCreate implements webhook.Validator so a webhook will be registered for the type. +func (*ServiceTemplateValidator) ValidateCreate(_ context.Context, _ runtime.Object) (admission.Warnings, error) { + return nil, nil +} + +// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type. +func (*ServiceTemplateValidator) ValidateUpdate(_ context.Context, _ runtime.Object, _ runtime.Object) (admission.Warnings, error) { + return nil, nil +} + +// ValidateDelete implements webhook.Validator so a webhook will be registered for the type. +func (*ServiceTemplateValidator) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) { + return nil, nil +} + +// Default implements webhook.Defaulter so a webhook will be registered for the type. +func (*ServiceTemplateValidator) Default(_ context.Context, _ runtime.Object) error { + return nil +} + +type ProviderTemplateValidator struct { client.Client } -func (in *TemplateValidator) SetupWebhookWithManager(mgr ctrl.Manager) error { +func (in *ProviderTemplateValidator) SetupWebhookWithManager(mgr ctrl.Manager) error { in.Client = mgr.GetClient() return ctrl.NewWebhookManagedBy(mgr). - For(&v1alpha1.Template{}). + For(&v1alpha1.ProviderTemplate{}). WithValidator(in). WithDefaulter(in). Complete() } var ( - _ webhook.CustomValidator = &TemplateValidator{} - _ webhook.CustomDefaulter = &TemplateValidator{} + _ webhook.CustomValidator = &ProviderTemplateValidator{} + _ webhook.CustomDefaulter = &ProviderTemplateValidator{} ) // ValidateCreate implements webhook.Validator so a webhook will be registered for the type. -func (*TemplateValidator) ValidateCreate(_ context.Context, _ runtime.Object) (admission.Warnings, error) { +func (*ProviderTemplateValidator) ValidateCreate(_ context.Context, _ runtime.Object) (admission.Warnings, error) { return nil, nil } // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type. -func (*TemplateValidator) ValidateUpdate(_ context.Context, _ runtime.Object, _ runtime.Object) (admission.Warnings, error) { +func (*ProviderTemplateValidator) ValidateUpdate(_ context.Context, _ runtime.Object, _ runtime.Object) (admission.Warnings, error) { return nil, nil } // ValidateDelete implements webhook.Validator so a webhook will be registered for the type. -func (*TemplateValidator) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) { +func (*ProviderTemplateValidator) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) { return nil, nil } // Default implements webhook.Defaulter so a webhook will be registered for the type. -func (*TemplateValidator) Default(_ context.Context, _ runtime.Object) error { +func (*ProviderTemplateValidator) Default(_ context.Context, _ runtime.Object) error { return nil } diff --git a/templates/aws-hosted-cp/.helmignore b/templates/cluster/aws-hosted-cp/.helmignore similarity index 100% rename from templates/aws-hosted-cp/.helmignore rename to templates/cluster/aws-hosted-cp/.helmignore diff --git a/templates/aws-hosted-cp/Chart.yaml b/templates/cluster/aws-hosted-cp/Chart.yaml similarity index 96% rename from templates/aws-hosted-cp/Chart.yaml rename to templates/cluster/aws-hosted-cp/Chart.yaml index f108d64d8..ca357f875 100644 --- a/templates/aws-hosted-cp/Chart.yaml +++ b/templates/cluster/aws-hosted-cp/Chart.yaml @@ -14,7 +14,6 @@ version: 0.1.2 # It is recommended to use it with quotes. appVersion: "1.30.2+k0s.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-hosted-cp/templates/_helpers.tpl b/templates/cluster/aws-hosted-cp/templates/_helpers.tpl similarity index 100% rename from templates/aws-hosted-cp/templates/_helpers.tpl rename to templates/cluster/aws-hosted-cp/templates/_helpers.tpl diff --git a/templates/aws-hosted-cp/templates/awscluster.yaml b/templates/cluster/aws-hosted-cp/templates/awscluster.yaml similarity index 100% rename from templates/aws-hosted-cp/templates/awscluster.yaml rename to templates/cluster/aws-hosted-cp/templates/awscluster.yaml diff --git a/templates/aws-hosted-cp/templates/awsmachinetemplate.yaml b/templates/cluster/aws-hosted-cp/templates/awsmachinetemplate.yaml similarity index 100% rename from templates/aws-hosted-cp/templates/awsmachinetemplate.yaml rename to templates/cluster/aws-hosted-cp/templates/awsmachinetemplate.yaml diff --git a/templates/aws-hosted-cp/templates/cluster.yaml b/templates/cluster/aws-hosted-cp/templates/cluster.yaml similarity index 100% rename from templates/aws-hosted-cp/templates/cluster.yaml rename to templates/cluster/aws-hosted-cp/templates/cluster.yaml diff --git a/templates/aws-hosted-cp/templates/k0smotroncontrolplane.yaml b/templates/cluster/aws-hosted-cp/templates/k0smotroncontrolplane.yaml similarity index 100% rename from templates/aws-hosted-cp/templates/k0smotroncontrolplane.yaml rename to templates/cluster/aws-hosted-cp/templates/k0smotroncontrolplane.yaml diff --git a/templates/aws-hosted-cp/templates/k0sworkerconfigtemplate.yaml b/templates/cluster/aws-hosted-cp/templates/k0sworkerconfigtemplate.yaml similarity index 100% rename from templates/aws-hosted-cp/templates/k0sworkerconfigtemplate.yaml rename to templates/cluster/aws-hosted-cp/templates/k0sworkerconfigtemplate.yaml diff --git a/templates/aws-hosted-cp/templates/machinedeployment.yaml b/templates/cluster/aws-hosted-cp/templates/machinedeployment.yaml similarity index 100% rename from templates/aws-hosted-cp/templates/machinedeployment.yaml rename to templates/cluster/aws-hosted-cp/templates/machinedeployment.yaml diff --git a/templates/aws-hosted-cp/values.schema.json b/templates/cluster/aws-hosted-cp/values.schema.json similarity index 100% rename from templates/aws-hosted-cp/values.schema.json rename to templates/cluster/aws-hosted-cp/values.schema.json diff --git a/templates/aws-hosted-cp/values.yaml b/templates/cluster/aws-hosted-cp/values.yaml similarity index 100% rename from templates/aws-hosted-cp/values.yaml rename to templates/cluster/aws-hosted-cp/values.yaml diff --git a/templates/aws-standalone-cp/.helmignore b/templates/cluster/aws-standalone-cp/.helmignore similarity index 100% rename from templates/aws-standalone-cp/.helmignore rename to templates/cluster/aws-standalone-cp/.helmignore diff --git a/templates/aws-standalone-cp/Chart.yaml b/templates/cluster/aws-standalone-cp/Chart.yaml similarity index 96% rename from templates/aws-standalone-cp/Chart.yaml rename to templates/cluster/aws-standalone-cp/Chart.yaml index 6879b1231..3bb77479d 100644 --- a/templates/aws-standalone-cp/Chart.yaml +++ b/templates/cluster/aws-standalone-cp/Chart.yaml @@ -13,7 +13,6 @@ version: 0.1.2 # It is recommended to use it with quotes. appVersion: "1.30.2+k0s.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 diff --git a/templates/aws-standalone-cp/README.md b/templates/cluster/aws-standalone-cp/README.md similarity index 100% rename from templates/aws-standalone-cp/README.md rename to templates/cluster/aws-standalone-cp/README.md diff --git a/templates/aws-standalone-cp/templates/_helpers.tpl b/templates/cluster/aws-standalone-cp/templates/_helpers.tpl similarity index 100% rename from templates/aws-standalone-cp/templates/_helpers.tpl rename to templates/cluster/aws-standalone-cp/templates/_helpers.tpl diff --git a/templates/aws-standalone-cp/templates/awscluster.yaml b/templates/cluster/aws-standalone-cp/templates/awscluster.yaml similarity index 100% rename from templates/aws-standalone-cp/templates/awscluster.yaml rename to templates/cluster/aws-standalone-cp/templates/awscluster.yaml diff --git a/templates/aws-standalone-cp/templates/awsmachinetemplate-controlplane.yaml b/templates/cluster/aws-standalone-cp/templates/awsmachinetemplate-controlplane.yaml similarity index 100% rename from templates/aws-standalone-cp/templates/awsmachinetemplate-controlplane.yaml rename to templates/cluster/aws-standalone-cp/templates/awsmachinetemplate-controlplane.yaml diff --git a/templates/aws-standalone-cp/templates/awsmachinetemplate-worker.yaml b/templates/cluster/aws-standalone-cp/templates/awsmachinetemplate-worker.yaml similarity index 100% rename from templates/aws-standalone-cp/templates/awsmachinetemplate-worker.yaml rename to templates/cluster/aws-standalone-cp/templates/awsmachinetemplate-worker.yaml diff --git a/templates/aws-standalone-cp/templates/beachheadservices/cert-manager.yaml b/templates/cluster/aws-standalone-cp/templates/beachheadservices/cert-manager.yaml similarity index 100% rename from templates/aws-standalone-cp/templates/beachheadservices/cert-manager.yaml rename to templates/cluster/aws-standalone-cp/templates/beachheadservices/cert-manager.yaml diff --git a/templates/aws-standalone-cp/templates/beachheadservices/nginx-ingress.yaml b/templates/cluster/aws-standalone-cp/templates/beachheadservices/nginx-ingress.yaml similarity index 100% rename from templates/aws-standalone-cp/templates/beachheadservices/nginx-ingress.yaml rename to templates/cluster/aws-standalone-cp/templates/beachheadservices/nginx-ingress.yaml diff --git a/templates/aws-standalone-cp/templates/cluster.yaml b/templates/cluster/aws-standalone-cp/templates/cluster.yaml similarity index 100% rename from templates/aws-standalone-cp/templates/cluster.yaml rename to templates/cluster/aws-standalone-cp/templates/cluster.yaml diff --git a/templates/aws-standalone-cp/templates/k0scontrolplane.yaml b/templates/cluster/aws-standalone-cp/templates/k0scontrolplane.yaml similarity index 100% rename from templates/aws-standalone-cp/templates/k0scontrolplane.yaml rename to templates/cluster/aws-standalone-cp/templates/k0scontrolplane.yaml diff --git a/templates/aws-standalone-cp/templates/k0sworkerconfigtemplate.yaml b/templates/cluster/aws-standalone-cp/templates/k0sworkerconfigtemplate.yaml similarity index 100% rename from templates/aws-standalone-cp/templates/k0sworkerconfigtemplate.yaml rename to templates/cluster/aws-standalone-cp/templates/k0sworkerconfigtemplate.yaml diff --git a/templates/aws-standalone-cp/templates/machinedeployment.yaml b/templates/cluster/aws-standalone-cp/templates/machinedeployment.yaml similarity index 100% rename from templates/aws-standalone-cp/templates/machinedeployment.yaml rename to templates/cluster/aws-standalone-cp/templates/machinedeployment.yaml diff --git a/templates/aws-standalone-cp/values.schema.json b/templates/cluster/aws-standalone-cp/values.schema.json similarity index 100% rename from templates/aws-standalone-cp/values.schema.json rename to templates/cluster/aws-standalone-cp/values.schema.json diff --git a/templates/aws-standalone-cp/values.yaml b/templates/cluster/aws-standalone-cp/values.yaml similarity index 100% rename from templates/aws-standalone-cp/values.yaml rename to templates/cluster/aws-standalone-cp/values.yaml diff --git a/templates/azure-hosted-cp/.helmignore b/templates/cluster/azure-hosted-cp/.helmignore similarity index 100% rename from templates/azure-hosted-cp/.helmignore rename to templates/cluster/azure-hosted-cp/.helmignore diff --git a/templates/azure-hosted-cp/Chart.yaml b/templates/cluster/azure-hosted-cp/Chart.yaml similarity index 96% rename from templates/azure-hosted-cp/Chart.yaml rename to templates/cluster/azure-hosted-cp/Chart.yaml index 54068bc9b..9f97c38b7 100644 --- a/templates/azure-hosted-cp/Chart.yaml +++ b/templates/cluster/azure-hosted-cp/Chart.yaml @@ -14,7 +14,6 @@ version: 0.1.1 # It is recommended to use it with quotes. appVersion: "1.30.4+k0s.0" annotations: - hmc.mirantis.com/type: deployment hmc.mirantis.com/infrastructure-providers: azure hmc.mirantis.com/controlplane-providers: k0s hmc.mirantis.com/bootstrap-providers: k0s diff --git a/templates/azure-hosted-cp/templates/_helpers.tpl b/templates/cluster/azure-hosted-cp/templates/_helpers.tpl similarity index 100% rename from templates/azure-hosted-cp/templates/_helpers.tpl rename to templates/cluster/azure-hosted-cp/templates/_helpers.tpl diff --git a/templates/azure-hosted-cp/templates/azurecluster.yaml b/templates/cluster/azure-hosted-cp/templates/azurecluster.yaml similarity index 100% rename from templates/azure-hosted-cp/templates/azurecluster.yaml rename to templates/cluster/azure-hosted-cp/templates/azurecluster.yaml diff --git a/templates/azure-hosted-cp/templates/azuremachinetemplate.yaml b/templates/cluster/azure-hosted-cp/templates/azuremachinetemplate.yaml similarity index 100% rename from templates/azure-hosted-cp/templates/azuremachinetemplate.yaml rename to templates/cluster/azure-hosted-cp/templates/azuremachinetemplate.yaml diff --git a/templates/azure-hosted-cp/templates/cluster.yaml b/templates/cluster/azure-hosted-cp/templates/cluster.yaml similarity index 100% rename from templates/azure-hosted-cp/templates/cluster.yaml rename to templates/cluster/azure-hosted-cp/templates/cluster.yaml diff --git a/templates/azure-hosted-cp/templates/k0smotroncontrolplane.yaml b/templates/cluster/azure-hosted-cp/templates/k0smotroncontrolplane.yaml similarity index 100% rename from templates/azure-hosted-cp/templates/k0smotroncontrolplane.yaml rename to templates/cluster/azure-hosted-cp/templates/k0smotroncontrolplane.yaml diff --git a/templates/azure-hosted-cp/templates/k0sworkerconfigtemplate.yaml b/templates/cluster/azure-hosted-cp/templates/k0sworkerconfigtemplate.yaml similarity index 100% rename from templates/azure-hosted-cp/templates/k0sworkerconfigtemplate.yaml rename to templates/cluster/azure-hosted-cp/templates/k0sworkerconfigtemplate.yaml diff --git a/templates/azure-hosted-cp/templates/machinedeployment.yaml b/templates/cluster/azure-hosted-cp/templates/machinedeployment.yaml similarity index 100% rename from templates/azure-hosted-cp/templates/machinedeployment.yaml rename to templates/cluster/azure-hosted-cp/templates/machinedeployment.yaml diff --git a/templates/azure-hosted-cp/values.schema.json b/templates/cluster/azure-hosted-cp/values.schema.json similarity index 100% rename from templates/azure-hosted-cp/values.schema.json rename to templates/cluster/azure-hosted-cp/values.schema.json diff --git a/templates/azure-hosted-cp/values.yaml b/templates/cluster/azure-hosted-cp/values.yaml similarity index 100% rename from templates/azure-hosted-cp/values.yaml rename to templates/cluster/azure-hosted-cp/values.yaml diff --git a/templates/azure-standalone-cp/.helmignore b/templates/cluster/azure-standalone-cp/.helmignore similarity index 100% rename from templates/azure-standalone-cp/.helmignore rename to templates/cluster/azure-standalone-cp/.helmignore diff --git a/templates/azure-standalone-cp/Chart.yaml b/templates/cluster/azure-standalone-cp/Chart.yaml similarity index 96% rename from templates/azure-standalone-cp/Chart.yaml rename to templates/cluster/azure-standalone-cp/Chart.yaml index d47838fac..cc88cd3c1 100644 --- a/templates/azure-standalone-cp/Chart.yaml +++ b/templates/cluster/azure-standalone-cp/Chart.yaml @@ -13,7 +13,6 @@ version: 0.1.1 # It is recommended to use it with quotes. appVersion: "1.30.4+k0s.0" annotations: - hmc.mirantis.com/type: deployment hmc.mirantis.com/infrastructure-providers: azure hmc.mirantis.com/controlplane-providers: k0s hmc.mirantis.com/bootstrap-providers: k0s diff --git a/templates/azure-standalone-cp/templates/_helpers.tpl b/templates/cluster/azure-standalone-cp/templates/_helpers.tpl similarity index 100% rename from templates/azure-standalone-cp/templates/_helpers.tpl rename to templates/cluster/azure-standalone-cp/templates/_helpers.tpl diff --git a/templates/azure-standalone-cp/templates/azurecluster.yaml b/templates/cluster/azure-standalone-cp/templates/azurecluster.yaml similarity index 100% rename from templates/azure-standalone-cp/templates/azurecluster.yaml rename to templates/cluster/azure-standalone-cp/templates/azurecluster.yaml diff --git a/templates/azure-standalone-cp/templates/azuremachinetemplate-controlplane.yaml b/templates/cluster/azure-standalone-cp/templates/azuremachinetemplate-controlplane.yaml similarity index 100% rename from templates/azure-standalone-cp/templates/azuremachinetemplate-controlplane.yaml rename to templates/cluster/azure-standalone-cp/templates/azuremachinetemplate-controlplane.yaml diff --git a/templates/azure-standalone-cp/templates/azuremachinetemplate-worker.yaml b/templates/cluster/azure-standalone-cp/templates/azuremachinetemplate-worker.yaml similarity index 100% rename from templates/azure-standalone-cp/templates/azuremachinetemplate-worker.yaml rename to templates/cluster/azure-standalone-cp/templates/azuremachinetemplate-worker.yaml diff --git a/templates/azure-standalone-cp/templates/cluster.yaml b/templates/cluster/azure-standalone-cp/templates/cluster.yaml similarity index 100% rename from templates/azure-standalone-cp/templates/cluster.yaml rename to templates/cluster/azure-standalone-cp/templates/cluster.yaml diff --git a/templates/azure-standalone-cp/templates/k0scontrolplane.yaml b/templates/cluster/azure-standalone-cp/templates/k0scontrolplane.yaml similarity index 100% rename from templates/azure-standalone-cp/templates/k0scontrolplane.yaml rename to templates/cluster/azure-standalone-cp/templates/k0scontrolplane.yaml diff --git a/templates/azure-standalone-cp/templates/k0sworkerconfigtemplate.yaml b/templates/cluster/azure-standalone-cp/templates/k0sworkerconfigtemplate.yaml similarity index 100% rename from templates/azure-standalone-cp/templates/k0sworkerconfigtemplate.yaml rename to templates/cluster/azure-standalone-cp/templates/k0sworkerconfigtemplate.yaml diff --git a/templates/azure-standalone-cp/templates/machinedeployment.yaml b/templates/cluster/azure-standalone-cp/templates/machinedeployment.yaml similarity index 100% rename from templates/azure-standalone-cp/templates/machinedeployment.yaml rename to templates/cluster/azure-standalone-cp/templates/machinedeployment.yaml diff --git a/templates/azure-standalone-cp/values.schema.json b/templates/cluster/azure-standalone-cp/values.schema.json similarity index 100% rename from templates/azure-standalone-cp/values.schema.json rename to templates/cluster/azure-standalone-cp/values.schema.json diff --git a/templates/azure-standalone-cp/values.yaml b/templates/cluster/azure-standalone-cp/values.yaml similarity index 100% rename from templates/azure-standalone-cp/values.yaml rename to templates/cluster/azure-standalone-cp/values.yaml diff --git a/templates/cluster-api-provider-aws/.helmignore b/templates/provider/cluster-api-provider-aws/.helmignore similarity index 100% rename from templates/cluster-api-provider-aws/.helmignore rename to templates/provider/cluster-api-provider-aws/.helmignore diff --git a/templates/cluster-api-provider-aws/Chart.yaml b/templates/provider/cluster-api-provider-aws/Chart.yaml similarity index 97% rename from templates/cluster-api-provider-aws/Chart.yaml rename to templates/provider/cluster-api-provider-aws/Chart.yaml index 8c66e6b3a..022a29335 100644 --- a/templates/cluster-api-provider-aws/Chart.yaml +++ b/templates/provider/cluster-api-provider-aws/Chart.yaml @@ -20,5 +20,4 @@ version: 0.1.1 # It is recommended to use it with quotes. appVersion: "2.6.1" annotations: - hmc.mirantis.com/type: provider hmc.mirantis.com/infrastructure-providers: aws diff --git a/templates/cluster-api-provider-aws/templates/provider.yaml b/templates/provider/cluster-api-provider-aws/templates/provider.yaml similarity index 100% rename from templates/cluster-api-provider-aws/templates/provider.yaml rename to templates/provider/cluster-api-provider-aws/templates/provider.yaml diff --git a/templates/cluster-api-provider-aws/templates/secret.yaml b/templates/provider/cluster-api-provider-aws/templates/secret.yaml similarity index 100% rename from templates/cluster-api-provider-aws/templates/secret.yaml rename to templates/provider/cluster-api-provider-aws/templates/secret.yaml diff --git a/templates/cluster-api-provider-aws/values.schema.json b/templates/provider/cluster-api-provider-aws/values.schema.json similarity index 100% rename from templates/cluster-api-provider-aws/values.schema.json rename to templates/provider/cluster-api-provider-aws/values.schema.json diff --git a/templates/cluster-api-provider-aws/values.yaml b/templates/provider/cluster-api-provider-aws/values.yaml similarity index 100% rename from templates/cluster-api-provider-aws/values.yaml rename to templates/provider/cluster-api-provider-aws/values.yaml diff --git a/templates/cluster-api-provider-azure/.helmignore b/templates/provider/cluster-api-provider-azure/.helmignore similarity index 100% rename from templates/cluster-api-provider-azure/.helmignore rename to templates/provider/cluster-api-provider-azure/.helmignore diff --git a/templates/cluster-api-provider-azure/Chart.yaml b/templates/provider/cluster-api-provider-azure/Chart.yaml similarity index 97% rename from templates/cluster-api-provider-azure/Chart.yaml rename to templates/provider/cluster-api-provider-azure/Chart.yaml index 1d01e46c1..c7aba8223 100644 --- a/templates/cluster-api-provider-azure/Chart.yaml +++ b/templates/provider/cluster-api-provider-azure/Chart.yaml @@ -20,5 +20,4 @@ version: 0.0.1 # It is recommended to use it with quotes. appVersion: "1.16.0" annotations: - hmc.mirantis.com/type: provider hmc.mirantis.com/infrastructure-providers: azure diff --git a/templates/cluster-api-provider-azure/templates/provider.yaml b/templates/provider/cluster-api-provider-azure/templates/provider.yaml similarity index 100% rename from templates/cluster-api-provider-azure/templates/provider.yaml rename to templates/provider/cluster-api-provider-azure/templates/provider.yaml diff --git a/templates/cluster-api-provider-azure/templates/secret.yaml b/templates/provider/cluster-api-provider-azure/templates/secret.yaml similarity index 100% rename from templates/cluster-api-provider-azure/templates/secret.yaml rename to templates/provider/cluster-api-provider-azure/templates/secret.yaml diff --git a/templates/cluster-api-provider-azure/values.schema.json b/templates/provider/cluster-api-provider-azure/values.schema.json similarity index 100% rename from templates/cluster-api-provider-azure/values.schema.json rename to templates/provider/cluster-api-provider-azure/values.schema.json diff --git a/templates/cluster-api-provider-azure/values.yaml b/templates/provider/cluster-api-provider-azure/values.yaml similarity index 100% rename from templates/cluster-api-provider-azure/values.yaml rename to templates/provider/cluster-api-provider-azure/values.yaml diff --git a/templates/cluster-api/.helmignore b/templates/provider/cluster-api/.helmignore similarity index 100% rename from templates/cluster-api/.helmignore rename to templates/provider/cluster-api/.helmignore diff --git a/templates/cluster-api/Chart.yaml b/templates/provider/cluster-api/Chart.yaml similarity index 96% rename from templates/cluster-api/Chart.yaml rename to templates/provider/cluster-api/Chart.yaml index 534ef5610..49cb715f1 100644 --- a/templates/cluster-api/Chart.yaml +++ b/templates/provider/cluster-api/Chart.yaml @@ -19,5 +19,3 @@ version: 0.1.1 # follow Semantic Versioning. They should reflect the version the application is using. # It is recommended to use it with quotes. appVersion: "1.7.2" -annotations: - hmc.mirantis.com/type: core diff --git a/templates/cluster-api/templates/provider.yaml b/templates/provider/cluster-api/templates/provider.yaml similarity index 100% rename from templates/cluster-api/templates/provider.yaml rename to templates/provider/cluster-api/templates/provider.yaml diff --git a/templates/cluster-api/templates/secret.yaml b/templates/provider/cluster-api/templates/secret.yaml similarity index 100% rename from templates/cluster-api/templates/secret.yaml rename to templates/provider/cluster-api/templates/secret.yaml diff --git a/templates/cluster-api/values.schema.json b/templates/provider/cluster-api/values.schema.json similarity index 100% rename from templates/cluster-api/values.schema.json rename to templates/provider/cluster-api/values.schema.json diff --git a/templates/cluster-api/values.yaml b/templates/provider/cluster-api/values.yaml similarity index 100% rename from templates/cluster-api/values.yaml rename to templates/provider/cluster-api/values.yaml diff --git a/templates/hmc-templates/.helmignore b/templates/provider/hmc-templates/.helmignore similarity index 100% rename from templates/hmc-templates/.helmignore rename to templates/provider/hmc-templates/.helmignore diff --git a/templates/hmc-templates/Chart.yaml b/templates/provider/hmc-templates/Chart.yaml similarity index 96% rename from templates/hmc-templates/Chart.yaml rename to templates/provider/hmc-templates/Chart.yaml index 37c1ad74f..7fdbaf1f8 100644 --- a/templates/hmc-templates/Chart.yaml +++ b/templates/provider/hmc-templates/Chart.yaml @@ -19,5 +19,3 @@ 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: core diff --git a/templates/hmc-templates/files/templates/aws-hosted-cp.yaml b/templates/provider/hmc-templates/files/templates/aws-hosted-cp.yaml similarity index 86% rename from templates/hmc-templates/files/templates/aws-hosted-cp.yaml rename to templates/provider/hmc-templates/files/templates/aws-hosted-cp.yaml index 3e6a46838..34254aacb 100644 --- a/templates/hmc-templates/files/templates/aws-hosted-cp.yaml +++ b/templates/provider/hmc-templates/files/templates/aws-hosted-cp.yaml @@ -1,5 +1,5 @@ apiVersion: hmc.mirantis.com/v1alpha1 -kind: Template +kind: ClusterTemplate metadata: name: aws-hosted-cp spec: diff --git a/templates/hmc-templates/files/templates/aws-standalone-cp.yaml b/templates/provider/hmc-templates/files/templates/aws-standalone-cp.yaml similarity index 86% rename from templates/hmc-templates/files/templates/aws-standalone-cp.yaml rename to templates/provider/hmc-templates/files/templates/aws-standalone-cp.yaml index 31f785f0d..5f6d1b55d 100644 --- a/templates/hmc-templates/files/templates/aws-standalone-cp.yaml +++ b/templates/provider/hmc-templates/files/templates/aws-standalone-cp.yaml @@ -1,5 +1,5 @@ apiVersion: hmc.mirantis.com/v1alpha1 -kind: Template +kind: ClusterTemplate metadata: name: aws-standalone-cp spec: diff --git a/templates/hmc-templates/files/templates/azure-hosted-cp.yaml b/templates/provider/hmc-templates/files/templates/azure-hosted-cp.yaml similarity index 86% rename from templates/hmc-templates/files/templates/azure-hosted-cp.yaml rename to templates/provider/hmc-templates/files/templates/azure-hosted-cp.yaml index 4f91571ad..d8c45c35d 100644 --- a/templates/hmc-templates/files/templates/azure-hosted-cp.yaml +++ b/templates/provider/hmc-templates/files/templates/azure-hosted-cp.yaml @@ -1,5 +1,5 @@ apiVersion: hmc.mirantis.com/v1alpha1 -kind: Template +kind: ClusterTemplate metadata: name: azure-hosted-cp spec: diff --git a/templates/hmc-templates/files/templates/azure-standalone-cp.yaml b/templates/provider/hmc-templates/files/templates/azure-standalone-cp.yaml similarity index 87% rename from templates/hmc-templates/files/templates/azure-standalone-cp.yaml rename to templates/provider/hmc-templates/files/templates/azure-standalone-cp.yaml index 7276ef07a..bf5aece44 100644 --- a/templates/hmc-templates/files/templates/azure-standalone-cp.yaml +++ b/templates/provider/hmc-templates/files/templates/azure-standalone-cp.yaml @@ -1,5 +1,5 @@ apiVersion: hmc.mirantis.com/v1alpha1 -kind: Template +kind: ClusterTemplate metadata: name: azure-standalone-cp spec: diff --git a/templates/hmc-templates/files/templates/cluster-api-provider-aws.yaml b/templates/provider/hmc-templates/files/templates/cluster-api-provider-aws.yaml similarity index 87% rename from templates/hmc-templates/files/templates/cluster-api-provider-aws.yaml rename to templates/provider/hmc-templates/files/templates/cluster-api-provider-aws.yaml index f362de5fd..6e3bdd67b 100644 --- a/templates/hmc-templates/files/templates/cluster-api-provider-aws.yaml +++ b/templates/provider/hmc-templates/files/templates/cluster-api-provider-aws.yaml @@ -1,5 +1,5 @@ apiVersion: hmc.mirantis.com/v1alpha1 -kind: Template +kind: ProviderTemplate metadata: name: cluster-api-provider-aws spec: diff --git a/templates/hmc-templates/files/templates/cluster-api-provider-azure.yaml b/templates/provider/hmc-templates/files/templates/cluster-api-provider-azure.yaml similarity index 87% rename from templates/hmc-templates/files/templates/cluster-api-provider-azure.yaml rename to templates/provider/hmc-templates/files/templates/cluster-api-provider-azure.yaml index ebc64f6ec..e3e31ccc7 100644 --- a/templates/hmc-templates/files/templates/cluster-api-provider-azure.yaml +++ b/templates/provider/hmc-templates/files/templates/cluster-api-provider-azure.yaml @@ -1,5 +1,5 @@ apiVersion: hmc.mirantis.com/v1alpha1 -kind: Template +kind: ProviderTemplate metadata: name: cluster-api-provider-azure spec: diff --git a/templates/hmc-templates/files/templates/cluster-api.yaml b/templates/provider/hmc-templates/files/templates/cluster-api.yaml similarity index 85% rename from templates/hmc-templates/files/templates/cluster-api.yaml rename to templates/provider/hmc-templates/files/templates/cluster-api.yaml index 661b74267..5b3bc3970 100644 --- a/templates/hmc-templates/files/templates/cluster-api.yaml +++ b/templates/provider/hmc-templates/files/templates/cluster-api.yaml @@ -1,5 +1,5 @@ apiVersion: hmc.mirantis.com/v1alpha1 -kind: Template +kind: ProviderTemplate metadata: name: cluster-api spec: diff --git a/templates/hmc-templates/files/templates/hmc.yaml b/templates/provider/hmc-templates/files/templates/hmc.yaml similarity index 83% rename from templates/hmc-templates/files/templates/hmc.yaml rename to templates/provider/hmc-templates/files/templates/hmc.yaml index 5dceb1c29..4dd8f23f1 100644 --- a/templates/hmc-templates/files/templates/hmc.yaml +++ b/templates/provider/hmc-templates/files/templates/hmc.yaml @@ -1,5 +1,5 @@ apiVersion: hmc.mirantis.com/v1alpha1 -kind: Template +kind: ProviderTemplate metadata: name: hmc spec: diff --git a/templates/hmc-templates/files/templates/k0smotron.yaml b/templates/provider/hmc-templates/files/templates/k0smotron.yaml similarity index 84% rename from templates/hmc-templates/files/templates/k0smotron.yaml rename to templates/provider/hmc-templates/files/templates/k0smotron.yaml index cd2c2ea33..98e12fb44 100644 --- a/templates/hmc-templates/files/templates/k0smotron.yaml +++ b/templates/provider/hmc-templates/files/templates/k0smotron.yaml @@ -1,5 +1,5 @@ apiVersion: hmc.mirantis.com/v1alpha1 -kind: Template +kind: ProviderTemplate metadata: name: k0smotron spec: diff --git a/templates/hmc-templates/templates/templates.yaml b/templates/provider/hmc-templates/templates/templates.yaml similarity index 100% rename from templates/hmc-templates/templates/templates.yaml rename to templates/provider/hmc-templates/templates/templates.yaml diff --git a/templates/hmc-templates/values.schema.json b/templates/provider/hmc-templates/values.schema.json similarity index 100% rename from templates/hmc-templates/values.schema.json rename to templates/provider/hmc-templates/values.schema.json diff --git a/templates/hmc-templates/values.yaml b/templates/provider/hmc-templates/values.yaml similarity index 100% rename from templates/hmc-templates/values.yaml rename to templates/provider/hmc-templates/values.yaml diff --git a/templates/hmc/.helmignore b/templates/provider/hmc/.helmignore similarity index 100% rename from templates/hmc/.helmignore rename to templates/provider/hmc/.helmignore diff --git a/templates/hmc/Chart.lock b/templates/provider/hmc/Chart.lock similarity index 100% rename from templates/hmc/Chart.lock rename to templates/provider/hmc/Chart.lock diff --git a/templates/hmc/Chart.yaml b/templates/provider/hmc/Chart.yaml similarity index 97% rename from templates/hmc/Chart.yaml rename to templates/provider/hmc/Chart.yaml index f99b27224..b9d03de91 100644 --- a/templates/hmc/Chart.yaml +++ b/templates/provider/hmc/Chart.yaml @@ -19,8 +19,6 @@ 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: core dependencies: - name: flux2 diff --git a/templates/hmc/templates/_helpers.tpl b/templates/provider/hmc/templates/_helpers.tpl similarity index 100% rename from templates/hmc/templates/_helpers.tpl rename to templates/provider/hmc/templates/_helpers.tpl diff --git a/templates/hmc/templates/certificate.yaml b/templates/provider/hmc/templates/certificate.yaml similarity index 100% rename from templates/hmc/templates/certificate.yaml rename to templates/provider/hmc/templates/certificate.yaml diff --git a/templates/hmc/templates/crds/hmc.mirantis.com_templates.yaml b/templates/provider/hmc/templates/crds/hmc.mirantis.com_clustertemplates.yaml similarity index 88% rename from templates/hmc/templates/crds/hmc.mirantis.com_templates.yaml rename to templates/provider/hmc/templates/crds/hmc.mirantis.com_clustertemplates.yaml index 91f461259..9a96c6da1 100644 --- a/templates/hmc/templates/crds/hmc.mirantis.com_templates.yaml +++ b/templates/provider/hmc/templates/crds/hmc.mirantis.com_clustertemplates.yaml @@ -4,24 +4,19 @@ kind: CustomResourceDefinition metadata: annotations: controller-gen.kubebuilder.io/version: v0.14.0 - name: templates.hmc.mirantis.com + name: clustertemplates.hmc.mirantis.com spec: group: hmc.mirantis.com names: - kind: Template - listKind: TemplateList - plural: templates + kind: ClusterTemplate + listKind: ClusterTemplateList + plural: clustertemplates shortNames: - - hmc-tmpl - - tmpl - singular: template + - clustertmpl + singular: clustertemplate scope: Namespaced versions: - additionalPrinterColumns: - - description: Type - jsonPath: .status.type - name: type - type: string - description: Valid jsonPath: .status.valid name: valid @@ -39,7 +34,7 @@ spec: name: v1alpha1 schema: openAPIV3Schema: - description: Template is the Schema for the templates API + description: ClusterTemplate is the Schema for the cluster templates API properties: apiVersion: description: |- @@ -59,7 +54,7 @@ spec: metadata: type: object spec: - description: TemplateSpec defines the desired state of Template + description: ClusterTemplateSpec defines the desired state of ClusterTemplate properties: helm: description: Helm holds a reference to a Helm chart representing the @@ -132,20 +127,11 @@ spec: 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 status: - description: TemplateStatus defines the observed state of Template + description: ClusterTemplateStatus defines the observed state of ClusterTemplate properties: chartRef: description: |- @@ -212,14 +198,6 @@ spec: type: string type: array type: object - type: - description: Type specifies the type of the provided template, as - discovered from the Helm chart metadata. - enum: - - deployment - - provider - - core - type: string valid: description: Valid indicates whether the template passed validation or not. diff --git a/templates/hmc/templates/crds/hmc.mirantis.com_managedclusters.yaml b/templates/provider/hmc/templates/crds/hmc.mirantis.com_managedclusters.yaml similarity index 100% rename from templates/hmc/templates/crds/hmc.mirantis.com_managedclusters.yaml rename to templates/provider/hmc/templates/crds/hmc.mirantis.com_managedclusters.yaml diff --git a/templates/hmc/templates/crds/hmc.mirantis.com_managements.yaml b/templates/provider/hmc/templates/crds/hmc.mirantis.com_managements.yaml similarity index 100% rename from templates/hmc/templates/crds/hmc.mirantis.com_managements.yaml rename to templates/provider/hmc/templates/crds/hmc.mirantis.com_managements.yaml diff --git a/templates/provider/hmc/templates/crds/hmc.mirantis.com_providertemplates.yaml b/templates/provider/hmc/templates/crds/hmc.mirantis.com_providertemplates.yaml new file mode 100644 index 000000000..146435ccf --- /dev/null +++ b/templates/provider/hmc/templates/crds/hmc.mirantis.com_providertemplates.yaml @@ -0,0 +1,216 @@ +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.14.0 + name: providertemplates.hmc.mirantis.com +spec: + group: hmc.mirantis.com + names: + kind: ProviderTemplate + listKind: ProviderTemplateList + plural: providertemplates + shortNames: + - providertmpl + singular: providertemplate + scope: Cluster + versions: + - additionalPrinterColumns: + - 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: ProviderTemplate is the Schema for the provider templates API + properties: + apiVersion: + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + type: string + kind: + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + description: ProviderTemplateSpec defines the desired state of ProviderTemplate + properties: + helm: + description: Helm holds a reference to a Helm chart representing the + HMC template + properties: + chartName: + description: ChartName is a name of a Helm chart representing + the template in the HMC repository. + type: string + chartRef: + description: |- + ChartRef is a reference to a source controller resource containing the + Helm chart representing the template. + properties: + apiVersion: + description: APIVersion of the referent. + type: string + kind: + description: Kind of the referent. + enum: + - OCIRepository + - HelmChart + type: string + name: + description: Name of the referent. + maxLength: 253 + minLength: 1 + type: string + namespace: + description: |- + Namespace of the referent, defaults to the namespace of the Kubernetes + resource object that contains the reference. + maxLength: 63 + minLength: 1 + type: string + required: + - kind + - name + type: object + chartVersion: + description: ChartVersion is a version of a Helm chart representing + the template in the HMC repository. + type: string + type: object + x-kubernetes-validations: + - 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 + required: + - helm + type: object + status: + description: ProviderTemplateStatus defines the observed state of ProviderTemplate + properties: + chartRef: + description: |- + ChartRef is a reference to a source controller resource containing the + Helm chart representing the template. + properties: + apiVersion: + description: APIVersion of the referent. + type: string + kind: + description: Kind of the referent. + enum: + - OCIRepository + - HelmChart + type: string + name: + description: Name of the referent. + maxLength: 253 + minLength: 1 + type: string + namespace: + description: |- + Namespace of the referent, defaults to the namespace of the Kubernetes + resource object that contains the reference. + maxLength: 63 + minLength: 1 + type: string + required: + - kind + - name + type: object + config: + description: |- + Config demonstrates available parameters for template customization, + that can be used when creating ManagedCluster objects. + x-kubernetes-preserve-unknown-fields: true + description: + description: Description contains information about the template. + type: string + 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 + valid: + description: Valid indicates whether the template passed validation + or not. + type: boolean + validationError: + description: ValidationError provides information regarding issues + encountered during template validation. + type: string + required: + - valid + type: object + type: object + served: true + storage: true + subresources: + status: {} diff --git a/templates/provider/hmc/templates/crds/hmc.mirantis.com_servicetemplates.yaml b/templates/provider/hmc/templates/crds/hmc.mirantis.com_servicetemplates.yaml new file mode 100644 index 000000000..f8c48a216 --- /dev/null +++ b/templates/provider/hmc/templates/crds/hmc.mirantis.com_servicetemplates.yaml @@ -0,0 +1,216 @@ +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.14.0 + name: servicetemplates.hmc.mirantis.com +spec: + group: hmc.mirantis.com + names: + kind: ServiceTemplate + listKind: ServiceTemplateList + plural: servicetemplates + shortNames: + - svctmpl + singular: servicetemplate + scope: Namespaced + versions: + - additionalPrinterColumns: + - 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: ServiceTemplate is the Schema for the service templates API + properties: + apiVersion: + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + type: string + kind: + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + description: ServiceTemplateSpec defines the desired state of ServiceTemplate + properties: + helm: + description: Helm holds a reference to a Helm chart representing the + HMC template + properties: + chartName: + description: ChartName is a name of a Helm chart representing + the template in the HMC repository. + type: string + chartRef: + description: |- + ChartRef is a reference to a source controller resource containing the + Helm chart representing the template. + properties: + apiVersion: + description: APIVersion of the referent. + type: string + kind: + description: Kind of the referent. + enum: + - OCIRepository + - HelmChart + type: string + name: + description: Name of the referent. + maxLength: 253 + minLength: 1 + type: string + namespace: + description: |- + Namespace of the referent, defaults to the namespace of the Kubernetes + resource object that contains the reference. + maxLength: 63 + minLength: 1 + type: string + required: + - kind + - name + type: object + chartVersion: + description: ChartVersion is a version of a Helm chart representing + the template in the HMC repository. + type: string + type: object + x-kubernetes-validations: + - 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 + required: + - helm + type: object + status: + description: ServiceTemplateStatus defines the observed state of ServiceTemplate + properties: + chartRef: + description: |- + ChartRef is a reference to a source controller resource containing the + Helm chart representing the template. + properties: + apiVersion: + description: APIVersion of the referent. + type: string + kind: + description: Kind of the referent. + enum: + - OCIRepository + - HelmChart + type: string + name: + description: Name of the referent. + maxLength: 253 + minLength: 1 + type: string + namespace: + description: |- + Namespace of the referent, defaults to the namespace of the Kubernetes + resource object that contains the reference. + maxLength: 63 + minLength: 1 + type: string + required: + - kind + - name + type: object + config: + description: |- + Config demonstrates available parameters for template customization, + that can be used when creating ManagedCluster objects. + x-kubernetes-preserve-unknown-fields: true + description: + description: Description contains information about the template. + type: string + 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 + valid: + description: Valid indicates whether the template passed validation + or not. + type: boolean + validationError: + description: ValidationError provides information regarding issues + encountered during template validation. + type: string + required: + - valid + type: object + type: object + served: true + storage: true + subresources: + status: {} diff --git a/templates/hmc/templates/deployment.yaml b/templates/provider/hmc/templates/deployment.yaml similarity index 100% rename from templates/hmc/templates/deployment.yaml rename to templates/provider/hmc/templates/deployment.yaml diff --git a/templates/hmc/templates/issuer.yaml b/templates/provider/hmc/templates/issuer.yaml similarity index 100% rename from templates/hmc/templates/issuer.yaml rename to templates/provider/hmc/templates/issuer.yaml diff --git a/templates/hmc/templates/metrics-service.yaml b/templates/provider/hmc/templates/metrics-service.yaml similarity index 100% rename from templates/hmc/templates/metrics-service.yaml rename to templates/provider/hmc/templates/metrics-service.yaml diff --git a/templates/hmc/templates/rbac/leader-election-rbac.yaml b/templates/provider/hmc/templates/rbac/leader-election-rbac.yaml similarity index 100% rename from templates/hmc/templates/rbac/leader-election-rbac.yaml rename to templates/provider/hmc/templates/rbac/leader-election-rbac.yaml diff --git a/templates/hmc/templates/rbac/rolebindings.yaml b/templates/provider/hmc/templates/rbac/rolebindings.yaml similarity index 100% rename from templates/hmc/templates/rbac/rolebindings.yaml rename to templates/provider/hmc/templates/rbac/rolebindings.yaml diff --git a/templates/hmc/templates/rbac/roles.yaml b/templates/provider/hmc/templates/rbac/roles.yaml similarity index 88% rename from templates/hmc/templates/rbac/roles.yaml rename to templates/provider/hmc/templates/rbac/roles.yaml index 68b0cd575..4a72d9312 100644 --- a/templates/hmc/templates/rbac/roles.yaml +++ b/templates/provider/hmc/templates/rbac/roles.yaml @@ -79,7 +79,9 @@ rules: - apiGroups: - hmc.mirantis.com resources: - - templates + - clustertemplates + - servicetemplates + - providertemplates verbs: - create - delete @@ -91,13 +93,17 @@ rules: - apiGroups: - hmc.mirantis.com resources: - - templates/finalizers + - clustertemplates/finalizers + - servicetemplates/finalizers + - providertemplates/finalizers verbs: - update - apiGroups: - hmc.mirantis.com resources: - - templates/status + - clustertemplates/status + - servicetemplates/status + - providertemplates/status verbs: - get - patch diff --git a/templates/hmc/templates/service.yaml b/templates/provider/hmc/templates/service.yaml similarity index 100% rename from templates/hmc/templates/service.yaml rename to templates/provider/hmc/templates/service.yaml diff --git a/templates/hmc/templates/serviceaccount.yaml b/templates/provider/hmc/templates/serviceaccount.yaml similarity index 100% rename from templates/hmc/templates/serviceaccount.yaml rename to templates/provider/hmc/templates/serviceaccount.yaml diff --git a/templates/hmc/templates/webhooks.yaml b/templates/provider/hmc/templates/webhooks.yaml similarity index 59% rename from templates/hmc/templates/webhooks.yaml rename to templates/provider/hmc/templates/webhooks.yaml index 418d4f060..6eaca0138 100644 --- a/templates/hmc/templates/webhooks.yaml +++ b/templates/provider/hmc/templates/webhooks.yaml @@ -57,10 +57,10 @@ webhooks: service: name: {{ include "hmc.webhook.serviceName" . }} namespace: {{ include "hmc.webhook.serviceNamespace" . }} - path: /mutate-hmc-mirantis-com-v1alpha1-template + path: /mutate-hmc-mirantis-com-v1alpha1-clustertemplate failurePolicy: Fail matchPolicy: Equivalent - name: mutation.template.hmc.mirantis.com + name: mutation.clustertemplate.hmc.mirantis.com rules: - apiGroups: - hmc.mirantis.com @@ -70,7 +70,51 @@ webhooks: - CREATE - UPDATE resources: - - templates + - clustertemplates + sideEffects: None + - admissionReviewVersions: + - v1 + - v1beta1 + clientConfig: + service: + name: {{ include "hmc.webhook.serviceName" . }} + namespace: {{ include "hmc.webhook.serviceNamespace" . }} + path: /mutate-hmc-mirantis-com-v1alpha1-servicetemplate + failurePolicy: Fail + matchPolicy: Equivalent + name: mutation.servicetemplate.hmc.mirantis.com + rules: + - apiGroups: + - hmc.mirantis.com + apiVersions: + - v1alpha1 + operations: + - CREATE + - UPDATE + resources: + - servicetemplates + sideEffects: None + - admissionReviewVersions: + - v1 + - v1beta1 + clientConfig: + service: + name: {{ include "hmc.webhook.serviceName" . }} + namespace: {{ include "hmc.webhook.serviceNamespace" . }} + path: /mutate-hmc-mirantis-com-v1alpha1-providertemplate + failurePolicy: Fail + matchPolicy: Equivalent + name: mutation.providertemplate.hmc.mirantis.com + rules: + - apiGroups: + - hmc.mirantis.com + apiVersions: + - v1alpha1 + operations: + - CREATE + - UPDATE + resources: + - providertemplates sideEffects: None --- apiVersion: admissionregistration.k8s.io/v1 @@ -133,10 +177,56 @@ webhooks: service: name: {{ include "hmc.webhook.serviceName" . }} namespace: {{ include "hmc.webhook.serviceNamespace" . }} - path: /validate-hmc-mirantis-com-v1alpha1-template + path: /validate-hmc-mirantis-com-v1alpha1-clustertemplate + failurePolicy: Fail + matchPolicy: Equivalent + name: validation.clustertemplate.hmc.mirantis.com + rules: + - apiGroups: + - hmc.mirantis.com + apiVersions: + - v1alpha1 + operations: + - CREATE + - UPDATE + - DELETE + resources: + - clustertemplates + sideEffects: None + - admissionReviewVersions: + - v1 + - v1beta1 + clientConfig: + service: + name: {{ include "hmc.webhook.serviceName" . }} + namespace: {{ include "hmc.webhook.serviceNamespace" . }} + path: /validate-hmc-mirantis-com-v1alpha1-servicetemplate + failurePolicy: Fail + matchPolicy: Equivalent + name: validation.servicetemplate.hmc.mirantis.com + rules: + - apiGroups: + - hmc.mirantis.com + apiVersions: + - v1alpha1 + operations: + - CREATE + - UPDATE + - DELETE + resources: + - servicetemplates + sideEffects: None + - admissionReviewVersions: + - v1 + - v1beta1 + clientConfig: + service: + name: {{ include "hmc.webhook.serviceName" . }} + namespace: {{ include "hmc.webhook.serviceNamespace" . }} + path: /validate-hmc-mirantis-com-v1alpha1-providertemplate failurePolicy: Fail matchPolicy: Equivalent - name: validation.template.hmc.mirantis.com + name: validation.providertemplate.hmc.mirantis.com rules: - apiGroups: - hmc.mirantis.com @@ -147,6 +237,6 @@ webhooks: - UPDATE - DELETE resources: - - templates + - providertemplates sideEffects: None {{- end }} diff --git a/templates/hmc/values.schema.json b/templates/provider/hmc/values.schema.json similarity index 100% rename from templates/hmc/values.schema.json rename to templates/provider/hmc/values.schema.json diff --git a/templates/hmc/values.yaml b/templates/provider/hmc/values.yaml similarity index 100% rename from templates/hmc/values.yaml rename to templates/provider/hmc/values.yaml diff --git a/templates/k0smotron/.helmignore b/templates/provider/k0smotron/.helmignore similarity index 100% rename from templates/k0smotron/.helmignore rename to templates/provider/k0smotron/.helmignore diff --git a/templates/k0smotron/Chart.yaml b/templates/provider/k0smotron/Chart.yaml similarity index 97% rename from templates/k0smotron/Chart.yaml rename to templates/provider/k0smotron/Chart.yaml index 8e715a2ef..2220637c1 100644 --- a/templates/k0smotron/Chart.yaml +++ b/templates/provider/k0smotron/Chart.yaml @@ -20,7 +20,6 @@ version: 0.1.3 # It is recommended to use it with quotes. appVersion: "1.0.4" annotations: - hmc.mirantis.com/type: provider hmc.mirantis.com/infrastructure-providers: k0smotron hmc.mirantis.com/bootstrap-providers: k0s hmc.mirantis.com/control-plane-providers: k0s,k0smotron diff --git a/templates/k0smotron/templates/providers.yaml b/templates/provider/k0smotron/templates/providers.yaml similarity index 100% rename from templates/k0smotron/templates/providers.yaml rename to templates/provider/k0smotron/templates/providers.yaml diff --git a/templates/k0smotron/templates/secret.yaml b/templates/provider/k0smotron/templates/secret.yaml similarity index 100% rename from templates/k0smotron/templates/secret.yaml rename to templates/provider/k0smotron/templates/secret.yaml diff --git a/templates/k0smotron/values.schema.json b/templates/provider/k0smotron/values.schema.json similarity index 100% rename from templates/k0smotron/values.schema.json rename to templates/provider/k0smotron/values.schema.json diff --git a/templates/k0smotron/values.yaml b/templates/provider/k0smotron/values.yaml similarity index 100% rename from templates/k0smotron/values.yaml rename to templates/provider/k0smotron/values.yaml diff --git a/test/objects/template/template.go b/test/objects/template/template.go index 27e5b7bf7..3cda23d3f 100644 --- a/test/objects/template/template.go +++ b/test/objects/template/template.go @@ -26,73 +26,93 @@ const ( DefaultNamespace = "hmc-system" ) -type Opt func(template *v1alpha1.Template) +type Template struct { + metav1.ObjectMeta `json:",inline"` + Spec v1alpha1.TemplateSpecMixin `json:"spec"` + Status v1alpha1.TemplateStatusMixin `json:"status"` +} + +type Opt func(template *Template) + +func NewClusterTemplate(opts ...Opt) *v1alpha1.ClusterTemplate { + templateState := NewTemplate(opts...) + return &v1alpha1.ClusterTemplate{ + ObjectMeta: templateState.ObjectMeta, + Spec: v1alpha1.ClusterTemplateSpec{TemplateSpecMixin: templateState.Spec}, + Status: v1alpha1.ClusterTemplateStatus{TemplateStatusMixin: templateState.Status}, + } +} + +func NewServiceTemplate(opts ...Opt) *v1alpha1.ServiceTemplate { + templateState := NewTemplate(opts...) + return &v1alpha1.ServiceTemplate{ + ObjectMeta: templateState.ObjectMeta, + Spec: v1alpha1.ServiceTemplateSpec{TemplateSpecMixin: templateState.Spec}, + Status: v1alpha1.ServiceTemplateStatus{TemplateStatusMixin: templateState.Status}, + } +} + +func NewProviderTemplate(opts ...Opt) *v1alpha1.ProviderTemplate { + templateState := NewTemplate(opts...) + return &v1alpha1.ProviderTemplate{ + ObjectMeta: templateState.ObjectMeta, + Spec: v1alpha1.ProviderTemplateSpec{TemplateSpecMixin: templateState.Spec}, + Status: v1alpha1.ProviderTemplateStatus{TemplateStatusMixin: templateState.Status}, + } +} -func NewTemplate(opts ...Opt) *v1alpha1.Template { - p := &v1alpha1.Template{ +func NewTemplate(opts ...Opt) *Template { + template := &Template{ ObjectMeta: metav1.ObjectMeta{ Name: DefaultName, Namespace: DefaultNamespace, }, } - for _, opt := range opts { - opt(p) + opt(template) } - return p + return template } func WithName(name string) Opt { - return func(p *v1alpha1.Template) { - p.Name = name + return func(t *Template) { + t.Name = name } } func WithNamespace(namespace string) Opt { - return func(p *v1alpha1.Template) { - p.Namespace = namespace + return func(t *Template) { + t.Namespace = namespace } } func WithHelmSpec(helmSpec v1alpha1.HelmSpec) Opt { - return func(p *v1alpha1.Template) { - p.Spec.Helm = helmSpec - } -} - -func WithType(templateType v1alpha1.TemplateType) Opt { - return func(p *v1alpha1.Template) { - p.Spec.Type = templateType + return func(t *Template) { + t.Spec.Helm = helmSpec } } func WithProviders(providers v1alpha1.Providers) Opt { - return func(p *v1alpha1.Template) { - p.Spec.Providers = providers - } -} - -func WithTypeStatus(templateType v1alpha1.TemplateType) Opt { - return func(p *v1alpha1.Template) { - p.Status.Type = templateType + return func(t *Template) { + t.Spec.Providers = providers } } func WithValidationStatus(validationStatus v1alpha1.TemplateValidationStatus) Opt { - return func(p *v1alpha1.Template) { - p.Status.TemplateValidationStatus = validationStatus + return func(t *Template) { + t.Status.TemplateValidationStatus = validationStatus } } func WithProvidersStatus(providers v1alpha1.Providers) Opt { - return func(p *v1alpha1.Template) { - p.Status.Providers = providers + return func(t *Template) { + t.Status.Providers = providers } } func WithConfigStatus(config string) Opt { - return func(p *v1alpha1.Template) { - p.Status.Config = &apiextensionsv1.JSON{ + return func(t *Template) { + t.Status.Config = &apiextensionsv1.JSON{ Raw: []byte(config), } }