Skip to content

Commit 69fb552

Browse files
authored
feat: validate template webhook deletion protection (#15)
1 parent 891d405 commit 69fb552

File tree

3 files changed

+57
-8
lines changed

3 files changed

+57
-8
lines changed

.test-dependencies.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ components:
142142
package: "edge-orch/cluster/charts/cluster-manager"
143143
namespace: "default"
144144
version: "" # Use the latest version when nil
145-
overrides: "--set clusterManager.extraArgs.disable-mt=true --set clusterManager.extraArgs.disable-auth=true --set clusterManager.extraArgs.disable-inventory=true"
145+
overrides: "--set clusterManager.extraArgs.disable-mt=true --set clusterManager.extraArgs.disable-auth=true --set clusterManager.extraArgs.disable-inventory=true --set templateController.extraArgs[0]='--webhook-enabled=true' --set webhookService.enabled=true"
146146
- url: "oci://registry-rs.edgeorchestration.intel.com"
147147
release-name: "cluster-template-crd"
148148
package: "edge-orch/cluster/charts/cluster-template-crd"

test-plan/test-plan.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,16 @@ Test Case format shall look like below:
197197
1. Use kubeconfig to fetch list of pods
198198
- **Expected Results:**
199199
- The pod list information is retrieved successfully.
200+
201+
### Test Case ID: TC-CO-INT-009
202+
203+
- **Test Description:** Should verify that a cluster template cannot be deleted if there is a cluster using it.
204+
- **Preconditions:**
205+
- Ensure the namespace exists or create it if it does not.
206+
- Port forward to the cluster manager service.
207+
- Import the cluster template and ensure it is ready.
208+
- Create a cluster using the imported cluster template.
209+
- **Test Steps:**
210+
1. Attempt to delete the cluster template using the DELETE API.
211+
- **Expected Results:**
212+
- The DELETE request fails with an error message indicating that the cluster template is in use.

tests/functional-test/cluster_orch_functional_test.go

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ import (
2020
)
2121

2222
const (
23-
defaultNamespace = "53cd37b9-66b2-4cc8-b080-3722ed7af64a"
24-
defaultNodeGUID = "12345678-1234-1234-1234-123456789012"
25-
namespaceEnvVar = "NAMESPACE"
26-
nodeGUIDEnvVar = "NODEGUID"
27-
clusterName = "demo-cluster"
28-
clusterTemplateName = "baseline-v2.0.1"
23+
defaultNamespace = "53cd37b9-66b2-4cc8-b080-3722ed7af64a"
24+
defaultNodeGUID = "12345678-1234-1234-1234-123456789012"
25+
namespaceEnvVar = "NAMESPACE"
26+
nodeGUIDEnvVar = "NODEGUID"
27+
clusterName = "demo-cluster"
28+
29+
clusterTemplateOnlyName = "baseline"
30+
clusterTemplateOnlyVersion = "v2.0.1"
2931
clusterOrchFunctionalTest = "cluster-orch-functional-test"
3032
portForwardAddress = "0.0.0.0"
3133
portForwardService = "svc/cluster-manager"
@@ -41,7 +43,8 @@ const (
4143
)
4244

4345
var (
44-
skipDeleteCluster = os.Getenv("SKIP_DELETE_CLUSTER") == "true"
46+
clusterTemplateName = fmt.Sprintf("%s-%s", clusterTemplateOnlyName, clusterTemplateOnlyVersion)
47+
skipDeleteCluster = os.Getenv("SKIP_DELETE_CLUSTER") == "true"
4548
)
4649

4750
func TestClusterOrchFunctionalTest(t *testing.T) {
@@ -190,6 +193,12 @@ var _ = Describe("Cluster Orch Functional tests", Ordered, Label(clusterOrchFunc
190193
_, err = cmd.Output()
191194
Expect(err).NotTo(HaveOccurred())
192195
})
196+
It("TC-CO-INT-009: Should verify that a cluster template cannot be deleted if there is a cluster using it", func() {
197+
By("Trying to delete the cluster template")
198+
err := deleteTemplate(namespace)
199+
Expect(err).To(HaveOccurred())
200+
Expect(err.Error()).To(ContainSubstring("denied the request: clusterTemplate is in use"))
201+
})
193202
// TODO: Add more functional tests
194203
})
195204

@@ -355,6 +364,33 @@ func deleteCluster(namespace string) error {
355364
return nil
356365
}
357366

367+
func deleteTemplate(namespace string) error {
368+
url := fmt.Sprintf("%s/%s/%s", clusterTemplateURL, clusterTemplateOnlyName, clusterTemplateOnlyVersion)
369+
370+
req, err := http.NewRequest("DELETE", url, nil)
371+
if err != nil {
372+
return err
373+
}
374+
375+
req.Header.Set("Activeprojectid", namespace)
376+
req.Header.Set("Content-Type", "application/json")
377+
req.Header.Set("Accept", "application/json")
378+
379+
client := &http.Client{}
380+
resp, err := client.Do(req)
381+
if err != nil {
382+
return err
383+
}
384+
defer resp.Body.Close()
385+
386+
if resp.StatusCode != http.StatusNoContent {
387+
body, _ := io.ReadAll(resp.Body)
388+
return fmt.Errorf("failed to delete template: %s", string(body))
389+
}
390+
391+
return nil
392+
}
393+
358394
func getClusterInfo(namespace, clusterName string) (*http.Response, error) {
359395
url := fmt.Sprintf("%s/%s", clusterCreateURL, clusterName)
360396
req, err := http.NewRequest("GET", url, nil)

0 commit comments

Comments
 (0)