github.com/openshift/installer@v1.4.17/pkg/asset/installconfig/basedomain.go (about) 1 package installconfig 2 3 import ( 4 "context" 5 6 survey "github.com/AlecAivazis/survey/v2" 7 "github.com/aws/aws-sdk-go/aws/request" 8 "github.com/pkg/errors" 9 10 "github.com/openshift/installer/pkg/asset" 11 awsconfig "github.com/openshift/installer/pkg/asset/installconfig/aws" 12 azureconfig "github.com/openshift/installer/pkg/asset/installconfig/azure" 13 gcpconfig "github.com/openshift/installer/pkg/asset/installconfig/gcp" 14 ibmcloudconfig "github.com/openshift/installer/pkg/asset/installconfig/ibmcloud" 15 powervsconfig "github.com/openshift/installer/pkg/asset/installconfig/powervs" 16 "github.com/openshift/installer/pkg/types" 17 "github.com/openshift/installer/pkg/types/aws" 18 "github.com/openshift/installer/pkg/types/azure" 19 "github.com/openshift/installer/pkg/types/gcp" 20 "github.com/openshift/installer/pkg/types/ibmcloud" 21 "github.com/openshift/installer/pkg/types/powervs" 22 "github.com/openshift/installer/pkg/validate" 23 ) 24 25 type baseDomain struct { 26 BaseDomain string 27 Publish types.PublishingStrategy 28 } 29 30 var _ asset.Asset = (*baseDomain)(nil) 31 32 // Dependencies returns no dependencies. 33 func (a *baseDomain) Dependencies() []asset.Asset { 34 return []asset.Asset{ 35 &platform{}, 36 } 37 } 38 39 // Generate queries for the base domain from the user. 40 func (a *baseDomain) Generate(_ context.Context, parents asset.Parents) error { 41 platform := &platform{} 42 parents.Get(platform) 43 44 var err error 45 switch platform.CurrentName() { 46 case aws.Name: 47 a.BaseDomain, err = awsconfig.GetBaseDomain() 48 cause := errors.Cause(err) 49 if !(awsconfig.IsForbidden(cause) || request.IsErrorThrottle(cause)) { 50 return err 51 } 52 case azure.Name: 53 // Create client using public cloud because install config has not been generated yet. 54 ssn, err := azureconfig.GetSession(azure.PublicCloud, "") 55 if err != nil { 56 return err 57 } 58 azureDNS := azureconfig.NewDNSConfig(ssn) 59 zone, err := azureDNS.GetDNSZone() 60 if err != nil { 61 return err 62 } 63 a.BaseDomain = zone.Name 64 return platform.Azure.SetBaseDomain(zone.ID) 65 case gcp.Name: 66 a.BaseDomain, err = gcpconfig.GetBaseDomain(platform.GCP.ProjectID) 67 68 // We are done if success (err == nil) or an err besides forbidden/throttling 69 if !(gcpconfig.IsForbidden(err) || gcpconfig.IsThrottled(err)) { 70 return err 71 } 72 case ibmcloud.Name: 73 zone, err := ibmcloudconfig.GetDNSZone() 74 if err != nil { 75 return err 76 } 77 a.BaseDomain = zone.Name 78 return nil 79 case powervs.Name: 80 zone, err := powervsconfig.GetDNSZone() 81 if err != nil { 82 return err 83 } 84 a.BaseDomain = zone.Name 85 a.Publish = zone.Publish 86 return nil 87 default: 88 //Do nothing 89 } 90 91 if err := survey.Ask([]*survey.Question{ 92 { 93 Prompt: &survey.Input{ 94 Message: "Base Domain", 95 Help: "The base domain of the cluster. All DNS records will be sub-domains of this base and will also include the cluster name.", 96 }, 97 Validate: survey.ComposeValidators(survey.Required, func(ans interface{}) error { 98 return validate.DomainName(ans.(string), true) 99 }), 100 }, 101 }, &a.BaseDomain); err != nil { 102 return errors.Wrap(err, "failed UserInput") 103 } 104 return nil 105 } 106 107 // Name returns the human-friendly name of the asset. 108 func (a *baseDomain) Name() string { 109 return "Base Domain" 110 }