diff --git a/cmd/plural/cd.go b/cmd/plural/cd.go index e5aba9b7..b66d0431 100644 --- a/cmd/plural/cd.go +++ b/cmd/plural/cd.go @@ -38,7 +38,7 @@ func (p *Plural) cdCommands() []cli.Command { Usage: "install deployments operator", Flags: []cli.Flag{ cli.StringFlag{Name: "url", Usage: "console url", Required: true}, - cli.StringFlag{Name: "token", Usage: "console token", Required: true}, + cli.StringFlag{Name: "token", Usage: "deployment token", Required: true}, }, }, { @@ -81,7 +81,7 @@ func (p *Plural) doInstallOperator(url, token string) error { return err } err = p.Kube.CreateNamespace(operatorNamespace) - if !apierrors.IsAlreadyExists(err) { + if err != nil && !apierrors.IsAlreadyExists(err) { return err } err = console.InstallAgent(url, token, operatorNamespace) diff --git a/cmd/plural/cd_clusters.go b/cmd/plural/cd_clusters.go index 394859bc..114d3e69 100644 --- a/cmd/plural/cd_clusters.go +++ b/cmd/plural/cd_clusters.go @@ -235,7 +235,7 @@ func (p *Plural) handleGetClusterCredentials(c *cli.Context) error { return fmt.Errorf("cluster is nil") } - return cd.SaveClusterKubeconfig(cluster, consoleToken) + return cd.SaveClusterKubeconfig(cluster, p.ConsoleClient.Token()) } func (p *Plural) handleCreateCluster(c *cli.Context) error { diff --git a/cmd/plural/cd_services.go b/cmd/plural/cd_services.go index 5b46763f..444a0e00 100644 --- a/cmd/plural/cd_services.go +++ b/cmd/plural/cd_services.go @@ -38,6 +38,7 @@ func (p *Plural) cdServiceCommands() []cli.Command { cli.StringFlag{Name: "repo-id", Usage: "repository ID", Required: true}, cli.StringFlag{Name: "git-ref", Usage: "git ref, can be branch, tag or commit sha", Required: true}, cli.StringFlag{Name: "git-folder", Usage: "folder within the source tree where manifests are located", Required: true}, + cli.StringFlag{Name: "kustomize-folder", Usage: "folder within the kustomize file is located"}, cli.StringSliceFlag{ Name: "conf", Usage: "config name value", @@ -56,6 +57,7 @@ func (p *Plural) cdServiceCommands() []cli.Command { cli.StringFlag{Name: "version", Usage: "service version"}, cli.StringFlag{Name: "git-ref", Usage: "git ref, can be branch, tag or commit sha"}, cli.StringFlag{Name: "git-folder", Usage: "folder within the source tree where manifests are located"}, + cli.StringFlag{Name: "kustomize-folder", Usage: "folder within the kustomize file is located"}, cli.StringSliceFlag{ Name: "conf", Usage: "config name value", @@ -125,6 +127,12 @@ func (p *Plural) handleCreateClusterService(c *cli.Context) error { Configuration: []*gqlclient.ConfigAttributes{}, } + if c.String("kustomize-folder") != "" { + attributes.Kustomize = &gqlclient.KustomizeAttributes{ + Path: c.String("kustomize-folder"), + } + } + if c.String("config-file") != "" { configFile, err := utils.ReadFile(c.String("config-file")) if err != nil { @@ -190,6 +198,11 @@ func (p *Plural) handleUpdateClusterService(c *cli.Context) error { }, Configuration: []*gqlclient.ConfigAttributes{}, } + if existing.Kustomize != nil { + attributes.Kustomize = &gqlclient.KustomizeAttributes{ + Path: existing.Kustomize.Path, + } + } for _, conf := range existing.Configuration { existingConfigurations[conf.Name] = conf.Value @@ -226,7 +239,11 @@ func (p *Plural) handleUpdateClusterService(c *cli.Context) error { Value: lo.ToPtr(value), }) } - + if c.String("kustomize-folder") != "" { + attributes.Kustomize = &gqlclient.KustomizeAttributes{ + Path: c.String("kustomize-folder"), + } + } sd, err := p.ConsoleClient.UpdateClusterService(serviceId, serviceName, clusterName, attributes) if err != nil { return err diff --git a/go.mod b/go.mod index 6e44eae2..0614e04e 100644 --- a/go.mod +++ b/go.mod @@ -54,7 +54,7 @@ require ( github.com/packethost/packngo v0.29.0 github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 github.com/pluralsh/cluster-api-migration v0.2.15 - github.com/pluralsh/console-client-go v0.0.31 + github.com/pluralsh/console-client-go v0.0.33 github.com/pluralsh/gqlclient v1.11.0 github.com/pluralsh/plural-operator v0.5.5 github.com/pluralsh/polly v0.1.1 diff --git a/go.sum b/go.sum index 19d95946..2e9764ad 100644 --- a/go.sum +++ b/go.sum @@ -1423,8 +1423,8 @@ github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZ github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg= github.com/pluralsh/cluster-api-migration v0.2.15 h1:TIfusD+wnhZTGmwNfIlKlKJOT2dE3rUaZawDJw98GjY= github.com/pluralsh/cluster-api-migration v0.2.15/go.mod h1:J6lEvC/70KouikX16mE331cxc3y3sBwtmfHGwZqu06w= -github.com/pluralsh/console-client-go v0.0.31 h1:M8NPmVmuL4sH8/gC+WlgbXmxOp/y3pX4sQEsqMP86v4= -github.com/pluralsh/console-client-go v0.0.31/go.mod h1:kZjk0pXAWnvyj+miXveCho4kKQaX1Tm3CGAM+iwurWU= +github.com/pluralsh/console-client-go v0.0.33 h1:Bmh5CRBIYyb5wfYlrAntqQZ3GduBTUmzJlmCeo4HAWU= +github.com/pluralsh/console-client-go v0.0.33/go.mod h1:kZjk0pXAWnvyj+miXveCho4kKQaX1Tm3CGAM+iwurWU= github.com/pluralsh/controller-reconcile-helper v0.0.4 h1:1o+7qYSyoeqKFjx+WgQTxDz4Q2VMpzprJIIKShxqG0E= github.com/pluralsh/controller-reconcile-helper v0.0.4/go.mod h1:AfY0gtteD6veBjmB6jiRx/aR4yevEf6K0M13/pGan/s= github.com/pluralsh/gqlclient v1.11.0 h1:FfXW7FiEJLHOfTAa7NxDb8jb3aMZNIpCAcG+bg8uHYA= diff --git a/pkg/console/agent.go b/pkg/console/agent.go index 105ac992..0eba65f1 100644 --- a/pkg/console/agent.go +++ b/pkg/console/agent.go @@ -1,13 +1,12 @@ package console import ( - "errors" "fmt" "time" + "github.com/pkg/errors" "github.com/pluralsh/plural/pkg/helm" "helm.sh/helm/v3/pkg/action" - "helm.sh/helm/v3/pkg/chart/loader" "helm.sh/helm/v3/pkg/cli" "helm.sh/helm/v3/pkg/storage/driver" @@ -47,20 +46,21 @@ func InstallAgent(url, token, namespace string) error { } histClient := action.NewHistory(helmConfig) - histClient.Max = 1 - _, err = histClient.Run(releaseName) - if errors.Is(err, driver.ErrReleaseNotFound) { + histClient.Max = 5 + + if _, err = histClient.Run(releaseName); errors.Is(err, driver.ErrReleaseNotFound) { fmt.Println("installing deployment operator...") instClient := action.NewInstall(helmConfig) instClient.Namespace = namespace instClient.ReleaseName = releaseName instClient.Timeout = time.Minute * 5 _, err = instClient.Run(chart, vals) - return err - } else if err != nil { - return err + if err != nil { + return err + } + return nil } - + fmt.Println("upgrading deployment operator...") client := action.NewUpgrade(helmConfig) client.Namespace = namespace client.Timeout = time.Minute * 5 diff --git a/pkg/console/console.go b/pkg/console/console.go index 289cda93..18d7ba43 100644 --- a/pkg/console/console.go +++ b/pkg/console/console.go @@ -12,10 +12,12 @@ type consoleClient struct { ctx context.Context client *consoleclient.Client url string + token string } type ConsoleClient interface { Url() string + Token() string ListClusters() (*consoleclient.ListClusters, error) GetCluster(clusterId, clusterName *string) (*consoleclient.ClusterFragment, error) UpdateCluster(id string, attr consoleclient.ClusterUpdateAttributes) (*consoleclient.UpdateCluster, error) @@ -38,7 +40,8 @@ type ConsoleClient interface { func NewConsoleClient(token, url string) (ConsoleClient, error) { return &consoleClient{ - url: url, + url: url, + token: token, client: consoleclient.NewClient(http.DefaultClient, fmt.Sprintf("%s/gql", url), func(req *http.Request) { req.Header.Set("Authorization", fmt.Sprintf("Token %s", token)) }), @@ -49,3 +52,7 @@ func NewConsoleClient(token, url string) (ConsoleClient, error) { func (client *consoleClient) Url() string { return client.url } + +func (client *consoleClient) Token() string { + return client.token +} diff --git a/pkg/console/describe.go b/pkg/console/describe.go index dd3b10f4..3e68b39e 100644 --- a/pkg/console/describe.go +++ b/pkg/console/describe.go @@ -92,6 +92,10 @@ func DescribeService(service *consoleclient.ServiceDeploymentExtended) (string, w.Write(LEVEL_2, "Id:\t%s\n", service.Revision.ID) } + if service.Kustomize != nil { + w.Write(LEVEL_0, "Kustomize:\t\n") + w.Write(LEVEL_1, "Path:\t%s\n", service.Kustomize.Path) + } if service.Repository != nil { w.Write(LEVEL_0, "Repository:\t\n") w.Write(LEVEL_1, "Id:\t%s\n", service.Repository.ID)