Skip to content

Commit 013d9c8

Browse files
Bumping envtest to 1.24 (#5835)
* bumped envtest to 1.24 * 1.24.1 * new kind version Signed-off-by: Venkat Ramaraju <[email protected]> * update e2e tests per k8s 1.24 changes * fix helm & ansible e2e * add license header to sa_secret.go Signed-off-by: Bryce Palmer <[email protected]> Co-authored-by: Bryce Palmer <[email protected]>
1 parent b093949 commit 013d9c8

File tree

5 files changed

+81
-14
lines changed

5 files changed

+81
-14
lines changed

Makefile

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ export IMAGE_VERSION = v1.21.0
99
export SIMPLE_VERSION = $(shell (test "$(shell git describe --tags)" = "$(shell git describe --tags --abbrev=0)" && echo $(shell git describe --tags)) || echo $(shell git describe --tags --abbrev=0)+git)
1010
export GIT_VERSION = $(shell git describe --dirty --tags --always)
1111
export GIT_COMMIT = $(shell git rev-parse HEAD)
12-
export K8S_VERSION = 1.23
13-
# TODO: bump this to 1.21, after kubectl `--generator` flag is removed from e2e tests.
14-
export ENVTEST_K8S_VERSION = 1.23.1
12+
export K8S_VERSION = 1.24.1
1513

1614
# Build settings
1715
export TOOLS_DIR = tools/bin
@@ -155,21 +153,21 @@ e2e_targets := test-e2e $(e2e_tests)
155153
.PHONY: test-e2e-setup
156154
export KIND_CLUSTER := osdk-test
157155

158-
KUBEBUILDER_ASSETS = $(PWD)/$(shell go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest && $(shell go env GOPATH)/bin/setup-envtest use $(ENVTEST_K8S_VERSION) --bin-dir tools/bin/ -p path)
156+
KUBEBUILDER_ASSETS = $(PWD)/$(shell go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest && $(shell go env GOPATH)/bin/setup-envtest use $(K8S_VERSION) --bin-dir tools/bin/ -p path)
159157
test-e2e-setup:: build dev-install cluster-create
160158

161159
.PHONY: cluster-create
162160
cluster-create::
163-
[[ "`$(TOOLS_DIR)/kind get clusters`" =~ "$(KIND_CLUSTER)" ]] || $(TOOLS_DIR)/kind create cluster --image="kindest/node:v$(ENVTEST_K8S_VERSION)" --name $(KIND_CLUSTER)
161+
[[ "`$(TOOLS_DIR)/kind get clusters`" =~ "$(KIND_CLUSTER)" ]] || $(TOOLS_DIR)/kind create cluster --image="kindest/node:v$(K8S_VERSION)" --name $(KIND_CLUSTER)
164162

165163
.PHONY: dev-install
166164
dev-install::
167-
$(SCRIPTS_DIR)/fetch kind 0.11.0
168-
$(SCRIPTS_DIR)/fetch kubectl $(ENVTEST_K8S_VERSION) # Install kubectl AFTER envtest because envtest includes its own kubectl binary
165+
$(SCRIPTS_DIR)/fetch kind 0.14.0
166+
$(SCRIPTS_DIR)/fetch kubectl $(K8S_VERSION) # Install kubectl AFTER envtest because envtest includes its own kubectl binary
169167

170168
.PHONY: test-e2e-teardown
171169
test-e2e-teardown:
172-
$(SCRIPTS_DIR)/fetch kind 0.11.0
170+
$(SCRIPTS_DIR)/fetch kind 0.14.0
173171
$(TOOLS_DIR)/kind delete cluster --name $(KIND_CLUSTER)
174172
rm -f $(KUBECONFIG)
175173

test/common/sa_secret.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2022 The Operator-SDK Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package common
16+
17+
import (
18+
"fmt"
19+
"os"
20+
)
21+
22+
var saSecretTemplate = `---
23+
apiVersion: v1
24+
kind: Secret
25+
type: kubernetes.io/service-account-token
26+
metadata:
27+
name: %s
28+
annotations:
29+
kubernetes.io/service-account.name: "%s"
30+
`
31+
32+
// GetSASecret writes a service account token secret to a file. It returns a string to the file or an error if it fails to write the file
33+
func GetSASecret(name string, dir string) (string, error) {
34+
secretName := name + "-secret"
35+
fileName := dir + "/" + secretName + ".yaml"
36+
err := os.WriteFile(fileName, []byte(fmt.Sprintf(saSecretTemplate, secretName, name)), 0777)
37+
if err != nil {
38+
return "", err
39+
}
40+
41+
return fileName, nil
42+
}

test/e2e/ansible/cluster_test.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
kbtutil "sigs.k8s.io/kubebuilder/v3/pkg/plugin/util"
2727

2828
"github.com/operator-framework/operator-sdk/internal/testutils"
29+
"github.com/operator-framework/operator-sdk/test/common"
2930
)
3031

3132
var _ = Describe("Running ansible projects", func() {
@@ -244,6 +245,15 @@ var _ = Describe("Running ansible projects", func() {
244245
}
245246
Eventually(verifyMemcachedPatch, time.Minute, time.Second).Should(Succeed())
246247

248+
// As of Kubernetes 1.24 a ServiceAccount no longer has a ServiceAccount token secret autogenerated. We have to create it manually here
249+
By("Creating the ServiceAccount token")
250+
secretFile, err := common.GetSASecret(tc.Kubectl.ServiceAccount, tc.Dir)
251+
Expect(err).NotTo(HaveOccurred())
252+
Eventually(func() error {
253+
_, err = tc.Kubectl.Apply(true, "-f", secretFile)
254+
return err
255+
}, time.Minute, time.Second).Should(Succeed())
256+
247257
By("granting permissions to access the metrics and read the token")
248258
_, err = tc.Kubectl.Command("create", "clusterrolebinding", metricsClusterRoleBindingName,
249259
fmt.Sprintf("--clusterrole=%s-metrics-reader", tc.ProjectName),
@@ -263,8 +273,7 @@ var _ = Describe("Running ansible projects", func() {
263273

264274
By("creating a curl pod")
265275
cmdOpts := []string{
266-
"run", "curl", "--image=curlimages/curl:7.68.0", "--restart=OnFailure",
267-
"--serviceaccount", tc.Kubectl.ServiceAccount, "--",
276+
"run", "curl", "--image=curlimages/curl:7.68.0", "--restart=OnFailure", "--",
268277
"curl", "-v", "-k", "-H", fmt.Sprintf(`Authorization: Bearer %s`, token),
269278
fmt.Sprintf("https://%s-controller-manager-metrics-service.%s.svc:8443/metrics", tc.ProjectName, tc.Kubectl.Namespace),
270279
}

test/e2e/go/cluster_test.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
. "github.com/onsi/ginkgo"
3131
. "github.com/onsi/gomega"
3232
"github.com/operator-framework/operator-sdk/internal/testutils"
33+
"github.com/operator-framework/operator-sdk/test/common"
3334
)
3435

3536
var _ = Describe("operator-sdk", func() {
@@ -124,6 +125,15 @@ var _ = Describe("operator-sdk", func() {
124125
fmt.Sprintf("--serviceaccount=%s:%s", tc.Kubectl.Namespace, tc.Kubectl.ServiceAccount))
125126
Expect(err).NotTo(HaveOccurred())
126127

128+
// As of Kubernetes 1.24 a ServiceAccount no longer has a ServiceAccount token secret autogenerated. We have to create it manually here
129+
By("Creating the ServiceAccount token")
130+
secretFile, err := common.GetSASecret(tc.Kubectl.ServiceAccount, tc.Dir)
131+
Expect(err).NotTo(HaveOccurred())
132+
Eventually(func() error {
133+
_, err = tc.Kubectl.Apply(true, "-f", secretFile)
134+
return err
135+
}, time.Minute, time.Second).Should(Succeed())
136+
127137
By("reading the metrics token")
128138
// Filter token query by service account in case more than one exists in a namespace.
129139
query := fmt.Sprintf(`{.items[?(@.metadata.annotations.kubernetes\.io/service-account\.name=="%s")].data.token}`,
@@ -137,8 +147,7 @@ var _ = Describe("operator-sdk", func() {
137147

138148
By("creating a curl pod")
139149
cmdOpts := []string{
140-
"run", "curl", "--image=curlimages/curl:7.68.0", "--restart=OnFailure",
141-
"--serviceaccount", tc.Kubectl.ServiceAccount, "--",
150+
"run", "curl", "--image=curlimages/curl:7.68.0", "--restart=OnFailure", "--",
142151
"curl", "-v", "-k", "-H", fmt.Sprintf(`Authorization: Bearer %s`, token),
143152
fmt.Sprintf("https://%s-controller-manager-metrics-service.%s.svc:8443/metrics", tc.ProjectName, tc.Kubectl.Namespace),
144153
}

test/e2e/helm/cluster_test.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
kbutil "sigs.k8s.io/kubebuilder/v3/pkg/plugin/util"
2727

2828
"github.com/operator-framework/operator-sdk/internal/testutils"
29+
"github.com/operator-framework/operator-sdk/test/common"
2930
)
3031

3132
var _ = Describe("Running Helm projects", func() {
@@ -201,6 +202,15 @@ var _ = Describe("Running Helm projects", func() {
201202
}
202203
Eventually(verifyReleaseUpgrade, time.Minute, time.Second).Should(Succeed())
203204

205+
// As of Kubernetes 1.24 a ServiceAccount no longer has a ServiceAccount token secret autogenerated. We have to create it manually here
206+
By("Creating the ServiceAccount token")
207+
secretFile, err := common.GetSASecret(tc.Kubectl.ServiceAccount, tc.Dir)
208+
Expect(err).NotTo(HaveOccurred())
209+
Eventually(func() error {
210+
_, err = tc.Kubectl.Apply(true, "-f", secretFile)
211+
return err
212+
}, time.Minute, time.Second).Should(Succeed())
213+
204214
By("granting permissions to access the metrics and read the token")
205215
_, err = tc.Kubectl.Command("create", "clusterrolebinding", metricsClusterRoleBindingName,
206216
fmt.Sprintf("--clusterrole=%s-metrics-reader", tc.ProjectName),
@@ -220,8 +230,7 @@ var _ = Describe("Running Helm projects", func() {
220230

221231
By("creating a curl pod")
222232
cmdOpts := []string{
223-
"run", "curl", "--image=curlimages/curl:7.68.0", "--restart=OnFailure",
224-
"--serviceaccount", tc.Kubectl.ServiceAccount, "--",
233+
"run", "curl", "--image=curlimages/curl:7.68.0", "--restart=OnFailure", "--",
225234
"curl", "-v", "-k", "-H", fmt.Sprintf(`Authorization: Bearer %s`, token),
226235
fmt.Sprintf("https://%s-controller-manager-metrics-service.%s.svc:8443/metrics", tc.ProjectName, tc.Kubectl.Namespace),
227236
}

0 commit comments

Comments
 (0)