Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/deployments' into deployments
Browse files Browse the repository at this point in the history
  • Loading branch information
maciaszczykm committed Nov 10, 2023
2 parents fbcf43e + a97fc58 commit dcc779c
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 17 deletions.
4 changes: 2 additions & 2 deletions cmd/plural/cd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
},
},
{
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cmd/plural/cd_clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
19 changes: 18 additions & 1 deletion cmd/plural/cd_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
18 changes: 9 additions & 9 deletions pkg/console/agent.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion pkg/console/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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))
}),
Expand All @@ -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
}
4 changes: 4 additions & 0 deletions pkg/console/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit dcc779c

Please sign in to comment.