Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add dry run support for cd commands #484

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading