Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ setup-test-e2e: ## Set up a Kind cluster for e2e tests if it does not exist
esac

.PHONY: test-e2e
test-e2e: cleanup-test-e2e setup-test-e2e manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
test-e2e: cleanup-test-e2e setup-test-e2e manifests generate ## Run the e2e tests. Expected an isolated environment using Kind.
KIND_CLUSTER=$(KIND_CLUSTER) go test ./test/e2e/ -v -ginkgo.v
$(MAKE) cleanup-test-e2e

Expand Down Expand Up @@ -183,6 +183,7 @@ deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in

.PHONY: undeploy
undeploy: kustomize ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
$(KUBECTL) --context ${KUBE_CONTEXT} patch nodes.drain.k8s.slyng.dk --type=json -p='[{"op": "replace", "path": "/metadata/finalizers", "value": []}]' $$($(KUBECTL) --context ${KUBE_CONTEXT} get nodes.drain.k8s.slyng.dk --template='{{ range .items }}{{.metadata.name}} {{end}}')
$(KUSTOMIZE) build config/${KUSTOMIZE_CONFIG} | $(KUBECTL) --context ${KUBE_CONTEXT} delete --ignore-not-found=$(ignore-not-found) -f -

##@ Dependencies
Expand Down
29 changes: 16 additions & 13 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,6 @@ var _ = Describe("Manager", Ordered, func() {
cmd := exec.Command("kubectl", "delete", "pod", "curl-metrics", "-n", namespace)
_, _ = utils.Run(cmd)

By("delete nodes.drain.k8s.slyng.dk")
cmd = exec.Command("kubectl", "delete", "--all", "nodes.drain.k8s.slyng.dk")
_, _ = utils.Run(cmd)

By("wait for delete nodes.drain.k8s.slyng.dk")
cmd = exec.Command("kubectl", "wait", "--for=delete", "--all", "nodes.drain.k8s.slyng.dk")
_, _ = utils.Run(cmd)

By("undeploying the controller-manager")
cmd = exec.Command("make", "undeploy")
_, _ = utils.Run(cmd)
Expand All @@ -98,10 +90,6 @@ var _ = Describe("Manager", Ordered, func() {
By("removing manager namespace")
cmd = exec.Command("kubectl", "delete", "ns", namespace)
_, _ = utils.Run(cmd)

By("removing cluster role binding for metrics test")
cmd = exec.Command("kubectl", "delete", "clusterrolebinding", metricsRoleBindingName)
_, _ = utils.Run(cmd)
})

// After each test, check for failures and collect logs, events,
Expand Down Expand Up @@ -234,6 +222,7 @@ var _ = Describe("Manager", Ordered, func() {
"command": ["/bin/sh", "-c"],
"args": ["curl -v -k -H 'Authorization: Bearer %s' https://%s.%s.svc.cluster.local:8443/metrics"],
"securityContext": {
"readOnlyRootFilesystem": true,
"allowPrivilegeEscalation": false,
"capabilities": {
"drop": ["ALL"]
Expand All @@ -245,7 +234,7 @@ var _ = Describe("Manager", Ordered, func() {
}
}
}],
"serviceAccount": "%s"
"serviceAccountName": "%s"
}
}`, token, metricsServiceName, namespace, serviceAccountName))
_, err = utils.Run(cmd)
Expand Down Expand Up @@ -309,6 +298,20 @@ var _ = Describe("Manager", Ordered, func() {

// +kubebuilder:scaffold:e2e-webhooks-checks

It("should have a nodes.drain.k8s.slyng.dk generated", func() {
By("checking for nodes.drain.k8s.slyng.dk")
controlPlaneNodedrainStatus := func(g Gomega) {
cmd := exec.Command("kubectl", "get",
"nodes.drain.k8s.slyng.dk",
"nodedrain-test-e2e-control-plane",
"-o", "jsonpath={.status.currentState}")
output, err := utils.Run(cmd)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(output).To(Equal("OK"))
}
Eventually(controlPlaneNodedrainStatus).Should(Succeed())
})

// TODO: Customize the e2e test suite with scenarios specific to your project.
// Consider applying sample/CR(s) and check their status and/or verifying
// the reconciliation by using the metrics, i.e.:
Expand Down
Loading