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

     1  package baremetal
     2  
     3  import (
     4  	"github.com/pkg/errors"
     5  	"k8s.io/apimachinery/pkg/util/validation/field"
     6  
     7  	"github.com/openshift/installer/pkg/types"
     8  	"github.com/openshift/installer/pkg/types/baremetal/validation"
     9  )
    10  
    11  // ValidateBaremetalPlatformSet ensures that the BareMetal platform data is populated
    12  func ValidateBaremetalPlatformSet(ic *types.InstallConfig) error {
    13  	if ic.Platform.BareMetal == nil {
    14  		return errors.New(field.Required(field.NewPath("platform", "baremetal"), "Baremetal validation requires a baremetal platform configuration").Error())
    15  	}
    16  
    17  	return nil
    18  }
    19  
    20  // ValidateProvisioning performs platform validation specifically for any optional requirement
    21  // to be called when the cluster creation takes place
    22  func ValidateProvisioning(ic *types.InstallConfig) error {
    23  	return validation.ValidateProvisioning(ic.Platform.BareMetal, ic.Networking, field.NewPath("platform").Child("baremetal")).ToAggregate()
    24  }
    25  
    26  // ValidateStaticBootstrapNetworking ensures that both or neither of  BootstrapExternalStaticIP and BootstrapExternalStaticGateway are set
    27  func ValidateStaticBootstrapNetworking(ic *types.InstallConfig) error {
    28  	if ic.Platform.BareMetal.BootstrapExternalStaticIP != "" && ic.Platform.BareMetal.BootstrapExternalStaticGateway == "" {
    29  		return errors.New(field.Required(field.NewPath("platform", "baremetal"), "You must specify a value for BootstrapExternalStaticGateway when BootstrapExternalStaticIP is set.").Error())
    30  	}
    31  
    32  	if ic.Platform.BareMetal.BootstrapExternalStaticIP != "" && ic.Platform.BareMetal.BootstrapExternalStaticDNS == "" {
    33  		return errors.New(field.Required(field.NewPath("platform", "baremetal"), "You must specify a value for BootstrapExternalStaticDNS when BootstrapExternalStaticIP is set.").Error())
    34  	}
    35  
    36  	if ic.Platform.BareMetal.BootstrapExternalStaticGateway != "" && ic.Platform.BareMetal.BootstrapExternalStaticIP == "" {
    37  		return errors.New(field.Required(field.NewPath("platform", "baremetal"), "You must specify a value for BootstrapExternalStaticIP when BootstrapExternalStaticGateway is set.").Error())
    38  	}
    39  
    40  	if ic.Platform.BareMetal.BootstrapExternalStaticGateway != "" && ic.Platform.BareMetal.BootstrapExternalStaticDNS == "" {
    41  		return errors.New(field.Required(field.NewPath("platform", "baremetal"), "You must specify a value for BootstrapExternalStaticDNS when BootstrapExternalStaticGateway is set.").Error())
    42  	}
    43  
    44  	if ic.Platform.BareMetal.BootstrapExternalStaticDNS != "" && ic.Platform.BareMetal.BootstrapExternalStaticIP == "" {
    45  		return errors.New(field.Required(field.NewPath("platform", "baremetal"), "You must specify a value for BootstrapExternalStaticIP when BootstrapExternalStaticDNS is set.").Error())
    46  	}
    47  
    48  	if ic.Platform.BareMetal.BootstrapExternalStaticDNS != "" && ic.Platform.BareMetal.BootstrapExternalStaticGateway == "" {
    49  		return errors.New(field.Required(field.NewPath("platform", "baremetal"), "You must specify a value for BootstrapExternalStaticGateway when BootstrapExternalStaticDNS is set.").Error())
    50  	}
    51  
    52  	return nil
    53  }