Skip to content

Commit 0be2288

Browse files
committed
Fix integration tests.
1 parent 1aed1c3 commit 0be2288

File tree

7 files changed

+25
-21
lines changed

7 files changed

+25
-21
lines changed

.github/workflows/lint.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ jobs:
1515
- name: Setup Go
1616
uses: actions/setup-go@v5
1717
with:
18-
go-version: '~1.23'
18+
go-version-file: 'go.mod'
19+
cache: false
1920

2021
- name: Run Linter
2122
uses: golangci/golangci-lint-action@v6

.github/workflows/test-e2e.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- name: Setup Go
1616
uses: actions/setup-go@v5
1717
with:
18-
go-version: '~1.23'
18+
go-version-file: 'go.mod'
1919

2020
- name: Install the latest version of kind
2121
run: |

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- name: Setup Go
1616
uses: actions/setup-go@v5
1717
with:
18-
go-version: '~1.23'
18+
go-version-file: 'go.mod'
1919

2020
- name: Running Tests
2121
run: |

Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ vet: ## Run go vet against code.
7979
test: manifests generate fmt vet envtest ## Run tests.
8080
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v /e2e) -coverprofile cover.out
8181

82-
# TODO(user): To use a different vendor for e2e tests, modify the setup under 'tests/e2e'.
8382
# The default setup assumes Kind is pre-installed and builds/loads the Manager Docker image locally.
8483
# Prometheus and CertManager are installed by default; skip with:
8584
# - PROMETHEUS_INSTALL_SKIP=true

config/default/kustomization.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,22 @@ resources:
1818
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'. 'WEBHOOK' components are required.
1919
#- ../certmanager
2020
# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
21-
#- ../prometheus
21+
- ../prometheus
2222
# [METRICS] Expose the controller manager metrics service.
23-
# - metrics_service.yaml
23+
- metrics_service.yaml
2424
# [NETWORK POLICY] Protect the /metrics endpoint and Webhook Server with NetworkPolicy.
2525
# Only Pod(s) running a namespace labeled with 'metrics: enabled' will be able to gather the metrics.
2626
# Only CR(s) which requires webhooks and are applied on namespaces labeled with 'webhooks: enabled' will
2727
# be able to communicate with the Webhook Server.
2828
#- ../network-policy
2929

3030
# Uncomment the patches line if you enable Metrics, and/or are using webhooks and cert-manager
31-
# patches:
31+
patches:
3232
# [METRICS] The following patch will enable the metrics endpoint using HTTPS and the port :8443.
3333
# More info: https://book.kubebuilder.io/reference/metrics
34-
# - path: manager_metrics_patch.yaml
35-
# target:
36-
# kind: Deployment
34+
- path: manager_metrics_patch.yaml
35+
target:
36+
kind: Deployment
3737

3838
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
3939
# crd/kustomization.yaml

test/e2e/e2e_suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ var (
4343

4444
// projectImage is the name of the image which will be build and loaded
4545
// with the code source changes to be tested.
46-
projectImage = "example.com/cluster-api-provider-metal-stack:v0.0.1"
46+
projectImage = "capms-controller:latest"
4747
)
4848

4949
// TestE2E runs the end-to-end (e2e) test suite for the project. These tests execute in an isolated,

test/e2e/e2e_test.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@ import (
3131
)
3232

3333
// namespace where the project is deployed in
34-
const namespace = "cluster-api-provider-metal-stack-system"
34+
const namespace = "capms-system"
3535

3636
// serviceAccountName created for the project
37-
const serviceAccountName = "cluster-api-provider-metal-stack-controller-manager"
37+
const serviceAccountName = "capms-controller-manager"
3838

3939
// metricsServiceName is the name of the metrics service of the project
40-
const metricsServiceName = "cluster-api-provider-metal-stack-controller-manager-metrics-service"
40+
const metricsServiceName = "capms-controller-manager-metrics-service"
4141

4242
// metricsRoleBindingName is the name of the RBAC that will be created to allow get the metrics data
43-
const metricsRoleBindingName = "cluster-api-provider-metal-stack-metrics-binding"
43+
const metricsRoleBindingName = "capms-metrics-binding"
4444

4545
var _ = Describe("Manager", Ordered, func() {
4646
var controllerPodName string
@@ -68,7 +68,11 @@ var _ = Describe("Manager", Ordered, func() {
6868
// and deleting the namespace.
6969
AfterAll(func() {
7070
By("cleaning up the curl pod for metrics")
71-
cmd := exec.Command("kubectl", "delete", "pod", "curl-metrics", "-n", namespace)
71+
cmd := exec.Command("kubectl", "delete", "pod", "curl-metrics", "-n", "kube-system")
72+
_, _ = utils.Run(cmd)
73+
74+
By("cleaning up metrics-server cluster role binding")
75+
cmd = exec.Command("kubectl", "delete", "clusterrolebinding", metricsRoleBindingName)
7276
_, _ = utils.Run(cmd)
7377

7478
By("undeploying the controller-manager")
@@ -108,7 +112,7 @@ var _ = Describe("Manager", Ordered, func() {
108112
}
109113

110114
By("Fetching curl-metrics logs")
111-
cmd = exec.Command("kubectl", "logs", "curl-metrics", "-n", namespace)
115+
cmd = exec.Command("kubectl", "logs", "curl-metrics", "-n", "kube-system")
112116
metricsOutput, err := utils.Run(cmd)
113117
if err == nil {
114118
_, _ = fmt.Fprintf(GinkgoWriter, "Metrics logs:\n %s", metricsOutput)
@@ -166,7 +170,7 @@ var _ = Describe("Manager", Ordered, func() {
166170
It("should ensure the metrics endpoint is serving metrics", func() {
167171
By("creating a ClusterRoleBinding for the service account to allow access to metrics")
168172
cmd := exec.Command("kubectl", "create", "clusterrolebinding", metricsRoleBindingName,
169-
"--clusterrole=cluster-api-provider-metal-stack-metrics-reader",
173+
"--clusterrole=capms-metrics-reader",
170174
fmt.Sprintf("--serviceaccount=%s:%s", namespace, serviceAccountName),
171175
)
172176
_, err := utils.Run(cmd)
@@ -208,7 +212,7 @@ var _ = Describe("Manager", Ordered, func() {
208212

209213
By("creating the curl-metrics pod to access the metrics endpoint")
210214
cmd = exec.Command("kubectl", "run", "curl-metrics", "--restart=Never",
211-
"--namespace", namespace,
215+
"--namespace", "kube-system",
212216
"--image=curlimages/curl:7.78.0",
213217
"--", "/bin/sh", "-c", fmt.Sprintf(
214218
"curl -v -k -H 'Authorization: Bearer %s' https://%s.%s.svc.cluster.local:8443/metrics",
@@ -220,7 +224,7 @@ var _ = Describe("Manager", Ordered, func() {
220224
verifyCurlUp := func(g Gomega) {
221225
cmd := exec.Command("kubectl", "get", "pods", "curl-metrics",
222226
"-o", "jsonpath={.status.phase}",
223-
"-n", namespace)
227+
"-n", "kube-system")
224228
output, err := utils.Run(cmd)
225229
g.Expect(err).NotTo(HaveOccurred())
226230
g.Expect(output).To(Equal("Succeeded"), "curl pod in wrong status")
@@ -291,7 +295,7 @@ func serviceAccountToken() (string, error) {
291295
// getMetricsOutput retrieves and returns the logs from the curl pod used to access the metrics endpoint.
292296
func getMetricsOutput() string {
293297
By("getting the curl-metrics logs")
294-
cmd := exec.Command("kubectl", "logs", "curl-metrics", "-n", namespace)
298+
cmd := exec.Command("kubectl", "logs", "curl-metrics", "-n", "kube-system")
295299
metricsOutput, err := utils.Run(cmd)
296300
Expect(err).NotTo(HaveOccurred(), "Failed to retrieve logs from curl pod")
297301
Expect(metricsOutput).To(ContainSubstring("< HTTP/1.1 200 OK"))

0 commit comments

Comments
 (0)