Skip to content
This repository was archived by the owner on Mar 26, 2025. It is now read-only.

Commit e8d39bc

Browse files
authored
Update Ginkgo from v1 to v2 (#890)
1 parent 9a121e7 commit e8d39bc

20 files changed

+121
-103
lines changed

controllers/cruisecontroloperation_controller.go

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func (r *CruiseControlOperationReconciler) Reconcile(ctx context.Context, reques
9393
}
9494
}
9595

96-
if currentCCOperation == nil || r.isCCTaskTest(currentCCOperation) {
96+
if currentCCOperation == nil {
9797
return reconciled()
9898
}
9999

@@ -239,22 +239,6 @@ func (r *CruiseControlOperationReconciler) Reconcile(ctx context.Context, reques
239239
return reconciled()
240240
}
241241

242-
// isCCTaskTest returns true when the CruiseControlOperation is created by the cruisecontroltask_controller_test
243-
// In this case the CR should be skipped because the scale mock interference
244-
func (r *CruiseControlOperationReconciler) isCCTaskTest(operation *banzaiv1alpha1.CruiseControlOperation) bool {
245-
if _, ok := r.scaler.(*scale.MockCruiseControlScaler); !ok {
246-
return false
247-
}
248-
249-
for _, ownerRef := range operation.GetOwnerReferences() {
250-
if ownerRef.Name == CruiseControlTaskTestKafkaClusterName {
251-
return true
252-
}
253-
}
254-
255-
return false
256-
}
257-
258242
func (r *CruiseControlOperationReconciler) addFinalizer(ctx context.Context, currentCCOperation *banzaiv1alpha1.CruiseControlOperation) error {
259243
// examine DeletionTimestamp to determine if object is under deletion
260244
if currentCCOperation.ObjectMeta.DeletionTimestamp.IsZero() {

controllers/cruisecontroltask_controller.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ import (
4242
)
4343

4444
const (
45-
DefaultRequeueAfterTimeInSec = 20
46-
CruiseControlTaskTestKafkaClusterName = "cruisecontroltask-test"
45+
DefaultRequeueAfterTimeInSec = 20
4746
)
4847

4948
// CruiseControlTaskReconciler reconciles a kafka cluster object

controllers/tests/clusterregistry/cruisecontroltask_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020

2121
clusterregv1alpha1 "github.com/cisco-open/cluster-registry-controller/api/v1alpha1"
2222

23-
. "github.com/onsi/ginkgo"
23+
. "github.com/onsi/ginkgo/v2"
2424
. "github.com/onsi/gomega"
2525
corev1 "k8s.io/api/core/v1"
2626
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

controllers/tests/clusterregistry/kafkacluster_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020

2121
clusterregv1alpha1 "github.com/cisco-open/cluster-registry-controller/api/v1alpha1"
2222

23-
. "github.com/onsi/ginkgo"
23+
. "github.com/onsi/ginkgo/v2"
2424
. "github.com/onsi/gomega"
2525
corev1 "k8s.io/api/core/v1"
2626
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

controllers/tests/clusterregistry/kafkatopic_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"fmt"
1919
"sync/atomic"
2020

21-
. "github.com/onsi/ginkgo"
21+
. "github.com/onsi/ginkgo/v2"
2222
. "github.com/onsi/gomega"
2323

2424
clusterregv1alpha1 "github.com/cisco-open/cluster-registry-controller/api/v1alpha1"

controllers/tests/clusterregistry/kafkauser_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"fmt"
1919
"sync/atomic"
2020

21-
. "github.com/onsi/ginkgo"
21+
. "github.com/onsi/ginkgo/v2"
2222
. "github.com/onsi/gomega"
2323

2424
clusterregv1alpha1 "github.com/cisco-open/cluster-registry-controller/api/v1alpha1"

controllers/tests/clusterregistry/suite_test.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ import (
3636
"time"
3737

3838
"github.com/go-logr/logr"
39-
. "github.com/onsi/ginkgo"
40-
ginkoconfig "github.com/onsi/ginkgo/config"
39+
. "github.com/onsi/ginkgo/v2"
4140
. "github.com/onsi/gomega"
4241

4342
apiv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
4443
"k8s.io/apimachinery/pkg/runtime"
4544
"k8s.io/apimachinery/pkg/types"
4645
k8sscheme "k8s.io/client-go/kubernetes/scheme"
46+
"k8s.io/client-go/rest"
4747
ctrl "sigs.k8s.io/controller-runtime"
4848
"sigs.k8s.io/controller-runtime/pkg/client"
4949
"sigs.k8s.io/controller-runtime/pkg/envtest"
@@ -78,9 +78,6 @@ var (
7878

7979
func TestControllersWithClusterRegistry(t *testing.T) {
8080
RegisterFailHandler(Fail)
81-
82-
ginkoconfig.DefaultReporterConfig.SlowSpecThreshold = 120
83-
8481
RunSpecs(t, "Controller Suite with Cluster Registry")
8582
}
8683

@@ -103,9 +100,17 @@ var _ = BeforeSuite(func() {
103100
AttachControlPlaneOutput: false,
104101
}
105102

106-
cfg, err := testEnv.Start()
107-
Expect(err).ToNot(HaveOccurred())
108-
Expect(cfg).ToNot(BeNil())
103+
var cfg *rest.Config
104+
var err error
105+
done := make(chan interface{})
106+
go func() {
107+
defer GinkgoRecover()
108+
cfg, err = testEnv.Start()
109+
close(done)
110+
}()
111+
Eventually(done).WithTimeout(time.Minute).Should(BeClosed())
112+
Expect(err).NotTo(HaveOccurred())
113+
Expect(cfg).NotTo(BeNil())
109114

110115
scheme := runtime.NewScheme()
111116

@@ -152,6 +157,7 @@ var _ = BeforeSuite(func() {
152157
// +kubebuilder:scaffold:builder
153158

154159
go func() {
160+
defer GinkgoRecover()
155161
ctrl.Log.Info("starting manager")
156162
err = mgr.Start(ctrl.SetupSignalHandler())
157163
Expect(err).ToNot(HaveOccurred())
@@ -174,7 +180,7 @@ var _ = BeforeSuite(func() {
174180
err = k8sClient.Get(context.TODO(), types.NamespacedName{Name: "kafkausers.kafka.banzaicloud.io"}, crd)
175181
Expect(err).NotTo(HaveOccurred())
176182
Expect(crd.Spec.Names.Kind).To(Equal("KafkaUser"))
177-
}, 240)
183+
})
178184

179185
var _ = AfterSuite(func() {
180186
By("tearing down the test environment")

controllers/tests/cruisecontroloperation_controller_test.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ package tests
1616

1717
import (
1818
"context"
19+
"errors"
1920
"fmt"
2021
"sync/atomic"
2122
"time"
2223

2324
"github.com/golang/mock/gomock"
24-
. "github.com/onsi/ginkgo"
25+
. "github.com/onsi/ginkgo/v2"
2526
. "github.com/onsi/gomega"
2627
"sigs.k8s.io/controller-runtime/pkg/client"
2728

@@ -67,8 +68,12 @@ var _ = Describe("CruiseControlTaskReconciler", func() {
6768
Expect(err).NotTo(HaveOccurred())
6869

6970
})
70-
71-
When("there is an add_broker operation for execution", func() {
71+
JustAfterEach(func() {
72+
cruiseControlOperationReconciler.ScaleFactory = func(ctx context.Context, kafkaCluster *v1beta1.KafkaCluster) (scale.CruiseControlScaler, error) {
73+
return nil, errors.New("there is no scale mock")
74+
}
75+
})
76+
When("there is an add_broker operation for execution", Serial, func() {
7277
JustBeforeEach(func() {
7378
cruiseControlOperationReconciler.ScaleFactory = NewMockScaleFactory(getScaleMock1())
7479
operation := generateCruiseControlOperation(opName1, namespace, kafkaCluster.GetName())
@@ -96,7 +101,7 @@ var _ = Describe("CruiseControlTaskReconciler", func() {
96101
}, 10*time.Second, 500*time.Millisecond).Should(Equal(v1beta1.CruiseControlTaskCompleted))
97102
})
98103
})
99-
When("add_broker operation is finished with completedWithError and 30s has not elapsed", func() {
104+
When("add_broker operation is finished with completedWithError and 30s has not elapsed", Serial, func() {
100105
JustBeforeEach(func() {
101106
cruiseControlOperationReconciler.ScaleFactory = NewMockScaleFactory(getScaleMock2())
102107
operation := generateCruiseControlOperation(opName1, namespace, kafkaCluster.GetName())
@@ -123,7 +128,7 @@ var _ = Describe("CruiseControlTaskReconciler", func() {
123128
}, 10*time.Second, 500*time.Millisecond).Should(BeTrue())
124129
})
125130
})
126-
When("add_broker operation is finished with completedWithError and 30s has elapsed", func() {
131+
When("add_broker operation is finished with completedWithError and 30s has elapsed", Serial, func() {
127132
JustBeforeEach(func() {
128133
cruiseControlOperationReconciler.ScaleFactory = NewMockScaleFactory(getScaleMock5())
129134
operation := generateCruiseControlOperation(opName1, namespace, kafkaCluster.GetName())
@@ -152,7 +157,7 @@ var _ = Describe("CruiseControlTaskReconciler", func() {
152157
}, 10*time.Second, 500*time.Millisecond).Should(BeTrue())
153158
})
154159
})
155-
When("there is an errored remove_broker and an add_broker operation", func() {
160+
When("there is an errored remove_broker and an add_broker operation", Serial, func() {
156161
JustBeforeEach(func() {
157162
cruiseControlOperationReconciler.ScaleFactory = NewMockScaleFactory(getScaleMock3())
158163
// First operation will get completedWithError
@@ -199,7 +204,7 @@ var _ = Describe("CruiseControlTaskReconciler", func() {
199204
}, 10*time.Second, 500*time.Millisecond).Should(BeTrue())
200205
})
201206
})
202-
When("there is a new remove_broker and an errored remove_broker operation with pause annotation", func() {
207+
When("there is a new remove_broker and an errored remove_broker operation with pause annotation", Serial, func() {
203208
JustBeforeEach(func() {
204209
cruiseControlOperationReconciler.ScaleFactory = NewMockScaleFactory(getScaleMock4())
205210
operation := generateCruiseControlOperation(opName1, namespace, kafkaCluster.GetName())
@@ -248,7 +253,7 @@ var _ = Describe("CruiseControlTaskReconciler", func() {
248253
}, 10*time.Second, 500*time.Millisecond).Should(BeTrue())
249254
})
250255
})
251-
When("there is a new remove_broker and an errored remove_broker operation with ignore ErrorPolicy", func() {
256+
When("there is a new remove_broker and an errored remove_broker operation with ignore ErrorPolicy", Serial, func() {
252257
JustBeforeEach(func() {
253258
cruiseControlOperationReconciler.ScaleFactory = NewMockScaleFactory(getScaleMock4())
254259
// Creating first operation
@@ -445,7 +450,7 @@ func getScaleMock5() *scale.MockCruiseControlScaler {
445450
TaskID: "12345",
446451
StartedAt: "Sat, 27 Aug 2022 12:22:21 GMT",
447452
State: v1beta1.CruiseControlTaskActive,
448-
}), nil).Times(2)
453+
}), nil).Times(1)
449454
return scaleMock
450455
}
451456

controllers/tests/cruisecontroloperation_ttl_controller_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"sync/atomic"
2121
"time"
2222

23-
. "github.com/onsi/ginkgo"
23+
. "github.com/onsi/ginkgo/v2"
2424
. "github.com/onsi/gomega"
2525
"sigs.k8s.io/controller-runtime/pkg/client"
2626

@@ -31,7 +31,6 @@ import (
3131

3232
"github.com/banzaicloud/koperator/api/v1alpha1"
3333
"github.com/banzaicloud/koperator/api/v1beta1"
34-
"github.com/banzaicloud/koperator/controllers"
3534
"github.com/banzaicloud/koperator/pkg/util"
3635
)
3736

@@ -58,7 +57,7 @@ var _ = Describe("CruiseControlTaskReconciler", func() {
5857
Name: namespace,
5958
},
6059
}
61-
kafkaClusterCRName = controllers.CruiseControlTaskTestKafkaClusterName
60+
kafkaClusterCRName = fmt.Sprintf("kafkacluster-ttl-%v", count)
6261
kafkaCluster = createMinimalKafkaClusterCR(kafkaClusterCRName, namespace)
6362
})
6463

@@ -73,7 +72,7 @@ var _ = Describe("CruiseControlTaskReconciler", func() {
7372

7473
})
7574

76-
When("there is a finished (completed) operation with TTL", func() {
75+
When("there is a finished (completed) operation with TTL", Serial, func() {
7776
JustBeforeEach(func() {
7877
operation := generateCruiseControlOperation(opName, namespace, kafkaCluster.GetName())
7978
operation.Spec.TTLSecondsAfterFinished = util.IntPointer(5)
@@ -104,7 +103,7 @@ var _ = Describe("CruiseControlTaskReconciler", func() {
104103
}, maxReconcileDuration, reconcilePollingPeriod).Should(BeTrue())
105104
})
106105
})
107-
When("there is a finished (completedWithError and errorPolicy: ignore) operation with TTL", func() {
106+
When("there is a finished (completedWithError and errorPolicy: ignore) operation with TTL", Serial, func() {
108107
JustBeforeEach(func() {
109108
operation := generateCruiseControlOperation(opName, namespace, kafkaCluster.GetName())
110109
operation.Spec.TTLSecondsAfterFinished = util.IntPointer(5)
@@ -136,7 +135,7 @@ var _ = Describe("CruiseControlTaskReconciler", func() {
136135
}, maxReconcileDuration, reconcilePollingPeriod).Should(BeTrue())
137136
})
138137
})
139-
When("there is a finished operation without TTL", func() {
138+
When("there is a finished operation without TTL", Serial, func() {
140139
JustBeforeEach(func() {
141140
operation := generateCruiseControlOperation(opName, namespace, kafkaCluster.GetName())
142141
err := k8sClient.Create(context.Background(), &operation)

0 commit comments

Comments
 (0)