-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Github workflow and helper scripts to build, deploy and test. (#11)
Initial workflow to test PRs that builds the operator, deploys it and runs a basic test on it. Created scripts/ci folder with some helper bash scripts to build (build.sh), install the operator in a kind cluster (deploy.sh) and run a basic smoke test (smoke_test.sh). The smoke test applies the sample resources in config/samples, patching the existing kustomization.yaml to include the yamls in config/samples/extra (configMap and secret). Both the controller's container image and the sidecar app image are injected by means of kustomization patches + env vars. The sidecar image is now set using the corresponding env var SIDECAR_APP_IMG from the controller's container manifest.
- Loading branch information
Showing
15 changed files
with
295 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/bin/bash | ||
# | ||
# Builds the operator's controller and sidecar images. The manager's env var | ||
# with the sidecar app image is also replaced with the new name, which is set | ||
# using the value from env var SIDECAR_IMG. It will be defaulted to DEFAULT_SIDECAR_IMG | ||
# if that env var is not found. | ||
# | ||
# This script is intended to be used in CI workflows to create loca/test images just for | ||
# testing purposes, but can also be used to generate images for new official releases. In | ||
# that case, the following env vars should have been exported before running this script: | ||
# VERSION : The desired new/test version tag that will be applied to both images. | ||
# IMG : The image for the controller's container. | ||
# | ||
|
||
# Bash settings: display (expanded) commands and fast exit on first error. | ||
set -o xtrace | ||
set -o errexit | ||
|
||
DEFAULT_TEST_VERSION="0.0.1-test" | ||
DEFAULT_SIDECAR_IMG="local-test-sidecar-image:v$DEFAULT_TEST_VERSION" | ||
DEFAULT_IMG="ci-cnf-op:v$DEFAULT_TEST_VERSION" | ||
|
||
export VERSION="${VERSION:-$DEFAULT_TEST_VERSION}" | ||
export SIDECAR_IMG="${SIDECAR_IMG:-$DEFAULT_SIDECAR_IMG}" | ||
export IMG="${IMG:-$DEFAULT_IMG}" | ||
|
||
# step: Build manifests and controller app | ||
make build | ||
|
||
# step: Run tests | ||
make test | ||
|
||
# step: Build sidecar app | ||
docker build --no-cache -t "${SIDECAR_IMG}" -f cnf-cert-sidecar/Dockerfile . | ||
|
||
# Local install kustomize app that is needed to edit/patch the kustomization.yaml | ||
make kustomize | ||
|
||
# step: Add env var to the controller's container to set the sidecar image app that was built right before | ||
pushd config/manager | ||
../../bin/kustomize edit add patch --kind Deployment --patch "[{\"op\": \"replace\", \"path\": \"/spec/template/spec/containers/0/env/1\", \"value\": {\"name\": \"SIDECAR_APP_IMG\", \"value\": \"${SIDECAR_IMG}\"} }]" | ||
popd | ||
|
||
# step: Build docker image for the controller. This will use IMG pointing to local docker image for the controller, which | ||
# will be pushed to kind with "docker load docker-image $IMG" | ||
make docker-build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/bin/bash | ||
# | ||
# This script deploys a recently built operator in a kind cluster. | ||
# Both the operator's controller and the sidecar app images are | ||
# preloaded into the kind cluster's nodes to avoid the need of | ||
# uploading the images to an external registry (quay/docker). | ||
# | ||
# The operator is deployed in the namespace set by env var CNF_CERTSUITE_OPERATOR_NAMESPACE | ||
# or in the defaulted namespace "cnf-certsuite-operator" if that env var is not found. | ||
# | ||
|
||
# Bash settings: display (expanded) commands and fast exit on first error. | ||
set -o xtrace | ||
set -o errexit | ||
|
||
DEFAULT_CNF_CERTSUITE_OPERATOR_NAMESPACE="cnf-certsuite-operator" | ||
DEFAULT_TEST_VERSION="0.0.1-test" | ||
DEFAULT_SIDECAR_IMG="local-test-sidecar-image:v$DEFAULT_TEST_VERSION" | ||
DEFAULT_IMG="ci-cnf-op:v$DEFAULT_TEST_VERSION" | ||
|
||
CNF_CERTSUITE_OPERATOR_NAMESPACE=${CNF_CERTSUITE_OPERATOR_NAMESPACE:-$DEFAULT_CNF_CERTSUITE_OPERATOR_NAMESPACE} | ||
|
||
export VERSION="${VERSION:-$DEFAULT_TEST_VERSION}" | ||
export SIDECAR_IMG="${SIDECAR_IMG:-$DEFAULT_SIDECAR_IMG}" | ||
export IMG="${IMG:-$DEFAULT_IMG}" | ||
|
||
kind load docker-image "${SIDECAR_IMG}" | ||
kind load docker-image "${IMG}" | ||
|
||
# "make deploy" uses the IMG env var internally, and it needs to be exported. | ||
# let's patch the installation namespace. | ||
make kustomize | ||
|
||
pushd config/default | ||
../../bin/kustomize edit set namespace "${CNF_CERTSUITE_OPERATOR_NAMESPACE}" | ||
popd | ||
|
||
make deploy | ||
|
||
# step: Wait for the controller's containers to be ready | ||
oc wait --for=condition=ready pod --all=true -n cnf-certsuite-operator --timeout=2m |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/bin/bash | ||
# | ||
# WARNING: This is a helper script to be run with the "timeout" command, like: | ||
# $ timeout 60s $0 pod mypodname mynamespace | ||
# | ||
# Polls the cluster with "oc get ..." every N secs and returns with 0 status | ||
# code as soon as the given resource by name is found in a given namespace. | ||
# In case the resource is not found or there's any problem with "oc get", the | ||
# script will never return, as it's polling every N secs, no matter the type of | ||
# error was returned. | ||
# | ||
# $1 resource kind, e.g. pod, deployment... | ||
# $2 name | ||
# $3 namespace | ||
# $4 check interval time (optional, defaults to 5 segs) | ||
# | ||
# Examples: | ||
# $0 pod mypodname mypodnamespace | ||
|
||
DEFAULT_INTERVAL_CHECK_SEGS=5 | ||
INTERVAL_CHECK_SEGS=${DEFAULT_INTERVAL_CHECK_SEGS} | ||
|
||
RESOURCE_KIND=$1 | ||
RESOURCE_NAME=$2 | ||
NAMESPACE=$3 | ||
|
||
if [ "$4" != "" ] ; then | ||
INTERVAL_CHECK_SEGS=$4 | ||
fi | ||
|
||
echo "Polling every ${INTERVAL_CHECK_SEGS} secs for ${RESOURCE_NAME} (kind: ${RESOURCE_KIND}) to exist in namespace ${NAMESPACE}" | ||
|
||
while true; do | ||
if oc get "${RESOURCE_KIND}" -n "${NAMESPACE}" "${RESOURCE_NAME}" ; then | ||
echo "${RESOURCE_NAME} (kind: ${RESOURCE_KIND}) found in namespace ${NAMESPACE}." | ||
exit 0 | ||
fi | ||
|
||
echo "${RESOURCE_NAME} (kind: ${RESOURCE_KIND}) not found yet in namespace ${NAMESPACE}..." | ||
sleep "${INTERVAL_CHECK_SEGS}" | ||
done |
Oops, something went wrong.