Skip to content

Commit

Permalink
Validate unique modules in kyma spec (#611)
Browse files Browse the repository at this point in the history
* Validate for duplicate modules in SKR kyma

* remove webhook duplicate test
  • Loading branch information
nesmabadr authored May 17, 2023
1 parent 2c3d556 commit c979578
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 25 deletions.
2 changes: 2 additions & 0 deletions api/v1beta2/kyma_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ type KymaSpec struct {
Channel string `json:"channel"`

// Modules specifies the list of modules to be installed
// +listType=map
// +listMapKey=name
Modules []Module `json:"modules,omitempty"`
}

Expand Down
25 changes: 0 additions & 25 deletions api/v1beta2/webhook_kyma_crd_validation_test.go
Original file line number Diff line number Diff line change
@@ -1,38 +1,13 @@
package v1beta2_test

import (
"errors"

"github.com/kyma-project/lifecycle-manager/api/v1beta2"
"github.com/kyma-project/lifecycle-manager/pkg/testutils"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
)

var _ = Describe("Webhook Validation Kyma Create", Ordered, func() {
It("should not create kyma contains duplicate module", func() {
kyma := testutils.NewTestKyma("test-kyma")
for _, module := range []string{"module1", "module1"} {
kyma.Spec.Modules = append(
kyma.Spec.Modules, v1beta2.Module{
ControllerName: "manifest",
Name: module,
Channel: v1beta2.DefaultChannel,
})
}
err := k8sClient.Create(webhookServerContext, kyma)

Expect(err).To(HaveOccurred())
var statusErr *k8serrors.StatusError
isStatusErr := errors.As(err, &statusErr)
Expect(isStatusErr).To(BeTrue())
Expect(statusErr.ErrStatus.Status).To(Equal("Failure"))
Expect(string(statusErr.ErrStatus.Reason)).To(Equal("Invalid"))
Expect(statusErr.ErrStatus.Message).
To(ContainSubstring(v1beta2.ErrDuplicateModule.Error()))
})

It("should create kyma without duplicate module", func() {
kyma := testutils.NewTestKyma("test-kyma")
for _, module := range []string{"module1", "module2"} {
Expand Down
3 changes: 3 additions & 0 deletions config/crd/bases/operator.kyma-project.io_kymas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,9 @@ spec:
- name
type: object
type: array
x-kubernetes-list-map-keys:
- name
x-kubernetes-list-type: map
required:
- channel
type: object
Expand Down

0 comments on commit c979578

Please sign in to comment.