Skip to content

Commit d674739

Browse files
⚠️ Migrate scaffolding of v3 / v4-alpha to ginkgo v2 (#2939)
* migrate scaffolding of v3 / v4-alpha to ginkgo v2 * fix typo in docs/book/src/migration/manually_migration_guide_v2_v3.md Co-authored-by: Bryce Palmer <[email protected]> Co-authored-by: Bryce Palmer <[email protected]>
1 parent 1e09811 commit d674739

File tree

56 files changed

+209
-277
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+209
-277
lines changed

docs/book/src/migration/manually_migration_guide_v2_v3.md

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,8 @@ module example
356356
go 1.18
357357
358358
require (
359-
github.com/onsi/ginkgo v1.16.5
360-
github.com/onsi/gomega v1.18.1
359+
github.com/onsi/ginkgo/v2 v2.1.4
360+
github.com/onsi/gomega v1.19.0
361361
k8s.io/api v0.24.0
362362
k8s.io/apimachinery v0.24.0
363363
k8s.io/client-go v0.24.0
@@ -522,6 +522,78 @@ func (r *<MyKind>Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
522522
log := r.Log.WithValues("cronjob", req.NamespacedName)
523523
```
524524

525+
#### Update your controller and webhook test suite
526+
527+
<aside class="note warning">
528+
<h1>Ginkgo V2 version update has breaking changes</h1>
529+
530+
Check [https://onsi.github.io/ginkgo/MIGRATING_TO_V2][Ginkgo V2 Migration] for breaking changes.
531+
532+
</aside>
533+
534+
Replace:
535+
536+
```go
537+
. "github.com/onsi/ginkgo"
538+
```
539+
540+
With:
541+
542+
```go
543+
. "github.com/onsi/ginkgo/v2"
544+
```
545+
546+
Also, adjust your test suite.
547+
548+
For Controller Suite:
549+
550+
```go
551+
RunSpecsWithDefaultAndCustomReporters(t,
552+
"Controller Suite",
553+
[]Reporter{printer.NewlineReporter{}})
554+
```
555+
556+
With:
557+
558+
```go
559+
RunSpecs(t, "Controller Suite")
560+
```
561+
562+
For Webhook Suite:
563+
564+
```go
565+
RunSpecsWithDefaultAndCustomReporters(t,
566+
"Webhook Suite",
567+
[]Reporter{printer.NewlineReporter{}})
568+
```
569+
570+
With:
571+
572+
```go
573+
RunSpecs(t, "Webhook Suite")
574+
```
575+
576+
Last but not least, remove the timeout variable from the `BeforeSuite` blocks:
577+
578+
Replace:
579+
580+
```go
581+
var _ = BeforeSuite(func(done Done) {
582+
....
583+
}, 60)
584+
```
585+
586+
With
587+
588+
589+
```go
590+
var _ = BeforeSuite(func(done Done) {
591+
....
592+
})
593+
```
594+
595+
596+
525597
#### Change Logger to use flag options
526598

527599
In the `main.go` file replace:

pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/controllers/controller-test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,14 @@ import (
6565
"time"
6666
"fmt"
6767
68-
. "github.com/onsi/ginkgo"
68+
. "github.com/onsi/ginkgo/v2"
6969
. "github.com/onsi/gomega"
7070
appsv1 "k8s.io/api/apps/v1"
7171
corev1 "k8s.io/api/core/v1"
7272
"k8s.io/apimachinery/pkg/api/errors"
7373
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
7474
"k8s.io/apimachinery/pkg/types"
7575
"sigs.k8s.io/controller-runtime/pkg/reconcile"
76-
. "github.com/onsi/ginkgo"
77-
. "github.com/onsi/gomega"
7876
7977
{{ if not (isEmptyStr .Resource.Path) -}}
8078
{{ .Resource.ImportAlias }} "{{ .Resource.Path }}"

pkg/plugins/golang/v3/scaffolds/internal/templates/api/webhook_suitetest.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ import (
140140
"testing"
141141
"fmt"
142142
143-
. "github.com/onsi/ginkgo"
143+
. "github.com/onsi/ginkgo/v2"
144144
. "github.com/onsi/gomega"
145145
%s
146146
"k8s.io/client-go/kubernetes/scheme"
@@ -166,9 +166,7 @@ var cancel context.CancelFunc
166166
func TestAPIs(t *testing.T) {
167167
RegisterFailHandler(Fail)
168168
169-
RunSpecsWithDefaultAndCustomReporters(t,
170-
"Webhook Suite",
171-
[]Reporter{printer.NewlineReporter{}})
169+
RunSpecs(t, "Webhook Suite")
172170
}
173171
174172
var _ = BeforeSuite(func() {
@@ -236,7 +234,7 @@ var _ = BeforeSuite(func() {
236234
return nil
237235
}).Should(Succeed())
238236
239-
}, 60)
237+
})
240238
241239
var _ = AfterSuite(func() {
242240
cancel()

pkg/plugins/golang/v3/scaffolds/internal/templates/controllers/controller_suitetest.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ import (
131131
"path/filepath"
132132
"testing"
133133
134-
. "github.com/onsi/ginkgo"
134+
. "github.com/onsi/ginkgo/v2"
135135
. "github.com/onsi/gomega"
136136
137137
"k8s.io/client-go/kubernetes/scheme"
@@ -154,9 +154,7 @@ var testEnv *envtest.Environment
154154
func TestAPIs(t *testing.T) {
155155
RegisterFailHandler(Fail)
156156
157-
RunSpecsWithDefaultAndCustomReporters(t,
158-
"Controller Suite",
159-
[]Reporter{printer.NewlineReporter{}})
157+
RunSpecs(t, "Controller Suite")
160158
}
161159
162160
var _ = BeforeSuite(func() {
@@ -180,7 +178,7 @@ var _ = BeforeSuite(func() {
180178
Expect(err).NotTo(HaveOccurred())
181179
Expect(k8sClient).NotTo(BeNil())
182180
183-
}, 60)
181+
})
184182
185183
var _ = AfterSuite(func() {
186184
By("tearing down the test environment")

testdata/project-v3-addon-and-grafana/controllers/suite_test.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@ import (
2020
"path/filepath"
2121
"testing"
2222

23-
. "github.com/onsi/ginkgo"
23+
. "github.com/onsi/ginkgo/v2"
2424
. "github.com/onsi/gomega"
2525

2626
"k8s.io/client-go/kubernetes/scheme"
2727
"k8s.io/client-go/rest"
2828
"sigs.k8s.io/controller-runtime/pkg/client"
2929
"sigs.k8s.io/controller-runtime/pkg/envtest"
30-
"sigs.k8s.io/controller-runtime/pkg/envtest/printer"
3130
logf "sigs.k8s.io/controller-runtime/pkg/log"
3231
"sigs.k8s.io/controller-runtime/pkg/log/zap"
3332

@@ -45,9 +44,7 @@ var testEnv *envtest.Environment
4544
func TestAPIs(t *testing.T) {
4645
RegisterFailHandler(Fail)
4746

48-
RunSpecsWithDefaultAndCustomReporters(t,
49-
"Controller Suite",
50-
[]Reporter{printer.NewlineReporter{}})
47+
RunSpecs(t, "Controller Suite")
5148
}
5249

5350
var _ = BeforeSuite(func() {
@@ -74,7 +71,7 @@ var _ = BeforeSuite(func() {
7471
Expect(err).NotTo(HaveOccurred())
7572
Expect(k8sClient).NotTo(BeNil())
7673

77-
}, 60)
74+
})
7875

7976
var _ = AfterSuite(func() {
8077
By("tearing down the test environment")

testdata/project-v3-addon-and-grafana/go.mod

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.19
44

55
require (
66
github.com/go-logr/logr v1.2.3
7-
github.com/onsi/ginkgo v1.16.5
7+
github.com/onsi/ginkgo/v2 v2.1.4
88
github.com/onsi/gomega v1.19.0
99
k8s.io/apimachinery v0.25.0
1010
k8s.io/client-go v0.25.0
@@ -74,7 +74,6 @@ require (
7474
github.com/modern-go/reflect2 v1.0.2 // indirect
7575
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
7676
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
77-
github.com/nxadm/tail v1.4.8 // indirect
7877
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
7978
github.com/pkg/errors v0.9.1 // indirect
8079
github.com/prometheus/client_golang v1.12.2 // indirect
@@ -102,7 +101,6 @@ require (
102101
google.golang.org/appengine v1.6.7 // indirect
103102
google.golang.org/protobuf v1.28.0 // indirect
104103
gopkg.in/inf.v0 v0.9.1 // indirect
105-
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
106104
gopkg.in/warnings.v0 v0.1.2 // indirect
107105
gopkg.in/yaml.v2 v2.4.0 // indirect
108106
gopkg.in/yaml.v3 v3.0.1 // indirect

testdata/project-v3-config/api/v1/webhook_suite_test.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"testing"
2626
"time"
2727

28-
. "github.com/onsi/ginkgo"
28+
. "github.com/onsi/ginkgo/v2"
2929
. "github.com/onsi/gomega"
3030

3131
admissionv1beta1 "k8s.io/api/admission/v1beta1"
@@ -35,7 +35,6 @@ import (
3535
ctrl "sigs.k8s.io/controller-runtime"
3636
"sigs.k8s.io/controller-runtime/pkg/client"
3737
"sigs.k8s.io/controller-runtime/pkg/envtest"
38-
"sigs.k8s.io/controller-runtime/pkg/envtest/printer"
3938
logf "sigs.k8s.io/controller-runtime/pkg/log"
4039
"sigs.k8s.io/controller-runtime/pkg/log/zap"
4140
)
@@ -52,9 +51,7 @@ var cancel context.CancelFunc
5251
func TestAPIs(t *testing.T) {
5352
RegisterFailHandler(Fail)
5453

55-
RunSpecsWithDefaultAndCustomReporters(t,
56-
"Webhook Suite",
57-
[]Reporter{printer.NewlineReporter{}})
54+
RunSpecs(t, "Webhook Suite")
5855
}
5956

6057
var _ = BeforeSuite(func() {
@@ -128,7 +125,7 @@ var _ = BeforeSuite(func() {
128125
return nil
129126
}).Should(Succeed())
130127

131-
}, 60)
128+
})
132129

133130
var _ = AfterSuite(func() {
134131
cancel()

testdata/project-v3-config/controllers/suite_test.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@ import (
2020
"path/filepath"
2121
"testing"
2222

23-
. "github.com/onsi/ginkgo"
23+
. "github.com/onsi/ginkgo/v2"
2424
. "github.com/onsi/gomega"
2525

2626
"k8s.io/client-go/kubernetes/scheme"
2727
"k8s.io/client-go/rest"
2828
"sigs.k8s.io/controller-runtime/pkg/client"
2929
"sigs.k8s.io/controller-runtime/pkg/envtest"
30-
"sigs.k8s.io/controller-runtime/pkg/envtest/printer"
3130
logf "sigs.k8s.io/controller-runtime/pkg/log"
3231
"sigs.k8s.io/controller-runtime/pkg/log/zap"
3332

@@ -45,9 +44,7 @@ var testEnv *envtest.Environment
4544
func TestAPIs(t *testing.T) {
4645
RegisterFailHandler(Fail)
4746

48-
RunSpecsWithDefaultAndCustomReporters(t,
49-
"Controller Suite",
50-
[]Reporter{printer.NewlineReporter{}})
47+
RunSpecs(t, "Controller Suite")
5148
}
5249

5350
var _ = BeforeSuite(func() {
@@ -74,7 +71,7 @@ var _ = BeforeSuite(func() {
7471
Expect(err).NotTo(HaveOccurred())
7572
Expect(k8sClient).NotTo(BeNil())
7673

77-
}, 60)
74+
})
7875

7976
var _ = AfterSuite(func() {
8077
By("tearing down the test environment")

testdata/project-v3-config/go.mod

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module sigs.k8s.io/kubebuilder/testdata/project-v3-config
33
go 1.19
44

55
require (
6-
github.com/onsi/ginkgo v1.16.5
6+
github.com/onsi/ginkgo/v2 v2.1.4
77
github.com/onsi/gomega v1.19.0
88
k8s.io/api v0.25.0
99
k8s.io/apimachinery v0.25.0
@@ -48,7 +48,6 @@ require (
4848
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
4949
github.com/modern-go/reflect2 v1.0.2 // indirect
5050
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
51-
github.com/nxadm/tail v1.4.8 // indirect
5251
github.com/pkg/errors v0.9.1 // indirect
5352
github.com/prometheus/client_golang v1.12.2 // indirect
5453
github.com/prometheus/client_model v0.2.0 // indirect
@@ -69,7 +68,6 @@ require (
6968
google.golang.org/appengine v1.6.7 // indirect
7069
google.golang.org/protobuf v1.28.0 // indirect
7170
gopkg.in/inf.v0 v0.9.1 // indirect
72-
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
7371
gopkg.in/yaml.v2 v2.4.0 // indirect
7472
gopkg.in/yaml.v3 v3.0.1 // indirect
7573
k8s.io/apiextensions-apiserver v0.25.0 // indirect

testdata/project-v3-multigroup/apis/crew/v1/webhook_suite_test.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"testing"
2626
"time"
2727

28-
. "github.com/onsi/ginkgo"
28+
. "github.com/onsi/ginkgo/v2"
2929
. "github.com/onsi/gomega"
3030

3131
admissionv1beta1 "k8s.io/api/admission/v1beta1"
@@ -35,7 +35,6 @@ import (
3535
ctrl "sigs.k8s.io/controller-runtime"
3636
"sigs.k8s.io/controller-runtime/pkg/client"
3737
"sigs.k8s.io/controller-runtime/pkg/envtest"
38-
"sigs.k8s.io/controller-runtime/pkg/envtest/printer"
3938
logf "sigs.k8s.io/controller-runtime/pkg/log"
4039
"sigs.k8s.io/controller-runtime/pkg/log/zap"
4140
)
@@ -52,9 +51,7 @@ var cancel context.CancelFunc
5251
func TestAPIs(t *testing.T) {
5352
RegisterFailHandler(Fail)
5453

55-
RunSpecsWithDefaultAndCustomReporters(t,
56-
"Webhook Suite",
57-
[]Reporter{printer.NewlineReporter{}})
54+
RunSpecs(t, "Webhook Suite")
5855
}
5956

6057
var _ = BeforeSuite(func() {
@@ -125,7 +122,7 @@ var _ = BeforeSuite(func() {
125122
return nil
126123
}).Should(Succeed())
127124

128-
}, 60)
125+
})
129126

130127
var _ = AfterSuite(func() {
131128
cancel()

0 commit comments

Comments
 (0)