Skip to content

Commit

Permalink
Merge pull request openshift#111 from clnperez/aws-vsphere-validation…
Browse files Browse the repository at this point in the history
…-sync

aws and vsphere validation sync
  • Loading branch information
clnperez authored Feb 5, 2022
2 parents b8ba124 + c67ea2d commit d279ae1
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 8 deletions.
3 changes: 1 addition & 2 deletions pkg/asset/installconfig/aws/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/route53"
"github.com/pkg/errors"
"golang.org/x/net/proxy"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/validation/field"
Expand Down Expand Up @@ -329,7 +328,7 @@ func validateEndpointAccessibility(endpointURL string) error {
if port == "" {
port = "https"
}
conn, err := proxy.Dial(context.Background(), "tcp", net.JoinHostPort(URL.Hostname(), port))
conn, err := net.Dial("tcp", net.JoinHostPort(URL.Hostname(), port))
if err != nil {
return err
}
Expand Down
28 changes: 24 additions & 4 deletions pkg/asset/installconfig/vsphere/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,30 @@ func Validate(ic *types.InstallConfig) error {
return errors.New(field.Required(field.NewPath("platform", "vsphere"), "vSphere validation requires a vSphere platform configuration").Error())
}

return validation.ValidatePlatform(ic.Platform.VSphere, field.NewPath("platform").Child("vsphere")).ToAggregate()
p := ic.Platform.VSphere
if errs := validation.ValidatePlatform(p, field.NewPath("platform").Child("vsphere")); len(errs) != 0 {
return errs.ToAggregate()
}

vim25Client, _, err := vspheretypes.CreateVSphereClients(context.TODO(),
p.VCenter,
p.Username,
p.Password)

if err != nil {
return errors.New(field.InternalError(field.NewPath("platform", "vsphere"), errors.Wrapf(err, "unable to connect to vCenter %s.", p.VCenter)).Error())
}
finder := NewFinder(vim25Client)
return validateResources(finder, ic)
}

func validateResources(finder Finder, ic *types.InstallConfig) error {
allErrs := field.ErrorList{}
p := ic.Platform.VSphere
if p.Network != "" {
allErrs = append(allErrs, validateNetwork(finder, p, field.NewPath("platform").Child("vsphere").Child("network"))...)
}
return allErrs.ToAggregate()
}

// ValidateForProvisioning performs platform validation specifically for installer-
Expand Down Expand Up @@ -51,9 +74,6 @@ func validateProvisioning(finder Finder, ic *types.InstallConfig) error {
allErrs = append(allErrs, validation.ValidateForProvisioning(ic.Platform.VSphere, field.NewPath("platform").Child("vsphere"))...)
allErrs = append(allErrs, folderExists(finder, ic, field.NewPath("platform").Child("vsphere").Child("folder"))...)
allErrs = append(allErrs, resourcePoolExists(finder, ic, field.NewPath("platform").Child("vsphere").Child("resourcePool"))...)
if p := ic.Platform.VSphere; p.Network != "" {
allErrs = append(allErrs, validateNetwork(finder, p, field.NewPath("platform").Child("vsphere").Child("network"))...)
}

return allErrs.ToAggregate()
}
Expand Down
29 changes: 27 additions & 2 deletions pkg/asset/installconfig/vsphere/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,38 @@ func validIPIInstallConfig() *types.InstallConfig {
}
}

func validUPIInstallConfig() *types.InstallConfig {
return &types.InstallConfig{
Networking: &types.Networking{
MachineNetwork: []types.MachineNetworkEntry{
{CIDR: *ipnet.MustParseCIDR(validCIDR)},
},
},
Publish: types.ExternalPublishingStrategy,
Platform: types.Platform{
VSphere: &vsphere.Platform{
Datacenter: "valid_dc",
DefaultDatastore: "valid_ds",
Password: "valid_password",
Username: "valid_username",
VCenter: "valid-vcenter",
Network: "valid_network",
},
},
}
}

func TestValidate(t *testing.T) {
tests := []struct {
name string
installConfig *types.InstallConfig
validationMethod func(Finder, *types.InstallConfig) error
expectErr string
}{{
name: "valid UPI install config",
installConfig: validUPIInstallConfig(),
validationMethod: validateResources,
}, {
name: "valid IPI install config",
installConfig: validIPIInstallConfig(),
validationMethod: validateProvisioning,
Expand All @@ -68,7 +93,7 @@ func TestValidate(t *testing.T) {
c.Platform.VSphere.Datacenter = "invalid_dc"
return c
}(),
validationMethod: validateProvisioning,
validationMethod: validateResources,
expectErr: `^platform.vsphere.network: Invalid value: "invalid_dc": 404$`,
}, {
name: "invalid IPI - invalid network",
Expand All @@ -77,7 +102,7 @@ func TestValidate(t *testing.T) {
c.Platform.VSphere.Network = "invalid_network"
return c
}(),
validationMethod: validateProvisioning,
validationMethod: validateResources,
expectErr: `^platform.vsphere.network: Invalid value: "invalid_network": unable to find network provided$`,
}, {
name: "invalid IPI - no cluster",
Expand Down

0 comments on commit d279ae1

Please sign in to comment.