Skip to content

Commit

Permalink
fix: webhook: Don't check common template namespace
Browse files Browse the repository at this point in the history
The namespace of common templates is not checked in webhook.

Even if the webhook passes, user can still remove the namespace later.

Signed-off-by: Andrej Krejcir <[email protected]>
  • Loading branch information
akrejcir committed Dec 4, 2023
1 parent 8b9bd1d commit f08e4a9
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 60 deletions.
14 changes: 0 additions & 14 deletions tests/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,6 @@ var _ = Describe("Validation webhook", func() {
strategy.RevertToOriginalSspCr()
})

It("[test_id:6056] should fail to create SSP CR with invalid commonTemplates.namespace", func() {
newSsp.Spec.CommonTemplates.Namespace = "nonexisting-templates-namespace"

err := apiClient.Create(ctx, newSsp, client.DryRunAll)
if err == nil {
Fail("SSP CR with invalid commonTemplates.namespace created.")
return
}
Expect(err.Error()).To(ContainSubstring(fmt.Sprintf(
"creation failed, the configured namespace for common templates does not exist: %v",
newSsp.Spec.CommonTemplates.Namespace,
)))
})

Context("Placement API validation", func() {
It("[test_id:5988]should succeed with valid template-validator placement fields", func() {
newSsp.Spec.TemplateValidator = &sspv1beta2.TemplateValidator{
Expand Down
8 changes: 0 additions & 8 deletions webhooks/ssp_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,6 @@ func (s *sspValidator) ValidateCreate(ctx context.Context, obj runtime.Object) e
return fmt.Errorf("creation failed, an SSP CR already exists in namespace %v: %v", ssps.Items[0].ObjectMeta.Namespace, ssps.Items[0].ObjectMeta.Name)
}

// Check if the common templates namespace exists
namespaceName := sspObj.Spec.CommonTemplates.Namespace
var namespace v1.Namespace
err = s.apiClient.Get(ctx, client.ObjectKey{Name: namespaceName}, &namespace)
if err != nil {
return fmt.Errorf("creation failed, the configured namespace for common templates does not exist: %v", namespaceName)
}

return s.validateSspObject(ctx, sspObj)
}

Expand Down
38 changes: 0 additions & 38 deletions webhooks/ssp_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,24 +115,6 @@ var _ = Describe("SSP Validation", func() {
})
})

It("should fail if template namespace does not exist", func() {
const nonexistingNamespace = "nonexisting-namespace"
ssp := &sspv1beta2.SSP{
ObjectMeta: metav1.ObjectMeta{
Name: "test-ssp",
Namespace: "test-ns",
},
Spec: sspv1beta2.SSPSpec{
CommonTemplates: sspv1beta2.CommonTemplates{
Namespace: nonexistingNamespace,
},
},
}
err := validator.ValidateCreate(ctx, toUnstructured(ssp))
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("creation failed, the configured namespace for common templates does not exist: " + nonexistingNamespace))
})

It("should accept old v1beta1 SSP CR", func() {
ssp := &sspv1beta1.SSP{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -166,26 +148,6 @@ var _ = Describe("SSP Validation", func() {
})
})

It("should allow update of commonTemplates.namespace", func() {
oldSsp := &sspv1beta2.SSP{
ObjectMeta: metav1.ObjectMeta{
Name: "test-ssp",
Namespace: "test-ns",
},
Spec: sspv1beta2.SSPSpec{
CommonTemplates: sspv1beta2.CommonTemplates{
Namespace: "old-ns",
},
},
}

newSsp := oldSsp.DeepCopy()
newSsp.Spec.CommonTemplates.Namespace = "new-ns"

err := validator.ValidateUpdate(ctx, toUnstructured(oldSsp), toUnstructured(newSsp))
Expect(err).ToNot(HaveOccurred())
})

Context("DataImportCronTemplates", func() {
const (
templatesNamespace = "test-templates-ns"
Expand Down

0 comments on commit f08e4a9

Please sign in to comment.