Skip to content

Commit

Permalink
RABSW-985: Prefix webhook resource names for unit tests (#33)
Browse files Browse the repository at this point in the history
* RABSW-985: Prefix webhook resource names for unit tests

This commit fixes an issue where the DWS workflow validation webhook was
colliding with the NNF storage profile validation webhook. This was because
the ValidatingWebhookConfiguration resource generated by the controller-gen
tool has the same name between the projects.

I added a script to prefix the names of the ValidatingWebhookConfiguration
and Service resource with "nnf-". The script makes a copy of the original
yaml files and passes the new location to the test code through an environment
variable.

Signed-off-by: Matt Richerson <[email protected]>

* move export

Signed-off-by: Matt Richerson <[email protected]>

Co-authored-by: Matt Richerson <[email protected]>
  • Loading branch information
matthew-richerson and Matt Richerson authored Jul 19, 2022
1 parent 716ffd5 commit 10352d2
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ WORKDIR /workspace

ARG FAILFAST
COPY hack/ hack/
COPY test-tools.sh .
COPY initiateContainerTest.sh .
COPY Makefile .

Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ FAILFAST ?= no
test: manifests generate fmt vet ## Run tests.
find controllers -name "*.db" -type d -exec rm -rf {} +
mkdir -p ${ENVTEST_ASSETS_DIR}
source test-tools.sh; prefix_webhook_names config/webhook ${ENVTEST_ASSETS_DIR}/webhook

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
if [[ "${FAILFAST}" == yes ]]; then \
failfast="-ginkgo.failFast"; \
Expand All @@ -222,6 +224,7 @@ test: manifests generate fmt vet ## Run tests.
for subdir in ${TESTDIRS}; do \
export GOMEGA_DEFAULT_EVENTUALLY_TIMEOUT=${EVENTUALLY_TIMEOUT}; \
export GOMEGA_DEFAULT_EVENTUALLY_INTERVAL=${EVENTUALLY_INTERVAL}; \
export WEBHOOK_DIR=${ENVTEST_ASSETS_DIR}/webhook; \
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test -v ./$$subdir/... -coverprofile cover.out -args -ginkgo.v -ginkgo.progress $$failfast; \
done

Expand Down
2 changes: 1 addition & 1 deletion controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ var _ = BeforeSuite(func() {
WebhookInstallOptions: envtest.WebhookInstallOptions{Paths: []string{
filepath.Join("..", "vendor", "github.com", "HewlettPackard", "dws", "config", "webhook"),
filepath.Join("..", "config", "dws"),
filepath.Join("..", "config", "webhook"),
os.Getenv("WEBHOOK_DIR"),
}},
ErrorIfCRDPathMissing: true,
CRDDirectoryPaths: []string{
Expand Down
4 changes: 4 additions & 0 deletions initiateContainerTest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ echo "Running in $CWD, setting up envtest."
export ENVTEST_ASSETS_DIR=/nnf/testbin
export GOMEGA_DEFAULT_EVENTUALLY_TIMEOUT=20s
export GOMEGA_DEFAULT_EVENTUALLY_INTERVAL=100ms
export WEBHOOK_DIR=${ENVTEST_ASSETS_DIR}/webhook

source test-tools.sh; prefix_webhook_names config/webhook ${WEBHOOK_DIR}

mkdir -p ${ENVTEST_ASSETS_DIR}
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
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh
Expand Down
15 changes: 15 additions & 0 deletions test-tools.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

function prefix_webhook_names {
SOURCE_DIR=$1
DEST_DIR=$2

mkdir -p $DEST_DIR
cp $SOURCE_DIR/manifests.yaml $DEST_DIR
sed -i.bak -e 's/validating-webhook-configuration/nnf-validating-webhook-configuration/' $DEST_DIR/manifests.yaml
rm $DEST_DIR/manifests.yaml.bak

cp $SOURCE_DIR/service.yaml $DEST_DIR
sed -i.bak -e 's/webhook-service/nnf-webhook-service/' $DEST_DIR/service.yaml
rm $DEST_DIR/service.yaml.bak
}

0 comments on commit 10352d2

Please sign in to comment.