Skip to content

Commit a56009e

Browse files
authored
Merge pull request #289 from justinsb/fix_kubectl_version
tests: run with a known version of kubectl
2 parents 232a997 + 59f1e09 commit a56009e

File tree

7 files changed

+60
-13
lines changed

7 files changed

+60
-13
lines changed

bin/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
kubectl

dev/update-golden

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
# CI script to run tests in the mode where they write the golden output files
4+
set -o errexit
5+
set -o nounset
6+
set -o pipefail
7+
8+
# cd to the repo root
9+
REPO_ROOT=$(git rev-parse --show-toplevel)
10+
cd "${REPO_ROOT}"
11+
12+
# Ensure we run with a known version of kubectl
13+
if [[ ! -f "bin/kubectl" ]]; then
14+
echo "Downloading kubectl to bin/kubectl"
15+
mkdir -p bin/
16+
curl -L -o bin/kubectl https://dl.k8s.io/release/v1.26.0/bin/linux/amd64/kubectl
17+
fi
18+
chmod +x bin/kubectl
19+
export PATH="${REPO_ROOT}/bin:$PATH"
20+
echo "kubectl version is $(kubectl version --client)"
21+
22+
WRITE_GOLDEN_OUTPUT=1 go test -count=1 -v ./...

hack/ci/test.sh

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,22 @@ REPO_ROOT=$(dirname "${BASH_SOURCE}")/../..
2424
source "${CI_ROOT}/fetch_kubebuilder_release_bin.sh"
2525

2626
cd "${REPO_ROOT}"
27+
# Make sure REPO_ROOT is an absolute path
28+
REPO_ROOT=$(pwd)
29+
30+
# Ensure we run with a known version of kubectl
31+
if [[ ! -f "bin/kubectl" ]]; then
32+
echo "Downloading kubectl to bin/kubectl"
33+
mkdir -p bin/
34+
curl -L -o bin/kubectl https://dl.k8s.io/release/v1.26.0/bin/linux/amd64/kubectl
35+
fi
36+
chmod +x bin/kubectl
37+
export PATH="${REPO_ROOT}/bin:$PATH"
38+
echo "kubectl version is $(kubectl version --client)"
2739

2840
export GO111MODULE=on
2941

30-
go test sigs.k8s.io/kubebuilder-declarative-pattern/pkg/...
42+
go test -v -count=1 sigs.k8s.io/kubebuilder-declarative-pattern/pkg/...
3143

3244
cd examples/guestbook-operator
3345
go test sigs.k8s.io/kubebuilder-declarative-pattern/examples/guestbook-operator/controllers/...

pkg/patterns/declarative/pkg/applier/exec_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,18 @@ metadata:
144144
}
145145

146146
func TestKubectlApplier(t *testing.T) {
147+
kubectlPath, err := exec.LookPath("kubectl")
148+
if err != nil {
149+
t.Fatalf("failed to find kubectl on path: %v", err)
150+
}
151+
t.Logf("kubectl found at %q", kubectlPath)
152+
153+
kubectlVersion, err := exec.Command("kubectl", "version", "--client").CombinedOutput()
154+
if err != nil {
155+
t.Fatalf("failed to run kubectl version: %v", err)
156+
}
157+
t.Logf("kubectl version is %q", kubectlVersion)
158+
147159
applier := NewExec()
148160
runApplierGoldenTests(t, "testdata/kubectl", true, applier)
149161
}

pkg/patterns/declarative/pkg/applier/testdata/kubectl/simple1/expected-apiserver.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Kubectl-Command: kubectl apply
99
---
1010

1111
GET /api?timeout=32s
12-
Accept: application/json, */*
12+
Accept: application/json;g=apidiscovery.k8s.io;v=v2beta1;as=APIGroupDiscoveryList,application/json
1313
Accept-Encoding: gzip
1414
Kubectl-Command: kubectl apply
1515

@@ -28,8 +28,8 @@ Kubectl-Command: kubectl apply
2828

2929
---
3030

31-
GET /api/v1?timeout=32s
32-
Accept: application/json, */*
31+
GET /apis?timeout=32s
32+
Accept: application/json;g=apidiscovery.k8s.io;v=v2beta1;as=APIGroupDiscoveryList,application/json
3333
Accept-Encoding: gzip
3434
Kubectl-Command: kubectl apply
3535

@@ -38,7 +38,7 @@ Kubectl-Command: kubectl apply
3838

3939
---
4040

41-
GET /apis?timeout=32s
41+
GET /apis/v1?timeout=32s
4242
Accept: application/json, */*
4343
Accept-Encoding: gzip
4444
Kubectl-Command: kubectl apply

pkg/patterns/declarative/pkg/applier/testdata/kubectl/simple2/expected-apiserver.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Kubectl-Command: kubectl apply
99
---
1010

1111
GET /api?timeout=32s
12-
Accept: application/json, */*
12+
Accept: application/json;g=apidiscovery.k8s.io;v=v2beta1;as=APIGroupDiscoveryList,application/json
1313
Accept-Encoding: gzip
1414
Kubectl-Command: kubectl apply
1515

@@ -28,8 +28,8 @@ Kubectl-Command: kubectl apply
2828

2929
---
3030

31-
GET /api/v1?timeout=32s
32-
Accept: application/json, */*
31+
GET /apis?timeout=32s
32+
Accept: application/json;g=apidiscovery.k8s.io;v=v2beta1;as=APIGroupDiscoveryList,application/json
3333
Accept-Encoding: gzip
3434
Kubectl-Command: kubectl apply
3535

@@ -38,7 +38,7 @@ Kubectl-Command: kubectl apply
3838

3939
---
4040

41-
GET /apis?timeout=32s
41+
GET /apis/v1?timeout=32s
4242
Accept: application/json, */*
4343
Accept-Encoding: gzip
4444
Kubectl-Command: kubectl apply

pkg/patterns/declarative/pkg/applier/testdata/kubectl/simple3/expected-apiserver.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Kubectl-Command: kubectl apply
99
---
1010

1111
GET /api?timeout=32s
12-
Accept: application/json, */*
12+
Accept: application/json;g=apidiscovery.k8s.io;v=v2beta1;as=APIGroupDiscoveryList,application/json
1313
Accept-Encoding: gzip
1414
Kubectl-Command: kubectl apply
1515

@@ -28,8 +28,8 @@ Kubectl-Command: kubectl apply
2828

2929
---
3030

31-
GET /api/v1?timeout=32s
32-
Accept: application/json, */*
31+
GET /apis?timeout=32s
32+
Accept: application/json;g=apidiscovery.k8s.io;v=v2beta1;as=APIGroupDiscoveryList,application/json
3333
Accept-Encoding: gzip
3434
Kubectl-Command: kubectl apply
3535

@@ -38,7 +38,7 @@ Kubectl-Command: kubectl apply
3838

3939
---
4040

41-
GET /apis?timeout=32s
41+
GET /apis/v1?timeout=32s
4242
Accept: application/json, */*
4343
Accept-Encoding: gzip
4444
Kubectl-Command: kubectl apply

0 commit comments

Comments
 (0)