diff --git a/Makefile b/Makefile index 238672f16..e1a99db4b 100644 --- a/Makefile +++ b/Makefile @@ -376,7 +376,7 @@ AWSCLI ?= $(LOCALBIN)/aws ## Tool Versions CONTROLLER_TOOLS_VERSION ?= v0.14.0 ENVTEST_VERSION ?= release-0.17 -GOLANGCI_LINT_VERSION ?= v1.60.1 +GOLANGCI_LINT_VERSION ?= v1.61.0 HELM_VERSION ?= v3.15.1 KIND_VERSION ?= v0.23.0 YQ_VERSION ?= v4.44.2 diff --git a/PROJECT b/PROJECT index d42dd0100..678c620b4 100644 --- a/PROJECT +++ b/PROJECT @@ -14,7 +14,7 @@ resources: controller: true domain: hmc.mirantis.com group: hmc.mirantis.com - kind: Template + kind: ManagedCluster path: github.com/Mirantis/hmc/api/v1alpha1 version: v1alpha1 - api: @@ -23,7 +23,14 @@ resources: controller: true domain: hmc.mirantis.com group: hmc.mirantis.com - kind: ManagedCluster + kind: Management + path: github.com/Mirantis/hmc/api/v1alpha1 + version: v1alpha1 +- api: + crdVersion: v1 + domain: hmc.mirantis.com + group: hmc.mirantis.com + kind: Release path: github.com/Mirantis/hmc/api/v1alpha1 version: v1alpha1 - api: @@ -32,14 +39,49 @@ resources: controller: true domain: hmc.mirantis.com group: hmc.mirantis.com - kind: Management + kind: ClusterTemplate path: github.com/Mirantis/hmc/api/v1alpha1 version: v1alpha1 - api: crdVersion: v1 + namespaced: true + controller: true domain: hmc.mirantis.com group: hmc.mirantis.com - kind: Release + kind: ProviderTemplate + path: github.com/Mirantis/hmc/api/v1alpha1 + version: v1alpha1 +- api: + crdVersion: v1 + namespaced: true + controller: true + domain: hmc.mirantis.com + group: hmc.mirantis.com + kind: ServiceTemplate + path: github.com/Mirantis/hmc/api/v1alpha1 + version: v1alpha1 +- api: + crdVersion: v1 + namespaced: true + controller: true + domain: hmc.mirantis.com + group: hmc.mirantis.com + kind: TemplateManagement + path: github.com/Mirantis/hmc/api/v1alpha1 + version: v1alpha1 +- api: + crdVersion: v1 + namespaced: true + domain: hmc.mirantis.com + group: hmc.mirantis.com + kind: ClusterTemplateChain + path: github.com/Mirantis/hmc/api/v1alpha1 + version: v1alpha1 +- api: + crdVersion: v1 + domain: hmc.mirantis.com + group: hmc.mirantis.com + kind: ServiceTemplateChain path: github.com/Mirantis/hmc/api/v1alpha1 version: v1alpha1 version: "3" diff --git a/api/v1alpha1/clustertemplate_types.go b/api/v1alpha1/clustertemplate_types.go index eacf2fd0e..2af641b4f 100644 --- a/api/v1alpha1/clustertemplate_types.go +++ b/api/v1alpha1/clustertemplate_types.go @@ -18,6 +18,24 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) +// ClusterTemplateSpec defines the desired state of ClusterTemplate +type ClusterTemplateSpec struct { + TemplateSpecCommon `json:",inline"` +} + +// ClusterTemplateStatus defines the observed state of ClusterTemplate +type ClusterTemplateStatus struct { + TemplateStatusCommon `json:",inline"` +} + +func (t *ClusterTemplate) GetSpec() *TemplateSpecCommon { + return &t.Spec.TemplateSpecCommon +} + +func (t *ClusterTemplate) GetStatus() *TemplateStatusCommon { + return &t.Status.TemplateStatusCommon +} + // +kubebuilder:object:root=true // +kubebuilder:subresource:status // +kubebuilder:resource:shortName=clustertmpl @@ -25,12 +43,13 @@ import ( // +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 +// ClusterTemplate is the Schema for the clustertemplates API type ClusterTemplate struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Spec is immutable" + Spec ClusterTemplateSpec `json:"spec,omitempty"` Status ClusterTemplateStatus `json:"status,omitempty"` } @@ -44,20 +63,6 @@ type ClusterTemplateList struct { 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 +func init() { + SchemeBuilder.Register(&ClusterTemplate{}, &ClusterTemplateList{}) } diff --git a/api/v1alpha1/clustertemplatechain_types.go b/api/v1alpha1/clustertemplatechain_types.go new file mode 100644 index 000000000..f20b4bf57 --- /dev/null +++ b/api/v1alpha1/clustertemplatechain_types.go @@ -0,0 +1,45 @@ +// 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:resource:scope=Cluster + +// ClusterTemplateChain is the Schema for the clustertemplatechains API +type ClusterTemplateChain struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Spec is immutable" + + Spec TemplateChainSpec `json:"spec,omitempty"` +} + +// +kubebuilder:object:root=true + +// ClusterTemplateChainList contains a list of ClusterTemplateChain +type ClusterTemplateChainList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []ClusterTemplateChain `json:"items"` +} + +func init() { + SchemeBuilder.Register(&ClusterTemplateChain{}, &ClusterTemplateChainList{}) +} diff --git a/api/v1alpha1/managedcluster_types.go b/api/v1alpha1/managedcluster_types.go index 158f4c7a7..7ce6ccf5a 100644 --- a/api/v1alpha1/managedcluster_types.go +++ b/api/v1alpha1/managedcluster_types.go @@ -62,27 +62,25 @@ const ( // ManagedClusterSpec defines the desired state of ManagedCluster type ManagedClusterSpec struct { - // DryRun specifies whether the template should be applied after validation or only validated. - // +optional - DryRun bool `json:"dryRun,omitempty"` - // Template is a reference to a Template object located in the same namespace. - // +kubebuilder:validation:Required - // +kubebuilder:validation:MinLength=1 - Template string `json:"template"` // Config allows to provide parameters for template customization. // If no Config provided, the field will be populated with the default values for // the template and DryRun will be enabled. - // +optional Config *apiextensionsv1.JSON `json:"config,omitempty"` + + // +kubebuilder:validation:MinLength=1 + + // Template is a reference to a Template object located in the same namespace. + Template string `json:"template"` + // DryRun specifies whether the template should be applied after validation or only validated. + DryRun bool `json:"dryRun,omitempty"` } // ManagedClusterStatus defines the observed state of ManagedCluster type ManagedClusterStatus struct { - // ObservedGeneration is the last observed generation. - // +optional - ObservedGeneration int64 `json:"observedGeneration,omitempty"` // Conditions contains details for the current state of the ManagedCluster Conditions []metav1.Condition `json:"conditions,omitempty"` + // ObservedGeneration is the last observed generation. + ObservedGeneration int64 `json:"observedGeneration,omitempty"` } //+kubebuilder:object:root=true diff --git a/api/v1alpha1/management_types.go b/api/v1alpha1/management_types.go index c6e8c4135..36adcd8ea 100644 --- a/api/v1alpha1/management_types.go +++ b/api/v1alpha1/management_types.go @@ -51,14 +51,13 @@ type Core struct { // Component represents HMC management component type Component struct { - // Template is the name of the Template associated with this component. - // If not specified, will be taken from the Release object. - Template string `json:"template,omitempty"` // Config allows to provide parameters for management component customization. // If no Config provided, the field will be populated with the default // values for the template. - // +optional Config *apiextensionsv1.JSON `json:"config,omitempty"` + // Template is the name of the Template associated with this component. + // If not specified, will be taken from the Release object. + Template string `json:"template,omitempty"` } type Provider struct { @@ -88,7 +87,6 @@ func (m *ManagementSpec) SetProvidersDefaults() error { // ManagementStatus defines the observed state of Management type ManagementStatus struct { // ObservedGeneration is the last observed generation. - // +optional ObservedGeneration int64 `json:"observedGeneration,omitempty"` // AvailableProviders holds all CAPI providers available on the Management cluster. AvailableProviders Providers `json:"availableProviders,omitempty"` diff --git a/api/v1alpha1/providertemplate_types.go b/api/v1alpha1/providertemplate_types.go index 01ddd7910..b0e30a97d 100644 --- a/api/v1alpha1/providertemplate_types.go +++ b/api/v1alpha1/providertemplate_types.go @@ -18,6 +18,24 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) +// ProviderTemplateSpec defines the desired state of ProviderTemplate +type ProviderTemplateSpec struct { + TemplateSpecCommon `json:",inline"` +} + +// ProviderTemplateStatus defines the observed state of ProviderTemplate +type ProviderTemplateStatus struct { + TemplateStatusCommon `json:",inline"` +} + +func (t *ProviderTemplate) GetSpec() *TemplateSpecCommon { + return &t.Spec.TemplateSpecCommon +} + +func (t *ProviderTemplate) GetStatus() *TemplateStatusCommon { + return &t.Status.TemplateStatusCommon +} + // +kubebuilder:object:root=true // +kubebuilder:subresource:status // +kubebuilder:resource:shortName=providertmpl,scope=Cluster @@ -25,12 +43,13 @@ import ( // +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 +// ProviderTemplate is the Schema for the providertemplates API type ProviderTemplate struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Spec is immutable" + Spec ProviderTemplateSpec `json:"spec,omitempty"` Status ProviderTemplateStatus `json:"status,omitempty"` } @@ -44,20 +63,6 @@ type ProviderTemplateList struct { 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 +func init() { + SchemeBuilder.Register(&ProviderTemplate{}, &ProviderTemplateList{}) } diff --git a/api/v1alpha1/servicetemplate_types.go b/api/v1alpha1/servicetemplate_types.go index 75fa41dd5..e9d083d18 100644 --- a/api/v1alpha1/servicetemplate_types.go +++ b/api/v1alpha1/servicetemplate_types.go @@ -18,6 +18,24 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) +// ServiceTemplateSpec defines the desired state of ServiceTemplate +type ServiceTemplateSpec struct { + TemplateSpecCommon `json:",inline"` +} + +// ServiceTemplateStatus defines the observed state of ServiceTemplate +type ServiceTemplateStatus struct { + TemplateStatusCommon `json:",inline"` +} + +func (t *ServiceTemplate) GetSpec() *TemplateSpecCommon { + return &t.Spec.TemplateSpecCommon +} + +func (t *ServiceTemplate) GetStatus() *TemplateStatusCommon { + return &t.Status.TemplateStatusCommon +} + // +kubebuilder:object:root=true // +kubebuilder:subresource:status // +kubebuilder:resource:shortName=svctmpl @@ -25,12 +43,13 @@ import ( // +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 +// ServiceTemplate is the Schema for the servicetemplates API type ServiceTemplate struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Spec is immutable" + Spec ServiceTemplateSpec `json:"spec,omitempty"` Status ServiceTemplateStatus `json:"status,omitempty"` } @@ -44,20 +63,6 @@ type ServiceTemplateList struct { 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 +func init() { + SchemeBuilder.Register(&ServiceTemplate{}, &ServiceTemplateList{}) } diff --git a/api/v1alpha1/servicetemplatechain_types.go b/api/v1alpha1/servicetemplatechain_types.go new file mode 100644 index 000000000..96eb4eb06 --- /dev/null +++ b/api/v1alpha1/servicetemplatechain_types.go @@ -0,0 +1,45 @@ +// 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:resource:scope=Cluster + +// ServiceTemplateChain is the Schema for the servicetemplatechains API +type ServiceTemplateChain struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Spec is immutable" + + Spec TemplateChainSpec `json:"spec,omitempty"` +} + +// +kubebuilder:object:root=true + +// ServiceTemplateChainList contains a list of ServiceTemplateChain +type ServiceTemplateChainList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []ServiceTemplateChain `json:"items"` +} + +func init() { + SchemeBuilder.Register(&ServiceTemplateChain{}, &ServiceTemplateChainList{}) +} diff --git a/api/v1alpha1/templatechain_common.go b/api/v1alpha1/templatechain_common.go new file mode 100644 index 000000000..36a2d29c3 --- /dev/null +++ b/api/v1alpha1/templatechain_common.go @@ -0,0 +1,35 @@ +// 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 + +// TemplateChainSpec defines the observed state of TemplateChain +type TemplateChainSpec struct { + // SupportedTemplates is the list of supported Templates definitions and all available upgrade sequences for it. + SupportedTemplates []SupportedTemplate `json:"supportedTemplates,omitempty"` +} + +// SupportedTemplate is the supported Template definition and all available upgrade sequences for it +type SupportedTemplate struct { + // Name is the name of the Template. + Name string `json:"name"` + // AvailableUpgrades is the list of available upgrades for the specified Template. + AvailableUpgrades []AvailableUpgrade `json:"availableUpgrades,omitempty"` +} + +// AvailableUpgrade is the definition of the available upgrade for the Template +type AvailableUpgrade struct { + // Name is the name of the Template to which the upgrade is available. + Name string `json:"name"` +} diff --git a/api/v1alpha1/templatechain_types.go b/api/v1alpha1/templatechain_types.go deleted file mode 100644 index 16e8cc12a..000000000 --- a/api/v1alpha1/templatechain_types.go +++ /dev/null @@ -1,88 +0,0 @@ -// 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:resource:scope=Cluster - -// ClusterTemplateChain is the Schema for the cluster template chain API -type ClusterTemplateChain struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - - // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Spec is immutable" - Spec TemplateChainSpec `json:"spec,omitempty"` -} - -// +kubebuilder:object:root=true - -// ClusterTemplateChainList contains a list of ClusterTemplateChain -type ClusterTemplateChainList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata,omitempty"` - Items []ClusterTemplateChain `json:"items"` -} - -// +kubebuilder:object:root=true -// +kubebuilder:resource:scope=Cluster - -// ServiceTemplateChain is the Schema for the service template chain API -type ServiceTemplateChain struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - - // +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Spec is immutable" - Spec TemplateChainSpec `json:"spec,omitempty"` -} - -// +kubebuilder:object:root=true - -// ServiceTemplateChainList contains a list of ServiceTemplateChain -type ServiceTemplateChainList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata,omitempty"` - Items []ServiceTemplateChain `json:"items"` -} - -// TemplateChainSpec defines the observed state of TemplateChain -type TemplateChainSpec struct { - // SupportedTemplates is the list of supported Templates definitions and all available upgrade sequences for it. - // +optional - SupportedTemplates []SupportedTemplate `json:"supportedTemplates,omitempty"` -} - -// SupportedTemplate is the supported Template definition and all available upgrade sequences for it -type SupportedTemplate struct { - // Name is the name of the Template. - Name string `json:"name"` - // AvailableUpgrades is the list of available upgrades for the specified Template. - // +optional - AvailableUpgrades []AvailableUpgrade `json:"availableUpgrades,omitempty"` -} - -// AvailableUpgrade is the definition of the available upgrade for the Template -type AvailableUpgrade struct { - // Name is the name of the Template to which the upgrade is available. - Name string `json:"name"` -} - -func init() { - SchemeBuilder.Register(&ClusterTemplateChain{}, &ClusterTemplateChainList{}) - SchemeBuilder.Register(&ServiceTemplateChain{}, &ServiceTemplateChainList{}) -} diff --git a/api/v1alpha1/templatemanagement_types.go b/api/v1alpha1/templatemanagement_types.go index e279fd96c..109b9b19a 100644 --- a/api/v1alpha1/templatemanagement_types.go +++ b/api/v1alpha1/templatemanagement_types.go @@ -18,28 +18,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -// +kubebuilder:object:root=true -// +kubebuilder:subresource:status -// +kubebuilder:resource:shortName=tm,scope=Cluster - -// TemplateManagement is the Schema for the template management API -type TemplateManagement struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - - Spec TemplateManagementSpec `json:"spec,omitempty"` - Status TemplateManagementStatus `json:"status,omitempty"` -} - -// +kubebuilder:object:root=true - -// TemplateManagementList contains a list of TemplateManagement -type TemplateManagementList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata,omitempty"` - Items []TemplateManagement `json:"items"` -} - // TemplateManagementSpec defines the desired state of TemplateManagement type TemplateManagementSpec struct { // AccessRules is the list of access rules. Each AccessRule enforces @@ -47,20 +25,27 @@ type TemplateManagementSpec struct { AccessRules []AccessRule `json:"accessRules,omitempty"` } +// TemplateManagementStatus defines the observed state of TemplateManagement +type TemplateManagementStatus struct { + // Error is the error message occurred during the reconciliation (if any) + Error string `json:"error,omitempty"` + // Current reflects the applied access rules configuration. + Current []AccessRule `json:"current,omitempty"` + // ObservedGeneration is the last observed generation. + ObservedGeneration int64 `json:"observedGeneration,omitempty"` +} + // AccessRule is the definition of the TemplateManagement access rule. Each AccessRule enforces // Templates distribution to the TargetNamespaces type AccessRule struct { // TargetNamespaces defines the namespaces where selected Templates will be distributed. // Templates will be distributed to all namespaces if unset. - // +optional TargetNamespaces TargetNamespaces `json:"targetNamespaces,omitempty"` // ClusterTemplateChains lists the names of ClusterTemplateChains whose ClusterTemplates // will be distributed to all namespaces specified in TargetNamespaces. - // +optional ClusterTemplateChains []string `json:"clusterTemplateChains,omitempty"` // ServiceTemplateChains lists the names of ServiceTemplateChains whose ServiceTemplates // will be distributed to all namespaces specified in TargetNamespaces. - // +optional ServiceTemplateChains []string `json:"serviceTemplateChains,omitempty"` } @@ -70,27 +55,35 @@ type AccessRule struct { type TargetNamespaces struct { // StringSelector is a label query to select namespaces. // Mutually exclusive with Selector and List. - // +optional StringSelector string `json:"stringSelector,omitempty"` // Selector is a structured label query to select namespaces. // Mutually exclusive with StringSelector and List. - // +optional Selector *metav1.LabelSelector `json:"selector,omitempty"` // List is the list of namespaces to select. // Mutually exclusive with StringSelector and Selector. - // +optional List []string `json:"list,omitempty"` } -// TemplateManagementStatus defines the observed state of TemplateManagement -type TemplateManagementStatus struct { - // ObservedGeneration is the last observed generation. - // +optional - ObservedGeneration int64 `json:"observedGeneration,omitempty"` - // Current reflects the applied access rules configuration. - Current []AccessRule `json:"current,omitempty"` - // Error is the error message occurred during the reconciliation (if any) - Error string `json:"error,omitempty"` +// +kubebuilder:object:root=true +// +kubebuilder:subresource:status +// +kubebuilder:resource:shortName=tm,scope=Cluster + +// TemplateManagement is the Schema for the templatemanagements API +type TemplateManagement struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec TemplateManagementSpec `json:"spec,omitempty"` + Status TemplateManagementStatus `json:"status,omitempty"` +} + +// +kubebuilder:object:root=true + +// TemplateManagementList contains a list of TemplateManagement +type TemplateManagementList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []TemplateManagement `json:"items"` } func init() { diff --git a/api/v1alpha1/template_types.go b/api/v1alpha1/templates_common.go similarity index 85% rename from api/v1alpha1/template_types.go rename to api/v1alpha1/templates_common.go index 67ad60060..98bd9ccf0 100644 --- a/api/v1alpha1/template_types.go +++ b/api/v1alpha1/templates_common.go @@ -28,10 +28,9 @@ const ( ChartAnnotationControlPlaneProviders = "hmc.mirantis.com/control-plane-providers" ) -// TemplateSpecMixin is a Template configuration common for all Template types -type TemplateSpecMixin struct { +// TemplateSpecCommon is a Template configuration common for all Template types +type TemplateSpecCommon struct { // Helm holds a reference to a Helm chart representing the HMC template - // +kubebuilder:validation:Required Helm HelmSpec `json:"helm"` // Providers represent required/exposed CAPI providers depending on the template type. // Should be set if not present in the Helm chart metadata. @@ -42,49 +41,35 @@ type TemplateSpecMixin struct { // HelmSpec references a Helm chart representing the HMC template type HelmSpec struct { + // ChartRef is a reference to a source controller resource containing the + // Helm chart representing the template. + ChartRef *helmcontrollerv2.CrossNamespaceSourceReference `json:"chartRef,omitempty"` // ChartName is a name of a Helm chart representing the template in the HMC repository. - // +optional ChartName string `json:"chartName,omitempty"` // ChartVersion is a version of a Helm chart representing the template in the HMC repository. - // +optional ChartVersion string `json:"chartVersion,omitempty"` - // ChartRef is a reference to a source controller resource containing the - // Helm chart representing the template. - // +optional - ChartRef *helmcontrollerv2.CrossNamespaceSourceReference `json:"chartRef,omitempty"` } -// TemplateStatusMixin defines the observed state of Template common for all Template types -type TemplateStatusMixin struct { +// TemplateStatusCommon defines the observed state of Template common for all Template types +type TemplateStatusCommon struct { TemplateValidationStatus `json:",inline"` // Description contains information about the template. - // +optional Description string `json:"description,omitempty"` // Config demonstrates available parameters for template customization, // that can be used when creating ManagedCluster objects. - // +optional Config *apiextensionsv1.JSON `json:"config,omitempty"` // ChartRef is a reference to a source controller resource containing the // Helm chart representing the template. - // +optional ChartRef *helmcontrollerv2.CrossNamespaceSourceReference `json:"chartRef,omitempty"` // Providers represent required/exposed CAPI providers depending on the template type. Providers Providers `json:"providers,omitempty"` // ObservedGeneration is the last observed generation. - // +optional ObservedGeneration int64 `json:"observedGeneration,omitempty"` } type TemplateValidationStatus struct { - // Valid indicates whether the template passed validation or not. - Valid bool `json:"valid"` // ValidationError provides information regarding issues encountered during template validation. - // +optional ValidationError string `json:"validationError,omitempty"` -} - -func init() { - SchemeBuilder.Register(&ClusterTemplate{}, &ClusterTemplateList{}) - SchemeBuilder.Register(&ServiceTemplate{}, &ServiceTemplateList{}) - SchemeBuilder.Register(&ProviderTemplate{}, &ProviderTemplateList{}) + // Valid indicates whether the template passed validation or not. + Valid bool `json:"valid"` } diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 91b8eaf70..bc342372d 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -186,7 +186,7 @@ func (in *ClusterTemplateList) DeepCopyObject() runtime.Object { // 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) + in.TemplateSpecCommon.DeepCopyInto(&out.TemplateSpecCommon) } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterTemplateSpec. @@ -202,7 +202,7 @@ func (in *ClusterTemplateSpec) DeepCopy() *ClusterTemplateSpec { // 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) + in.TemplateStatusCommon.DeepCopyInto(&out.TemplateStatusCommon) } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterTemplateStatus. @@ -606,7 +606,7 @@ func (in *ProviderTemplateList) DeepCopyObject() runtime.Object { // 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) + in.TemplateSpecCommon.DeepCopyInto(&out.TemplateSpecCommon) } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ProviderTemplateSpec. @@ -622,7 +622,7 @@ func (in *ProviderTemplateSpec) DeepCopy() *ProviderTemplateSpec { // 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) + in.TemplateStatusCommon.DeepCopyInto(&out.TemplateStatusCommon) } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ProviderTemplateStatus. @@ -894,7 +894,7 @@ func (in *ServiceTemplateList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ServiceTemplateSpec) DeepCopyInto(out *ServiceTemplateSpec) { *out = *in - in.TemplateSpecMixin.DeepCopyInto(&out.TemplateSpecMixin) + in.TemplateSpecCommon.DeepCopyInto(&out.TemplateSpecCommon) } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ServiceTemplateSpec. @@ -910,7 +910,7 @@ func (in *ServiceTemplateSpec) DeepCopy() *ServiceTemplateSpec { // 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) + in.TemplateStatusCommon.DeepCopyInto(&out.TemplateStatusCommon) } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ServiceTemplateStatus. @@ -1094,24 +1094,24 @@ func (in *TemplateManagementStatus) DeepCopy() *TemplateManagementStatus { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *TemplateSpecMixin) DeepCopyInto(out *TemplateSpecMixin) { +func (in *TemplateSpecCommon) DeepCopyInto(out *TemplateSpecCommon) { *out = *in in.Helm.DeepCopyInto(&out.Helm) in.Providers.DeepCopyInto(&out.Providers) } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TemplateSpecMixin. -func (in *TemplateSpecMixin) DeepCopy() *TemplateSpecMixin { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TemplateSpecCommon. +func (in *TemplateSpecCommon) DeepCopy() *TemplateSpecCommon { if in == nil { return nil } - out := new(TemplateSpecMixin) + out := new(TemplateSpecCommon) in.DeepCopyInto(out) return out } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *TemplateStatusMixin) DeepCopyInto(out *TemplateStatusMixin) { +func (in *TemplateStatusCommon) DeepCopyInto(out *TemplateStatusCommon) { *out = *in out.TemplateValidationStatus = in.TemplateValidationStatus if in.Config != nil { @@ -1127,12 +1127,12 @@ func (in *TemplateStatusMixin) DeepCopyInto(out *TemplateStatusMixin) { in.Providers.DeepCopyInto(&out.Providers) } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TemplateStatusMixin. -func (in *TemplateStatusMixin) DeepCopy() *TemplateStatusMixin { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TemplateStatusCommon. +func (in *TemplateStatusCommon) DeepCopy() *TemplateStatusCommon { if in == nil { return nil } - out := new(TemplateStatusMixin) + out := new(TemplateStatusCommon) in.DeepCopyInto(out) return out } diff --git a/cmd/main.go b/cmd/main.go index 03419819b..ab63d73f0 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -168,6 +168,12 @@ func main() { os.Exit(1) } + ctx := ctrl.SetupSignalHandler() + if err = hmcmirantiscomv1alpha1.SetupIndexers(ctx, mgr); err != nil { + setupLog.Error(err, "unable to setup indexers") + os.Exit(1) + } + currentNamespace := utils.CurrentNamespace() templateReconciler := controller.TemplateReconciler{ @@ -186,13 +192,6 @@ func main() { setupLog.Error(err, "unable to create controller", "controller", "ClusterTemplate") os.Exit(1) } - - ctx := ctrl.SetupSignalHandler() - if err = hmcmirantiscomv1alpha1.SetupIndexers(ctx, mgr); err != nil { - setupLog.Error(err, "unable to setup indexers") - os.Exit(1) - } - if err = (&controller.ServiceTemplateReconciler{ TemplateReconciler: templateReconciler, }).SetupWithManager(mgr); err != nil { diff --git a/internal/controller/managedcluster_controller_test.go b/internal/controller/managedcluster_controller_test.go index 60dc5db02..ae357c10f 100644 --- a/internal/controller/managedcluster_controller_test.go +++ b/internal/controller/managedcluster_controller_test.go @@ -73,7 +73,7 @@ var _ = Describe("ManagedCluster Controller", func() { Namespace: managedClusterNamespace, }, Spec: hmc.ClusterTemplateSpec{ - TemplateSpecMixin: hmc.TemplateSpecMixin{ + TemplateSpecCommon: hmc.TemplateSpecCommon{ Helm: hmc.HelmSpec{ ChartRef: &hcv2.CrossNamespaceSourceReference{ Kind: "HelmChart", @@ -86,7 +86,7 @@ var _ = Describe("ManagedCluster Controller", func() { } Expect(k8sClient.Create(ctx, template)).To(Succeed()) template.Status = hmc.ClusterTemplateStatus{ - TemplateStatusMixin: hmc.TemplateStatusMixin{ + TemplateStatusCommon: hmc.TemplateStatusCommon{ TemplateValidationStatus: hmc.TemplateValidationStatus{ Valid: true, }, diff --git a/internal/controller/management_controller.go b/internal/controller/management_controller.go index d5fe3387e..761db09e8 100644 --- a/internal/controller/management_controller.go +++ b/internal/controller/management_controller.go @@ -218,9 +218,9 @@ type component struct { hmc.Component helmReleaseName string + targetNamespace string // helm release dependencies dependsOn []meta.NamespacedObjectReference - targetNamespace string createNamespace bool } @@ -234,16 +234,20 @@ func wrappedComponents(mgmt *hmc.Management, release *hmc.Release) []component { hmcComp.Template = release.Spec.HMC.Template } components = append(components, hmcComp) - capiComp := component{Component: mgmt.Spec.Core.CAPI, helmReleaseName: hmc.CoreCAPIName, - dependsOn: []meta.NamespacedObjectReference{{Name: hmc.CoreHMCName}}} + capiComp := component{ + Component: mgmt.Spec.Core.CAPI, helmReleaseName: hmc.CoreCAPIName, + dependsOn: []meta.NamespacedObjectReference{{Name: hmc.CoreHMCName}}, + } if capiComp.Template == "" { capiComp.Template = release.Spec.CAPI.Template } components = append(components, capiComp) for _, p := range mgmt.Spec.Providers { - c := component{Component: p.Component, helmReleaseName: p.Name, - dependsOn: []meta.NamespacedObjectReference{{Name: hmc.CoreCAPIName}}} + c := component{ + Component: p.Component, helmReleaseName: p.Name, + dependsOn: []meta.NamespacedObjectReference{{Name: hmc.CoreCAPIName}}, + } // Try to find corresponding provider in the Release object if c.Template == "" { c.Template = release.ProviderTemplate(p.Name) diff --git a/internal/controller/release_controller.go b/internal/controller/release_controller.go index c25343a69..6f74d4301 100644 --- a/internal/controller/release_controller.go +++ b/internal/controller/release_controller.go @@ -227,6 +227,7 @@ func (p *Poller) reconcileHMCTemplates(ctx context.Context) error { } return nil } + func (p *Poller) getCurrentReleaseName(ctx context.Context) (string, error) { releases := &hmc.ReleaseList{} listOptions := client.ListOptions{ diff --git a/internal/controller/suite_test.go b/internal/controller/suite_test.go index 622de0f10..652bb99aa 100644 --- a/internal/controller/suite_test.go +++ b/internal/controller/suite_test.go @@ -56,11 +56,13 @@ const ( validatingWebhookKind = "ValidatingWebhookConfiguration" ) -var cfg *rest.Config -var k8sClient client.Client -var testEnv *envtest.Environment -var ctx context.Context -var cancel context.CancelFunc +var ( + cfg *rest.Config + k8sClient client.Client + testEnv *envtest.Environment + ctx context.Context + cancel context.CancelFunc +) func TestControllers(t *testing.T) { RegisterFailHandler(Fail) @@ -83,7 +85,8 @@ var _ = BeforeSuite(func() { testEnv = &envtest.Environment{ CRDDirectoryPaths: []string{ filepath.Join("..", "..", "templates", "provider", "hmc", "templates", "crds"), - filepath.Join("..", "..", "bin", "crd")}, + filepath.Join("..", "..", "bin", "crd"), + }, ErrorIfCRDPathMissing: true, // The BinaryAssetsDirectory is only required if you want to run the tests directly @@ -193,7 +196,7 @@ func loadWebhooks(path string) ([]*admissionv1.ValidatingWebhookConfiguration, [ return nil, nil, err } - var re = regexp.MustCompile("{{.*}}") + re := regexp.MustCompile("{{.*}}") s := re.ReplaceAllString(string(webhookFile), "") objs, err := utilyaml.ToUnstructured([]byte(s)) if err != nil { @@ -209,8 +212,8 @@ func loadWebhooks(path string) ([]*admissionv1.ValidatingWebhookConfiguration, [ return nil, nil, err } validatingWebhooks = append(validatingWebhooks, webhookConfig) - } + if o.GetKind() == mutatingWebhookKind { o.SetName("mutating-webhook") webhookConfig := &admissionv1.MutatingWebhookConfiguration{} diff --git a/internal/controller/template_controller.go b/internal/controller/template_controller.go index 4d5b909f6..688d9a76f 100644 --- a/internal/controller/template_controller.go +++ b/internal/controller/template_controller.go @@ -127,8 +127,8 @@ func (r *ProviderTemplateReconciler) Reconcile(ctx context.Context, req ctrl.Req // Template is the interface defining a list of methods to interact with templates type Template interface { client.Object - GetSpec() *hmc.TemplateSpecMixin - GetStatus() *hmc.TemplateStatusMixin + GetSpec() *hmc.TemplateSpecCommon + GetStatus() *hmc.TemplateStatusCommon } func (r *TemplateReconciler) ReconcileTemplate(ctx context.Context, template Template) (ctrl.Result, error) { @@ -224,11 +224,7 @@ func (r *TemplateReconciler) ReconcileTemplate(ctx context.Context, template Tem } func templateManagedByHMC(template Template) bool { - labels := template.GetLabels() - if labels == nil { - return false - } - return labels[hmc.HMCManagedLabelKey] == hmc.HMCManagedLabelValue + return template.GetLabels()[hmc.HMCManagedLabelKey] == hmc.HMCManagedLabelValue } func (r *TemplateReconciler) parseChartMetadata(template Template, chart *chart.Chart) error { diff --git a/internal/controller/template_controller_test.go b/internal/controller/template_controller_test.go index 8433e192c..c7b95ef51 100644 --- a/internal/controller/template_controller_test.go +++ b/internal/controller/template_controller_test.go @@ -38,7 +38,7 @@ var _ = Describe("Template Controller", func() { const helmChartName = "test-helmchart" const helmChartURL = "http://source-controller.hmc-system.svc.cluster.local./helmchart/hmc-system/test-chart/0.1.0.tar.gz" - var fakeDownloadHelmChartFunc = func(context.Context, *sourcev1.Artifact) (*chart.Chart, error) { + fakeDownloadHelmChartFunc := func(context.Context, *sourcev1.Artifact) (*chart.Chart, error) { return &chart.Chart{ Metadata: &chart.Metadata{ APIVersion: "v2", @@ -60,7 +60,7 @@ var _ = Describe("Template Controller", func() { helmRepo := &sourcev1.HelmRepository{} helmChart := &sourcev1.HelmChart{} - templateSpec := hmcmirantiscomv1alpha1.TemplateSpecMixin{ + templateSpec := hmcmirantiscomv1alpha1.TemplateSpecCommon{ Helm: hmcmirantiscomv1alpha1.HelmSpec{ ChartRef: &v2.CrossNamespaceSourceReference{ Kind: "HelmChart", @@ -120,7 +120,7 @@ var _ = Describe("Template Controller", func() { Name: resourceName, Namespace: "default", }, - Spec: hmcmirantiscomv1alpha1.ClusterTemplateSpec{TemplateSpecMixin: templateSpec}, + Spec: hmcmirantiscomv1alpha1.ClusterTemplateSpec{TemplateSpecCommon: templateSpec}, } Expect(k8sClient.Create(ctx, resource)).To(Succeed()) } @@ -132,7 +132,7 @@ var _ = Describe("Template Controller", func() { Name: resourceName, Namespace: "default", }, - Spec: hmcmirantiscomv1alpha1.ServiceTemplateSpec{TemplateSpecMixin: templateSpec}, + Spec: hmcmirantiscomv1alpha1.ServiceTemplateSpec{TemplateSpecCommon: templateSpec}, } Expect(k8sClient.Create(ctx, resource)).To(Succeed()) } @@ -144,7 +144,7 @@ var _ = Describe("Template Controller", func() { Name: resourceName, Namespace: "default", }, - Spec: hmcmirantiscomv1alpha1.ProviderTemplateSpec{TemplateSpecMixin: templateSpec}, + Spec: hmcmirantiscomv1alpha1.ProviderTemplateSpec{TemplateSpecCommon: templateSpec}, } Expect(k8sClient.Create(ctx, resource)).To(Succeed()) } diff --git a/internal/controller/templatemanagement_controller.go b/internal/controller/templatemanagement_controller.go index df70e6bea..745b64644 100644 --- a/internal/controller/templatemanagement_controller.go +++ b/internal/controller/templatemanagement_controller.go @@ -153,7 +153,7 @@ func (r *TemplateManagementReconciler) applyTemplates(ctx context.Context, kind return fmt.Errorf("invalid kind %s. Only %s or %s kinds are supported", kind, templateutil.ClusterTemplateKind, templateutil.ServiceTemplateKind) } - spec := hmc.TemplateSpecMixin{ + spec := hmc.TemplateSpecCommon{ Helm: hmc.HelmSpec{ ChartRef: &helmcontrollerv2.CrossNamespaceSourceReference{ Kind: sourcev1.HelmChartKind, @@ -167,10 +167,10 @@ func (r *TemplateManagementReconciler) applyTemplates(ctx context.Context, kind var target client.Object meta.Namespace = ns if kind == templateutil.ClusterTemplateKind { - target = &hmc.ClusterTemplate{ObjectMeta: meta, Spec: hmc.ClusterTemplateSpec{TemplateSpecMixin: spec}} + target = &hmc.ClusterTemplate{ObjectMeta: meta, Spec: hmc.ClusterTemplateSpec{TemplateSpecCommon: spec}} } if kind == templateutil.ServiceTemplateKind { - target = &hmc.ServiceTemplate{ObjectMeta: meta, Spec: hmc.ServiceTemplateSpec{TemplateSpecMixin: spec}} + target = &hmc.ServiceTemplate{ObjectMeta: meta, Spec: hmc.ServiceTemplateSpec{TemplateSpecCommon: spec}} } if keep { if !sourceFound { diff --git a/internal/webhook/managedcluster_webhook.go b/internal/webhook/managedcluster_webhook.go index 4018ad266..a362349c0 100644 --- a/internal/webhook/managedcluster_webhook.go +++ b/internal/webhook/managedcluster_webhook.go @@ -37,7 +37,7 @@ type ManagedClusterValidator struct { client.Client } -var InvalidManagedClusterErr = errors.New("the ManagedCluster is invalid") +var invalidManagedClusterErr = errors.New("the ManagedCluster is invalid") func (v *ManagedClusterValidator) SetupWebhookWithManager(mgr ctrl.Manager) error { v.Client = mgr.GetClient() @@ -61,11 +61,11 @@ func (v *ManagedClusterValidator) ValidateCreate(ctx context.Context, obj runtim } template, err := v.getManagedClusterTemplate(ctx, managedCluster.Namespace, managedCluster.Spec.Template) if err != nil { - return nil, fmt.Errorf("%s: %v", InvalidManagedClusterErr, err) + return nil, fmt.Errorf("%s: %v", invalidManagedClusterErr, err) } err = v.isTemplateValid(ctx, template) if err != nil { - return nil, fmt.Errorf("%s: %v", InvalidManagedClusterErr, err) + return nil, fmt.Errorf("%s: %v", invalidManagedClusterErr, err) } return nil, nil } @@ -78,11 +78,11 @@ func (v *ManagedClusterValidator) ValidateUpdate(ctx context.Context, _ runtime. } template, err := v.getManagedClusterTemplate(ctx, newManagedCluster.Namespace, newManagedCluster.Spec.Template) if err != nil { - return nil, fmt.Errorf("%s: %v", InvalidManagedClusterErr, err) + return nil, fmt.Errorf("%s: %v", invalidManagedClusterErr, err) } err = v.isTemplateValid(ctx, template) if err != nil { - return nil, fmt.Errorf("%s: %v", InvalidManagedClusterErr, err) + return nil, fmt.Errorf("%s: %v", invalidManagedClusterErr, err) } return nil, nil } @@ -173,7 +173,7 @@ func (v *ManagedClusterValidator) verifyProviders(ctx context.Context, template func getMissingProviders(exposedProviders []string, requiredProviders []string) []string { exposedBootstrapProviders := utils.SliceToMapKeys[[]string, map[string]struct{}](exposedProviders) - diff, isSubset := utils.DiffSliceSubset[[]string, map[string]struct{}](requiredProviders, exposedBootstrapProviders) + diff, isSubset := utils.DiffSliceSubset(requiredProviders, exposedBootstrapProviders) if !isSubset { return diff } diff --git a/internal/webhook/management_webhook.go b/internal/webhook/management_webhook.go index acd12601c..3e2f3cb19 100644 --- a/internal/webhook/management_webhook.go +++ b/internal/webhook/management_webhook.go @@ -34,8 +34,8 @@ type ManagementValidator struct { } var ( - ErrManagementDeletionForbidden = errors.New("management deletion is forbidden") - ErrCreateManagementReenablingForbidden = errors.New("reenabling of the createManagement parameter is forbidden") + errManagementDeletionForbidden = errors.New("management deletion is forbidden") + errCreateManagementReenablingForbidden = errors.New("reenabling of the createManagement parameter is forbidden") ) func (in *ManagementValidator) SetupWebhookWithManager(mgr ctrl.Manager) error { @@ -84,7 +84,7 @@ func (*ManagementValidator) ValidateUpdate(_ context.Context, _ runtime.Object, // Check if 'createManagement' exists and is true. if createManagement, ok := controller["createManagement"].(bool); ok && createManagement { - return nil, ErrCreateManagementReenablingForbidden + return nil, errCreateManagementReenablingForbidden } return nil, nil @@ -98,7 +98,7 @@ func (v *ManagementValidator) ValidateDelete(ctx context.Context, _ runtime.Obje return nil, err } if len(managedClusters.Items) > 0 { - return admission.Warnings{"The Management object can't be removed if ManagedCluster objects still exist"}, ErrManagementDeletionForbidden + return admission.Warnings{"The Management object can't be removed if ManagedCluster objects still exist"}, errManagementDeletionForbidden } return nil, nil } diff --git a/internal/webhook/template_webhook.go b/internal/webhook/template_webhook.go index 33b70879a..4076c782a 100644 --- a/internal/webhook/template_webhook.go +++ b/internal/webhook/template_webhook.go @@ -34,9 +34,7 @@ type ClusterTemplateValidator struct { client.Client } -var ( - ErrTemplateDeletionForbidden = errors.New("template deletion is forbidden") -) +var errTemplateDeletionForbidden = errors.New("template deletion is forbidden") func (in *ClusterTemplateValidator) SetupWebhookWithManager(mgr ctrl.Manager) error { in.Client = mgr.GetClient() @@ -81,7 +79,7 @@ func (v *ClusterTemplateValidator) ValidateDelete(ctx context.Context, obj runti } if len(managedClusters.Items) > 0 { - return admission.Warnings{"The ClusterTemplate object can't be removed if ManagedCluster objects referencing it still exist"}, ErrTemplateDeletionForbidden + return admission.Warnings{"The ClusterTemplate object can't be removed if ManagedCluster objects referencing it still exist"}, errTemplateDeletionForbidden } return nil, nil diff --git a/internal/webhook/templatechain_webhook.go b/internal/webhook/templatechain_webhook.go index 08150940a..d250e6be4 100644 --- a/internal/webhook/templatechain_webhook.go +++ b/internal/webhook/templatechain_webhook.go @@ -29,9 +29,7 @@ import ( "github.com/Mirantis/hmc/api/v1alpha1" ) -var ( - ErrInvalidTemplateChainSpec = errors.New("the template chain spec is invalid") -) +var errInvalidTemplateChainSpec = errors.New("the template chain spec is invalid") type ClusterTemplateChainValidator struct { client.Client @@ -60,7 +58,7 @@ func (*ClusterTemplateChainValidator) ValidateCreate(_ context.Context, obj runt warnings := isTemplateChainValid(chain.Spec) if len(warnings) > 0 { - return warnings, ErrInvalidTemplateChainSpec + return warnings, errInvalidTemplateChainSpec } return nil, nil } @@ -106,7 +104,7 @@ func (*ServiceTemplateChainValidator) ValidateCreate(_ context.Context, obj runt } warnings := isTemplateChainValid(chain.Spec) if len(warnings) > 0 { - return warnings, ErrInvalidTemplateChainSpec + return warnings, errInvalidTemplateChainSpec } return nil, nil } diff --git a/templates/provider/hmc/templates/crds/hmc.mirantis.com_clustertemplatechains.yaml b/templates/provider/hmc/templates/crds/hmc.mirantis.com_clustertemplatechains.yaml index c2aed20cb..494a7c5c8 100644 --- a/templates/provider/hmc/templates/crds/hmc.mirantis.com_clustertemplatechains.yaml +++ b/templates/provider/hmc/templates/crds/hmc.mirantis.com_clustertemplatechains.yaml @@ -17,7 +17,7 @@ spec: - name: v1alpha1 schema: openAPIV3Schema: - description: ClusterTemplateChain is the Schema for the cluster template chain + description: ClusterTemplateChain is the Schema for the clustertemplatechains API properties: apiVersion: diff --git a/templates/provider/hmc/templates/crds/hmc.mirantis.com_clustertemplates.yaml b/templates/provider/hmc/templates/crds/hmc.mirantis.com_clustertemplates.yaml index 1dca24f82..60726eba9 100644 --- a/templates/provider/hmc/templates/crds/hmc.mirantis.com_clustertemplates.yaml +++ b/templates/provider/hmc/templates/crds/hmc.mirantis.com_clustertemplates.yaml @@ -34,7 +34,7 @@ spec: name: v1alpha1 schema: openAPIV3Schema: - description: ClusterTemplate is the Schema for the cluster templates API + description: ClusterTemplate is the Schema for the clustertemplates API properties: apiVersion: description: |- diff --git a/templates/provider/hmc/templates/crds/hmc.mirantis.com_providertemplates.yaml b/templates/provider/hmc/templates/crds/hmc.mirantis.com_providertemplates.yaml index 70e3a0829..0c13a883f 100644 --- a/templates/provider/hmc/templates/crds/hmc.mirantis.com_providertemplates.yaml +++ b/templates/provider/hmc/templates/crds/hmc.mirantis.com_providertemplates.yaml @@ -34,7 +34,7 @@ spec: name: v1alpha1 schema: openAPIV3Schema: - description: ProviderTemplate is the Schema for the provider templates API + description: ProviderTemplate is the Schema for the providertemplates API properties: apiVersion: description: |- diff --git a/templates/provider/hmc/templates/crds/hmc.mirantis.com_servicetemplatechains.yaml b/templates/provider/hmc/templates/crds/hmc.mirantis.com_servicetemplatechains.yaml index 881235c0b..37f12c8f1 100644 --- a/templates/provider/hmc/templates/crds/hmc.mirantis.com_servicetemplatechains.yaml +++ b/templates/provider/hmc/templates/crds/hmc.mirantis.com_servicetemplatechains.yaml @@ -17,7 +17,7 @@ spec: - name: v1alpha1 schema: openAPIV3Schema: - description: ServiceTemplateChain is the Schema for the service template chain + description: ServiceTemplateChain is the Schema for the servicetemplatechains API properties: apiVersion: diff --git a/templates/provider/hmc/templates/crds/hmc.mirantis.com_servicetemplates.yaml b/templates/provider/hmc/templates/crds/hmc.mirantis.com_servicetemplates.yaml index 176a7bcd8..975b526d8 100644 --- a/templates/provider/hmc/templates/crds/hmc.mirantis.com_servicetemplates.yaml +++ b/templates/provider/hmc/templates/crds/hmc.mirantis.com_servicetemplates.yaml @@ -34,7 +34,7 @@ spec: name: v1alpha1 schema: openAPIV3Schema: - description: ServiceTemplate is the Schema for the service templates API + description: ServiceTemplate is the Schema for the servicetemplates API properties: apiVersion: description: |- diff --git a/templates/provider/hmc/templates/crds/hmc.mirantis.com_templatemanagements.yaml b/templates/provider/hmc/templates/crds/hmc.mirantis.com_templatemanagements.yaml index 586bd9823..776351956 100644 --- a/templates/provider/hmc/templates/crds/hmc.mirantis.com_templatemanagements.yaml +++ b/templates/provider/hmc/templates/crds/hmc.mirantis.com_templatemanagements.yaml @@ -19,7 +19,7 @@ spec: - name: v1alpha1 schema: openAPIV3Schema: - description: TemplateManagement is the Schema for the template management + description: TemplateManagement is the Schema for the templatemanagements API properties: apiVersion: diff --git a/test/objects/template/template.go b/test/objects/template/template.go index fd08d7d50..668f40191 100644 --- a/test/objects/template/template.go +++ b/test/objects/template/template.go @@ -28,8 +28,8 @@ const ( type Template struct { metav1.ObjectMeta `json:",inline"` - Spec v1alpha1.TemplateSpecMixin `json:"spec"` - Status v1alpha1.TemplateStatusMixin `json:"status"` + Spec v1alpha1.TemplateSpecCommon `json:"spec"` + Status v1alpha1.TemplateStatusCommon `json:"status"` } type Opt func(template *Template) @@ -38,8 +38,8 @@ 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}, + Spec: v1alpha1.ClusterTemplateSpec{TemplateSpecCommon: templateState.Spec}, + Status: v1alpha1.ClusterTemplateStatus{TemplateStatusCommon: templateState.Status}, } } @@ -47,8 +47,8 @@ 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}, + Spec: v1alpha1.ServiceTemplateSpec{TemplateSpecCommon: templateState.Spec}, + Status: v1alpha1.ServiceTemplateStatus{TemplateStatusCommon: templateState.Status}, } } @@ -56,8 +56,8 @@ 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}, + Spec: v1alpha1.ProviderTemplateSpec{TemplateSpecCommon: templateState.Spec}, + Status: v1alpha1.ProviderTemplateStatus{TemplateStatusCommon: templateState.Status}, } }