From 94eeb5dadca60b16102de852d11b7a1174d523ac Mon Sep 17 00:00:00 2001 From: Sandhya Dasu Date: Tue, 2 Apr 2024 08:56:30 -0400 Subject: [PATCH] Improve error handling around compact-cluster installs Worker machinesets generated, during create manifests can be deleted before creating the cluster. Detect this case and take action based on whether masters are marked as schedulable. This fixes compact cluster installs on GCP, AWS and Azure. --- pkg/asset/cluster/tfvars/tfvars.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/pkg/asset/cluster/tfvars/tfvars.go b/pkg/asset/cluster/tfvars/tfvars.go index 9c80141a3b6..6e86d963254 100644 --- a/pkg/asset/cluster/tfvars/tfvars.go +++ b/pkg/asset/cluster/tfvars/tfvars.go @@ -272,6 +272,13 @@ func (t *TerraformVariables) Generate(parents asset.Parents) error { if err != nil { return err } + // Based on the number of workers, we could have the following outcomes: + // 1. workers > 0, masters not schedulable, valid cluster + // 2. workers = 0, masters schedulable, valid compact cluster but currently unsupported + // 3. workers = 0, masters not schedulable, invalid cluster + if len(workers) == 0 { + return errors.Errorf("compact clusters with 0 workers are not supported at this time") + } workerConfigs := make([]*machinev1beta1.AWSMachineProviderConfig, len(workers)) for i, m := range workers { workerConfigs[i] = m.Spec.Template.Spec.ProviderSpec.Value.Object.(*machinev1beta1.AWSMachineProviderConfig) //nolint:errcheck // legacy, pre-linter @@ -370,6 +377,13 @@ func (t *TerraformVariables) Generate(parents asset.Parents) error { if err != nil { return err } + // Based on the number of workers, we could have the following outcomes: + // 1. workers > 0, masters not schedulable, valid cluster + // 2. workers = 0, masters schedulable, valid compact cluster but currently unsupported + // 3. workers = 0, masters not schedulable, invalid cluster + if len(workers) == 0 { + return errors.Errorf("compact clusters with 0 workers are not supported at this time") + } workerConfigs := make([]*machinev1beta1.AzureMachineProviderSpec, len(workers)) for i, w := range workers { workerConfigs[i] = w.Spec.Template.Spec.ProviderSpec.Value.Object.(*machinev1beta1.AzureMachineProviderSpec) //nolint:errcheck // legacy, pre-linter @@ -485,6 +499,13 @@ func (t *TerraformVariables) Generate(parents asset.Parents) error { if err != nil { return err } + // Based on the number of workers, we could have the following outcomes: + // 1. workers > 0, masters not schedulable, valid cluster + // 2. workers = 0, masters schedulable, valid compact cluster but currently unsupported + // 3. workers = 0, masters not schedulable, invalid cluster + if len(workers) == 0 { + return errors.Errorf("compact clusters with 0 workers are not supported at this time") + } workerConfigs := make([]*machinev1beta1.GCPMachineProviderSpec, len(workers)) for i, w := range workers { workerConfigs[i] = w.Spec.Template.Spec.ProviderSpec.Value.Object.(*machinev1beta1.GCPMachineProviderSpec) //nolint:errcheck // legacy, pre-linter