Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulait committed Nov 25, 2024
1 parent 66afcae commit 8dcf54b
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .github/filters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Any file that is not a doc *.md file
src:
- "!**/**.md"
72 changes: 71 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,30 @@ on:
push:
branches:
- main
pull_request: null
pull_request:
branches:
- "*"

jobs:
changes:
runs-on: ubuntu-latest
outputs:
paths: ${{ steps.filter.outputs.changes }}
steps:
- uses: actions/checkout@v4
- name: Harden Runner
uses: step-security/harden-runner@v2
with:
disable-sudo: true
egress-policy: block
allowed-endpoints: >
api.github.com:443
github.com:443
- uses: dorny/paths-filter@v3
id: filter
with:
base: ${{ github.ref }}
filters: .github/filters.yml
ci:
runs-on: ubuntu-latest
strategy:
Expand Down Expand Up @@ -61,3 +82,52 @@ jobs:
labels: ${{ steps.meta.outputs.labels }}
build-args: |
REV=${{ github.ref_name }}
e2e-tests:
runs-on: ubuntu-latest
needs: changes
if: ${{ contains(fromJSON(needs.changes.outputs.paths), 'src') }}
env:
GITHUB_TOKEN: ${{ secrets.github_token }}
LINODE_TOKEN: ${{ secrets.LINODE_TOKEN }}
IMG: rahulait/ccm:${{ github.ref == 'refs/heads/main' && 'latest' || format('pr-{0}', github.event.number) || github.ref_name }}
LINODE_REGION: us-lax
LINODE_CONTROL_PLANE_MACHINE_TYPE: g6-standard-2
LINODE_MACHINE_TYPE: g6-standard-2
WORKER_NODES: ${{ github.ref == 'refs/heads/main' && '3' || '1' }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
check-latest: true

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Install devbox
uses: jetify-com/[email protected]

- name: Setup CAPL Management Kind Cluster and CAPL Child Cluster For Testing
run: devbox run mgmt-and-capl-cluster

- name: Run E2E Tests
run: devbox run e2e-test

- name: Run CSI-Sanity Tests
run: devbox run csi-sanity-test

- name: run upstream E2E Tests
if: github.ref == 'refs/heads/main'
run: devbox run upstream-e2e-tests

- name: Cleanup Resources
if: always()
run: devbox run cleanup-cluster
59 changes: 58 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
IMG ?= linode/linode-cloud-controller-manager:canary
RELEASE_DIR ?= release
PLATFORM ?= linux/amd64
LINODE_FIREWALL_ENABLED ?= true

# Use CACHE_BIN for tools that cannot use devbox and LOCALBIN for tools that can use either method
CACHE_BIN ?= $(CURDIR)/bin
Expand Down Expand Up @@ -88,9 +89,11 @@ docker-build: build-linux
.PHONY: docker-push
# must run the docker build before pushing the image
docker-push:
echo "[reminder] Did you run `make docker-build`?"
docker push ${IMG}

.PHONY: docker-setup
docker-setup: docker-build docker-push

.PHONY: run
# run the ccm locally, really only makes sense on linux anyway
run: build
Expand All @@ -108,6 +111,60 @@ run-debug: build
--kubeconfig=${KUBECONFIG} \
--linodego-debug

#####################################################################
# E2E Test Setup
#####################################################################

.PHONY: mgmt-and-capl-cluster
mgmt-and-capl-cluster: docker-setup mgmt-cluster capl-cluster

.PHONY: capl-cluster
capl-cluster: generate-capl-cluster-manifests create-capl-cluster patch-linode-ccm

.PHONY: generate-capl-cluster-manifests
generate-capl-cluster-manifests:
# Create the CAPL cluster manifests without any CSI driver stuff
LINODE_FIREWALL_ENABLED=$(LINODE_FIREWALL_ENABLED) clusterctl generate cluster $(CLUSTER_NAME) \
--kubernetes-version $(K8S_VERSION) \
--infrastructure linode-linode:$(CAPL_VERSION) \
--control-plane-machine-count $(CONTROLPLANE_NODES) --worker-machine-count $(WORKER_NODES) > capl-cluster-manifests.yaml

.PHONY: create-capl-cluster
create-capl-cluster:
# Create a CAPL cluster with updated CCM and wait for it to be ready
kubectl apply -f capl-cluster-manifests.yaml
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)
kubectl wait --for=condition=NodeHealthy=true machines -l cluster.x-k8s.io/cluster-name=$(CLUSTER_NAME) --timeout=900s
clusterctl get kubeconfig $(CLUSTER_NAME) > test-cluster-kubeconfig.yaml
KUBECONFIG=test-cluster-kubeconfig.yaml kubectl wait --for=condition=Ready nodes --all --timeout=600s

.PHONY: patch-linode-ccm
patch-linode-ccm:
KUBECONFIG=test-cluster-kubeconfig.yaml kubectl patch -n kube-system daemonset ccm-linode --type='json' -p="[{'op': 'replace', 'path': '/spec/template/spec/containers/0/image', 'value': '${IMG}'}]"
KUBECONFIG=test-cluster-kubeconfig.yaml kubectl rollout status -n kube-system daemonset/ccm-linode --timeout=600s

.PHONY: mgmt-cluster
mgmt-cluster:
# Create a mgmt cluster
ctlptl apply -f e2e/setup/ctlptl-config.yaml
clusterctl init \
--wait-providers \
--wait-provider-timeout 600 \
--core cluster-api:${CAPI_VERSION} \
--addon helm:${HELM_VERSION} \
--infrastructure linode-linode:${CAPL_VERSION}

.PHONY: cleanup-cluster
cleanup-cluster:
kubectl delete cluster --all
kubectl delete linodefirewalls --all
kubectl delete lvpc --all
kind delete cluster -n caplccm

#####################################################################
# OS / ARCH
#####################################################################

# Set the host's OS. Only linux and darwin supported for now
HOSTOS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
ifeq ($(filter darwin linux,$(HOSTOS)),)
Expand Down
6 changes: 5 additions & 1 deletion devbox.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
"init_hook": [
"export \"GOROOT=$(go env GOROOT)\""
],
"scripts": {}
"scripts": {
"mgmt-and-capl-cluster": "make mgmt-and-capl-cluster",
"e2e-test": "make e2e-test",
"cleanup-cluster": "make cleanup-cluster"
}
}
}
9 changes: 9 additions & 0 deletions e2e/setup/ctlptl-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
apiVersion: ctlptl.dev/v1alpha1
kind: Cluster
product: kind
kindV1Alpha4Cluster:
name: caplccm
nodes:
- role: control-plane
image: kindest/node:v1.29.2

0 comments on commit 8dcf54b

Please sign in to comment.