Skip to content

Commit

Permalink
plural up command
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
michaeljguarino committed Dec 31, 2023
1 parent 3233f98 commit 51eb792
Show file tree
Hide file tree
Showing 20 changed files with 516 additions and 167 deletions.
21 changes: 21 additions & 0 deletions cmd/plural/cd.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ func (p *Plural) cdCommands() []cli.Command {
Action: p.handleInstallControlPlane,
Usage: "sets up the plural console in an existing k8s cluster",
},
{
Name: "control-plane-values",
Action: p.handlePrintControlPlaneValues,
Usage: "dumps a values file for installing the plural console",
Flags: []cli.Flag{
cli.StringFlag{Name: "domain", Usage: "The plural domain to use for this console", Required: true},
cli.StringFlag{Name: "dsn", Usage: "The Postgres DSN to use for database connections", Required: true},
cli.StringFlag{Name: "name", Usage: "The name given to the cluster", Required: true},
cli.StringFlag{Name: "file", Usage: "The file to dump values to", Required: true},
},
},
{
Name: "uninstall",
Action: p.handleUninstallOperator,
Expand Down Expand Up @@ -166,6 +177,16 @@ func (p *Plural) handleInstallControlPlane(_ *cli.Context) error {
return nil
}

func (p *Plural) handlePrintControlPlaneValues(c *cli.Context) error {
conf := config.Read()
vals, err := cd.ControlPlaneValues(conf, c.String("domain"), c.String("dsn"), c.String("name"))
if err != nil {
return err
}

return os.WriteFile(c.String("file"), []byte(vals), 0644)
}

func (p *Plural) handleEject(c *cli.Context) (err error) {
if !c.Args().Present() {
return fmt.Errorf("clusterid cannot be empty")
Expand Down
1 change: 1 addition & 0 deletions cmd/plural/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ context.yaml filter=plural-crypt diff=plural-crypt
workspace.yaml filter=plural-crypt diff=plural-crypt
context.yaml* filter=plural-crypt diff=plural-crypt
workspace.yaml* filter=plural-crypt diff=plural-crypt
helm-values/*.yaml filter=plural-crypt diff=plural-crypt
.gitattributes !filter !diff
`

Expand Down
5 changes: 5 additions & 0 deletions cmd/plural/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ func (p *Plural) handleInit(c *cli.Context) error {
gitCreated := false
repo := ""

if utils.Exists("./workspace.yaml") {
utils.Highlight("Found workspace.yaml, skipping init as this repo has already been initialized...\n")
return nil
}

git, err := wkspace.Preflight()
if err != nil && git {
return err
Expand Down
80 changes: 48 additions & 32 deletions cmd/plural/plural.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,53 @@ func (p *Plural) getCommands() []cli.Command {
Usage: "Gets cli version info",
Action: versionInfo,
},
{
Name: "up",
Usage: "sets up your repository and an initial management cluster",
Flags: []cli.Flag{
cli.StringFlag{
Name: "endpoint",
Usage: "the endpoint for the plural installation you're working with",
},
cli.StringFlag{
Name: "service-account",
Usage: "email for the service account you'd like to use for this workspace",
},
cli.BoolFlag{
Name: "ignore-preflights",
Usage: "whether to ignore preflight check failures prior to init",
},
cli.StringFlag{
Name: "commit",
Usage: "commits your changes with this message",
},
},
Action: latestVersion(p.handleUp),
},
{
Name: "down",
Usage: "destroys your management cluster and any apps installed on it",
Action: latestVersion(p.handleDown),
},
{
Name: "init",
Usage: "initializes plural within a git repo",
Flags: []cli.Flag{
cli.StringFlag{
Name: "endpoint",
Usage: "the endpoint for the plural installation you're working with",
},
cli.StringFlag{
Name: "service-account",
Usage: "email for the service account you'd like to use for this workspace",
},
cli.BoolFlag{
Name: "ignore-preflights",
Usage: "whether to ignore preflight check failures prior to init",
},
},
Action: tracked(latestVersion(p.handleInit), "cli.init"),
},
{
Name: "build",
Aliases: []string{"bld"},
Expand Down Expand Up @@ -272,25 +319,6 @@ func (p *Plural) getCommands() []cli.Command {
Usage: "Handles authentication to the plural api",
Subcommands: p.authCommands(),
},
{
Name: "init",
Usage: "initializes plural within a git repo",
Flags: []cli.Flag{
cli.StringFlag{
Name: "endpoint",
Usage: "the endpoint for the plural installation you're working with",
},
cli.StringFlag{
Name: "service-account",
Usage: "email for the service account you'd like to use for this workspace",
},
cli.BoolFlag{
Name: "ignore-preflights",
Usage: "whether to ignore preflight check failures prior to init",
},
},
Action: tracked(latestVersion(p.handleInit), "cli.init"),
},
{
Name: "preflights",
Usage: "runs provider preflight checks",
Expand Down Expand Up @@ -443,17 +471,11 @@ func (p *Plural) getCommands() []cli.Command {
Subcommands: p.opsCommands(),
Category: "Debugging",
},
{
Name: "utils",
Usage: "useful plural utilities",
Subcommands: utilsCommands(),
Category: "Miscellaneous",
},
{
Name: "vpn",
Usage: "interacting with the plural vpn",
Subcommands: p.vpnCommands(),
Category: "Miscellaneous",
Category: "Workspace",
},
{
Name: "ai",
Expand Down Expand Up @@ -501,12 +523,6 @@ func (p *Plural) getCommands() []cli.Command {
Action: latestVersion(diffed),
Category: "Workspace",
},
{
Name: "from-grafana",
Usage: "imports a grafana dashboard to a plural crd",
Action: latestVersion(formatDashboard),
Category: "Publishing",
},
{
Name: "bootstrap",
Usage: "Commands for bootstrapping cluster",
Expand Down
67 changes: 67 additions & 0 deletions cmd/plural/up.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package plural

import (
"fmt"

"github.com/urfave/cli"

"github.com/pluralsh/plural-cli/pkg/up"
"github.com/pluralsh/plural-cli/pkg/utils"
"github.com/pluralsh/plural-cli/pkg/utils/git"
)

const (
affirmUp = "Are you ready to set up your initial management cluster? You can check the generated terraform/helm to confirm everything looks good first"
affirmDown = "Are you ready to destroy your plural infrastructure? This will destroy all k8s clusters and any data stored within"
)

func (p *Plural) handleUp(c *cli.Context) error {
if err := p.handleInit(c); err != nil {
return err
}
p.InitPluralClient()

repoRoot, err := git.Root()
if err != nil {
return err
}

ctx, err := up.Build()
if err != nil {
return err
}

if err := ctx.Generate(); err != nil {
return err
}

if !affirm(affirmUp, "PLURAL_UP_AFFIRM_DEPLOY") {
return fmt.Errorf("cancelled deploy")
}

if err := ctx.Deploy(); err != nil {
return err
}

utils.Highlight("\n==> Commit and push your configuration\n\n")

if commit := commitMsg(c); commit != "" {
utils.Highlight("Pushing upstream...\n")
return git.Sync(repoRoot, commit, c.Bool("force"))
}

return nil
}

func (p *Plural) handleDown(c *cli.Context) error {
if !affirm(affirmDown, "PLURAL_DOWN_AFFIRM_DESTROY") {
return fmt.Errorf("cancelled destroy")
}

ctx, err := up.Build()
if err != nil {
return err
}

return ctx.Destroy()
}
127 changes: 0 additions & 127 deletions cmd/plural/utils.go

This file was deleted.

Loading

0 comments on commit 51eb792

Please sign in to comment.