Skip to content

Commit

Permalink
test: setup test suite basics (#90)
Browse files Browse the repository at this point in the history
* setup test suite basics
  • Loading branch information
waveywaves authored Feb 26, 2024
1 parent 9c5a639 commit 67ec5e9
Show file tree
Hide file tree
Showing 40 changed files with 961 additions and 175 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/e2e-with-cluster.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: EnvTest with Cluster

on:
pull_request:
branches: [ main ]
types: [opened,reopened,synchronize,closed]

permissions:
contents: read
pull-requests: write
id-token: write

jobs:
minikube:
name: Run E2E tests with Minikube
if: ${{ github.event_name == 'pull_request' && github.event.action != 'closed' }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Minikube
run: minikube start --driver=docker

- name: Install FluxCD
run: |
curl -s https://fluxcd.io/install.sh | sudo bash
flux install --namespace=flux-system --components="source-controller,helm-controller"
- name: Run e2e tests
run: |
make e2e-test-with-cluster
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: E2E - Helm Chart Deployment and Tests
name: E2E - Helm Chart Deployment Test

on:
pull_request:
Expand Down Expand Up @@ -120,8 +120,6 @@ jobs:
# kubectl apply -f examples/k3s-manifest-basic.yml
# kubectl apply -f examples/k8s-manifest-basic.yml
# kubectl kuttl test
- name: Create or Update Comment with Deployment URL
uses: peter-evans/create-or-update-comment@v2
with:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
(cd ./chart && helm dep update .)
helm lint ./chart --with-subcharts
- name: Test
run: go test -coverprofile=coverage.txt -covermode=atomic -v ./...
run: |
go test -coverprofile=coverage.txt -covermode=atomic -v ./src/controllers/...
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
5 changes: 2 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ RUN go mod download

# Copy the go source
COPY main.go main.go
COPY src/api/ src/api/
COPY src/controllers/ src/controllers/
COPY src/ src/

# Build
# the GOARCH has not a default value to allow the binary be built according to the host where the command
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager main.go
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH:-arm64} go build -a -o manager main.go

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
Expand Down
32 changes: 18 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include test/e2e/Makefile

VERSION ?= 1.5.6

# check if we are using MacOS or LINUX and use that to determine the sed command
Expand Down Expand Up @@ -109,10 +107,16 @@ fmt: ## Run go fmt against code.
vet: ## Run go vet against code.
go vet ./...

.PHONY: test
test: manifests generate fmt vet envtest ## Run test.
##@ Test

.PHONY: e2e-test-without-cluster
e2e-test-without-cluster: manifests generate fmt vet envtest ## Run test.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out

.PHONY: e2e-test-with-cluster
e2e-test-with-cluster: manifests generate fmt vet envtest ## Run test.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" ENVTEST_REMOTE=true go test ./... -coverprofile cover.out -v

##@ Build

.PHONY: build
Expand Down Expand Up @@ -160,28 +164,28 @@ endif

.PHONY: install
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd | kubectl apply -f -
$(KUSTOMIZE) build src/config/crd | kubectl apply -f -

.PHONY: uninstall
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
$(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
$(KUSTOMIZE) build src/config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -

.PHONY: deploy
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/default | kubectl apply -f -
cd src/config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build src/config/default | kubectl apply -f -

.PHONY: undeploy
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
$(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
$(KUSTOMIZE) build src/config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -

.PHONY: build-helm-chart
build-helm-chart: manifests generate fmt vet kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
# update the crd
$(KUSTOMIZE) build config/crd > chart/templates/uffizziclusters.uffizzi.com_customresourcedefinition.yaml
$(KUSTOMIZE) build src/config/crd > chart/templates/uffizziclusters.uffizzi.com_customresourcedefinition.yaml
$(SED) -i'' -e 's/labels:/labels: {{ include "common.labels.standard" . | nindent 4 }}/' chart/templates/uffizziclusters.uffizzi.com_customresourcedefinition.yaml
# update roles
cp config/rbac/role.yaml chart/templates/manager-role_clusterrole.yaml
cp src/config/rbac/role.yaml chart/templates/manager-role_clusterrole.yaml
$(SED) -i'' -e '/creationTimestamp: null/d' chart/templates/manager-role_clusterrole.yaml
$(SED) -i'' -e 's/name: manager-role/name: {{ include "common.names.fullname" . }}-manager-role/' chart/templates/manager-role_clusterrole.yaml
$(SED) -i'' -e 's/apiVersion: rbac.authorization.k8s.io\/v1/apiVersion: {{ include "common.capabilities.rbac.apiVersion" . }}/' chart/templates/manager-role_clusterrole.yaml
Expand Down Expand Up @@ -230,13 +234,13 @@ $(CONTROLLER_GEN): $(LOCALBIN)
.PHONY: envtest
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
$(ENVTEST): $(LOCALBIN)
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
@test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest

.PHONY: bundle
bundle: manifests kustomize ## Generate bundle manifests and metadata, then validate generated files.
operator-sdk generate kustomize manifests -q
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle $(BUNDLE_GEN_FLAGS)
cd src/config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
$(KUSTOMIZE) build src/config/manifests | operator-sdk generate bundle $(BUNDLE_GEN_FLAGS)
operator-sdk bundle validate ./bundle

.PHONY: bundle-build
Expand Down
2 changes: 1 addition & 1 deletion chart/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ version: 1.5.6
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "v1.5.5"
appVersion: "v1.5.6"
dependencies:
- name: common
repository: https://charts.bitnami.com/bitnami
Expand Down
2 changes: 1 addition & 1 deletion chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

image:
repository: docker.io/uffizzi/uffizzi-cluster-operator
tag: v1.5.5
tag: v1.5.6
# `flux` dependency values
flux:
helmController:
Expand Down
Loading

0 comments on commit 67ec5e9

Please sign in to comment.