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

     1  package installconfig
     2  
     3  import (
     4  	"context"
     5  
     6  	survey "github.com/AlecAivazis/survey/v2"
     7  	"github.com/pkg/errors"
     8  
     9  	"github.com/openshift/installer/pkg/asset"
    10  	"github.com/openshift/installer/pkg/types"
    11  	"github.com/openshift/installer/pkg/validate"
    12  )
    13  
    14  type clusterName struct {
    15  	ClusterName string
    16  }
    17  
    18  var _ asset.Asset = (*clusterName)(nil)
    19  
    20  // Dependencies returns no dependencies.
    21  func (a *clusterName) Dependencies() []asset.Asset {
    22  	return []asset.Asset{
    23  		&baseDomain{},
    24  		&platform{},
    25  	}
    26  }
    27  
    28  // Generate queries for the cluster name from the user.
    29  func (a *clusterName) Generate(_ context.Context, parents asset.Parents) error {
    30  	bd := &baseDomain{}
    31  	platform := &platform{}
    32  	parents.Get(bd, platform)
    33  
    34  	validator := survey.Required
    35  
    36  	if platform.GCP != nil || platform.Azure != nil {
    37  		validator = survey.ComposeValidators(validator, func(ans interface{}) error {
    38  			return validate.ClusterName1035(ans.(string))
    39  		})
    40  		if platform.GCP != nil {
    41  			validator = survey.ComposeValidators(validator, func(ans interface{}) error {
    42  				return validate.GCPClusterName(ans.(string))
    43  			})
    44  		}
    45  	}
    46  
    47  	if platform.Ovirt != nil {
    48  		validator = survey.ComposeValidators(validator, func(ans interface{}) error {
    49  			return validate.ClusterName(ans.(string))
    50  		})
    51  	}
    52  	if platform.VSphere != nil || platform.BareMetal != nil || platform.Nutanix != nil {
    53  		validator = survey.ComposeValidators(validator, func(ans interface{}) error {
    54  			return validate.OnPremClusterName(ans.(string))
    55  		})
    56  	}
    57  	validator = survey.ComposeValidators(validator, func(ans interface{}) error {
    58  		installConfig := &types.InstallConfig{BaseDomain: bd.BaseDomain}
    59  		installConfig.ObjectMeta.Name = ans.(string)
    60  		return validate.DomainName(installConfig.ClusterDomain(), false)
    61  	})
    62  
    63  	if err := survey.Ask([]*survey.Question{
    64  		{
    65  			Prompt: &survey.Input{
    66  				Message: "Cluster Name",
    67  				Help:    "The name of the cluster.  This will be used when generating sub-domains.\n\nFor libvirt, choose a name that is unique enough to be used as a prefix during cluster deletion.  For example, if you use 'demo' as your cluster name, `openshift-install destroy cluster` may destroy all domains, networks, pools, and volumes that begin with 'demo'.",
    68  			},
    69  			Validate: validator,
    70  		},
    71  	}, &a.ClusterName); err != nil {
    72  		return errors.Wrap(err, "failed UserInput")
    73  	}
    74  	return nil
    75  }
    76  
    77  // Name returns the human-friendly name of the asset.
    78  func (a *clusterName) Name() string {
    79  	return "Cluster Name"
    80  }