Skip to content

Commit e4fe108

Browse files
Rahul Sharmarahulait
authored andcommitted
update GHA to run e2e tests
1 parent 3510bc4 commit e4fe108

File tree

5 files changed

+165
-9
lines changed

5 files changed

+165
-9
lines changed

.github/filters.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Any file that is not a doc *.md file
2+
src:
3+
- "!**/**.md"

.github/workflows/ci.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,25 @@ on:
77
pull_request: null
88

99
jobs:
10+
changes:
11+
runs-on: ubuntu-latest
12+
outputs:
13+
paths: ${{ steps.filter.outputs.changes }}
14+
steps:
15+
- uses: actions/checkout@v4
16+
- name: Harden Runner
17+
uses: step-security/harden-runner@v2
18+
with:
19+
disable-sudo: true
20+
egress-policy: block
21+
allowed-endpoints: >
22+
api.github.com:443
23+
github.com:443
24+
- uses: dorny/paths-filter@v3
25+
id: filter
26+
with:
27+
base: ${{ github.ref }}
28+
filters: .github/filters.yml
1029
ci:
1130
runs-on: ubuntu-latest
1231
strategy:
@@ -61,3 +80,45 @@ jobs:
6180
labels: ${{ steps.meta.outputs.labels }}
6281
build-args: |
6382
REV=${{ github.ref_name }}
83+
84+
e2e-tests:
85+
runs-on: ubuntu-latest
86+
needs: changes
87+
if: ${{ contains(fromJSON(needs.changes.outputs.paths), 'src') }}
88+
env:
89+
GITHUB_TOKEN: ${{ secrets.github_token }}
90+
LINODE_TOKEN: ${{ secrets.LINODE_TOKEN }}
91+
IMG: linode/linode-cloud-controller-manager:${{ github.ref == 'refs/heads/main' && 'latest' || format('pr-{0}', github.event.number) || github.ref_name }}
92+
LINODE_REGION: us-lax
93+
LINODE_CONTROL_PLANE_MACHINE_TYPE: g6-standard-2
94+
LINODE_MACHINE_TYPE: g6-standard-2
95+
WORKER_NODES: '2'
96+
steps:
97+
- uses: actions/checkout@v4
98+
with:
99+
fetch-depth: 0
100+
101+
- name: Set up Go
102+
uses: actions/setup-go@v5
103+
with:
104+
go-version-file: 'go.mod'
105+
check-latest: true
106+
107+
- name: Login to Docker Hub
108+
uses: docker/login-action@v3
109+
with:
110+
username: ${{ secrets.DOCKER_USERNAME }}
111+
password: ${{ secrets.DOCKER_PASSWORD }}
112+
113+
- name: Install devbox
114+
uses: jetify-com/[email protected]
115+
116+
- name: Setup CAPL Management Kind Cluster and CAPL Child Cluster For Testing
117+
run: devbox run mgmt-and-capl-cluster
118+
119+
- name: Run E2E Tests
120+
run: devbox run e2e-test
121+
122+
- name: Cleanup Resources
123+
if: always()
124+
run: devbox run cleanup-cluster

Makefile

Lines changed: 84 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
1-
IMG ?= linode/linode-cloud-controller-manager:canary
2-
RELEASE_DIR ?= release
3-
PLATFORM ?= linux/amd64
1+
IMG ?= linode/linode-cloud-controller-manager:canary
2+
RELEASE_DIR ?= release
3+
PLATFORM ?= linux/amd64
44

55
# Use CACHE_BIN for tools that cannot use devbox and LOCALBIN for tools that can use either method
6-
CACHE_BIN ?= $(CURDIR)/bin
7-
LOCALBIN ?= $(CACHE_BIN)
8-
9-
DEVBOX_BIN ?= $(DEVBOX_PACKAGES_DIR)/bin
6+
CACHE_BIN ?= $(CURDIR)/bin
7+
LOCALBIN ?= $(CACHE_BIN)
8+
9+
DEVBOX_BIN ?= $(DEVBOX_PACKAGES_DIR)/bin
10+
11+
#####################################################################
12+
# Dev Setup
13+
#####################################################################
14+
CLUSTER_NAME ?= ccm-$(shell git rev-parse --short HEAD)
15+
K8S_VERSION ?= "v1.29.1"
16+
CAPI_VERSION ?= "v1.6.3"
17+
HELM_VERSION ?= "v0.2.1"
18+
CAPL_VERSION ?= "v0.7.1"
19+
CONTROLPLANE_NODES ?= 1
20+
WORKER_NODES ?= 1
21+
LINODE_FIREWALL_ENABLED ?= true
22+
LINODE_REGION ?= us-lax
23+
KUBECONFIG_PATH ?= $(CURDIR)/test-cluster-kubeconfig.yaml
1024

1125
# if the $DEVBOX_PACKAGES_DIR env variable exists that means we are within a devbox shell and can safely
1226
# use devbox's bin for our tools
@@ -88,9 +102,11 @@ docker-build: build-linux
88102
.PHONY: docker-push
89103
# must run the docker build before pushing the image
90104
docker-push:
91-
echo "[reminder] Did you run `make docker-build`?"
92105
docker push ${IMG}
93106

107+
.PHONY: docker-setup
108+
docker-setup: docker-build docker-push
109+
94110
.PHONY: run
95111
# run the ccm locally, really only makes sense on linux anyway
96112
run: build
@@ -108,6 +124,66 @@ run-debug: build
108124
--kubeconfig=${KUBECONFIG} \
109125
--linodego-debug
110126

127+
#####################################################################
128+
# E2E Test Setup
129+
#####################################################################
130+
131+
.PHONY: mgmt-and-capl-cluster
132+
mgmt-and-capl-cluster: docker-setup mgmt-cluster capl-cluster
133+
134+
.PHONY: capl-cluster
135+
capl-cluster: generate-capl-cluster-manifests create-capl-cluster patch-linode-ccm
136+
137+
.PHONY: generate-capl-cluster-manifests
138+
generate-capl-cluster-manifests:
139+
# Create the CAPL cluster manifests without any CSI driver stuff
140+
LINODE_FIREWALL_ENABLED=$(LINODE_FIREWALL_ENABLED) clusterctl generate cluster $(CLUSTER_NAME) \
141+
--kubernetes-version $(K8S_VERSION) \
142+
--infrastructure linode-linode:$(CAPL_VERSION) \
143+
--control-plane-machine-count $(CONTROLPLANE_NODES) --worker-machine-count $(WORKER_NODES) > capl-cluster-manifests.yaml
144+
145+
.PHONY: create-capl-cluster
146+
create-capl-cluster:
147+
# Create a CAPL cluster with updated CCM and wait for it to be ready
148+
kubectl apply -f capl-cluster-manifests.yaml
149+
kubectl wait --for=condition=ControlPlaneReady cluster/$(CLUSTER_NAME) --timeout=600s || (kubectl get cluster -o yaml; kubectl get linodecluster -o yaml; kubectl get linodemachines -o yaml)
150+
kubectl wait --for=condition=NodeHealthy=true machines -l cluster.x-k8s.io/cluster-name=$(CLUSTER_NAME) --timeout=900s
151+
clusterctl get kubeconfig $(CLUSTER_NAME) > $(KUBECONFIG_PATH)
152+
KUBECONFIG=$(KUBECONFIG_PATH) kubectl wait --for=condition=Ready nodes --all --timeout=600s
153+
# Remove all taints so that pods can be scheduled anywhere (without this, some tests fail)
154+
KUBECONFIG=$(KUBECONFIG_PATH) kubectl taint nodes -l node-role.kubernetes.io/control-plane node-role.kubernetes.io/control-plane-
155+
156+
.PHONY: patch-linode-ccm
157+
patch-linode-ccm:
158+
KUBECONFIG=$(KUBECONFIG_PATH) kubectl patch -n kube-system daemonset ccm-linode --type='json' -p="[{'op': 'replace', 'path': '/spec/template/spec/containers/0/image', 'value': '${IMG}'}]"
159+
KUBECONFIG=$(KUBECONFIG_PATH) kubectl rollout status -n kube-system daemonset/ccm-linode --timeout=600s
160+
161+
.PHONY: mgmt-cluster
162+
mgmt-cluster:
163+
# Create a mgmt cluster
164+
ctlptl apply -f e2e/setup/ctlptl-config.yaml
165+
clusterctl init \
166+
--wait-providers \
167+
--wait-provider-timeout 600 \
168+
--core cluster-api:$(CAPI_VERSION) \
169+
--addon helm:$(HELM_VERSION) \
170+
--infrastructure linode-linode:$(CAPL_VERSION)
171+
172+
.PHONY: cleanup-cluster
173+
cleanup-cluster:
174+
kubectl delete cluster --all
175+
kubectl delete linodefirewalls --all
176+
kubectl delete lvpc --all
177+
kind delete cluster -n caplccm
178+
179+
.PHONY: e2e-test
180+
e2e-test:
181+
$(MAKE) -C e2e test LINODE_API_TOKEN=$(LINODE_TOKEN) SUITE_ARGS="--region=$(LINODE_REGION) --use-existing --timeout=5m --kubeconfig=$(KUBECONFIG_PATH) --image=$(IMG) --linode-url https://api.linode.com/"
182+
183+
#####################################################################
184+
# OS / ARCH
185+
#####################################################################
186+
111187
# Set the host's OS. Only linux and darwin supported for now
112188
HOSTOS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
113189
ifeq ($(filter darwin linux,$(HOSTOS)),)

devbox.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@
1818
"init_hook": [
1919
"export \"GOROOT=$(go env GOROOT)\""
2020
],
21-
"scripts": {}
21+
"scripts": {
22+
"mgmt-and-capl-cluster": "make mgmt-and-capl-cluster",
23+
"e2e-test": "make e2e-test",
24+
"cleanup-cluster": "make cleanup-cluster"
25+
}
26+
},
27+
"env": {
28+
"EXP_CLUSTER_RESOURCE_SET": "true"
2229
}
2330
}

e2e/setup/ctlptl-config.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
apiVersion: ctlptl.dev/v1alpha1
3+
kind: Cluster
4+
product: kind
5+
kindV1Alpha4Cluster:
6+
name: caplccm
7+
nodes:
8+
- role: control-plane
9+
image: kindest/node:v1.29.2

0 commit comments

Comments
 (0)