Skip to content

Commit

Permalink
add dry run support for cd commands (#484)
Browse files Browse the repository at this point in the history
  • Loading branch information
zreigz authored Jan 18, 2024
1 parent 1685bfc commit 3861ee3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
12 changes: 12 additions & 0 deletions cmd/plural/cd_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func (p *Plural) cdServiceCommands() []cli.Command {
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.BoolFlag{Name: "dry-run", Usage: "dry run mode"},
cli.StringSliceFlag{
Name: "conf",
Usage: "config name value",
Expand All @@ -62,6 +63,7 @@ func (p *Plural) cdServiceCommands() []cli.Command {
Name: "conf",
Usage: "config name value",
},
cli.BoolFlag{Name: "dry-run", Usage: "dry run mode"},
},
},
{
Expand Down Expand Up @@ -129,6 +131,7 @@ func (p *Plural) handleCreateClusterService(c *cli.Context) error {
repoId := c.String("repo-id")
gitRef := c.String("git-ref")
gitFolder := c.String("git-folder")
dryRun := c.Bool("dry-run")
attributes := gqlclient.ServiceDeploymentAttributes{
Name: name,
Namespace: namespace,
Expand All @@ -139,6 +142,7 @@ func (p *Plural) handleCreateClusterService(c *cli.Context) error {
Folder: gitFolder,
},
Configuration: []*gqlclient.ConfigAttributes{},
DryRun: lo.ToPtr(dryRun),
}

if c.String("kustomize-folder") != "" {
Expand Down Expand Up @@ -266,6 +270,9 @@ func (p *Plural) handleUpdateClusterService(c *cli.Context) error {
},
Configuration: []*gqlclient.ConfigAttributes{},
}
if existing.DryRun != nil {
attributes.DryRun = existing.DryRun
}
if existing.Kustomize != nil {
attributes.Kustomize = &gqlclient.KustomizeAttributes{
Path: existing.Kustomize.Path,
Expand Down Expand Up @@ -312,6 +319,11 @@ func (p *Plural) handleUpdateClusterService(c *cli.Context) error {
Path: c.String("kustomize-folder"),
}
}
if c.IsSet("dry-run") {
dryRun := c.Bool("dry-run")
attributes.DryRun = &dryRun
}

sd, err := p.ConsoleClient.UpdateClusterService(serviceId, serviceName, clusterName, attributes)
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,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.70
github.com/pluralsh/console-client-go v0.0.80
github.com/pluralsh/gqlclient v1.11.0
github.com/pluralsh/plural-operator v0.5.5
github.com/pluralsh/polly v0.1.1
Expand All @@ -75,6 +75,7 @@ require (
golang.org/x/mod v0.10.0
golang.org/x/oauth2 v0.8.0
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1
helm.sh/helm/v3 v3.11.2
k8s.io/api v0.26.4
k8s.io/apimachinery v0.26.4
Expand Down Expand Up @@ -284,7 +285,6 @@ require (
gopkg.in/cheggaaa/pb.v1 v1.0.28 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/cluster-bootstrap v0.25.3 // indirect
k8s.io/kops v1.25.2 // indirect
k8s.io/kube-aggregator v0.25.2 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1428,8 +1428,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.70 h1:itLfOGpIpt+sASS+X0FTmB/OF3vUY6YnUGx9a+j34So=
github.com/pluralsh/console-client-go v0.0.70/go.mod h1:u/RjzXE3wtl3L6wiWxwhQHSpxFX46+EYvpkss2mALN4=
github.com/pluralsh/console-client-go v0.0.80 h1:jL0LE6YnddXz4j6LLBt7hRyIOOhxdVbvC6fvLlm8lMA=
github.com/pluralsh/console-client-go v0.0.80/go.mod h1:u/RjzXE3wtl3L6wiWxwhQHSpxFX46+EYvpkss2mALN4=
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
5 changes: 5 additions & 0 deletions pkg/console/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ func DescribeService(service *consoleclient.ServiceDeploymentExtended) (string,
if service.DeletedAt != nil {
w.Write(LEVEL_0, "Status:\tTerminating (lasts %s)\n", *service.DeletedAt)
}
dryRun := false
if service.DryRun != nil {
dryRun = *service.DryRun
}
w.Write(LEVEL_0, "Dry run:\t%v\n", dryRun)
w.Write(LEVEL_0, "Git:\t\n")
w.Write(LEVEL_1, "Ref:\t%s\n", service.Git.Ref)
w.Write(LEVEL_1, "Folder:\t%s\n", service.Git.Folder)
Expand Down

0 comments on commit 3861ee3

Please sign in to comment.