github.com/openshift/installer@v1.4.17/pkg/asset/installconfig/openstack/validate.go (about)

     1  package openstack
     2  
     3  import (
     4  	"context"
     5  	"os"
     6  
     7  	"github.com/sirupsen/logrus"
     8  	"k8s.io/apimachinery/pkg/util/validation/field"
     9  
    10  	"github.com/openshift/installer/pkg/asset/installconfig/openstack/validation"
    11  	"github.com/openshift/installer/pkg/types"
    12  	"github.com/openshift/installer/pkg/types/openstack"
    13  	openstackdefaults "github.com/openshift/installer/pkg/types/openstack/defaults"
    14  	"github.com/openshift/installer/pkg/types/openstack/validation/networkextensions"
    15  )
    16  
    17  // Validate validates the given installconfig for OpenStack platform
    18  func Validate(ctx context.Context, ic *types.InstallConfig) error {
    19  	if skip := os.Getenv("OPENSHIFT_INSTALL_SKIP_PREFLIGHT_VALIDATIONS"); skip == "1" {
    20  		logrus.Warnf("OVERRIDE: pre-flight validation disabled.")
    21  		return nil
    22  	}
    23  
    24  	ci, err := validation.GetCloudInfo(ctx, ic)
    25  	if err != nil {
    26  		return err
    27  	}
    28  	if ci == nil {
    29  		logrus.Warnf("Empty OpenStack cloud info and therefore will skip pre-flight validation.")
    30  		return nil
    31  	}
    32  
    33  	if err := ValidateCloud(ci); err != nil {
    34  		return err
    35  	}
    36  
    37  	allErrs := field.ErrorList{}
    38  
    39  	// Validate platform
    40  	allErrs = append(allErrs, validation.ValidatePlatform(ic.Platform.OpenStack, ic.Networking, ci)...)
    41  
    42  	// Validate control plane
    43  	controlPlane := defaultOpenStackMachinePoolPlatform()
    44  	controlPlane.Set(ic.Platform.OpenStack.DefaultMachinePlatform)
    45  	controlPlane.Set(ic.ControlPlane.Platform.OpenStack)
    46  	if controlPlane.RootVolume != nil && controlPlane.RootVolume.Zones == nil {
    47  		controlPlane.RootVolume.Zones = []string{openstackdefaults.DefaultRootVolumeAZ()}
    48  	}
    49  	allErrs = append(allErrs, validation.ValidateMachinePool(&controlPlane, ci, true, field.NewPath("controlPlane", "platform", "openstack"))...)
    50  
    51  	// Validate computes
    52  	for idx := range ic.Compute {
    53  		compute := defaultOpenStackMachinePoolPlatform()
    54  		compute.Set(ic.Platform.OpenStack.DefaultMachinePlatform)
    55  		compute.Set(ic.Compute[idx].Platform.OpenStack)
    56  		if compute.RootVolume != nil && compute.RootVolume.Zones == nil {
    57  			compute.RootVolume.Zones = []string{openstackdefaults.DefaultRootVolumeAZ()}
    58  		}
    59  		fldPath := field.NewPath("compute").Index(idx)
    60  		allErrs = append(allErrs, validation.ValidateMachinePool(&compute, ci, false, fldPath.Child("platform", "openstack"))...)
    61  	}
    62  
    63  	return allErrs.ToAggregate()
    64  }
    65  
    66  // ValidateForProvisioning validates that the install config is valid for provisioning the cluster.
    67  func ValidateForProvisioning(ic *types.InstallConfig) error {
    68  	if ic.ControlPlane.Replicas != nil && *ic.ControlPlane.Replicas > 3 {
    69  		return field.Invalid(field.NewPath("controlPlane", "replicas"), ic.ControlPlane.Replicas, "control plane cannot be more than three nodes when provisioning on OpenStack")
    70  	}
    71  	return nil
    72  }
    73  
    74  func defaultOpenStackMachinePoolPlatform() openstack.MachinePool {
    75  	return openstack.MachinePool{
    76  		Zones: []string{""},
    77  	}
    78  }
    79  
    80  // ValidateCloud checks OpenStack requirements, regardless of the InstallConfig.
    81  func ValidateCloud(ci *validation.CloudInfo) error {
    82  	return networkextensions.Validate(ci.NetworkExtensions)
    83  }