diff --git a/api/v1alpha1/managedcluster_types.go b/api/v1alpha1/managedcluster_types.go index ff88cd074..404a6de15 100644 --- a/api/v1alpha1/managedcluster_types.go +++ b/api/v1alpha1/managedcluster_types.go @@ -55,6 +55,7 @@ type ManagedClusterSpec struct { Config *apiextensionsv1.JSON `json:"config,omitempty"` // +kubebuilder:validation:MinLength=1 + // +kubebuilder:validation:MaxLength=253 // Template is a reference to a Template object located in the same namespace. Template string `json:"template"` diff --git a/api/v1alpha1/management_types.go b/api/v1alpha1/management_types.go index aa00dd2db..c34611bbd 100644 --- a/api/v1alpha1/management_types.go +++ b/api/v1alpha1/management_types.go @@ -33,6 +33,8 @@ const ( // ManagementSpec defines the desired state of Management type ManagementSpec struct { + // +kubebuilder:validation:MinLength=1 + // +kubebuilder:validation:MaxLength=253 // Release references the Release object. Release string `json:"release"` // Core holds the core Management components that are mandatory. diff --git a/api/v1alpha1/multiclusterservice_types.go b/api/v1alpha1/multiclusterservice_types.go index c4b88c607..70cd7b1ef 100644 --- a/api/v1alpha1/multiclusterservice_types.go +++ b/api/v1alpha1/multiclusterservice_types.go @@ -44,11 +44,13 @@ type ServiceSpec struct { Values string `json:"values,omitempty"` // +kubebuilder:validation:MinLength=1 + // +kubebuilder:validation:MaxLength=253 // Template is a reference to a Template object located in the same namespace. Template string `json:"template"` // +kubebuilder:validation:MinLength=1 + // +kubebuilder:validation:MaxLength=253 // Name is the chart release. Name string `json:"name"` diff --git a/internal/controller/managedcluster_controller_test.go b/internal/controller/managedcluster_controller_test.go index 57b58d9dc..f252e2e7c 100644 --- a/internal/controller/managedcluster_controller_test.go +++ b/internal/controller/managedcluster_controller_test.go @@ -138,7 +138,9 @@ var _ = Describe("ManagedCluster Controller", func() { ObjectMeta: metav1.ObjectMeta{ Name: hmc.ManagementName, }, - Spec: hmc.ManagementSpec{}, + Spec: hmc.ManagementSpec{ + Release: "test-release", + }, } Expect(k8sClient.Create(ctx, management)).To(Succeed()) management.Status = hmc.ManagementStatus{ diff --git a/internal/controller/management_controller_test.go b/internal/controller/management_controller_test.go index 8f6df261b..f31676207 100644 --- a/internal/controller/management_controller_test.go +++ b/internal/controller/management_controller_test.go @@ -59,6 +59,9 @@ var _ = Describe("Management Controller", func() { Name: resourceName, Namespace: "default", }, + Spec: hmcmirantiscomv1alpha1.ManagementSpec{ + Release: "test-release-name", + }, } Expect(k8sClient.Create(ctx, resource)).To(Succeed()) } diff --git a/internal/controller/template_controller_test.go b/internal/controller/template_controller_test.go index ceddb6201..11620ee2e 100644 --- a/internal/controller/template_controller_test.go +++ b/internal/controller/template_controller_test.go @@ -262,6 +262,9 @@ var _ = Describe("Template Controller", func() { ObjectMeta: metav1.ObjectMeta{ Name: mgmtName, }, + Spec: hmcmirantiscomv1alpha1.ManagementSpec{ + Release: "test-release", + }, } Expect(k8sClient.Create(ctx, mgmt)).To(Succeed()) mgmt.Status = hmcmirantiscomv1alpha1.ManagementStatus{ diff --git a/internal/webhook/management_webhook_test.go b/internal/webhook/management_webhook_test.go index cc4807345..054bed6ec 100644 --- a/internal/webhook/management_webhook_test.go +++ b/internal/webhook/management_webhook_test.go @@ -129,12 +129,13 @@ func TestManagementValidateUpdate(t *testing.T) { name: "release does not exist, should fail", oldMgmt: management.NewManagement( management.WithProviders(componentAwsDefaultTpl), + management.WithRelease("previous-release"), ), management: management.NewManagement( management.WithProviders(), - management.WithRelease(release.DefaultName), + management.WithRelease("new-release"), ), - err: fmt.Sprintf(`Management "%s" is invalid: spec.release: Forbidden: releases.hmc.mirantis.com "%s" not found`, management.DefaultName, release.DefaultName), + err: fmt.Sprintf(`Management "%s" is invalid: spec.release: Forbidden: releases.hmc.mirantis.com "new-release" not found`, management.DefaultName), }, { name: "removed provider does not have related providertemplate, should fail", diff --git a/templates/provider/hmc/templates/crds/hmc.mirantis.com_managedclusters.yaml b/templates/provider/hmc/templates/crds/hmc.mirantis.com_managedclusters.yaml index bf42b1a62..8e0ec18a3 100644 --- a/templates/provider/hmc/templates/crds/hmc.mirantis.com_managedclusters.yaml +++ b/templates/provider/hmc/templates/crds/hmc.mirantis.com_managedclusters.yaml @@ -82,6 +82,7 @@ spec: type: boolean name: description: Name is the chart release. + maxLength: 253 minLength: 1 type: string namespace: @@ -92,6 +93,7 @@ spec: template: description: Template is a reference to a Template object located in the same namespace. + maxLength: 253 minLength: 1 type: string values: @@ -126,6 +128,7 @@ spec: template: description: Template is a reference to a Template object located in the same namespace. + maxLength: 253 minLength: 1 type: string required: diff --git a/templates/provider/hmc/templates/crds/hmc.mirantis.com_managements.yaml b/templates/provider/hmc/templates/crds/hmc.mirantis.com_managements.yaml index 1dc941cca..7ff679588 100644 --- a/templates/provider/hmc/templates/crds/hmc.mirantis.com_managements.yaml +++ b/templates/provider/hmc/templates/crds/hmc.mirantis.com_managements.yaml @@ -104,6 +104,8 @@ spec: type: array release: description: Release references the Release object. + maxLength: 253 + minLength: 1 type: string required: - release diff --git a/templates/provider/hmc/templates/crds/hmc.mirantis.com_multiclusterservices.yaml b/templates/provider/hmc/templates/crds/hmc.mirantis.com_multiclusterservices.yaml index 52b3839b8..d4f05b686 100644 --- a/templates/provider/hmc/templates/crds/hmc.mirantis.com_multiclusterservices.yaml +++ b/templates/provider/hmc/templates/crds/hmc.mirantis.com_multiclusterservices.yaml @@ -100,6 +100,7 @@ spec: type: boolean name: description: Name is the chart release. + maxLength: 253 minLength: 1 type: string namespace: @@ -110,6 +111,7 @@ spec: template: description: Template is a reference to a Template object located in the same namespace. + maxLength: 253 minLength: 1 type: string values: diff --git a/test/objects/management/management.go b/test/objects/management/management.go index 785faa643..67ad95970 100644 --- a/test/objects/management/management.go +++ b/test/objects/management/management.go @@ -18,6 +18,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/Mirantis/hmc/api/v1alpha1" + "github.com/Mirantis/hmc/test/objects/release" ) const ( @@ -36,6 +37,9 @@ func NewManagement(opts ...Opt) *v1alpha1.Management { Name: DefaultName, Finalizers: []string{v1alpha1.ManagementFinalizer}, }, + Spec: v1alpha1.ManagementSpec{ + Release: release.DefaultName, + }, } for _, opt := range opts {