Skip to content

Commit c6a948a

Browse files
committed
chore: start using clusterctl context in external functions
1 parent 47d5e3c commit c6a948a

File tree

4 files changed

+24
-20
lines changed

4 files changed

+24
-20
lines changed

hack/tools/tilt-prepare/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,14 +542,14 @@ func preLoadImageTask(image string) taskFunction {
542542
// certManagerTask generates a task for installing cert-manager if not already present.
543543
func certManagerTask() taskFunction {
544544
return func(ctx context.Context, prefix string, errCh chan error) {
545-
config, err := config.New("")
545+
config, err := config.New(ctx, "")
546546
if err != nil {
547547
errCh <- errors.Wrapf(err, "[%s] failed create clusterctl config", prefix)
548548
return
549549
}
550550
cluster := cluster.New(cluster.Kubeconfig{}, config)
551551

552-
if err := cluster.CertManager().EnsureInstalled(); err != nil {
552+
if err := cluster.CertManager().EnsureInstalled(ctx); err != nil {
553553
errCh <- errors.Wrapf(err, "[%s] failed to install cert-manger", prefix)
554554
}
555555
}

test/framework/autoscaler_helpers.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,13 @@ type ProcessYAMLInput struct {
220220
}
221221

222222
func ProcessYAML(input *ProcessYAMLInput) ([]byte, error) {
223+
ctx := context.Background()
224+
223225
for n, v := range input.Env {
224226
_ = os.Setenv(n, v)
225227
}
226228

227-
c, err := clusterctlclient.New(input.ClusterctlConfigPath)
229+
c, err := clusterctlclient.New(ctx, input.ClusterctlConfigPath)
228230
if err != nil {
229231
return nil, err
230232
}
@@ -234,7 +236,7 @@ func ProcessYAML(input *ProcessYAMLInput) ([]byte, error) {
234236
},
235237
}
236238

237-
printer, err := c.ProcessYAML(options)
239+
printer, err := c.ProcessYAML(ctx, options)
238240
if err != nil {
239241
return nil, err
240242
}

test/framework/clusterctl/client.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ type InitInput struct {
6161
}
6262

6363
// Init calls clusterctl init with the list of providers defined in the local repository.
64-
func Init(_ context.Context, input InitInput) {
64+
func Init(ctx context.Context, input InitInput) {
6565
args := calculateClusterCtlInitArgs(input)
6666
log.Logf("clusterctl %s", strings.Join(args, " "))
6767

@@ -81,10 +81,10 @@ func Init(_ context.Context, input InitInput) {
8181
WaitProviders: true,
8282
}
8383

84-
clusterctlClient, log := getClusterctlClientWithLogger(input.ClusterctlConfigPath, "clusterctl-init.log", input.LogFolder)
84+
clusterctlClient, log := getClusterctlClientWithLogger(ctx, input.ClusterctlConfigPath, "clusterctl-init.log", input.LogFolder)
8585
defer log.Close()
8686

87-
_, err := clusterctlClient.Init(initOpt)
87+
_, err := clusterctlClient.Init(ctx, initOpt)
8888
Expect(err).ToNot(HaveOccurred(), "failed to run clusterctl init")
8989
}
9090

@@ -209,10 +209,10 @@ func Upgrade(ctx context.Context, input UpgradeInput) {
209209
WaitProviders: true,
210210
}
211211

212-
clusterctlClient, log := getClusterctlClientWithLogger(input.ClusterctlConfigPath, "clusterctl-upgrade.log", input.LogFolder)
212+
clusterctlClient, log := getClusterctlClientWithLogger(ctx, input.ClusterctlConfigPath, "clusterctl-upgrade.log", input.LogFolder)
213213
defer log.Close()
214214

215-
err := clusterctlClient.ApplyUpgrade(upgradeOpt)
215+
err := clusterctlClient.ApplyUpgrade(ctx, upgradeOpt)
216216
Expect(err).ToNot(HaveOccurred(), "failed to run clusterctl upgrade")
217217
}
218218

@@ -224,7 +224,7 @@ type DeleteInput struct {
224224
}
225225

226226
// Delete calls clusterctl delete --all.
227-
func Delete(_ context.Context, input DeleteInput) {
227+
func Delete(ctx context.Context, input DeleteInput) {
228228
log.Logf("clusterctl delete --all")
229229

230230
deleteOpts := clusterctlclient.DeleteOptions{
@@ -235,10 +235,10 @@ func Delete(_ context.Context, input DeleteInput) {
235235
DeleteAll: true,
236236
}
237237

238-
clusterctlClient, log := getClusterctlClientWithLogger(input.ClusterctlConfigPath, "clusterctl-delete.log", input.LogFolder)
238+
clusterctlClient, log := getClusterctlClientWithLogger(ctx, input.ClusterctlConfigPath, "clusterctl-delete.log", input.LogFolder)
239239
defer log.Close()
240240

241-
err := clusterctlClient.Delete(deleteOpts)
241+
err := clusterctlClient.Delete(ctx, deleteOpts)
242242
Expect(err).ToNot(HaveOccurred(), "failed to run clusterctl upgrade")
243243
}
244244

@@ -294,10 +294,10 @@ func ConfigCluster(ctx context.Context, input ConfigClusterInput) []byte {
294294
input.ClusterctlConfigPath = outputPath
295295
}
296296

297-
clusterctlClient, log := getClusterctlClientWithLogger(input.ClusterctlConfigPath, fmt.Sprintf("%s-cluster-template.yaml", input.ClusterName), input.LogFolder)
297+
clusterctlClient, log := getClusterctlClientWithLogger(ctx, input.ClusterctlConfigPath, fmt.Sprintf("%s-cluster-template.yaml", input.ClusterName), input.LogFolder)
298298
defer log.Close()
299299

300-
template, err := clusterctlClient.GetClusterTemplate(templateOptions)
300+
template, err := clusterctlClient.GetClusterTemplate(ctx, templateOptions)
301301
Expect(err).ToNot(HaveOccurred(), "Failed to run clusterctl config cluster")
302302

303303
yaml, err := template.Yaml()
@@ -403,25 +403,25 @@ func Move(ctx context.Context, input MoveInput) {
403403
input.Namespace,
404404
)
405405

406-
clusterctlClient, log := getClusterctlClientWithLogger(input.ClusterctlConfigPath, "clusterctl-move.log", logDir)
406+
clusterctlClient, log := getClusterctlClientWithLogger(ctx, input.ClusterctlConfigPath, "clusterctl-move.log", logDir)
407407
defer log.Close()
408408
options := clusterctlclient.MoveOptions{
409409
FromKubeconfig: clusterctlclient.Kubeconfig{Path: input.FromKubeconfigPath, Context: ""},
410410
ToKubeconfig: clusterctlclient.Kubeconfig{Path: input.ToKubeconfigPath, Context: ""},
411411
Namespace: input.Namespace,
412412
}
413413

414-
Expect(clusterctlClient.Move(options)).To(Succeed(), "Failed to run clusterctl move")
414+
Expect(clusterctlClient.Move(ctx, options)).To(Succeed(), "Failed to run clusterctl move")
415415
}
416416

417-
func getClusterctlClientWithLogger(configPath, logName, logFolder string) (clusterctlclient.Client, *logger.LogFile) {
417+
func getClusterctlClientWithLogger(ctx context.Context, configPath, logName, logFolder string) (clusterctlclient.Client, *logger.LogFile) {
418418
log := logger.OpenLogFile(logger.OpenLogFileInput{
419419
LogFolder: logFolder,
420420
Name: logName,
421421
})
422422
clusterctllog.SetLogger(log.Logger())
423423

424-
c, err := clusterctlclient.New(configPath)
424+
c, err := clusterctlclient.New(ctx, configPath)
425425
Expect(err).ToNot(HaveOccurred(), "Failed to create the clusterctl client library")
426426
return c, log
427427
}

test/framework/ownerreference_helpers.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ func AssertOwnerReferences(namespace, kubeconfigPath string, assertFuncs ...map[
8484
}
8585
Eventually(func() error {
8686
allErrs := []error{}
87-
graph, err := clusterctlcluster.GetOwnerGraph(namespace, kubeconfigPath)
87+
ctx := context.Background()
88+
89+
graph, err := clusterctlcluster.GetOwnerGraph(ctx, namespace, kubeconfigPath)
8890
Expect(err).To(BeNil())
8991
for _, v := range graph {
9092
if _, ok := allAssertFuncs[v.Object.Kind]; !ok {
@@ -340,7 +342,7 @@ func forceClusterClassReconcile(ctx context.Context, cli client.Client, clusterK
340342
}
341343

342344
func removeOwnerReferences(ctx context.Context, proxy ClusterProxy, namespace string) {
343-
graph, err := clusterctlcluster.GetOwnerGraph(namespace, proxy.GetKubeconfigPath())
345+
graph, err := clusterctlcluster.GetOwnerGraph(ctx, namespace, proxy.GetKubeconfigPath())
344346
Expect(err).To(BeNil())
345347
for _, object := range graph {
346348
ref := object.Object

0 commit comments

Comments
 (0)