Skip to content

Commit 93b5487

Browse files
authored
plural up ux improvements (#716)
* plural up ux improvements * linter * revert aws.go * fix dry-run * add byok * install agent * update * clean up * linter * update prune BYOK
1 parent 8fe1d0e commit 93b5487

17 files changed

Lines changed: 223 additions & 39 deletions

File tree

cmd/command/up/up.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,14 @@ func (p *Plural) handleUp(c *cli.Context) error {
8282
}
8383
p.InitPluralClient()
8484
dryRun := c.Bool("dry-run")
85+
cloud := c.Bool("cloud")
8586

8687
cd := &cdpkg.Plural{Plural: p.Plural}
8788

8889
var name, url string
8990
var err error
9091

91-
if c.Bool("cloud") {
92+
if cloud {
9293
name, url, err = p.choseCluster()
9394
if err != nil {
9495
return err
@@ -110,8 +111,10 @@ func (p *Plural) handleUp(c *cli.Context) error {
110111
return err
111112
}
112113

113-
if err := askAppDomain(project); err != nil {
114-
return err
114+
if !dryRun {
115+
if err := askAppDomain(project); err != nil {
116+
return err
117+
}
115118
}
116119

117120
repoRoot, err := git.Root()
@@ -121,13 +124,14 @@ func (p *Plural) handleUp(c *cli.Context) error {
121124

122125
ctx, err := up.Build(c.Bool("cloud"))
123126
ctx.IgnorePreflights(c.Bool("ignore-preflights") || c.Bool("dry-run"))
127+
124128
if err != nil {
125129
return err
126130
}
127131

128132
byok := ctx.Provider.Name() == api.BYOK
129133

130-
if c.Bool("cloud") {
134+
if cloud {
131135
id, err := getCluster(cd)
132136
if err != nil {
133137
return err
@@ -161,7 +165,7 @@ func (p *Plural) handleUp(c *cli.Context) error {
161165
return nil
162166
}
163167

164-
if !byok {
168+
if !cloud {
165169
if !common.Affirm(common.AffirmUp, "PLURAL_UP_AFFIRM_DEPLOY") {
166170
return fmt.Errorf("cancelled deploy")
167171
}
@@ -179,7 +183,7 @@ func (p *Plural) handleUp(c *cli.Context) error {
179183
}
180184

181185
utils.Success("Finished setting up your management cluster!\n")
182-
if byok {
186+
if byok && cloud {
183187
utils.Highlight("Since you're using BYOK, be sure to complete setup of your management cluster\n")
184188
utils.Highlight("IMPORTANT: You'll need to configure IAM permissions for the plrl-deploy-operator/stacks service account.\n")
185189
utils.Highlight("This is no longer handled automatically. See the terraform example in the docs for the required IAM policy.\n")

pkg/cd/control_plane_install.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ func ControlPlaneValues(conf config.Config, file, domain, dsn, name string) (str
108108
"clusterIssuer": "plural",
109109
}
110110

111+
if ingressClass := utils.ToString(prov.Context()["IngressClass"]); ingressClass != "" {
112+
configuration["ingressClass"] = ingressClass
113+
}
114+
111115
if existing.Secrets.AesKey != "" {
112116
configuration["aesKey"] = existing.Secrets.AesKey
113117
}

pkg/common/common.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ func Preflights(c *cli.Context) error {
118118

119119
func RunPreflights(c *cli.Context) (providerapi.Provider, error) {
120120
provider.SetCloudFlag(c.Bool("cloud"))
121+
provider.SetDryrunFlag(c.Bool("dry-run"))
122+
121123
prov, err := provider.GetProvider()
122124
if err != nil {
123125
return prov, err

pkg/provider/aws.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,12 @@ var (
7272
}
7373
)
7474

75-
func mkAWS(conf config.Config) (provider *AWSProvider, err error) {
75+
func mkAWS(conf config.Config, dryRun bool) (provider *AWSProvider, err error) {
7676
ctx := context.Background()
7777
provider = &AWSProvider{}
78+
if dryRun {
79+
return provider, nil
80+
}
7881
iamSession, callerIdentity, err := GetAWSCallerIdentity(ctx)
7982
if err != nil {
8083
return provider, plrlErrors.ErrorWrap(err, "Failed to get AWS caller identity")

pkg/provider/azure.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,11 @@ type AzureProvider struct {
8686
clients *ClientSet
8787
}
8888

89-
func mkAzure(conf config.Config) (prov *AzureProvider, err error) {
89+
func mkAzure(conf config.Config, dryRun bool) (prov *AzureProvider, err error) {
9090
prov = &AzureProvider{}
91+
if dryRun {
92+
return prov, nil
93+
}
9194
subId, tenID, subName, err := GetAzureAccount()
9295
if err != nil {
9396
return

pkg/provider/byok.go

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import (
1919
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
2020
)
2121

22+
const defaultValue = "default"
23+
2224
type ByokProvider struct {
2325
cluster string
2426
ctx map[string]interface{}
@@ -35,11 +37,20 @@ func ByokFromManifest(man *manifest.ProjectManifest) (*ByokProvider, error) {
3537
return prov, nil
3638
}
3739

38-
func mkBYOK(conf config.Config, name string) (prov *ByokProvider, err error) {
40+
func mkBYOK(conf config.Config, name string, dryRun, cloud bool) (prov *ByokProvider, err error) {
3941
prov = &ByokProvider{
40-
cluster: name,
41-
ctx: map[string]interface{}{},
42+
ctx: map[string]interface{}{},
43+
}
44+
if dryRun {
45+
return prov, nil
46+
}
47+
48+
if name == "" {
49+
if err := survey.AskOne(&survey.Input{Message: "Enter the name of your cluster"}, &name); err != nil {
50+
return nil, err
51+
}
4252
}
53+
prov.cluster = name
4354

4455
kubeconfigPath, err := askKubeconfig()
4556
if err != nil {
@@ -69,14 +80,31 @@ func mkBYOK(conf config.Config, name string) (prov *ByokProvider, err error) {
6980
kubeconfigBase64 := base64.StdEncoding.EncodeToString(kubeconfigData)
7081

7182
prov.ctx["kubeconfig"] = kubeconfigBase64
72-
7383
projectManifest := manifest.ProjectManifest{
7484
Cluster: name,
7585
Provider: api.BYOK,
7686
Owner: &manifest.Owner{Email: conf.Email, Endpoint: conf.Endpoint},
7787
Context: prov.Context(),
7888
}
79-
prov.writer = projectManifest.Configure(cloudFlag, prov.Cluster())
89+
if !cloud {
90+
var dbURL string
91+
if err := survey.AskOne(&survey.Input{
92+
Message: "Enter the jdbc connection string (postgres://<user>:<password>@<host>:5432/<db>) for the Plural console:",
93+
}, &dbURL); err != nil {
94+
return nil, err
95+
}
96+
prov.ctx["DbUrl"] = dbURL
97+
98+
var domain string
99+
if err := survey.AskOne(&survey.Input{
100+
Message: "Enter the domain you want to use for your Plural console:",
101+
}, &domain); err != nil {
102+
return nil, err
103+
}
104+
105+
projectManifest.Network = &manifest.NetworkConfig{Subdomain: domain, PluralDns: false}
106+
}
107+
prov.writer = func() error { return projectManifest.Write(manifest.ProjectManifestPath()) }
80108
return prov, nil
81109
}
82110

@@ -89,15 +117,15 @@ func (b *ByokProvider) Cluster() string {
89117
}
90118

91119
func (b *ByokProvider) Project() string {
92-
return ""
120+
return defaultValue
93121
}
94122

95123
func (b *ByokProvider) Region() string {
96-
return ""
124+
return defaultValue
97125
}
98126

99127
func (b *ByokProvider) Bucket() string {
100-
return ""
128+
return defaultValue
101129
}
102130

103131
func (b *ByokProvider) KubeConfig() error {
@@ -205,7 +233,7 @@ func (b *ByokProvider) Flush() error {
205233

206234
func (b *ByokProvider) testClusterConnectivity() error {
207235
if err := b.KubeConfig(); err != nil {
208-
return err
236+
return fmt.Errorf("failed to load kubeconfig: %w", err)
209237
}
210238
kube, err := kubernetes.Kubernetes()
211239
if err != nil {

pkg/provider/gcp/option.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ import (
1111

1212
type Option func(*Provider) error
1313

14-
func WithConfig(c config.Config, defaultCluster string, cloudEnabled bool) Option {
14+
func WithConfig(c config.Config, defaultCluster string, cloudEnabled, dryRun bool) Option {
1515
return func(gcp *Provider) error {
16+
if dryRun {
17+
return nil
18+
}
1619
err := printUserInfo()
1720
if err != nil {
1821
return err

pkg/provider/gcp/validation.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (in *Provider) validateEnabled() error {
4141
resp, err := c.BatchGetServices(ctx, req)
4242
if err != nil {
4343
utils.LogError().Println(err)
44-
return fmt.Errorf("could not fetch services information for project %s, make sure your service account does have appropriate permissions", in.Project())
44+
return fmt.Errorf("could not check required GCP services for project %s (serviceusage.googleapis.com, cloudresourcemanager.googleapis.com, container.googleapis.com): make sure your service account has the serviceusage.services.list permission", in.Project())
4545
}
4646

4747
missing := algorithms.Filter(resp.Services, func(svc *serviceusagepb.Service) bool {
@@ -56,6 +56,7 @@ func (in *Provider) validateEnabled() error {
5656
}
5757
utils.LogError().Printf("Attempting to enable services %v", services)
5858
if err := tryToEnableServices(ctx, c, enableReq); err != nil {
59+
utils.Warn("Could not automatically enable required GCP services, please enable them manually.\n")
5960
return errEnabled
6061
}
6162
}
@@ -64,7 +65,7 @@ func (in *Provider) validateEnabled() error {
6465
}
6566

6667
func (in *Provider) validatePermissions() error {
67-
utils.LogInfo().Println("Validate GCP roles/permissions")
68+
utils.LogInfo().Println("Checking GCP roles/permissions")
6869
ctx := context.Background()
6970

7071
projectID, err := in.project()
@@ -75,7 +76,7 @@ func (in *Provider) validatePermissions() error {
7576
checker, _ := permissions.NewGcpChecker(ctx, projectID)
7677
missing, err := checker.MissingPermissions()
7778
if err != nil {
78-
return err
79+
return fmt.Errorf("failed to check GCP permissions for project %s: %w", projectID, err)
7980
}
8081

8182
if len(missing) == 0 {

pkg/provider/preflights/preflight.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ type Preflight struct {
1212
}
1313

1414
func (pf *Preflight) Validate() error {
15-
utils.Highlight("Executing preflight check :: %s ", pf.Name)
15+
utils.Highlight("Executing preflight check: %s ", pf.Name)
1616
if err := pf.Callback(); err != nil {
17-
fmt.Println("\nFound error:")
17+
fmt.Printf("\nPreflight check %q failed: %s\n", pf.Name, err.Error())
1818
return err
1919
}
2020

pkg/provider/provider.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
)
1717

1818
var cloudFlag bool
19+
var dryRunFlag bool
1920
var clusterFlag string
2021

2122
type Providers struct {
@@ -52,6 +53,10 @@ func SetCloudFlag(cloud bool) {
5253
cloudFlag = cloud
5354
}
5455

56+
func SetDryrunFlag(dryRun bool) {
57+
dryRunFlag = dryRun
58+
}
59+
5560
func SetClusterFlag(cluster string) {
5661
clusterFlag = cluster
5762
}
@@ -77,13 +82,13 @@ func New(provider string) (providerapi.Provider, error) {
7782
conf := config.Read()
7883
switch provider {
7984
case api.ProviderGCP:
80-
return gcp.NewProvider(gcp.WithConfig(conf, clusterFlag, cloudFlag))
85+
return gcp.NewProvider(gcp.WithConfig(conf, clusterFlag, cloudFlag, dryRunFlag))
8186
case api.ProviderAWS:
82-
return mkAWS(conf)
87+
return mkAWS(conf, dryRunFlag)
8388
case api.ProviderAzure:
84-
return mkAzure(conf)
89+
return mkAzure(conf, dryRunFlag)
8590
case api.BYOK:
86-
return mkBYOK(conf, clusterFlag)
91+
return mkBYOK(conf, clusterFlag, dryRunFlag, cloudFlag)
8792
default:
8893
return nil, fmt.Errorf("invalid provider name: %s", provider)
8994
}
@@ -100,8 +105,7 @@ func getAvailableProviders() error {
100105
available = containers.ToSet(available).Difference(filterProviders).List()
101106
providers.AvailableProviders = algorithms.Map(available, strings.ToLower)
102107
}
103-
if cloudFlag {
104-
providers.AvailableProviders = append(providers.AvailableProviders, api.BYOK)
105-
}
108+
providers.AvailableProviders = append(providers.AvailableProviders, api.BYOK)
109+
106110
return nil
107111
}

0 commit comments

Comments
 (0)