Skip to content
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

Bug 1853859: Add validations for IP inputs #3862

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions pkg/asset/installconfig/vsphere/vsphere.go
Expand Up @@ -363,6 +363,9 @@ func getVIPs() (string, string, error) {
Help: "The VIP to be used for ingress to the cluster.",
},
Validate: survey.ComposeValidators(survey.Required, func(ans interface{}) error {
if apiVIP == (ans.(string)) {
return fmt.Errorf("%q should not be equal to the Virtual IP address for the API", ans.(string))
}
return validate.IP((ans).(string))
}),
},
Expand Down
4 changes: 4 additions & 0 deletions pkg/types/vsphere/validation/platform.go
Expand Up @@ -74,6 +74,10 @@ func validateVIPs(p *vsphere.Platform, fldPath *field.Path) field.ErrorList {
allErrs = append(allErrs, field.Invalid(fldPath.Child("ingressVIP"), p.IngressVIP, err.Error()))
}

if len(p.APIVIP) != 0 && len(p.IngressVIP) != 0 && p.APIVIP == p.IngressVIP {
allErrs = append(allErrs, field.Invalid(fldPath.Child("apiVIP"), p.APIVIP, "IPs for both API and Ingress should not be the same."))
}

return allErrs
}

Expand Down
10 changes: 10 additions & 0 deletions pkg/types/vsphere/validation/platform_test.go
Expand Up @@ -124,6 +124,16 @@ func TestValidatePlatform(t *testing.T) {
}(),
expectedError: `^test-path.ingressVIP: Invalid value: "192.168.111": "192.168.111" is not a valid IP`,
},
{
name: "Same API and Ingress VIP",
platform: func() *vsphere.Platform {
p := validPlatform()
p.APIVIP = "192.168.111.1"
p.IngressVIP = "192.168.111.1"
return p
}(),
expectedError: `^test-path.apiVIP: Invalid value: "192.168.111.1": IPs for both API and Ingress should not be the same`,
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
Expand Down