1
0
mirror of https://github.com/openshift/installer.git synced 2026-02-05 15:47:14 +01:00

on-prem: Add check to validate cluster name for dots

On Prem clusters with a dot in the cluster name causes issues
in keepalived and should be validated to prevent this. Adding
an extra check to make sure there are no dots in the cluster
name.
This commit is contained in:
rna-afk
2022-05-19 10:48:53 -04:00
parent bdab9b334f
commit b8537e0dd0
4 changed files with 38 additions and 0 deletions

View File

@@ -48,6 +48,11 @@ func (a *clusterName) Generate(parents asset.Parents) error {
return validate.ClusterNameMaxLength(ans.(string), 14)
})
}
if platform.VSphere != nil || platform.BareMetal != nil {
validator = survey.ComposeValidators(validator, func(ans interface{}) error {
return validate.OnPremClusterName(ans.(string))
})
}
validator = survey.ComposeValidators(validator, func(ans interface{}) error {
installConfig := &types.InstallConfig{BaseDomain: bd.BaseDomain}
installConfig.ObjectMeta.Name = ans.(string)

View File

@@ -92,6 +92,9 @@ func ValidateInstallConfig(c *types.InstallConfig) field.ErrorList {
// FIX-ME: As soon bz#1915122 get resolved remove the limitation of 14 chars for the clustername
nameErr = validate.ClusterNameMaxLength(c.ObjectMeta.Name, 14)
}
if c.Platform.VSphere != nil || c.Platform.BareMetal != nil {
nameErr = validate.OnPremClusterName(c.ObjectMeta.Name)
}
if nameErr != nil {
allErrs = append(allErrs, field.Invalid(field.NewPath("metadata", "name"), c.ObjectMeta.Name, nameErr.Error()))
}

View File

@@ -279,3 +279,11 @@ func Host(v string) error {
}
return validateSubdomain(v)
}
// OnPremClusterName verifies if the cluster name contains a '.' and returns an error if it does.
func OnPremClusterName(v string) error {
if strings.Contains(v, ".") {
return errors.New("cluster name must not contain '.'")
}
return ClusterName(v)
}

View File

@@ -49,6 +49,28 @@ func TestClusterName(t *testing.T) {
}
}
func TestOnPremClusterName(t *testing.T) {
cases := []struct {
name string
clusterName string
valid bool
}{
{"single lowercase", "a", true},
{"has a dot", "a.a", false},
{"valid name", "abcde", true},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
err := OnPremClusterName(tc.clusterName)
if tc.valid {
assert.NoError(t, err)
} else {
assert.Error(t, err)
}
})
}
}
func TestClusterName1035(t *testing.T) {
maxSizeName := "a" + strings.Repeat("123456789.", 5) + "123"