-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[release-4.13] OCPBUGS-14432: Check that number of replicas matches hosts #7221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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++ | ||
| } | ||
| } | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will fail spuriously in a case like: We need to iterate over the hosts twice, once to count the explicit roles and once for the implicit ones.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that the original validation was taken from the #5205, where the very same test scenario was addressed by having the hosts sorted by role before applying the validation.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @andfasano, yes it was based on the baremetal validation. As this list will be sorted I think we can use the one loop as it currently has and not need to iterate over the hosts a 2nd time. |
||
|
|
||
| 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 { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given that defining hosts is completely optional, I don't think we should have a warning in the case where
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll add a check for numWorkers/numMasters != 0. Per the previous comment I'll add this a new master PR. |
||
| logrus.Warnf("The number of hosts configured as workers (%d) does not match the worker replicas (%d)", numWorkers, numRequiredWorkers) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be unconditional if we want to catch the case where there are more hosts defined than replicas.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. As this PR is auto cherry-pick of #7059 I'll create a new master PR/bug and fix it there, then cherry-pick that.