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

     1  package installconfig
     2  
     3  import (
     4  	"context"
     5  	"errors"
     6  	"fmt"
     7  
     8  	"k8s.io/apimachinery/pkg/util/validation/field"
     9  
    10  	configv1 "github.com/openshift/api/config/v1"
    11  	"github.com/openshift/installer/pkg/asset"
    12  	awsconfig "github.com/openshift/installer/pkg/asset/installconfig/aws"
    13  	azconfig "github.com/openshift/installer/pkg/asset/installconfig/azure"
    14  	bmconfig "github.com/openshift/installer/pkg/asset/installconfig/baremetal"
    15  	gcpconfig "github.com/openshift/installer/pkg/asset/installconfig/gcp"
    16  	ibmcloudconfig "github.com/openshift/installer/pkg/asset/installconfig/ibmcloud"
    17  	nutanixconfig "github.com/openshift/installer/pkg/asset/installconfig/nutanix"
    18  	osconfig "github.com/openshift/installer/pkg/asset/installconfig/openstack"
    19  	ovirtconfig "github.com/openshift/installer/pkg/asset/installconfig/ovirt"
    20  	powervsconfig "github.com/openshift/installer/pkg/asset/installconfig/powervs"
    21  	vsconfig "github.com/openshift/installer/pkg/asset/installconfig/vsphere"
    22  	"github.com/openshift/installer/pkg/types/aws"
    23  	"github.com/openshift/installer/pkg/types/azure"
    24  	"github.com/openshift/installer/pkg/types/baremetal"
    25  	baremetalvalidation "github.com/openshift/installer/pkg/types/baremetal/validation"
    26  	"github.com/openshift/installer/pkg/types/external"
    27  	"github.com/openshift/installer/pkg/types/gcp"
    28  	"github.com/openshift/installer/pkg/types/ibmcloud"
    29  	"github.com/openshift/installer/pkg/types/none"
    30  	"github.com/openshift/installer/pkg/types/nutanix"
    31  	"github.com/openshift/installer/pkg/types/openstack"
    32  	"github.com/openshift/installer/pkg/types/ovirt"
    33  	"github.com/openshift/installer/pkg/types/powervs"
    34  	"github.com/openshift/installer/pkg/types/vsphere"
    35  )
    36  
    37  // PlatformProvisionCheck is an asset that validates the install-config platform for
    38  // any requirements specific for provisioning infrastructure.
    39  type PlatformProvisionCheck struct {
    40  }
    41  
    42  var _ asset.Asset = (*PlatformProvisionCheck)(nil)
    43  
    44  // Dependencies returns the dependencies for PlatformProvisionCheck
    45  func (a *PlatformProvisionCheck) Dependencies() []asset.Asset {
    46  	return []asset.Asset{
    47  		&InstallConfig{},
    48  	}
    49  }
    50  
    51  // Generate queries for input from the user.
    52  //
    53  //nolint:gocyclo
    54  func (a *PlatformProvisionCheck) Generate(ctx context.Context, dependencies asset.Parents) error {
    55  	ic := &InstallConfig{}
    56  	dependencies.Get(ic)
    57  	platform := ic.Config.Platform.Name()
    58  
    59  	// IPI requires MachineAPI capability
    60  	enabledCaps := ic.Config.GetEnabledCapabilities()
    61  	if !enabledCaps.Has(configv1.ClusterVersionCapabilityMachineAPI) {
    62  		return errors.New("IPI requires MachineAPI capability")
    63  	}
    64  
    65  	switch platform {
    66  	case aws.Name:
    67  		session, err := ic.AWS.Session(ctx)
    68  		if err != nil {
    69  			return err
    70  		}
    71  		client := awsconfig.NewClient(session)
    72  		return awsconfig.ValidateForProvisioning(client, ic.Config, ic.AWS)
    73  	case azure.Name:
    74  		dnsConfig, err := ic.Azure.DNSConfig()
    75  		if err != nil {
    76  			return err
    77  		}
    78  		err = azconfig.ValidatePublicDNS(ic.Config, dnsConfig)
    79  		if err != nil {
    80  			return err
    81  		}
    82  		client, err := ic.Azure.Client()
    83  		if err != nil {
    84  			return err
    85  		}
    86  		return azconfig.ValidateForProvisioning(client, ic.Config)
    87  	case baremetal.Name:
    88  		err := bmconfig.ValidateBaremetalPlatformSet(ic.Config)
    89  		if err != nil {
    90  			return err
    91  		}
    92  		err = bmconfig.ValidateProvisioning(ic.Config)
    93  		if err != nil {
    94  			return err
    95  		}
    96  		err = bmconfig.ValidateStaticBootstrapNetworking(ic.Config)
    97  		if err != nil {
    98  			return err
    99  		}
   100  		err = baremetalvalidation.ValidateHosts(ic.Config.BareMetal, field.NewPath("platform"), ic.Config).ToAggregate()
   101  		if err != nil {
   102  			return err
   103  		}
   104  
   105  	case gcp.Name:
   106  		err := gcpconfig.ValidateForProvisioning(ic.Config)
   107  		if err != nil {
   108  			return err
   109  		}
   110  	case ibmcloud.Name:
   111  		client, err := ibmcloudconfig.NewClient(ic.Config.Platform.IBMCloud.ServiceEndpoints)
   112  		if err != nil {
   113  			return err
   114  		}
   115  		metadata := ibmcloudconfig.NewMetadata(ic.Config)
   116  		err = ibmcloudconfig.ValidatePreExistingPublicDNS(client, ic.Config, metadata)
   117  		if err != nil {
   118  			return err
   119  		}
   120  	case openstack.Name:
   121  		err := osconfig.ValidateForProvisioning(ic.Config)
   122  		if err != nil {
   123  			return err
   124  		}
   125  	case vsphere.Name:
   126  		if err := vsconfig.ValidateForProvisioning(ic.Config); err != nil {
   127  			return err
   128  		}
   129  	case ovirt.Name:
   130  		err := ovirtconfig.ValidateForProvisioning(ic.Config)
   131  		if err != nil {
   132  			return err
   133  		}
   134  	case powervs.Name:
   135  		client, err := powervsconfig.NewClient()
   136  		if err != nil {
   137  			return err
   138  		}
   139  
   140  		err = powervsconfig.ValidatePERAvailability(client, ic.Config)
   141  		if err != nil {
   142  			return err
   143  		}
   144  
   145  		err = powervsconfig.ValidatePreExistingDNS(client, ic.Config, ic.PowerVS)
   146  		if err != nil {
   147  			return err
   148  		}
   149  
   150  		err = powervsconfig.ValidateCustomVPCSetup(client, ic.Config)
   151  		if err != nil {
   152  			return err
   153  		}
   154  
   155  		err = powervsconfig.ValidateResourceGroup(client, ic.Config)
   156  		if err != nil {
   157  			return err
   158  		}
   159  
   160  		err = powervsconfig.ValidateSystemTypeForRegion(client, ic.Config)
   161  		if err != nil {
   162  			return err
   163  		}
   164  
   165  		err = powervsconfig.ValidateServiceInstance(client, ic.Config)
   166  		if err != nil {
   167  			return err
   168  		}
   169  	case external.Name, none.Name:
   170  		// no special provisioning requirements to check
   171  	case nutanix.Name:
   172  		err := nutanixconfig.ValidateForProvisioning(ic.Config)
   173  		if err != nil {
   174  			return err
   175  		}
   176  	default:
   177  		return fmt.Errorf("unknown platform type %q", platform)
   178  	}
   179  	return nil
   180  }
   181  
   182  // Name returns the human-friendly name of the asset.
   183  func (a *PlatformProvisionCheck) Name() string {
   184  	return "Platform Provisioning Check"
   185  }