1
0
mirror of https://github.com/rancher/rke.git synced 2025-08-02 07:43:04 +00:00

Merge pull request #344 from galal-hussein/stop_duplicate_nodes

Validate Duplicate nodes
This commit is contained in:
Alena Prokharchyk 2018-02-21 17:00:53 -08:00 committed by GitHub
commit bc8917702c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -13,6 +13,11 @@ func (c *Cluster) ValidateCluster() error {
return err
}
// validate duplicate nodes
if err := validateDuplicateNodes(c); err != nil {
return err
}
// validate hosts options
if err := validateHostsOptions(c); err != nil {
return err
@ -126,3 +131,20 @@ func ValidateHostCount(c *Cluster) error {
}
return nil
}
func validateDuplicateNodes(c *Cluster) error {
for i := range c.Nodes {
for j := range c.Nodes {
if i == j {
continue
}
if c.Nodes[i].Address == c.Nodes[j].Address {
return fmt.Errorf("Cluster can't have duplicate node: %s", c.Nodes[i].Address)
}
if c.Nodes[i].HostnameOverride == c.Nodes[j].HostnameOverride {
return fmt.Errorf("Cluster can't have duplicate node: %s", c.Nodes[i].HostnameOverride)
}
}
}
return nil
}