Skip to content

Commit

Permalink
Fix various issues with validating deployment
Browse files Browse the repository at this point in the history
Signed-off-by: Kyle Squizzato <[email protected]>
  • Loading branch information
squizzi committed Aug 23, 2024
1 parent 4f5d615 commit 4496f40
Show file tree
Hide file tree
Showing 7 changed files with 190 additions and 105 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@ jobs:
uses: azure/setup-kubectl@v4
- name: Run E2E tests
run: |
make e2e-test
make test-e2e
16 changes: 11 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ test: generate-all fmt vet envtest tidy external-crd ## Run tests.
# Utilize Kind or modify the e2e tests to load the image locally, enabling compatibility with other vendors.
.PHONY: test-e2e # Run the e2e tests against a Kind k8s instance that is spun up.
test-e2e: cli-install
KIND_CLUSTER_NAME=$(KIND_CLUSTER_NAME) KIND_VERSION=$(KIND_VERSION) go test ./test/e2e/ -v -ginkgo.v
KIND_CLUSTER_NAME="hmc-test" KIND_VERSION=$(KIND_VERSION) go test ./test/e2e/ -v -ginkgo.v -timeout=2h

.PHONY: lint
lint: golangci-lint ## Run golangci-lint linter & yamllint
Expand Down Expand Up @@ -270,10 +270,10 @@ dev-aws: yq
@$(YQ) e ".data.credentials = \"${AWS_CREDENTIALS}\"" config/dev/awscredentials.yaml | $(KUBECTL) -n $(NAMESPACE) apply -f -

.PHONY: dev-apply
dev-apply: kind-deploy registry-deploy dev-push dev-deploy dev-templates dev-aws
dev-apply: kind-deploy registry-deploy dev-push dev-deploy dev-templates dev-aws ## Deploy a kind cluster, local registry, push the image, deploy the controller, and apply the templates.

.PHONY: dev-destroy
dev-destroy: kind-undeploy registry-undeploy
dev-destroy: kind-undeploy registry-undeploy ## Destroy the development environment by deleting the kind cluster and local registry.

.PHONY: dev-aws-apply
dev-aws-apply: ## Apply the AWS deployment
Expand All @@ -286,11 +286,17 @@ dev-aws-destroy: ## Delete the AWS deployment
.PHONY: dev-aws-nuke
dev-aws-nuke: ## Warning: Destructive! Nuke all AWS resources deployed by 'dev-aws-apply', prefix with CLUSTER_NAME to nuke a specific cluster.
@CLUSTER_NAME=$(CLUSTER_NAME) envsubst < config/dev/cloud_nuke.yaml.tpl > config/dev/cloud_nuke.yaml
$(CLOUDNUKE) aws --region us-west-2 --force --config config/dev/cloud_nuke.yaml --resource-type vpc,eip,nat-gateway,ec2-subnet,internet-gateway,network-interface,security-group
DISABLE_TELEMETRY=true $(CLOUDNUKE) aws --region $$AWS_REGION --config config/dev/cloud_nuke.yaml --resource-type vpc,eip,nat-gateway,ec2-subnet,elb,elbv2,internet-gateway,network-interface,security-group
@rm config/dev/cloud_nuke.yaml

.PHONY: test-apply
test-apply: kind-deploy registry-deploy dev-push dev-deploy dev-templates

.PHONY: test-destroy
test-destroy: kind-undeploy registry-undeploy

.PHONY: cli-install
cli-install: clusterawsadm clusterctl cloud-nuke
cli-install: clusterawsadm clusterctl cloud-nuke yq ## Install the necessary CLI tools for deployment, development and testing.

##@ Dependencies

Expand Down
26 changes: 13 additions & 13 deletions config/dev/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
apiVersion: hmc.mirantis.com/v1alpha1
kind: Deployment
metadata:
name: aws-dev
name: bba1743d-e2e-test
spec:
template: aws-standalone-cp
config:
region: us-east-2
publicIP: true
controlPlaneNumber: 1
workersNumber: 1
controlPlane:
amiID: ami-02f3416038bdb17fb
instanceType: t3.small
worker:
amiID: ami-02f3416038bdb17fb
instanceType: t3.small
config:
controlPlane:
amiID: ami-0989c067ff3da4b27
instanceType: t3.small
controlPlaneNumber: 1
publicIP: true
region: us-west-2
worker:
amiID: ami-0989c067ff3da4b27
instanceType: t3.small
workersNumber: 1
template: aws-standalone-cp
63 changes: 36 additions & 27 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ import (
const namespace = "hmc-system"

var _ = Describe("controller", Ordered, func() {
BeforeAll(func() {
By("building and deploying the controller-manager")
cmd := exec.Command("make", "dev-apply")
_, err := utils.Run(cmd)
Expect(err).NotTo(HaveOccurred())
})

AfterAll(func() {
By("removing the controller-manager")
cmd := exec.Command("make", "dev-destroy")
_, err := utils.Run(cmd)
Expect(err).NotTo(HaveOccurred())
})
// BeforeAll(func() {
// By("building and deploying the controller-manager")
// cmd := exec.Command("make", "test-apply")
// _, err := utils.Run(cmd)
// Expect(err).NotTo(HaveOccurred())
// })

// AfterAll(func() {
// By("removing the controller-manager")
// cmd := exec.Command("make", "test-destroy")
// _, err := utils.Run(cmd)
// Expect(err).NotTo(HaveOccurred())
// })

Context("Operator", func() {
It("should run successfully", func() {
Expand All @@ -54,7 +54,7 @@ var _ = Describe("controller", Ordered, func() {
By("validating that the controller-manager pod is running as expected")
verifyControllerUp := func() error {
// Ensure only one controller pod is running.
podList, err := kc.Client.CoreV1().Pods(namespace).List(context.Background(), metav1.ListOptions{
podList, err := kc.Client.CoreV1().Pods(kc.Namespace).List(context.Background(), metav1.ListOptions{
LabelSelector: "control-plane=controller-manager,app.kubernetes.io/name=cluster-api",
})
if err != nil {
Expand All @@ -81,8 +81,16 @@ var _ = Describe("controller", Ordered, func() {
}

return nil
}()
EventuallyWithOffset(1, verifyControllerUp, time.Minute, time.Second).Should(Succeed())
}
EventuallyWithOffset(1, func() error {
err := verifyControllerUp()
if err != nil {
_, _ = fmt.Fprintf(GinkgoWriter, "Controller pod validation failed: %v\n", err)
return err
}

return nil
}(), 5*time.Minute, time.Second).Should(Succeed())
})
})

Expand All @@ -100,29 +108,30 @@ var _ = Describe("controller", Ordered, func() {
})

AfterAll(func() {
// Purge the AWS resources, the AfterAll for the controller will
// clean up the management cluster.
cmd := exec.Command("make", "dev-aws-nuke")
_, err := utils.Run(cmd)
ExpectWithOffset(2, err).NotTo(HaveOccurred())
// // Purge the AWS resources, the AfterAll for the controller will
// // clean up the management cluster.
// cmd := exec.Command("make", "dev-aws-nuke")
// _, err := utils.Run(cmd)
// ExpectWithOffset(2, err).NotTo(HaveOccurred())
})

It("should work with an AWS provider", func() {
By("using the aws-standalone-cp template")
clusterName, err := utils.ConfigureDeploymentConfig(utils.ProviderAWS, utils.AWSStandaloneCPTemplate)
ExpectWithOffset(2, err).NotTo(HaveOccurred())
//clusterName, err := utils.ConfigureDeploymentConfig(utils.ProviderAWS, utils.TemplateAWSStandaloneCP)
//ExpectWithOffset(1, err).NotTo(HaveOccurred())

clusterName := "bba1743d-e2e-test"

cmd := exec.Command("make", "dev-aws-apply")
_, err = utils.Run(cmd)
ExpectWithOffset(2, err).NotTo(HaveOccurred())
EventuallyWithOffset(2, func() error {
_, _ = fmt.Fprintf(GinkgoWriter, "Waiting for resource validation to succeed\n")
Eventually(func() error {
return verifyProviderDeployed(context.Background(), kc, clusterName)
}(), 30*time.Minute, 10*time.Second).Should(Succeed())

}).WithTimeout(30 * time.Minute).WithPolling(5 * time.Second).Should(Succeed())
By("using the aws-hosted-cp template")
// TODO: Use the standalone control plane resources to craft a hosted
// control plane and test it.

})
})
})
Loading

0 comments on commit 4496f40

Please sign in to comment.