Skip to content

Commit

Permalink
Running e2e with operator image and RBAC instead of local (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardozanini authored May 15, 2020
1 parent b5495de commit 0e400f0
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 31 deletions.
17 changes: 15 additions & 2 deletions .github/workflows/nexus-operator-integration-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
name: Operator OLM Tests
runs-on: ubuntu-latest
env:
NAMESPACE_TEST: operator-test
CLUSTER_NAME: operator-test
steps:
- name: Check out code
uses: actions/checkout@v2
Expand Down Expand Up @@ -101,7 +101,8 @@ jobs:
env:
CREATE_NAMESPACE: false
NAMESPACE_E2E: default
NAMESPACE_TEST: nexus-e2e
CLUSTER_NAME: nexus-e2e
CUSTOM_IMAGE_TAG: "nexus-operator:temp"
steps:
- name: Check out code
uses: actions/checkout@v2
Expand All @@ -127,6 +128,13 @@ jobs:
./hack/ci/install-operator-sdk.sh
echo "::add-path::$GITHUB_WORKSPACE/bin"
- name: Build Operator Image
env:
BUILDER: docker
CUSTOM_BASE_IMAGE: alpine:latest
run: |
./hack/go-build.sh
- name: Cacke KIND Binary
uses: actions/cache@v1
with:
Expand All @@ -143,5 +151,10 @@ jobs:
- name: Start KIND
run: ./hack/ci/start-kind.sh

- name: Load Operator Image
run: ./hack/ci/load-operator-image.sh

- name: Run e2e test
env:
RUN_WITH_IMAGE: true
run: ./hack/run-e2e-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@
# You should have received a copy of the GNU General Public License
# along with Nexus Operator. If not, see <https://www.gnu.org/licenses/>.

source ./hack/ci/operator-ensure-manifest.sh
echo "---> Loading Operator Image into Kind"
kind load docker-image ${CUSTOM_IMAGE_TAG} --name ${CLUSTER_NAME}

OPERATOR_TESTING_IMAGE="quay.io/operator-framework/operator-testing:latest"
OP_PATH="community-operators/nexus-operator-m88i"

docker pull ${OPERATOR_TESTING_IMAGE}
docker run --rm -v ${OUTPUT}:/community-operators:z ${OPERATOR_TESTING_IMAGE} operator.verify --no-print-directory OP_PATH=${OP_PATH} VERBOSE=true
node_name=$(kubectl get nodes -o jsonpath="{.items[0].metadata.name}")
echo "---> Checking internal loaded images on node ${node_name}"
docker exec ${node_name} crictl images
2 changes: 1 addition & 1 deletion hack/ci/operator-olm-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fi
echo "---> Building temporary catalog Image"
docker build --build-arg PERMISSIVE_LOAD=false -f ./hack/ci/operatorhubio-catalog.Dockerfile -t ${CATALOG_IMAGE} .
echo "---> Loading Catalog Image into Kind"
kind load docker-image ${CATALOG_IMAGE} --name operator-test
kind load docker-image ${CATALOG_IMAGE} --name ${CLUSTER_NAME}

# running tests
docker pull ${OPERATOR_TESTING_IMAGE}
Expand Down
10 changes: 7 additions & 3 deletions hack/ci/start-kind.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ else
KIND_VERBOSITY="--verbosity 0"
fi

if [[ ! "$(./bin/kind get clusters)" =~ "${NAMESPACE_TEST}" ]]; then
./bin/kind create cluster --name ${NAMESPACE_TEST} --wait 1m ${KIND_KUBE_VERSION} ${KIND_VERBOSITY}
if [[ ! "$(./bin/kind get clusters)" =~ "${CLUSTER_NAME}" ]]; then
./bin/kind create cluster --name ${CLUSTER_NAME} --wait 1m ${KIND_KUBE_VERSION} ${KIND_VERBOSITY}
else
echo "Already found cluster named '${NAMESPACE_TEST}'"
echo "---> Already found cluster named '${CLUSTER_NAME}'"
fi

echo "---> Checking KIND cluster conditions"
kubectl get nodes -o wide
kubectl get pods --all-namespaces -o wide
32 changes: 18 additions & 14 deletions hack/go-build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
# Copyright 2019 Nexus Operator and/or its authors
#
# This file is part of Nexus Operator.
Expand All @@ -16,26 +16,30 @@
# You should have received a copy of the GNU General Public License
# along with Nexus Operator. If not, see <https://www.gnu.org/licenses/>.

# CUSTOM_IMAGE_TAG: name of the operator tag. set this var to change the default name of the image being built. Default to quay.io/m88i/nexus-operator:current-version
# BUILDER: builder to build the image. either podman or docker. default to podman

. ./hack/go-mod-env.sh

# include
source ./hack/go-mod-env.sh
source ./hack/export-version.sh

REPO=https://github.com/m88i/nexus-operator
BRANCH=master
REGISTRY=quay.io/m88i
IMAGE=nexus-operator
TAG=${OP_VERSION}
TAR=${BRANCH}.tar.gz
URL=${REPO}/archive/${TAR}
CFLAGS=""
DEFAULT_BASE_IMAGE=registry.redhat.io/ubi8/ubi-minimal:latest

setGoModEnv
go generate ./...
if [[ -z ${CI} ]]; then
./hack/go-test.sh
# changed to podman, see: https://www.linuxuprising.com/2019/11/how-to-install-and-use-docker-on-fedora.html
operator-sdk build ${REGISTRY}/${IMAGE}:${TAG} --image-builder podman
else
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -mod=vendor -v -a -o build/_output/bin/nexus-operator github.com/m88i/nexus-operator/cmd/manager

if [[ ! -z ${CUSTOM_BASE_IMAGE} ]]; then
sed -i -e 's,'"${DEFAULT_BASE_IMAGE}"','"${CUSTOM_BASE_IMAGE}"',' ./build/Dockerfile
fi
if [[ -z ${CUSTOM_IMAGE_TAG} ]]; then
CUSTOM_IMAGE_TAG=${REGISTRY}/${IMAGE}:${TAG}
fi
if [[ -z ${BUILDER} ]]; then
BUILDER=podman
fi

# changed to podman, see: https://www.linuxuprising.com/2019/11/how-to-install-and-use-docker-on-fedora.html
operator-sdk build ${CUSTOM_IMAGE_TAG} --image-builder ${BUILDER}
Empty file modified hack/go-mod-env.sh
100644 → 100755
Empty file.
21 changes: 16 additions & 5 deletions hack/run-e2e-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,29 @@ if [[ -z ${NAMESPACE_E2E} ]]; then
fi

if [[ ${CREATE_NAMESPACE^^} == "TRUE" ]]; then
echo "Creating Namespace ${NAMESPACE_E2E} to run e2e tests"
echo "---> Creating Namespace ${NAMESPACE_E2E} to run e2e tests"
kubectl create namespace $NAMESPACE_E2E
else
echo "Skipping creating namespace"
echo "---> Skipping creating namespace"
fi

echo "---> Executing e2e tests on ${NAMESPACE_E2E}"

if [[ ${RUN_WITH_IMAGE^^} == "TRUE" ]]; then
echo "---> Running tests with image ${CUSTOM_IMAGE_TAG}"
# see: https://kind.sigs.k8s.io/docs/user/quick-start/#loading-an-image-into-your-cluster
echo "---> Updating deployment file to imagePullPolicy: Never"
sed -i 's/imagePullPolicy: Always/imagePullPolicy: Never/g' ./deploy/operator.yaml
operator-sdk test local ./test/e2e --go-test-flags "-v" --debug --image ${CUSTOM_IMAGE_TAG} --operator-namespace $NAMESPACE_E2E
else
echo "---> Running tests with local binary"
operator-sdk test local ./test/e2e --go-test-flags "-v" --debug --up-local --operator-namespace $NAMESPACE_E2E
fi

echo "Executing e2e tests on ${NAMESPACE_E2E}"
operator-sdk test local ./test/e2e --go-test-flags "-v" --debug --up-local --operator-namespace $NAMESPACE_E2E
test_exit_code=$?

if [[ ${CREATE_NAMESPACE^^} == "TRUE" ]]; then
echo "Cleaning up namespace ${NAMESPACE_E2E}"
echo "---> Cleaning up namespace ${NAMESPACE_E2E}"
kubectl delete namespace $NAMESPACE_E2E
fi

Expand Down

0 comments on commit 0e400f0

Please sign in to comment.