Skip to content

Commit eb1500c

Browse files
authored
Add integration test workflow (#71)
1 parent 9327352 commit eb1500c

File tree

8 files changed

+65
-13
lines changed

8 files changed

+65
-13
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: integration
2+
on:
3+
push:
4+
branches:
5+
- main
6+
jobs:
7+
integration-test:
8+
name: Run Integration Test
9+
runs-on: ubuntu-latest
10+
environment: Integration Test
11+
permissions:
12+
id-token: write
13+
steps:
14+
- name: Configure AWS credentials
15+
uses: aws-actions/configure-aws-credentials@master
16+
with:
17+
aws-region: us-west-2
18+
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
19+
role-session-name: IntegrationTestSession
20+
- name: Checkout code
21+
uses: actions/checkout@v2
22+
- name: Set up Go
23+
uses: actions/setup-go@v2
24+
with:
25+
go-version: 1.17
26+
- name: Set up env
27+
run: source ~/.bashrc
28+
- name: Start clean
29+
run: make integration-cleanup
30+
- name: Set up cluster
31+
run: make integration-setup
32+
- name: Run tests
33+
run: make integration-run
34+
- name: Clean up clusters
35+
run: make integration-cleanup

Makefile

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,26 @@ vet: ## Run go vet against code.
5555
go vet ./...
5656

5757
ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
58-
test: manifests generate generate-mocks fmt vet ## Run tests.
58+
test: manifests generate generate-mocks fmt vet test-setup ## Run tests.
59+
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out -covermode=atomic
60+
61+
test-setup: # setup test environment
5962
mkdir -p ${ENVTEST_ASSETS_DIR}
6063
test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.7.2/hack/setup-envtest.sh
61-
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out -covermode=atomic
64+
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR)
65+
66+
integration-suite: ## Provision and run integration tests with cleanup
67+
make integration-setup && \
68+
make integration-run && \
69+
make integration-cleanup
6270

63-
integration-setup: ## Setup the integration test using kind clusters
71+
integration-setup: build kind test-setup ## Setup the integration test using kind clusters
6472
@./integration/scripts/setup-kind.sh
6573

6674
integration-run: ## Run the integration test controller
6775
@./integration/scripts/run-tests.sh
6876

69-
integration-cleanup: ## Cleanup integration test resources in Cloud Map and local kind cluster
77+
integration-cleanup: kind ## Cleanup integration test resources in Cloud Map and local kind cluster
7078
@./integration/scripts/cleanup-cloudmap.sh
7179
@./integration/scripts/cleanup-kind.sh
7280

@@ -126,6 +134,9 @@ MOCKGEN = $(shell pwd)/bin/mockgen
126134
mockgen: ## Download mockgen
127135
$(call go-get-tool,$(MOCKGEN),github.com/golang/mock/[email protected])
128136

137+
KIND = $(shell pwd)/bin/kind
138+
kind: ## Download kind
139+
$(call go-get-tool,$(KIND),sigs.k8s.io/[email protected])
129140

130141
# go-get-tool will 'go get' any package $2 and install it to $1.
131142
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
[![CodeQL](https://github.com/aws/aws-cloud-map-mcs-controller-for-k8s/actions/workflows/codeql-analysis.yml/badge.svg?branch=main)](https://github.com/aws/aws-cloud-map-mcs-controller-for-k8s/actions/workflows/codeql-analysis.yml)
55
[![Build status](https://github.com/aws/aws-cloud-map-mcs-controller-for-k8s/actions/workflows/build.yml/badge.svg?branch=main)](https://github.com/aws/aws-cloud-map-mcs-controller-for-k8s/actions/workflows/build.yml)
66
[![Deploy status](https://github.com/aws/aws-cloud-map-mcs-controller-for-k8s/actions/workflows/deploy.yml/badge.svg?branch=main)](https://github.com/aws/aws-cloud-map-mcs-controller-for-k8s/actions/workflows/deploy.yml)
7+
[![Integration status](https://github.com/aws/aws-cloud-map-mcs-controller-for-k8s/actions/workflows/integration-test.yml/badge.svg?branch=main)](https://github.com/aws/aws-cloud-map-mcs-controller-for-k8s/actions/workflows/integration-test.yml)
78
[![codecov](https://codecov.io/gh/aws/aws-cloud-map-mcs-controller-for-k8s/branch/main/graph/badge.svg)](https://codecov.io/gh/aws/aws-cloud-map-mcs-controller-for-k8s)
89

910
[![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg?color=success)](http://www.apache.org/licenses/LICENSE-2.0)
@@ -60,7 +61,7 @@ kubectl apply -f https://raw.githubusercontent.com/aws/aws-cloud-map-mcs-control
6061

6162
### Import services
6263

63-
In your other cluster, the controller will automatically sync services registered in AWS CloudMap by applying the appropriate `ServiceImport`. To list them all, run
64+
In your other cluster, the controller will automatically sync services registered in AWS Cloud Map by applying the appropriate `ServiceImport`. To list them all, run
6465
```sh
6566
kubectl get ServiceImport -A
6667
```
@@ -93,6 +94,12 @@ To install from `latest` tag run
9394
kubectl apply -k "github.com/aws/aws-cloud-map-mcs-controller-for-k8s/config/controller_install_latest"
9495
```
9596

97+
## Integration testing
98+
The end-to-end integration test suite can be run locally to validate controller core functionality. This will provision a local Kind cluster and build and run the AWS Cloud Map MCS Controller for K8s. The test will verify service endpoints sync with AWS Cloud Map. If successful, the suite will then de-provision the local test cluster and delete AWS Cloud Map namespace `aws-cloud-map-mcs-e2e` along with test service and service instance resources.
99+
```sh
100+
make integration-suite
101+
```
102+
96103
## Contributing
97104
`aws-cloud-map-mcs-controller-for-k8s` is an open source project. See [CONTRIBUTING](https://github.com/aws/aws-cloud-map-mcs-controller-for-k8s/blob/main/CONTRIBUTING.md) for details.
98105

integration/scripts/cleanup-cloudmap.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
set -eo pipefail
66
source ./integration/scripts/common.sh
77

8-
go run ./integration/janitor/runner/main.go "$NAMESPACE"
8+
go run ./integration/janitor/runner/main.go "$NAMESPACE"

integration/scripts/cleanup-kind.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
set -eo pipefail
66
source ./integration/scripts/common.sh
77

8-
$KIND_BIN delete cluster --name "$KIND_SHORT"
8+
$KIND_BIN delete cluster --name "$KIND_SHORT"

integration/scripts/common.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
KIND_BIN='kind'
3+
KIND_BIN='./bin/kind'
44
KUBECTL_BIN='./testbin/bin/kubectl'
55
LOGS='./integration/testlog'
66
CONFIGS='./integration/configs'
@@ -11,4 +11,4 @@ ENDPT_PORT=80
1111
KIND_SHORT='cloud-map-e2e'
1212
CLUSTER='kind-cloud-map-e2e'
1313
IMAGE='kindest/node:v1.19.11@sha256:07db187ae84b4b7de440a73886f008cf903fcf5764ba8106a9fd5243d6f32729'
14-
EXPECTED_ENDPOINT_COUNT=5
14+
EXPECTED_ENDPOINT_COUNT=5

integration/scripts/poll-endpoints.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ do
2121
continue
2222
fi
2323

24-
endpts=$(echo "$addresses" | tr -s " " "$addresses" | cut -f 3 -d " ")
24+
endpts=$(echo "$addresses" | tr -s " " | cut -f 3 -d " ")
2525

2626
endpt_count=$(echo "$endpts" | tr ',' '\n' | wc -l | xargs)
2727
done
2828

2929
echo "$endpts"
30-
exit 0
30+
exit 0

integration/scripts/run-tests.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ $KUBECTL_BIN apply -f "$CONFIGS/e2e-export.yaml"
1313
endpts=$(./integration/scripts/poll-endpoints.sh "$EXPECTED_ENDPOINT_COUNT")
1414

1515
mkdir -p "$LOGS"
16-
make
1716
./bin/manager &> "$LOGS/ctl.log" &
1817
CTL_PID=$!
1918

2019
go run $SCENARIOS/runner/main.go $NAMESPACE $SERVICE $ENDPT_PORT "$endpts"
2120

22-
kill $CTL_PID
21+
kill $CTL_PID

0 commit comments

Comments
 (0)