@@ -17,7 +17,6 @@ limitations under the License.
17
17
package e2e
18
18
19
19
import (
20
- "context"
21
20
"fmt"
22
21
"net"
23
22
"os"
@@ -32,9 +31,9 @@ import (
32
31
"k8s.io/apimachinery/pkg/util/sets"
33
32
"k8s.io/klog/v2"
34
33
"sigs.k8s.io/cluster-api/test/framework"
34
+ "sigs.k8s.io/cluster-api/test/framework/clusterctl"
35
35
. "sigs.k8s.io/cluster-api/test/framework/ginkgoextensions"
36
36
crclient "sigs.k8s.io/controller-runtime/pkg/client"
37
- "sigs.k8s.io/yaml"
38
37
39
38
vsphereip "sigs.k8s.io/cluster-api-provider-vsphere/test/framework/ip"
40
39
vspherevcsim "sigs.k8s.io/cluster-api-provider-vsphere/test/framework/vcsim"
@@ -145,11 +144,11 @@ func Setup(specName string, f func(testSpecificSettings func() testSettings), op
145
144
// may re-write the file to add some variables, but it needs to exist already before that.
146
145
testSpecificClusterctlConfigPath = fmt .Sprintf ("%s-%s.yaml" , strings .TrimSuffix (clusterctlConfigPath , ".yaml" ), specName )
147
146
Byf ("Writing a new clusterctl config to %s" , testSpecificClusterctlConfigPath )
148
- copyAndAmendClusterctlConfig ( ctx , copyAndAmendClusterctlConfigInput {
147
+ Expect ( clusterctl . CopyAndAmendClusterctlConfig ( ctx , clusterctl. CopyAndAmendClusterctlConfigInput {
149
148
ClusterctlConfigPath : clusterctlConfigPath ,
150
149
OutputPath : testSpecificClusterctlConfigPath ,
151
150
Variables : testSpecificVariables ,
152
- })
151
+ })). To ( Succeed ())
153
152
154
153
// The setup done in `postNamespaceCreatedFunc` does
155
154
// 1. Create a VCSim Server (only for additional VCSim at separate management cluster)
@@ -176,11 +175,11 @@ func Setup(specName string, f func(testSpecificSettings func() testSettings), op
176
175
177
176
// Re-write the clusterctl config file and add the new variables created above (ip addresses, VCSim variables).
178
177
Byf ("Writing a new clusterctl config to %s" , testSpecificClusterctlConfigPath )
179
- copyAndAmendClusterctlConfig ( ctx , copyAndAmendClusterctlConfigInput {
178
+ Expect ( clusterctl . CopyAndAmendClusterctlConfig ( ctx , clusterctl. CopyAndAmendClusterctlConfigInput {
180
179
ClusterctlConfigPath : testSpecificClusterctlConfigPath ,
181
180
OutputPath : testSpecificClusterctlConfigPath ,
182
181
Variables : testSpecificVariables ,
183
- })
182
+ })). To ( Succeed ())
184
183
185
184
// Run additional initialization required for supervisor.
186
185
if testMode == SupervisorTestMode {
@@ -429,56 +428,3 @@ func setupNamespaceWithVMOperatorDependenciesVCenter(managementClusterProxy fram
429
428
err := vmoperator .ReconcileDependencies (ctx , c , dependenciesConfig )
430
429
Expect (err ).ToNot (HaveOccurred (), "Failed to reconcile VMOperatorDependencies" )
431
430
}
432
-
433
- // Note: Copy-paste from CAPI below.
434
-
435
- // copyAndAmendClusterctlConfigInput is the input for copyAndAmendClusterctlConfig.
436
- type copyAndAmendClusterctlConfigInput struct {
437
- ClusterctlConfigPath string
438
- OutputPath string
439
- Variables map [string ]string
440
- }
441
-
442
- // copyAndAmendClusterctlConfig copies the clusterctl-config from ClusterctlConfigPath to
443
- // OutputPath and adds the given Variables.
444
- func copyAndAmendClusterctlConfig (_ context.Context , input copyAndAmendClusterctlConfigInput ) {
445
- // Read clusterctl config from ClusterctlConfigPath.
446
- clusterctlConfigFile := & clusterctlConfig {
447
- Path : input .ClusterctlConfigPath ,
448
- }
449
- clusterctlConfigFile .read ()
450
-
451
- // Overwrite variables.
452
- if clusterctlConfigFile .Values == nil {
453
- clusterctlConfigFile .Values = map [string ]interface {}{}
454
- }
455
- for key , value := range input .Variables {
456
- clusterctlConfigFile .Values [key ] = value
457
- }
458
-
459
- // Write clusterctl config to OutputPath.
460
- clusterctlConfigFile .Path = input .OutputPath
461
- clusterctlConfigFile .write ()
462
- }
463
-
464
- type clusterctlConfig struct {
465
- Path string
466
- Values map [string ]interface {}
467
- }
468
-
469
- // write writes a clusterctl config file to disk.
470
- func (c * clusterctlConfig ) write () {
471
- data , err := yaml .Marshal (c .Values )
472
- Expect (err ).ToNot (HaveOccurred (), "Failed to marshal the clusterctl config file" )
473
-
474
- Expect (os .WriteFile (c .Path , data , 0600 )).To (Succeed (), "Failed to write the clusterctl config file" )
475
- }
476
-
477
- // read reads a clusterctl config file from disk.
478
- func (c * clusterctlConfig ) read () {
479
- data , err := os .ReadFile (c .Path )
480
- Expect (err ).ToNot (HaveOccurred ())
481
-
482
- err = yaml .Unmarshal (data , & c .Values )
483
- Expect (err ).ToNot (HaveOccurred (), "Failed to unmarshal the clusterctl config file" )
484
- }
0 commit comments