Skip to content

Commit 1685bfc

Browse files
plural up command (#483)
* `plural up` command This will use a new bootstrapping method more in line with CD-exclusive usecases. It works basically as follows: * set up a git submodule of our bootstrap repo w/ some base charts and terraform * template some of the variable settings from there into the installation repo * run terraform off those templates This will set up a management cluster and fully install console onto it. We can further extend this to do the full OSS app installation process on top of CD. The main benefits here are separating cluster provisioning concerns out of our purview (users will manually manage their own terraform after running up), and reduce our scope to just maintaining the helm chart updates for the console and our runtime via CD. It also makes reconfiguration more natural since the users can delink the submodule and take full ownership whenever needed. * bump console client go version to be compatible w/ provider * add detection of existing console values, especially to stabilize aes keys
1 parent 3233f98 commit 1685bfc

26 files changed

Lines changed: 893 additions & 202 deletions

cmd/plural/cd.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@ func (p *Plural) cdCommands() []cli.Command {
4444
Action: p.handleInstallControlPlane,
4545
Usage: "sets up the plural console in an existing k8s cluster",
4646
},
47+
{
48+
Name: "control-plane-values",
49+
Action: p.handlePrintControlPlaneValues,
50+
Usage: "dumps a values file for installing the plural console",
51+
Flags: []cli.Flag{
52+
cli.StringFlag{Name: "domain", Usage: "The plural domain to use for this console", Required: true},
53+
cli.StringFlag{Name: "dsn", Usage: "The Postgres DSN to use for database connections", Required: true},
54+
cli.StringFlag{Name: "name", Usage: "The name given to the cluster", Required: true},
55+
cli.StringFlag{Name: "file", Usage: "The file to dump values to", Required: true},
56+
},
57+
},
4758
{
4859
Name: "uninstall",
4960
Action: p.handleUninstallOperator,
@@ -166,6 +177,17 @@ func (p *Plural) handleInstallControlPlane(_ *cli.Context) error {
166177
return nil
167178
}
168179

180+
func (p *Plural) handlePrintControlPlaneValues(c *cli.Context) error {
181+
p.InitPluralClient()
182+
conf := config.Read()
183+
vals, err := cd.ControlPlaneValues(conf, c.String("file"), c.String("domain"), c.String("dsn"), c.String("name"))
184+
if err != nil {
185+
return err
186+
}
187+
188+
return os.WriteFile(c.String("file"), []byte(vals), 0644)
189+
}
190+
169191
func (p *Plural) handleEject(c *cli.Context) (err error) {
170192
if !c.Args().Present() {
171193
return fmt.Errorf("clusterid cannot be empty")

cmd/plural/cd_services.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ func (p *Plural) handleCreateClusterService(c *cli.Context) error {
182182
}
183183

184184
headers := []string{"Id", "Name", "Namespace", "Git Ref", "Git Folder", "Repo"}
185-
return utils.PrintTable([]*gqlclient.ServiceDeploymentFragment{sd}, headers, func(sd *gqlclient.ServiceDeploymentFragment) ([]string, error) {
185+
return utils.PrintTable([]*gqlclient.ServiceDeploymentExtended{sd}, headers, func(sd *gqlclient.ServiceDeploymentExtended) ([]string, error) {
186186
return []string{sd.ID, sd.Name, sd.Namespace, sd.Git.Ref, sd.Git.Folder, sd.Repository.URL}, nil
187187
})
188188
}
@@ -321,7 +321,7 @@ func (p *Plural) handleUpdateClusterService(c *cli.Context) error {
321321
}
322322

323323
headers := []string{"Id", "Name", "Namespace", "Git Ref", "Git Folder", "Repo"}
324-
return utils.PrintTable([]*gqlclient.ServiceDeploymentFragment{sd}, headers, func(sd *gqlclient.ServiceDeploymentFragment) ([]string, error) {
324+
return utils.PrintTable([]*gqlclient.ServiceDeploymentExtended{sd}, headers, func(sd *gqlclient.ServiceDeploymentExtended) ([]string, error) {
325325
return []string{sd.ID, sd.Name, sd.Namespace, sd.Git.Ref, sd.Git.Folder, sd.Repository.URL}, nil
326326
})
327327
}

cmd/plural/crypto.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ context.yaml filter=plural-crypt diff=plural-crypt
4141
workspace.yaml filter=plural-crypt diff=plural-crypt
4242
context.yaml* filter=plural-crypt diff=plural-crypt
4343
workspace.yaml* filter=plural-crypt diff=plural-crypt
44+
helm-values/*.yaml filter=plural-crypt diff=plural-crypt
45+
.env filter=plural-crypt diff=plural-crypt
4446
.gitattributes !filter !diff
4547
`
4648

cmd/plural/init.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ func (p *Plural) handleInit(c *cli.Context) error {
2929
gitCreated := false
3030
repo := ""
3131

32+
if utils.Exists("./workspace.yaml") {
33+
utils.Highlight("Found workspace.yaml, skipping init as this repo has already been initialized...\n")
34+
return nil
35+
}
36+
3237
git, err := wkspace.Preflight()
3338
if err != nil && git {
3439
return err

cmd/plural/plural.go

Lines changed: 48 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,53 @@ func (p *Plural) getCommands() []cli.Command {
105105
Usage: "Gets cli version info",
106106
Action: versionInfo,
107107
},
108+
{
109+
Name: "up",
110+
Usage: "sets up your repository and an initial management cluster",
111+
Flags: []cli.Flag{
112+
cli.StringFlag{
113+
Name: "endpoint",
114+
Usage: "the endpoint for the plural installation you're working with",
115+
},
116+
cli.StringFlag{
117+
Name: "service-account",
118+
Usage: "email for the service account you'd like to use for this workspace",
119+
},
120+
cli.BoolFlag{
121+
Name: "ignore-preflights",
122+
Usage: "whether to ignore preflight check failures prior to init",
123+
},
124+
cli.StringFlag{
125+
Name: "commit",
126+
Usage: "commits your changes with this message",
127+
},
128+
},
129+
Action: latestVersion(p.handleUp),
130+
},
131+
{
132+
Name: "down",
133+
Usage: "destroys your management cluster and any apps installed on it",
134+
Action: latestVersion(p.handleDown),
135+
},
136+
{
137+
Name: "init",
138+
Usage: "initializes plural within a git repo",
139+
Flags: []cli.Flag{
140+
cli.StringFlag{
141+
Name: "endpoint",
142+
Usage: "the endpoint for the plural installation you're working with",
143+
},
144+
cli.StringFlag{
145+
Name: "service-account",
146+
Usage: "email for the service account you'd like to use for this workspace",
147+
},
148+
cli.BoolFlag{
149+
Name: "ignore-preflights",
150+
Usage: "whether to ignore preflight check failures prior to init",
151+
},
152+
},
153+
Action: tracked(latestVersion(p.handleInit), "cli.init"),
154+
},
108155
{
109156
Name: "build",
110157
Aliases: []string{"bld"},
@@ -272,25 +319,6 @@ func (p *Plural) getCommands() []cli.Command {
272319
Usage: "Handles authentication to the plural api",
273320
Subcommands: p.authCommands(),
274321
},
275-
{
276-
Name: "init",
277-
Usage: "initializes plural within a git repo",
278-
Flags: []cli.Flag{
279-
cli.StringFlag{
280-
Name: "endpoint",
281-
Usage: "the endpoint for the plural installation you're working with",
282-
},
283-
cli.StringFlag{
284-
Name: "service-account",
285-
Usage: "email for the service account you'd like to use for this workspace",
286-
},
287-
cli.BoolFlag{
288-
Name: "ignore-preflights",
289-
Usage: "whether to ignore preflight check failures prior to init",
290-
},
291-
},
292-
Action: tracked(latestVersion(p.handleInit), "cli.init"),
293-
},
294322
{
295323
Name: "preflights",
296324
Usage: "runs provider preflight checks",
@@ -443,17 +471,11 @@ func (p *Plural) getCommands() []cli.Command {
443471
Subcommands: p.opsCommands(),
444472
Category: "Debugging",
445473
},
446-
{
447-
Name: "utils",
448-
Usage: "useful plural utilities",
449-
Subcommands: utilsCommands(),
450-
Category: "Miscellaneous",
451-
},
452474
{
453475
Name: "vpn",
454476
Usage: "interacting with the plural vpn",
455477
Subcommands: p.vpnCommands(),
456-
Category: "Miscellaneous",
478+
Category: "Workspace",
457479
},
458480
{
459481
Name: "ai",
@@ -501,12 +523,6 @@ func (p *Plural) getCommands() []cli.Command {
501523
Action: latestVersion(diffed),
502524
Category: "Workspace",
503525
},
504-
{
505-
Name: "from-grafana",
506-
Usage: "imports a grafana dashboard to a plural crd",
507-
Action: latestVersion(formatDashboard),
508-
Category: "Publishing",
509-
},
510526
{
511527
Name: "bootstrap",
512528
Usage: "Commands for bootstrapping cluster",

cmd/plural/up.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package plural
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/urfave/cli"
7+
8+
"github.com/pluralsh/plural-cli/pkg/up"
9+
"github.com/pluralsh/plural-cli/pkg/utils"
10+
"github.com/pluralsh/plural-cli/pkg/utils/git"
11+
)
12+
13+
const (
14+
affirmUp = "Are you ready to set up your initial management cluster? You can check the generated terraform/helm to confirm everything looks good first"
15+
affirmDown = "Are you ready to destroy your plural infrastructure? This will destroy all k8s clusters and any data stored within"
16+
)
17+
18+
func (p *Plural) handleUp(c *cli.Context) error {
19+
// provider.IgnoreProviders([]string{"GENERIC", "KIND"})
20+
if err := p.handleInit(c); err != nil {
21+
return err
22+
}
23+
p.InitPluralClient()
24+
25+
repoRoot, err := git.Root()
26+
if err != nil {
27+
return err
28+
}
29+
30+
ctx, err := up.Build()
31+
if err != nil {
32+
return err
33+
}
34+
35+
if err := ctx.Generate(); err != nil {
36+
return err
37+
}
38+
39+
if !affirm(affirmUp, "PLURAL_UP_AFFIRM_DEPLOY") {
40+
return fmt.Errorf("cancelled deploy")
41+
}
42+
43+
if err := ctx.Deploy(func() error {
44+
utils.Highlight("\n==> Commit and push your configuration\n\n")
45+
if commit := commitMsg(c); commit != "" {
46+
utils.Highlight("Pushing upstream...\n")
47+
return git.Sync(repoRoot, commit, c.Bool("force"))
48+
}
49+
return nil
50+
}); err != nil {
51+
return err
52+
}
53+
54+
return nil
55+
}
56+
57+
func (p *Plural) handleDown(c *cli.Context) error {
58+
if !affirm(affirmDown, "PLURAL_DOWN_AFFIRM_DESTROY") {
59+
return fmt.Errorf("cancelled destroy")
60+
}
61+
62+
ctx, err := up.Build()
63+
if err != nil {
64+
return err
65+
}
66+
67+
return ctx.Destroy()
68+
}

cmd/plural/utils.go

Lines changed: 0 additions & 127 deletions
This file was deleted.

0 commit comments

Comments
 (0)