From aa0ffc980d9fd8b0c57618c5d570c8e35f370757 Mon Sep 17 00:00:00 2001 From: Milos Pejanovic Date: Thu, 26 Jan 2023 13:52:41 +0100 Subject: [PATCH] tidy up suggests for config, add field defaults --- cmd/actions/config.go | 2 +- cmd/actions/root.go | 3 +-- config.go | 29 ++++------------------------- go.mod | 2 +- go.sum | 4 ++-- patch.go | 2 +- patch_test.go | 2 +- test.yaml | 9 +++++++++ 8 files changed, 20 insertions(+), 33 deletions(-) create mode 100644 test.yaml diff --git a/cmd/actions/config.go b/cmd/actions/config.go index 2f8a7d5..7b76d15 100644 --- a/cmd/actions/config.go +++ b/cmd/actions/config.go @@ -29,7 +29,7 @@ var ( if err != nil { return err } - if err := g.Patch(c.Repository, c.Image, c.Container, nil); err != nil { + if err := g.Patch(c.Image, c.Container, nil); err != nil { return err } defer g.Rollback() diff --git a/cmd/actions/root.go b/cmd/actions/root.go index e7c1623..0d72b40 100644 --- a/cmd/actions/root.go +++ b/cmd/actions/root.go @@ -14,7 +14,6 @@ func init() { rootCmd.PersistentFlags().StringVarP(&flagPod, "pod", "p", "", "pod name (default most recent one)") rootCmd.PersistentFlags().StringVarP(&flagContainer, "container", "c", "", "container name (default deployment name)") patchCmd.Flags().StringVar(&flagImage, "image", "alpine:latest", "image to be used for patching (default alpine:latest)") - patchCmd.Flags().StringVarP(&flagRepo, "repo", "r", "", "repository to be used for pushing patched image (default none)") patchCmd.Flags().StringArrayVarP(&flagMounts, "mount", "m", []string{}, "host path to be mounted (default none)") patchCmd.Flags().BoolVar(&flagRollback, "rollback", false, "rollback deployment to a previous state") delveCmd.Flags().StringVar(&flagSourcePath, "source", "", ".go file source path (default cwd)") @@ -79,7 +78,7 @@ var ( if err != nil { return err } - return grapple.Patch(flagRepo, flagImage, flagContainer, mounts) + return grapple.Patch(flagImage, flagContainer, mounts) }, } shellCmd = &cobra.Command{ diff --git a/config.go b/config.go index 577a991..57e9372 100644 --- a/config.go +++ b/config.go @@ -21,11 +21,10 @@ type Config struct { Namespace string `yaml:"namespace" depends:"Cluster"` Deployment string `yaml:"deployment" depends:"Namespace"` Container string `yaml:"container,omitempty" depends:"Deployment"` - Repository string `yaml:"repository,omitempty" depends:"Deployment"` - LaunchVscode bool `yaml:"launch_vscode"` - ListenAddr string `yaml:"listen_addr,omitempty"` - DelveContinue bool `yaml:"delve_continue"` - Image string `yaml:"image,omitempty"` + LaunchVscode bool `yaml:"launch_vscode" default:"false"` + ListenAddr string `yaml:"listen_addr,omitempty" default:":2345"` + DelveContinue bool `yaml:"delve_continue" default:"false"` + Image string `yaml:"image,omitempty" default:"alpine:latest"` } func (c Config) MarshalYAML() (interface{}, error) { @@ -75,12 +74,6 @@ func (c Config) ContainerSuggest(d prompt.Document) []prompt.Suggest { })) } -func (c Config) RepositorySuggest(d prompt.Document) []prompt.Suggest { - return suggest.Completer(d, suggest.MustList(func() ([]string, error) { - return kubectl.ListRepositories(c.Namespace, c.Deployment) - })) -} - func (c Config) LaunchVscodeSuggest(d prompt.Document) []prompt.Suggest { return []prompt.Suggest{{Text: "true"}, {Text: "false"}} } @@ -93,20 +86,6 @@ func (c Config) DelveContinueSuggest(d prompt.Document) []prompt.Suggest { return []prompt.Suggest{{Text: "true"}, {Text: "false"}} } -func (c Config) DockerfileSuggest(d prompt.Document) []prompt.Suggest { - completer := completer.FilePathCompleter{ - IgnoreCase: true, - Filter: func(fi os.FileInfo) bool { - return fi.IsDir() || strings.Contains(fi.Name(), "Dockerfile") - }, - } - return completer.Complete(d) -} - -func (c Config) PlatformSuggest(d prompt.Document) []prompt.Suggest { - return []prompt.Suggest{{Text: "linux/amd64"}, {Text: "linux/arm64"}} -} - func (c Config) ImageSuggest(d prompt.Document) []prompt.Suggest { suggestions := suggest.Completer(d, suggest.MustList(func() ([]string, error) { return kubectl.ListImages(c.Namespace, c.Deployment) diff --git a/go.mod b/go.mod index 518e8b5..0982fdf 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/go-delve/delve v1.8.2 github.com/life4/genesis v1.0.3 github.com/pkg/errors v0.9.1 - github.com/runz0rd/gencon v0.0.0-20220603133745-ec726311da0f + github.com/runz0rd/gencon v0.0.0-20230126123737-56d6d4022194 github.com/sirupsen/logrus v1.8.1 github.com/spf13/cobra v1.4.0 gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b diff --git a/go.sum b/go.sum index 99739c7..7b4c84d 100644 --- a/go.sum +++ b/go.sum @@ -264,8 +264,8 @@ github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= -github.com/runz0rd/gencon v0.0.0-20220603133745-ec726311da0f h1:w9uHnUrlWShGgi/7Th1bQa59iJ40rFxD+P7lSZXUJq4= -github.com/runz0rd/gencon v0.0.0-20220603133745-ec726311da0f/go.mod h1:dKjHe/Q3Fjfv5PNg/ssEhKXlZR9zfl+K7uMk8SxdmKE= +github.com/runz0rd/gencon v0.0.0-20230126123737-56d6d4022194 h1:PNDnfufSiFUVszrE9blUjXN11Nc7c3lGOwJJPuNjKX4= +github.com/runz0rd/gencon v0.0.0-20230126123737-56d6d4022194/go.mod h1:dKjHe/Q3Fjfv5PNg/ssEhKXlZR9zfl+K7uMk8SxdmKE= github.com/runz0rd/go-prompt v0.2.51 h1:XnDT/A+m/omQw4V91UcnywdmW+OXjf9ndsT3pe3e50s= github.com/runz0rd/go-prompt v0.2.51/go.mod h1:vFnjEGDIIA/Lib7giyE4E9c50Lvl8j0S+7FVlAwDAVw= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= diff --git a/patch.go b/patch.go index 80fc078..3cddea3 100644 --- a/patch.go +++ b/patch.go @@ -42,7 +42,7 @@ func (g Grapple) newPatchValues(deployment, container, image string, mounts []Mo } } -func (g Grapple) Patch(repo, image, container string, mounts []Mount) error { +func (g Grapple) Patch(image, container string, mounts []Mount) error { ctx := context.Background() if g.isPatched() { g.l.Warn("deployment already patched, rolling back first") diff --git a/patch_test.go b/patch_test.go index f6d8ae1..422a6b4 100644 --- a/patch_test.go +++ b/patch_test.go @@ -21,7 +21,7 @@ func TestGrapple_Patch(t *testing.T) { g := testGrapple(t, "example") for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if err := g.Patch(tt.args.repo, tt.args.dockerfile, tt.args.container, tt.args.mounts); (err != nil) != tt.wantErr { + if err := g.Patch(tt.args.dockerfile, tt.args.container, tt.args.mounts); (err != nil) != tt.wantErr { t.Errorf("Grapple.Patch() error = %v, wantErr %v", err, tt.wantErr) } }) diff --git a/test.yaml b/test.yaml new file mode 100644 index 0000000..96ee0b6 --- /dev/null +++ b/test.yaml @@ -0,0 +1,9 @@ +source_path: /Users/mpejanovic/Documents/dev/gograpple/test/app/main.go +cluster: k3d-local +namespace: default +deployment: example +container: example +launch_vscode: true +listen_addr: :2345 +delve_continue: false +image: alpine:latest