Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions pkg/asset/cluster/tfvars/tfvars.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we cannot check this during install-config validation because this happens after the manifests have been generated and (possibly) edited by users.
If this becomes a pattern, we should consider adding a manifest validation stage.

Copy link
Contributor Author

@sadasu sadasu Apr 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@r4f4 yes. I was surprised too that we allow customers to edit the manifests post creation but don't check if it has been modified in a sane way.

Also, this fix is added in the code path to generate terraform inputs. Let us invest the time to figure out how to add a manifest validation stage within the CAPI flow so we detect modified manifests and validate them.

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
Expand Down