@@ -15,6 +15,7 @@ import (
1515 coreosarch "github.com/coreos/stream-metadata-go/arch"
1616 "github.com/pkg/errors"
1717 "github.com/sirupsen/logrus"
18+ "k8s.io/utils/ptr"
1819 "sigs.k8s.io/yaml"
1920
2021 configv1 "github.com/openshift/api/config/v1"
@@ -214,6 +215,11 @@ func (t *TerraformVariables) Generate(parents asset.Parents) error {
214215 return errors .Errorf ("master slice cannot be empty" )
215216 }
216217
218+ numWorkers := int64 (0 )
219+ for _ , worker := range installConfig .Config .Compute {
220+ numWorkers += ptr .Deref (worker .Replicas , 0 )
221+ }
222+
217223 switch platform {
218224 case aws .Name :
219225 var vpc string
@@ -267,13 +273,7 @@ func (t *TerraformVariables) Generate(parents asset.Parents) error {
267273 if err != nil {
268274 return err
269275 }
270- // Based on the number of workers, we could have the following outcomes:
271- // 1. workers > 0, masters not schedulable, valid cluster
272- // 2. workers = 0, masters schedulable, valid compact cluster but currently unsupported
273- // 3. workers = 0, masters not schedulable, invalid cluster
274- if len (workers ) == 0 {
275- return errors .Errorf ("compact clusters with 0 workers are not supported at this time" )
276- }
276+
277277 workerConfigs := make ([]* machinev1beta1.AWSMachineProviderConfig , len (workers ))
278278 for i , m := range workers {
279279 workerConfigs [i ] = m .Spec .Template .Spec .ProviderSpec .Value .Object .(* machinev1beta1.AWSMachineProviderConfig ) //nolint:errcheck // legacy, pre-linter
@@ -372,13 +372,6 @@ func (t *TerraformVariables) Generate(parents asset.Parents) error {
372372 if err != nil {
373373 return err
374374 }
375- // Based on the number of workers, we could have the following outcomes:
376- // 1. workers > 0, masters not schedulable, valid cluster
377- // 2. workers = 0, masters schedulable, valid compact cluster but currently unsupported
378- // 3. workers = 0, masters not schedulable, invalid cluster
379- if len (workers ) == 0 {
380- return errors .Errorf ("compact clusters with 0 workers are not supported at this time" )
381- }
382375 workerConfigs := make ([]* machinev1beta1.AzureMachineProviderSpec , len (workers ))
383376 for i , w := range workers {
384377 workerConfigs [i ] = w .Spec .Template .Spec .ProviderSpec .Value .Object .(* machinev1beta1.AzureMachineProviderSpec ) //nolint:errcheck // legacy, pre-linter
@@ -495,12 +488,16 @@ func (t *TerraformVariables) Generate(parents asset.Parents) error {
495488 return err
496489 }
497490 // Based on the number of workers, we could have the following outcomes:
498- // 1. workers > 0, masters not schedulable, valid cluster
499- // 2. workers = 0, masters schedulable, valid compact cluster but currently unsupported
500- // 3. workers = 0, masters not schedulable, invalid cluster
501- if len (workers ) == 0 {
502- return errors .Errorf ("compact clusters with 0 workers are not supported at this time" )
491+ // 1. compute replicas > 0, worker machinesets > 0, masters not schedulable, valid cluster
492+ // 2. compute replicas > 0, worker machinesets = 0, invalid cluster
493+ // 3. compute replicas = 0, masters schedulable, valid cluster
494+ if numWorkers != 0 && len (workers ) == 0 {
495+ return fmt .Errorf ("invalid configuration. No worker assets available for requested number of compute replicas (%d)" , numWorkers )
503496 }
497+ if numWorkers == 0 && ! mastersSchedulable {
498+ return fmt .Errorf ("invalid configuration. No workers requested but masters are not schedulable" )
499+ }
500+
504501 workerConfigs := make ([]* machinev1beta1.GCPMachineProviderSpec , len (workers ))
505502 for i , w := range workers {
506503 workerConfigs [i ] = w .Spec .Template .Spec .ProviderSpec .Value .Object .(* machinev1beta1.GCPMachineProviderSpec ) //nolint:errcheck // legacy, pre-linter
0 commit comments