diff --git a/pkg/asset/agent/installconfig.go b/pkg/asset/agent/installconfig.go index 0239834bda1..a36dfd2606e 100644 --- a/pkg/asset/agent/installconfig.go +++ b/pkg/asset/agent/installconfig.go @@ -77,6 +77,9 @@ func (a *OptionalInstallConfig) validateInstallConfig(installConfig *types.Insta warnUnusedConfig(installConfig) + numMasters, numWorkers := GetReplicaCount(installConfig) + logrus.Infof(fmt.Sprintf("Configuration has %d master replicas and %d worker replicas", numMasters, numWorkers)) + if err := a.validateSNOConfiguration(installConfig); err != nil { allErrs = append(allErrs, err...) } @@ -388,3 +391,20 @@ func warnUnusedConfig(installConfig *types.InstallConfig) { logrus.Warnf(fmt.Sprintf("%s: %s is ignored", fieldPath, installConfig.BootstrapInPlace.InstallationDisk)) } } + +// GetReplicaCount gets the configured master and worker replicas. +func GetReplicaCount(installConfig *types.InstallConfig) (numMasters, numWorkers int64) { + numRequiredMasters := int64(0) + if installConfig.ControlPlane != nil && installConfig.ControlPlane.Replicas != nil { + numRequiredMasters += *installConfig.ControlPlane.Replicas + } + + numRequiredWorkers := int64(0) + for _, worker := range installConfig.Compute { + if worker.Replicas != nil { + numRequiredWorkers += *worker.Replicas + } + } + + return numRequiredMasters, numRequiredWorkers +} diff --git a/pkg/asset/agent/manifests/nmstateconfig.go b/pkg/asset/agent/manifests/nmstateconfig.go index 66f978f11bc..005875ed50d 100644 --- a/pkg/asset/agent/manifests/nmstateconfig.go +++ b/pkg/asset/agent/manifests/nmstateconfig.go @@ -22,6 +22,7 @@ import ( "github.com/openshift/installer/pkg/asset" "github.com/openshift/installer/pkg/asset/agent" "github.com/openshift/installer/pkg/asset/agent/agentconfig" + "github.com/openshift/installer/pkg/types" ) var ( @@ -82,6 +83,8 @@ func (n *NMStateConfig) Generate(dependencies asset.Parents) error { if len(agentConfig.Config.Hosts) == 0 { return nil } + checkHostCount(installConfig.Config, agentConfig) + for i, host := range agentConfig.Config.Hosts { if host.NetworkConfig.Raw != nil { isNetworkConfigAvailable = true @@ -336,3 +339,33 @@ func buildMacInterfaceMap(nmStateConfig aiv1beta1.NMStateConfig) models.MacInter } return macInterfaceMap } + +func checkHostCount(installConfig *types.InstallConfig, agentConfig *agentconfig.AgentConfig) { + numRequiredMasters, numRequiredWorkers := agent.GetReplicaCount(installConfig) + + // Check that the number of replicas matches the configured hosts + numMasters := int64(0) + numWorkers := int64(0) + for _, host := range agentConfig.Config.Hosts { + switch host.Role { + case "master": + numMasters++ + case "worker": + numWorkers++ + case "": + // If not defined, the roles will be matched to replicas + if numMasters < numRequiredMasters { + numMasters++ + } else if numWorkers < numRequiredWorkers { + numWorkers++ + } + } + } + + if numMasters != numRequiredMasters { + logrus.Warnf("The number of hosts configured as masters (%d) does not match the master replicas (%d)", numMasters, numRequiredMasters) + } + if numWorkers != numRequiredWorkers { + logrus.Warnf("The number of hosts configured as workers (%d) does not match the worker replicas (%d)", numWorkers, numRequiredWorkers) + } +}