From 43fbb06426e5f3f8e894059d9eff5b41e03c1cae Mon Sep 17 00:00:00 2001 From: Thomas Tendyck Date: Sun, 19 Mar 2023 16:05:01 +0100 Subject: [PATCH] cli: remove ctx parameter from rollbackOnError to prevent wrong use --- cli/internal/cloudcmd/create.go | 10 +++++----- cli/internal/cloudcmd/iam.go | 6 +++--- cli/internal/cloudcmd/rollback.go | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cli/internal/cloudcmd/create.go b/cli/internal/cloudcmd/create.go index 4f7c1c157..a722edeff 100644 --- a/cli/internal/cloudcmd/create.go +++ b/cli/internal/cloudcmd/create.go @@ -130,7 +130,7 @@ func (c *Creator) createAWS(ctx context.Context, cl terraformClient, config *con return clusterid.File{}, err } - defer rollbackOnError(context.Background(), c.out, &retErr, &rollbackerTerraform{client: cl}) + defer rollbackOnError(c.out, &retErr, &rollbackerTerraform{client: cl}) tfOutput, err := cl.CreateCluster(ctx) if err != nil { return clusterid.File{}, err @@ -168,7 +168,7 @@ func (c *Creator) createGCP(ctx context.Context, cl terraformClient, config *con return clusterid.File{}, err } - defer rollbackOnError(context.Background(), c.out, &retErr, &rollbackerTerraform{client: cl}) + defer rollbackOnError(c.out, &retErr, &rollbackerTerraform{client: cl}) tfOutput, err := cl.CreateCluster(ctx) if err != nil { return clusterid.File{}, err @@ -209,7 +209,7 @@ func (c *Creator) createAzure(ctx context.Context, cl terraformClient, config *c return clusterid.File{}, err } - defer rollbackOnError(context.Background(), c.out, &retErr, &rollbackerTerraform{client: cl}) + defer rollbackOnError(c.out, &retErr, &rollbackerTerraform{client: cl}) tfOutput, err := cl.CreateCluster(ctx) if err != nil { return clusterid.File{}, err @@ -288,7 +288,7 @@ func (c *Creator) createOpenStack(ctx context.Context, cl terraformClient, confi return clusterid.File{}, err } - defer rollbackOnError(context.Background(), c.out, &retErr, &rollbackerTerraform{client: cl}) + defer rollbackOnError(c.out, &retErr, &rollbackerTerraform{client: cl}) tfOutput, err := cl.CreateCluster(ctx) if err != nil { return clusterid.File{}, err @@ -306,7 +306,7 @@ func (c *Creator) createQEMU(ctx context.Context, cl terraformClient, lv libvirt controlPlaneCount, workerCount int, source string, ) (idFile clusterid.File, retErr error) { qemuRollbacker := &rollbackerQEMU{client: cl, libvirt: lv, createdWorkspace: false} - defer rollbackOnError(context.Background(), c.out, &retErr, qemuRollbacker) + defer rollbackOnError(c.out, &retErr, qemuRollbacker) // TODO: render progress bar downloader := c.newRawDownloader() diff --git a/cli/internal/cloudcmd/iam.go b/cli/internal/cloudcmd/iam.go index 73c84fafe..f83a68eb5 100644 --- a/cli/internal/cloudcmd/iam.go +++ b/cli/internal/cloudcmd/iam.go @@ -152,7 +152,7 @@ func (c *IAMCreator) Create(ctx context.Context, provider cloudprovider.Provider // createGCP creates the IAM configuration on GCP. func (c *IAMCreator) createGCP(ctx context.Context, cl terraformClient, iamConfig *IAMConfig) (retFile iamid.File, retErr error) { - defer rollbackOnError(context.Background(), c.out, &retErr, &rollbackerTerraform{client: cl}) + defer rollbackOnError(c.out, &retErr, &rollbackerTerraform{client: cl}) vars := terraform.GCPIAMVariables{ ServiceAccountID: iamConfig.GCP.ServiceAccountID, @@ -180,7 +180,7 @@ func (c *IAMCreator) createGCP(ctx context.Context, cl terraformClient, iamConfi // createAzure creates the IAM configuration on Azure. func (c *IAMCreator) createAzure(ctx context.Context, cl terraformClient, iamConfig *IAMConfig) (retFile iamid.File, retErr error) { - defer rollbackOnError(context.Background(), c.out, &retErr, &rollbackerTerraform{client: cl}) + defer rollbackOnError(c.out, &retErr, &rollbackerTerraform{client: cl}) vars := terraform.AzureIAMVariables{ Region: iamConfig.Azure.Region, @@ -211,7 +211,7 @@ func (c *IAMCreator) createAzure(ctx context.Context, cl terraformClient, iamCon // createAWS creates the IAM configuration on AWS. func (c *IAMCreator) createAWS(ctx context.Context, cl terraformClient, iamConfig *IAMConfig) (retFile iamid.File, retErr error) { - defer rollbackOnError(context.Background(), c.out, &retErr, &rollbackerTerraform{client: cl}) + defer rollbackOnError(c.out, &retErr, &rollbackerTerraform{client: cl}) vars := terraform.AWSIAMVariables{ Region: iamConfig.AWS.Region, diff --git a/cli/internal/cloudcmd/rollback.go b/cli/internal/cloudcmd/rollback.go index 50ff1a6e9..b98f65133 100644 --- a/cli/internal/cloudcmd/rollback.go +++ b/cli/internal/cloudcmd/rollback.go @@ -20,13 +20,13 @@ type rollbacker interface { // rollbackOnError calls rollback on the rollbacker if the handed error is not nil, // and writes logs to the writer w. -func rollbackOnError(ctx context.Context, w io.Writer, onErr *error, roll rollbacker) { +func rollbackOnError(w io.Writer, onErr *error, roll rollbacker) { if *onErr == nil { return } fmt.Fprintf(w, "An error occurred: %s\n", *onErr) fmt.Fprintln(w, "Attempting to roll back.") - if err := roll.rollback(ctx); err != nil { + if err := roll.rollback(context.Background()); err != nil { *onErr = errors.Join(*onErr, fmt.Errorf("on rollback: %w", err)) // TODO: print the error, or return it? return }