Skip to content

Commit 571a3a0

Browse files
committed
venconn: add integration tests using envtest
Note that I should probably have gone with a fake of the ConnectionHandler instead of an envtest. We will move to the fake later on. I added the venaficonnection CRDs manually for now. I have a PR to automate pulling these CRDs from the venafi-connection-lib project: #556 For now, I added these manifests manually with the following commands: gh pr checkout 556 git checkout - git checkout step1-makefile-modules -- deploy/charts/venafi-kubernetes-agent/templates/venafi-connection-crd{,.without-validations}.yaml
1 parent 7c91430 commit 571a3a0

File tree

7 files changed

+2339
-1
lines changed

7 files changed

+2339
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ predicate.json
1313
*.pub
1414
*.tgz
1515

16+
_bin

Makefile

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ build:
4848
install:
4949
cd $(ROOT_DIR) && $(GO_INSTALL)
5050

51+
export KUBEBUILDER_ASSETS=$(ROOT_DIR)/_bin/tools
52+
test: _bin/tools/etcd _bin/tools/kube-apiserver
5153
test:
5254
cd $(ROOT_DIR) && go test ./...
5355

@@ -142,3 +144,54 @@ ci-build: ci-test build build-docker-image build-all-platforms bundle-all-platfo
142144

143145
ci-publish: ci-build push-docker-image
144146
echo "ci-publish is going to be disabled. We are adopting Github actions"
147+
148+
# NOTE(mael): The download targets for yq, etcd, and kube-apiserver are a lesser
149+
# and suboptimal version of what's in venafi-enhanced-issuer. We will migrate to
150+
# makefile-modules and klone soon, so I didn't want to work too hard on this.
151+
152+
YQ_linux_amd64_SHA256SUM=bd695a6513f1196aeda17b174a15e9c351843fb1cef5f9be0af170f2dd744f08
153+
YQ_darwin_amd64_SHA256SUM=b2ff70e295d02695b284755b2a41bd889cfb37454e1fa71abc3a6ec13b2676cf
154+
YQ_darwin_arm64_SHA256SUM=e9fc15db977875de982e0174ba5dc2cf5ae4a644e18432a4262c96d4439b1686
155+
YQ_VERSION=v4.35.1
156+
157+
_bin/downloaded/tools/yq@$(YQ_VERSION)_%:
158+
mkdir -p _bin/downloaded/tools
159+
curl -L https://github.com/mikefarah/yq/releases/download/$(YQ_VERSION)/yq_$* -o $@
160+
./make/util/checkhash.sh $@ $(YQ_$*_SHA256SUM)
161+
chmod +x $@
162+
163+
HOST_OS=$(shell uname | tr '[:upper:]' '[:lower:]')
164+
HOST_ARCH=$(shell uname -m | sed 's/x86_64/amd64/')
165+
166+
_bin/tools/yq: _bin/downloaded/tools/yq@$(YQ_VERSION)_$(HOST_OS)_$(HOST_ARCH)
167+
@mkdir -p _bin/tools
168+
@cd $(dir $@) && ln -sf $(patsubst _bin/%,../%,$<) $(notdir $@)
169+
170+
KUBEBUILDER_TOOLS_linux_amd64_SHA256SUM=f9699df7b021f71a1ab55329b36b48a798e6ae3a44d2132255fc7e46c6790d4d
171+
KUBEBUILDER_TOOLS_darwin_amd64_SHA256SUM=e1913674bacaa70c067e15649237e1f67d891ba53f367c0a50786b4a274ee047
172+
KUBEBUILDER_TOOLS_darwin_arm64_SHA256SUM=0422632a2bbb0d4d14d7d8b0f05497a4d041c11d770a07b7a55c44bcc5e8ce66
173+
KUBEBUILDER_ASSETS_VERSION=1.27.1
174+
175+
_bin/downloaded/tools/etcd@$(KUBEBUILDER_ASSETS_VERSION)_%: _bin/downloaded/tools/kubebuilder_tools_$(KUBEBUILDER_ASSETS_VERSION)_%.tar.gz | _bin/downloaded/tools
176+
./make/util/checkhash.sh $< $(KUBEBUILDER_TOOLS_$*_SHA256SUM)
177+
@# O writes the specified file to stdout
178+
tar xfO $< kubebuilder/bin/etcd > $@ && chmod 775 $@
179+
180+
_bin/downloaded/tools/kube-apiserver@$(KUBEBUILDER_ASSETS_VERSION)_%: _bin/downloaded/tools/kubebuilder_tools_$(KUBEBUILDER_ASSETS_VERSION)_%.tar.gz | _bin/downloaded/tools
181+
./make/util/checkhash.sh $< $(KUBEBUILDER_TOOLS_$*_SHA256SUM)
182+
@# O writes the specified file to stdout
183+
tar xfO $< kubebuilder/bin/kube-apiserver > $@ && chmod 775 $@
184+
185+
_bin/downloaded/tools/kubebuilder_tools_$(KUBEBUILDER_ASSETS_VERSION)_$(HOST_OS)_$(HOST_ARCH).tar.gz: | _bin/downloaded/tools
186+
curl -L https://storage.googleapis.com/kubebuilder-tools/kubebuilder-tools-$(KUBEBUILDER_ASSETS_VERSION)-$(HOST_OS)-$(HOST_ARCH).tar.gz -o $@
187+
188+
_bin/downloaded/tools:
189+
@mkdir -p $@
190+
191+
_bin/tools/etcd: _bin/downloaded/tools/etcd@$(KUBEBUILDER_ASSETS_VERSION)_$(HOST_OS)_$(HOST_ARCH)
192+
@mkdir -p _bin/tools
193+
@cd $(dir $@) && ln -sf $(patsubst _bin/%,../%,$<) $(notdir $@)
194+
195+
_bin/tools/kube-apiserver: _bin/downloaded/tools/kube-apiserver@$(KUBEBUILDER_ASSETS_VERSION)_$(HOST_OS)_$(HOST_ARCH)
196+
@mkdir -p _bin/tools
197+
@cd $(dir $@) && ln -sf $(patsubst _bin/%,../%,$<) $(notdir $@)

deploy/charts/venafi-kubernetes-agent/templates/venafi-connection-crd.without-validations.yaml

Lines changed: 1116 additions & 0 deletions
Large diffs are not rendered by default.

deploy/charts/venafi-kubernetes-agent/templates/venafi-connection-crd.yaml

Lines changed: 1140 additions & 0 deletions
Large diffs are not rendered by default.

make/util/checkhash.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
3+
set -eu -o pipefail
4+
5+
# This script takes the hash of its first argument and verifies it against the
6+
# hex hash given in its second argument
7+
8+
SHASUM=$(./make/util/hash.sh "$1")
9+
10+
# When running 'make learn-sha-tools', we don't want this script to fail.
11+
# Instead we log what sha values are wrong, so the make.mk file can be updated.
12+
if [ "$SHASUM" != "$2" ] && [ "${LEARN_FILE:-}" != "" ]; then
13+
echo "s/$2/$SHASUM/g" >> "${LEARN_FILE:-}"
14+
exit 0
15+
fi
16+
17+
if [ "$SHASUM" != "$2" ]; then
18+
echo "invalid checksum for \"$1\": wanted \"$2\" but got \"$SHASUM\""
19+
exit 1
20+
fi

make/util/hash.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
3+
set -eu -o pipefail
4+
5+
# This script is a wrapper for outputting purely the sha256 hash of the input file,
6+
# ideally in a portable way.
7+
8+
sha256sum "$1" | cut -d" " -f1

pkg/client/client_venconn_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ func fakeTPP(t testing.TB) (*httptest.Server, *x509.Certificate) {
268268
func startEnvtest(t testing.TB) (_ *envtest.Environment, _ *rest.Config, kclient ctrlruntime.WithWatch) {
269269
envtest := &envtest.Environment{
270270
ErrorIfCRDPathMissing: true,
271-
CRDDirectoryPaths: []string{"/tmp/venafi-connection.yaml"},
271+
CRDDirectoryPaths: []string{"../../deploy/charts/venafi-kubernetes-agent/crd_bases/jetstack.io_venaficonnections.yaml"},
272272
}
273273
restconf, err := envtest.Start()
274274
require.NoError(t, err)

0 commit comments

Comments
 (0)