@@ -11,7 +11,11 @@ import (
11
11
"github.com/stretchr/testify/assert"
12
12
corev1 "k8s.io/api/core/v1"
13
13
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
14
+ "k8s.io/apimachinery/pkg/runtime"
15
+ utilruntime "k8s.io/apimachinery/pkg/util/runtime"
14
16
"k8s.io/apiserver/pkg/storage/names"
17
+ clientgoscheme "k8s.io/client-go/kubernetes/scheme"
18
+ clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
15
19
runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1"
16
20
17
21
"github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1"
@@ -126,15 +130,13 @@ func TestImageRegistriesPatch(t *testing.T) {
126
130
}
127
131
128
132
var _ = Describe ("Generate Image registry patches" , func () {
133
+ clientScheme := runtime .NewScheme ()
134
+ utilruntime .Must (clientgoscheme .AddToScheme (clientScheme ))
135
+ utilruntime .Must (clusterv1 .AddToScheme (clientScheme ))
136
+
129
137
patchGenerator := func () mutation.GeneratePatches {
130
- // Always initialize the testEnv variable in the closure.
131
- // This will allow ginkgo to initialize testEnv variable during test execution time.
132
- testEnv := helpers .TestEnv
133
- // use direct client instead of controller client. This will allow the patch handler to read k8s object
134
- // that are written by the tests.
135
- // Test cases writes credentials secret that the mutator handler reads.
136
- // Using direct client will enable reading it immediately.
137
- client , err := testEnv .GetK8sClient ()
138
+ // Use direct client to allow patch handler to read objects created by tests.
139
+ client , err := helpers .TestEnv .GetK8sClientWithScheme (clientScheme )
138
140
gomega .Expect (err ).To (gomega .BeNil ())
139
141
return mutation .NewMetaGeneratePatchesHandler ("" , client , NewPatch (client )).(mutation.GeneratePatches )
140
142
}
@@ -392,22 +394,44 @@ var _ = Describe("Generate Image registry patches", func() {
392
394
393
395
// Create credentials secret before each test
394
396
BeforeEach (func (ctx SpecContext ) {
395
- client , err := helpers .TestEnv .GetK8sClient ( )
397
+ client , err := helpers .TestEnv .GetK8sClientWithScheme ( clientScheme )
396
398
gomega .Expect (err ).To (gomega .BeNil ())
399
+
397
400
gomega .Expect (client .Create (
398
401
ctx ,
399
402
newRegistryCredentialsSecret (validSecretName , request .Namespace ),
400
403
)).To (gomega .BeNil ())
404
+
405
+ gomega .Expect (client .Create (
406
+ ctx ,
407
+ & clusterv1.Cluster {
408
+ ObjectMeta : metav1.ObjectMeta {
409
+ Name : request .ClusterName ,
410
+ Namespace : request .Namespace ,
411
+ },
412
+ },
413
+ )).To (gomega .BeNil ())
401
414
})
402
415
403
416
// Delete credentials secret after each test
404
417
AfterEach (func (ctx SpecContext ) {
405
- client , err := helpers .TestEnv .GetK8sClient ( )
418
+ client , err := helpers .TestEnv .GetK8sClientWithScheme ( clientScheme )
406
419
gomega .Expect (err ).To (gomega .BeNil ())
420
+
407
421
gomega .Expect (client .Delete (
408
422
ctx ,
409
423
newRegistryCredentialsSecret (validSecretName , request .Namespace ),
410
424
)).To (gomega .BeNil ())
425
+
426
+ gomega .Expect (client .Delete (
427
+ ctx ,
428
+ & clusterv1.Cluster {
429
+ ObjectMeta : metav1.ObjectMeta {
430
+ Name : request .ClusterName ,
431
+ Namespace : request .Namespace ,
432
+ },
433
+ },
434
+ )).To (gomega .BeNil ())
411
435
})
412
436
// create test node for each case
413
437
for testIdx := range testDefs {
0 commit comments