Skip to content

Commit

Permalink
Merge pull request #64 from jodevsa/subhi-it
Browse files Browse the repository at this point in the history
fix(tests): add integration test
  • Loading branch information
jodevsa committed May 19, 2023
2 parents 11f7ea4 + cc10ddd commit 8681a4d
Show file tree
Hide file tree
Showing 12 changed files with 428 additions and 121 deletions.
Binary file added .github/workflows/.DS_Store
Binary file not shown.
30 changes: 27 additions & 3 deletions .github/workflows/build-images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ on:
required: false
default: false
type: boolean
upload_images:
required: false
default: false
type: boolean
platforms:
description: 'Docker image platforms'
required: false
Expand Down Expand Up @@ -82,12 +86,32 @@ jobs:
with:
go-version: '^1.20'

- name: Build and push docker image
- name: Build and push docker images
if: ${{ inputs.push == true }}
uses: docker/build-push-action@v4
with:
context: .
file: images/${{ matrix.image }}/Dockerfile
platforms: ${{ inputs.platforms }}
push: true
tags: ${{ steps.image-meta.outputs.tags }}
labels: ${{ steps.image-meta.outputs.labels }}

- name: Build and upload docker image to job artifact
if: ${{ inputs.upload_images == true }}
uses: docker/build-push-action@v4
with:
context: .
file: images/${{ matrix.image }}/Dockerfile
platforms: ${{ inputs.platforms }}
push: ${{ inputs.push }}
outputs: type=docker,dest=/tmp/${{matrix.image}}.tar
push: false
tags: ${{ steps.image-meta.outputs.tags }}
labels: ${{ steps.image-meta.outputs.labels }}
labels: ${{ steps.image-meta.outputs.labels }}

- name: Upload artifact
if: ${{ inputs.upload_images == true }}
uses: actions/upload-artifact@v3
with:
name: images
path: /tmp/${{matrix.image}}.tar
4 changes: 2 additions & 2 deletions .github/workflows/manual-dev-release-workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ jobs:

- name: prepare new release
env:
MANAGER_IMAGE: ghcr.io/${{ inputs.repository }}/manager:${{ inputs.tag }}
AGENT_IMAGE: ghcr.io/${{ inputs.repository }}/agent:${{ inputs.tag }}
MANAGER_IMAGE: ghcr.io/${{ inputs.repository }}/manager:dev-${{ inputs.tag }}
AGENT_IMAGE: ghcr.io/${{ inputs.repository }}/agent:dev-${{ inputs.tag }}
run : |
make generate-release-file AGENT_IMAGE="$AGENT_IMAGE" MANAGER_IMAGE="$MANAGER_IMAGE"
- name: upload release
Expand Down
48 changes: 46 additions & 2 deletions .github/workflows/pull-request-workflow.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: build docker images
name: PR pipeline
on:
pull_request: {}

Expand All @@ -11,4 +11,48 @@ jobs:
uses: ./.github/workflows/build-images.yaml
with:
push: false
ref: ${{ github.ref }}
upload_images: true
platforms: "linux/amd64"
ref: ${{ github.ref }}
tag: dev

e2e:
runs-on: ubuntu-latest
needs: build-images
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Download artifact
uses: actions/download-artifact@v3
with:
name: images
path: /tmp

- name: Load image
run: |
docker load --input /tmp/agent.tar
docker load --input /tmp/manager.tar
docker image ls -a
- name: Checkout repository
uses: actions/checkout@v3
with:
repository: ${{ inputs.repository }}
ref: ${{ inputs.ref }}
submodules: true

- uses: actions/setup-go@v4
with:
go-version: '^1.20'

- uses: azure/setup-kubectl@v3

- name: run e2e
env:
REGISTRY: ghcr.io
AGENT_IMAGE: ghcr.io/${{ github.repository }}/agent:dev
MANAGER_IMAGE: ghcr.io/${{ github.repository }}/manager:dev
run: |
make kind
make run-e2e AGENT_IMAGE="$AGENT_IMAGE" MANAGER_IMAGE="$MANAGER_IMAGE"
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ testbin/*
*.swp
*.swo
*~


#
release_it.yaml
91 changes: 32 additions & 59 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,18 @@ $(LOCALBIN):
## Tool Binaries
KUSTOMIZE ?= $(LOCALBIN)/kustomize
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
KIND ?= $(LOCALBIN)/kind
ENVTEST ?= $(LOCALBIN)/setup-envtest

## Tool Versions
KUSTOMIZE_VERSION ?= v3.8.7
CONTROLLER_TOOLS_VERSION ?= v0.8.0
KIND_VERSION ?= v0.19.0


# images
AGENT_IMAGE ?= "agent:dev"
MANAGER_IMAGE ?= "manager:dev"

# CHANNELS define the bundle channels used in the bundle.
# Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable")
Expand Down Expand Up @@ -116,8 +123,26 @@ build-manager: generate fmt vet ## Build manager binary.
run: manifests generate fmt vet ## Run a controller from your host.
go run ./cmd/manager/main.go

docker-build: test ## Build docker image with the manager.
docker build -t ${IMG} .


docker-build-agent: ## Build docker image with the manager.
docker build -t ${AGENT_IMAGE} . -f ./images/agent/Dockerfile

docker-build-manager: ## Build docker image with the manager.
docker build -t ${MANAGER_IMAGE} . -f ./images/manager/Dockerfile

docker-build-integration-test: docker-build-manager
$(MAKE) docker-build-agent
$(MAKE) docker-build-manager


run-e2e:
AGENT_IMAGE=${AGENT_IMAGE} $(MAKE) update-agent-image
MANAGER_IMAGE=${MANAGER_IMAGE} $(MAKE) update-manager-image
$(KUSTOMIZE) build config/default > release_it.yaml
git checkout ./config/default/manager_auth_proxy_patch.yaml
git checkout ./config/manager/kustomization.yaml
KUBE_CONFIG=$(HOME)/.kube/config KIND_BIN=${KIND} WIREGUARD_OPERATOR_RELEASE_PATH="../../release_it.yaml" AGENT_IMAGE=${AGENT_IMAGE} MANAGER_IMAGE=${MANAGER_IMAGE} go test ./internal/it/ -v -count=1

docker-push: ## Push docker image with the manager.
docker push ${IMG}
Expand Down Expand Up @@ -156,6 +181,10 @@ controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessar
$(CONTROLLER_GEN): $(LOCALBIN)
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)

kind: $(KIND) ## Download kind locally if necessary.
$(KIND): $(LOCALBIN)
GOBIN=$(LOCALBIN) go install sigs.k8s.io/kind/cmd/kind@$(KIND_VERSION)

KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
Expand All @@ -165,60 +194,4 @@ $(KUSTOMIZE): $(LOCALBIN)
.PHONY: envtest
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
$(ENVTEST): $(LOCALBIN)
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 -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
operator-sdk bundle validate ./bundle

.PHONY: bundle-build
bundle-build: ## Build the bundle image.
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .

.PHONY: bundle-push
bundle-push: ## Push the bundle image.
$(MAKE) docker-push IMG=$(BUNDLE_IMG)

.PHONY: opm
OPM = ./bin/opm
opm: ## Download opm locally if necessary.
ifeq (,$(wildcard $(OPM)))
ifeq (,$(shell which opm 2>/dev/null))
@{ \
set -e ;\
mkdir -p $(dir $(OPM)) ;\
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.15.1/$${OS}-$${ARCH}-opm ;\
chmod +x $(OPM) ;\
}
else
OPM = $(shell which opm)
endif
endif

# A comma-separated list of bundle images (e.g. make catalog-build BUNDLE_IMGS=example.com/operator-bundle:v0.1.0,example.com/operator-bundle:v0.2.0).
# These images MUST exist in a registry and be pull-able.
BUNDLE_IMGS ?= $(BUNDLE_IMG)

# The image tag given to the resulting catalog image (e.g. make catalog-build CATALOG_IMG=example.com/operator-catalog:v0.2.0).
CATALOG_IMG ?= $(IMAGE_TAG_BASE)-catalog:v$(VERSION)

# Set CATALOG_BASE_IMG to an existing catalog image tag to add $BUNDLE_IMGS to that image.
ifneq ($(origin CATALOG_BASE_IMG), undefined)
FROM_INDEX_OPT := --from-index $(CATALOG_BASE_IMG)
endif

# Build a catalog image by adding bundle images to an empty catalog using the operator package manager tool, 'opm'.
# This recipe invokes 'opm' in 'semver' bundle add mode. For more information on add modes, see:
# https://github.com/operator-framework/community-operators/blob/7f1438c/docs/packaging-operator.md#updating-your-existing-operator
.PHONY: catalog-build
catalog-build: opm ## Build a catalog image.
$(OPM) index add --container-tool docker --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT)

# Push the catalog image.
.PHONY: catalog-push
catalog-push: ## Push a catalog image.
$(MAKE) docker-push IMG=$(CATALOG_IMG)
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ require (
github.com/imdario/mergo v0.3.12 // indirect
github.com/korylprince/ipnetgen v1.0.1
github.com/onsi/ginkgo v1.16.4
github.com/onsi/ginkgo/v2 v2.9.5
github.com/onsi/ginkgo/v2 v2.9.5 // indirect
github.com/onsi/gomega v1.27.6
github.com/vishvananda/netlink v1.1.0
golang.zx2c4.com/wireguard/wgctrl v0.0.0-20230429144221-925a1e7659e6
k8s.io/api v0.26.1
k8s.io/apimachinery v0.26.1
k8s.io/client-go v0.26.1
sigs.k8s.io/controller-runtime v0.14.6
sigs.k8s.io/kind v0.19.0
)
Loading

0 comments on commit 8681a4d

Please sign in to comment.