Skip to content

Commit 25a880b

Browse files
ybelMekksindrerh2Reasonable-Solutions
committed
chore(mod): clean up code
Co-authored-by: Sindre Rødseth Hansen <[email protected]> Co-authored-by: Carl Hedgren <[email protected]>
1 parent e987373 commit 25a880b

File tree

3 files changed

+7
-20
lines changed

3 files changed

+7
-20
lines changed

cmd/debugcmd/debugcmd.go

+5-17
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@ const (
1717
func Command() *cli.Command {
1818
return &cli.Command{
1919
Name: "debug",
20-
Usage: "Debug nais application",
20+
Usage: "Debug an application",
2121
ArgsUsage: "appname",
2222
Subcommands: []*cli.Command{
2323
tidyCommand(),
2424
},
2525
Flags: []cli.Flag{
26-
namespaceFlag(),
2726
kubeConfigFlag(),
2827
},
2928
Before: func(context *cli.Context) error {
@@ -36,11 +35,9 @@ func Command() *cli.Command {
3635
Action: func(cCtx *cli.Context) error {
3736
cfg := makeConfig(cCtx)
3837
cluster := cCtx.String(contextFlagName)
39-
namespace := cCtx.String(namespaceFlagName)
4038
client := k8s.SetupControllerRuntimeClient(k8s.WithKubeContext(cluster))
41-
cfg.Namespace = client.CurrentNamespace
42-
if namespace != "" {
43-
cfg.Namespace = namespace
39+
if cfg.Namespace == "" {
40+
cfg.Namespace = client.CurrentNamespace
4441
}
4542

4643
clientset, err := k8s.SetupClientGo(cluster)
@@ -50,22 +47,13 @@ func Command() *cli.Command {
5047

5148
dg := debug.Setup(clientset, cfg)
5249
if err := dg.Debug(); err != nil {
53-
return fmt.Errorf("error debugging instance: %w", err)
50+
return fmt.Errorf("debugging instance: %w", err)
5451
}
5552
return nil
5653
},
5754
}
5855
}
5956

60-
func namespaceFlag() *cli.StringFlag {
61-
return &cli.StringFlag{
62-
Name: namespaceFlagName,
63-
DefaultText: "The namespace from your current kubeconfig context",
64-
Usage: "The kubernetes `NAMESPACE` to use",
65-
Aliases: []string{"n"},
66-
}
67-
}
68-
6957
func kubeConfigFlag() *cli.StringFlag {
7058
return &cli.StringFlag{
7159
Name: contextFlagName,
@@ -76,7 +64,7 @@ func kubeConfigFlag() *cli.StringFlag {
7664
}
7765

7866
func makeConfig(cCtx *cli.Context) debug.Config {
79-
appName := cCtx.Args().Get(0)
67+
appName := cCtx.Args().First()
8068
namespace := cCtx.Args().Get(1)
8169

8270
return debug.Config{

cmd/debugcmd/tidycmd.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ func tidyCommand() *cli.Command {
1414
Usage: "Clean up ephemeral containers and debug pods",
1515
ArgsUsage: "appname",
1616
Flags: []cli.Flag{
17-
namespaceFlag(),
1817
kubeConfigFlag(),
1918
},
2019
Before: func(context *cli.Context) error {
@@ -41,7 +40,7 @@ func tidyCommand() *cli.Command {
4140

4241
dg := debug.Setup(clientset, cfg)
4342
if err := dg.Tidy(); err != nil {
44-
return fmt.Errorf("error debugging instance: %w", err)
43+
return fmt.Errorf("debugging instance: %w", err)
4544
}
4645
return nil
4746
},

pkg/debug/debug.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func Setup(client kubernetes.Interface, cfg Config) *Debug {
4141
func (d *Debug) getApp() (*v1.Deployment, error) {
4242
app, err := d.client.AppsV1().Deployments(d.cfg.Namespace).Get(d.ctx, d.cfg.AppName, metav1.GetOptions{})
4343
if err != nil {
44-
return nil, fmt.Errorf("failed to get application: %w", err)
44+
return nil, fmt.Errorf("failed to get application in namespace \"%s\": %w", d.cfg.Namespace, err)
4545
}
4646
return app, nil
4747
}

0 commit comments

Comments
 (0)