Skip to content

Commit a5b5eb8

Browse files
authored
Merge pull request #476 from dmvolod/update-example-controller-test-to-v0.5.0
Updating example controller test to e2e-framework v0.5.0 and make it running
2 parents 65f31fb + cef945c commit a5b5eb8

File tree

9 files changed

+4348
-4572
lines changed

9 files changed

+4348
-4572
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Fixes #
4040
#### Does this PR introduce a user-facing change?
4141
<!--
4242
If no, just write "NONE" in the release-note block below.
43-
If yes, please enter the details of what chanages are being introduced:
43+
If yes, please enter the details of what changes are being introduced:
4444
Enter your extended release note in the block below. If the PR requires additional action from users switching to the new release, include the string "action required".
4545
4646
For more information on release notes see: https://git.k8s.io/community/contributors/guide/release-notes.md

examples/controller_tests/README.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Testing Kubernetes Controllers with the e2e-framework
22

3-
This example shows you how to create end-to-end tests to test Kubernetes controller using the [CronJob controller](https://book.kubebuilder.io/cronjob-tutorial/cronjob-tutorial) example that comes with the The Kubernetes-SIGs [Kubebuilder](https://github.com/kubernetes-sigs/kubebuilder) project. It is based on blog post about the subject on [Medium](https://medium.com/programming-kubernetes/testing-kubernetes-controllers-with-the-e2e-framework-fac232843dc6).
3+
This example shows you how to create end-to-end tests to test Kubernetes controller using the [CronJob controller](https://book.kubebuilder.io/cronjob-tutorial/cronjob-tutorial) example that comes with the Kubernetes-SIGs [Kubebuilder](https://github.com/kubernetes-sigs/kubebuilder) project. It is based on blog post about the subject on [Medium](https://medium.com/programming-kubernetes/testing-kubernetes-controllers-with-the-e2e-framework-fac232843dc6).
44

5-
Find the example end-to-end test source code in [./testdata/e2e-test](./testdata/e2e-test/).
5+
Find the example end-to-end test source code in [./testdata/e2e-test](./testdata/e2e-test).
66

77
### Infrastructure setup
88

@@ -19,6 +19,7 @@ func TestMain(m *testing.M) {
1919
kindClusterName := "kind-test"
2020
kindCluster := kind.NewCluster(kindClusterName)
2121

22+
log.Println("Creating KinD cluster...")
2223
testEnv.Setup(
2324
envfuncs.CreateCluster(kindCluster, kindClusterName),
2425
envfuncs.CreateNamespace(namespace),
@@ -32,7 +33,7 @@ Next, we will install prometheus and cert-manager and wait for the cert manager
3233
```go
3334
var (
3435
...
35-
certmgrVer = "v1.13.1"
36+
certMgrVer = "v1.13.1"
3637
certMgrUrl = fmt.Sprintf("https://github.com/jetstack/cert-manager/releases/download/%s/cert-manager.yaml", certmgrVer)
3738

3839
promVer = "v0.60.0"
@@ -58,7 +59,7 @@ func TestMain(m *testing.M) {
5859
return ctx, p.Err()
5960
}
6061

61-
// wait for certmgr deployment to be ready
62+
// wait for CertManager deployment to be ready
6263
client := cfg.Client()
6364
if err := wait.For(
6465
conditions.New(client.Resources()).
@@ -79,16 +80,16 @@ The next function installs `kustomize` and `controller-gen` needed to generate t
7980
```go
8081
var (
8182
...
82-
kustomizeVer = "v5.1.1"
83-
ctrlgenVer = "v0.13.0"
83+
kustomizeVer = "v5.5.0"
84+
ctrlgenVer = "v0.16.4"
8485
)
8586

8687
func TestMain(m *testing.M) {
8788
...
8889
testEnv.Setup(
8990
...
9091
func(ctx context.Context, cfg *envconf.Config) (context.Context, error) {
91-
// install kubstomize binary
92+
// install kustomize binary
9293
if p := utils.RunCommand(
9394
fmt.Sprintf("go install sigs.k8s.io/kustomize/kustomize/v5@%s", kustomizeVer),
9495
); p.Err() != nil {
@@ -224,7 +225,7 @@ var (
224225
)
225226
```
226227

227-
Next, let's create a `Feature.Setup` to setup up a `Watcher` to watch for job pods created by our controller and put them on channel `podCreationSig` to be tested later:
228+
Next, let's create a `Feature.Setup` to setup a `Watcher` to watch for job pods created by our controller and put them on channel `podCreationSig` to be tested later:
228229

229230
```go
230231
func TestCron(t *testing.T) {
@@ -273,7 +274,7 @@ func TestCron(t *testing.T) {
273274
}
274275
```
275276

276-
In the next assessment, we will create a new instance of a `CronJob` in the cluster and use the `wait` package to construct a dierctive to wait for API object to be created:
277+
In the next assessment, we will create a new instance of a `CronJob` in the cluster and use the `wait` package to construct a directive to wait for API object to be created:
277278

278279
```go
279280
func TestCron(t *testing.T) {
@@ -312,7 +313,7 @@ func TestCron(t *testing.T) {
312313
feature.Assess("Watcher received pod job", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context {
313314
select {
314315
case <-time.After(30 * time.Second):
315-
t.Error("Timed out wating for job pod creation by cronjob contoller")
316+
t.Error("Timed out waiting for job pod creation by cronjob controller")
316317
case pod := <-podCreationSig:
317318
t.Log("Pod created by cronjob-controller")
318319
refname := pod.GetOwnerReferences()[0].Name
@@ -326,14 +327,14 @@ func TestCron(t *testing.T) {
326327
```
327328

328329
### Running the test
329-
Next, use the `go test` command to run the test. Go will automtomatically pull down all required packages and start the test:
330+
Next, use the `go test` command to run the test. Go will automatically pull down all required packages and start the test:
330331

331332
```
332333
$> cd ./testdata
333334
$> go test -v ./e2e-test
334335
335-
go: downloading sigs.k8s.io/e2e-framework v0.3.0
336-
go: downloading k8s.io/api v0.28.3
337-
go: downloading k8s.io/apimachinery v0.28.3
336+
go: downloading sigs.k8s.io/e2e-framework v0.5.0
337+
go: downloading k8s.io/api v0.31.1
338+
go: downloading k8s.io/apimachinery v0.31.1
338339
...
339340
```

examples/controller_tests/testdata/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
# Build the manager binary
16-
FROM golang:1.21 as builder
16+
FROM golang:1.23 AS builder
1717
ARG TARGETOS
1818
ARG TARGETARCH
1919

0 commit comments

Comments
 (0)