Skip to content

Commit

Permalink
[WIP]create deployments commands (#455)
Browse files Browse the repository at this point in the history
* create deployments commands

* add repositories commands

* update client auth

* add deployments repositories create command

* add deployments repositories list command

* refactor

* bump go client

* fix list deployments

* use go client model

* create and update service deployment

* Small style tweaks and show repository health in `repositories list` (#458)

* Small style tweaks and show repository health in `repositories list`

Pull status is definitely nice to be able to see here.

* show pull errors as well

* describe service

* install agent helm  method

* create agent namespace

* enable CAPI feature flag for e2e

* add services delete command

* Extend clusters list display (#460)

Shows the provider, and shows repo by url instead of id in some places where useful

* describe cluster + code refacor

* add flag validation

* support handle for plural deployments services list/describe

* add required flags

* add handle for create CD service

* add wait flag for agent installation

* update services by handle

* add console client mocks

* improve describe cluster and service

* read kubeconfig from env var if present

* respect KUBECONFIG env var in plural kube client too

* force update helm repos on install to prevent stale chart installations

* use correct release name

* don't swallow helm errors

* extend update cluster for kubeconfig

* add plural cd providers list command

* create/delete provider credentials

* pipeline create command

* fix some repositories commands

* add deployments clusters get-credentials command (#467)

* Add a persistent config file for console logins on cli

* Implement `plural cd clusters delete` (#468)

When the console-client-go pr is merged, we can implement the `--soft` flag too.

* fix pointer bug on config updates

* add create cluster command

* create azure cluster

* fix after schema changes

* bump console client

* bump console client

* update arg name

* refactor cluster commands

* refactor provider command

* remove provider id param

* don't wait in cd install command

* add clusters bootstrap command

* add operator uninstall, cluster tags on bootstrap

* more tweaks to agent installer

* some more agent install tweaks

* update gcp provider

* update provider create

* fix profile list cmd

* filter out existing providers

* remove gcp credenitials b64 encode logic

* BYOK installer for plural console

* wrap up console installer

* fix linter

* refactor cd structure

* fix unit tests

* fix cd install command

* add kustomize support

* init eject command

* fix token name for cd install

* make cd clusters kubeconfig more robust

* add kas_dns to server context

* add eject command and fix gcp capi provider bootstrapping

* modify control plane installer

* add service clone support

---------

Co-authored-by: Marcin Maciaszczyk <[email protected]>
Co-authored-by: michaeljguarino <[email protected]>
Co-authored-by: Sebastian Florek <[email protected]>
  • Loading branch information
4 people committed Aug 28, 2024
1 parent 161012f commit 30f7c3e
Show file tree
Hide file tree
Showing 44 changed files with 3,754 additions and 102 deletions.
154 changes: 154 additions & 0 deletions cmd/plural/cd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
package plural

import (
"fmt"
"os"

"github.com/urfave/cli"
apierrors "k8s.io/apimachinery/pkg/api/errors"

"github.com/pluralsh/plural/pkg/cd"
"github.com/pluralsh/plural/pkg/config"
"github.com/pluralsh/plural/pkg/console"
"github.com/pluralsh/plural/pkg/utils"
)

func init() {
consoleToken = ""
consoleURL = ""
}

const (
operatorNamespace = "plrl-deploy-operator"
)

var consoleToken string
var consoleURL string

func (p *Plural) cdCommands() []cli.Command {
return []cli.Command{
p.cdProviders(),
p.cdCredentials(),
p.cdClusters(),
p.cdServices(),
p.cdRepositories(),
p.cdPipelines(),
{
Name: "install",
Action: p.handleInstallDeploymentsOperator,
Usage: "install deployments operator",
Flags: []cli.Flag{
cli.StringFlag{Name: "url", Usage: "console url", Required: true},
cli.StringFlag{Name: "token", Usage: "deployment token", Required: true},
},
},
{
Name: "control-plane",
Action: p.handleInstallControlPlane,
Usage: "sets up the plural console in an existing k8s cluster",
},
{
Name: "uninstall",
Action: p.handleUninstallOperator,
Usage: "uninstalls the deployment operator from the current cluster",
},
{
Name: "login",
Action: p.handleCdLogin,
Usage: "logs into your plural console",
Flags: []cli.Flag{
cli.StringFlag{Name: "url", Usage: "console url", Required: true},
cli.StringFlag{Name: "token", Usage: "console access token"},
},
},
{
Name: "eject",
Action: p.handleEject,
Usage: "ejects cluster scaffolds",
ArgsUsage: "<cluster-id>",
// TODO: enable once logic is finished
Hidden: true,
},
}
}

func (p *Plural) handleInstallDeploymentsOperator(c *cli.Context) error {
return p.doInstallOperator(c.String("url"), c.String("token"))
}

func (p *Plural) handleUninstallOperator(_ *cli.Context) error {
err := p.InitKube()
if err != nil {
return err
}
return console.UninstallAgent(operatorNamespace)
}

func (p *Plural) doInstallOperator(url, token string) error {
err := p.InitKube()
if err != nil {
return err
}
err = p.Kube.CreateNamespace(operatorNamespace)
if err != nil && !apierrors.IsAlreadyExists(err) {
return err
}
err = console.InstallAgent(url, token, operatorNamespace)
if err == nil {
utils.Success("deployment operator installed successfully\n")
}
return err
}

func (p *Plural) handleCdLogin(c *cli.Context) (err error) {
url := c.String("url")
token := c.String("token")
if token == "" {
token, err = utils.ReadPwd("Enter your console access token")
if err != nil {
return
}
}
conf := console.Config{Url: url, Token: token}
return conf.Save()
}

func (p *Plural) handleInstallControlPlane(_ *cli.Context) error {
conf := config.Read()
vals, err := cd.CreateControlPlane(conf)
if err != nil {
return err
}

fmt.Print("\n\n")
utils.Highlight("===> writing values.secret.yaml, you should keep this in a secure location for future helm upgrades\n\n")
if err := os.WriteFile("values.secret.yaml", []byte(vals), 0644); err != nil {
return err
}

fmt.Println("After confirming everything looks correct in values.secret.yaml, run the following command to install:")
utils.Highlight("helm upgrade --install --create-namespace -f values.secret.yaml --repo https://pluralsh.github.io/console console console -n plrl-console")
return nil
}

func (p *Plural) handleEject(c *cli.Context) (err error) {
if !c.Args().Present() {
return fmt.Errorf("clusterid cannot be empty")
}

if err := p.InitConsoleClient(consoleToken, consoleURL); err != nil {
return err
}

clusterId := c.Args().First()
cluster, err := p.ConsoleClient.GetCluster(&clusterId, nil)
if err != nil {
return err
}

if cluster == nil {
return fmt.Errorf("could not find cluster with given id")
}

return cd.Eject(cluster)
}
Loading

0 comments on commit 30f7c3e

Please sign in to comment.