Skip to content

Commit

Permalink
Make releaes field mandatory for Management (#711)
Browse files Browse the repository at this point in the history
Signed-off-by: Andrei Pavlov <[email protected]>
  • Loading branch information
Kshatrix authored Dec 4, 2024
1 parent c0d6f12 commit dee18a4
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 3 deletions.
1 change: 1 addition & 0 deletions api/v1alpha1/managedcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
2 changes: 2 additions & 0 deletions api/v1alpha1/management_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions api/v1alpha1/multiclusterservice_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
4 changes: 3 additions & 1 deletion internal/controller/managedcluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
3 changes: 3 additions & 0 deletions internal/controller/management_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
3 changes: 3 additions & 0 deletions internal/controller/template_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
5 changes: 3 additions & 2 deletions internal/webhook/management_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ spec:
type: boolean
name:
description: Name is the chart release.
maxLength: 253
minLength: 1
type: string
namespace:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ spec:
type: array
release:
description: Release references the Release object.
maxLength: 253
minLength: 1
type: string
required:
- release
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ spec:
type: boolean
name:
description: Name is the chart release.
maxLength: 253
minLength: 1
type: string
namespace:
Expand All @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions test/objects/management/management.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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 {
Expand Down

0 comments on commit dee18a4

Please sign in to comment.