Skip to content

Commit

Permalink
K8S-10217 fix waiting for cluster update
Browse files Browse the repository at this point in the history
the status of the control plane components is flipped by a controller
which may not be quick enough before terraform checks it
  • Loading branch information
Robert Nemeti committed Jul 3, 2024
1 parent e9d599b commit 3bc02ea
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
28 changes: 13 additions & 15 deletions metakube/resource_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func metakubeResourceClusterCreate(ctx context.Context, d *schema.ResourceData,
return diag.FromErr(err)
}

if err := metakubeResourceClusterWaitForReady(ctx, meta, d.Timeout(schema.TimeoutCreate), projectID, d.Id()); err != nil {
if err := metakubeResourceClusterWaitForReady(ctx, meta, d.Timeout(schema.TimeoutCreate), projectID, d.Id(), ""); err != nil {
// In case of timeout, we still want to return the cluster resource
retDiags = append(retDiags, metakubeResourceClusterRead(ctx, d, m)...)
retDiags = append(retDiags, diag.Diagnostic{
Expand Down Expand Up @@ -610,7 +610,11 @@ func metakubeResourceClusterUpdate(ctx context.Context, d *schema.ResourceData,
}
}

if err := metakubeResourceClusterWaitForReady(ctx, k, d.Timeout(schema.TimeoutUpdate), projectID, d.Id()); err != nil {
configuredVersion, ok := d.GetOk("spec.0.version")
if !ok {
return nil
}
if err := metakubeResourceClusterWaitForReady(ctx, k, d.Timeout(schema.TimeoutUpdate), projectID, d.Id(), configuredVersion.(string)); err != nil {
return diag.Errorf("cluster '%s' is not ready: %v", d.Id(), err)
}

Expand Down Expand Up @@ -736,28 +740,22 @@ func assignSSHKeysToCluster(projectID, clusterID string, sshkeyIDs []string, k *
return nil
}

func metakubeResourceClusterWaitForReady(ctx context.Context, k *metakubeProviderMeta, timeout time.Duration, projectID, clusterID string) error {
func metakubeResourceClusterWaitForReady(ctx context.Context, k *metakubeProviderMeta, timeout time.Duration, projectID, clusterID, configuredVersion string) error {
return retry.RetryContext(ctx, timeout, func() *retry.RetryError {

p := project.NewGetClusterHealthV2Params()
p := project.NewGetClusterV2Params()
p.SetContext(ctx)
p.SetProjectID(projectID)
p.SetClusterID(clusterID)

r, err := k.client.Project.GetClusterHealthV2(p, k.auth)
r, err := k.client.Project.GetClusterV2(p, k.auth)
if err != nil {
return retry.RetryableError(fmt.Errorf("unable to get cluster '%s' health: %s", clusterID, stringifyResponseError(err)))
return retry.RetryableError(fmt.Errorf("unable to get cluster '%s': %s", clusterID, stringifyResponseError(err)))
}

const up models.HealthStatus = 1

if r.Payload.Apiserver == up &&
r.Payload.CloudProviderInfrastructure == up &&
r.Payload.Controller == up &&
r.Payload.Etcd == up &&
r.Payload.MachineController == up &&
r.Payload.Scheduler == up &&
r.Payload.UserClusterControllerManager == up {
if configuredVersion == "" {
return nil
} else if r.Payload.Status.Version == models.Semver(configuredVersion) {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion metakube/resource_maintenance_cronjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func metakubeResourceMaintenanceCronJobCreate(ctx context.Context, d *schema.Res
}

// TODO not sure to remove this
if err := metakubeResourceClusterWaitForReady(ctx, k, d.Timeout(schema.TimeoutCreate), projectID, clusterID); err != nil {
if err := metakubeResourceClusterWaitForReady(ctx, k, d.Timeout(schema.TimeoutCreate), projectID, clusterID, ""); err != nil {
return diag.Errorf("cluster is not ready: %v", err)
}

Expand Down
2 changes: 1 addition & 1 deletion metakube/resource_node_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func metakubeResourceNodeDeploymentCreate(ctx context.Context, d *schema.Resourc
return diag.FromErr(err)
}

if err := metakubeResourceClusterWaitForReady(ctx, k, d.Timeout(schema.TimeoutCreate), projectID, clusterID); err != nil {
if err := metakubeResourceClusterWaitForReady(ctx, k, d.Timeout(schema.TimeoutCreate), projectID, clusterID, ""); err != nil {
return diag.Errorf("cluster is not ready: %v", err)
}

Expand Down

0 comments on commit 3bc02ea

Please sign in to comment.