Skip to content

Commit f882d63

Browse files
fntlnzleodido
andcommitted
feat(kubectl-trace): removed old command and some cleanup
Co-authored-by: Leonardo Di Donato <[email protected]> Signed-off-by: Lorenzo Fontana <[email protected]>
1 parent eb190ff commit f882d63

File tree

12 files changed

+63
-396
lines changed

12 files changed

+63
-396
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ kubectl_trace ?= _output/bin/kubectl-trace
1919
build: clean ${kubectl_trace}
2020

2121
${kubectl_trace}:
22-
GO111MODULE=on $(GO) build -o $@ ./cmd
22+
GO111MODULE=on $(GO) build -o $@ ./cmd/kubectl-trace
2323

2424
.PHONY: clean
2525
clean:

cmd/kubectl-trace/delete.go

-68
This file was deleted.

cmd/kubectl-trace/get.go

-103
This file was deleted.

cmd/kubectl-trace/main.go

-5
This file was deleted.

cmd/kubectl-trace/root.go

+13-56
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,24 @@
11
package main
22

33
import (
4-
"fmt"
54
"os"
65

7-
homedir "github.com/mitchellh/go-homedir"
8-
"github.com/spf13/cobra"
9-
"github.com/spf13/viper"
10-
apiv1 "k8s.io/api/core/v1"
11-
//"k8s.io/cli-runtime/pkg/genericclioptions"
6+
"github.com/fntlnz/kubectl-trace/pkg/cmd"
7+
"github.com/spf13/pflag"
8+
"k8s.io/cli-runtime/pkg/genericclioptions"
129
)
1310

14-
var cfgFile string
11+
func main() {
12+
flags := pflag.NewFlagSet("kubectl-trace", pflag.ExitOnError)
13+
pflag.CommandLine = flags
1514

16-
var rootCmd = &cobra.Command{
17-
Use: "trace",
18-
Short: "Execute and manage bpftrace programs on your kubernetes cluster",
19-
}
20-
21-
func Execute() {
22-
if err := rootCmd.Execute(); err != nil {
23-
fmt.Println(err)
24-
os.Exit(1)
15+
streams := genericclioptions.IOStreams{
16+
In: os.Stdin,
17+
Out: os.Stdout,
18+
ErrOut: os.Stderr,
2519
}
26-
}
27-
28-
func init() {
29-
cobra.OnInitialize(initConfig)
30-
31-
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.kubectl-trace.yaml)")
32-
33-
rootCmd.PersistentFlags().String("kubeconfig", "", "Path to the kubeconfig file to use for CLI requests.")
34-
viper.BindPFlag("kubeconfig", rootCmd.PersistentFlags().Lookup("kubeconfig"))
35-
viper.BindEnv("kubeconfig", "KUBECONFIG")
36-
37-
rootCmd.PersistentFlags().StringP("namespace", "n", apiv1.NamespaceDefault, "If present, the namespace scope for this CLI request")
38-
viper.BindPFlag("namespace", rootCmd.PersistentFlags().Lookup("namespace"))
39-
40-
rootCmd.AddCommand(runCmd)
41-
rootCmd.AddCommand(deleteCmd)
42-
rootCmd.AddCommand(getCmd)
43-
}
44-
45-
// initConfig reads in config file and ENV variables if set.
46-
func initConfig() {
47-
if cfgFile != "" {
48-
// Use config file from the flag.
49-
viper.SetConfigFile(cfgFile)
50-
} else {
51-
// Find home directory.
52-
home, err := homedir.Dir()
53-
if err != nil {
54-
fmt.Println(err)
55-
os.Exit(1)
56-
}
57-
58-
// Search config in home directory with name ".kubectl-trace" (without extension).
59-
viper.AddConfigPath(home)
60-
viper.SetConfigName(".kubectl-trace")
61-
}
62-
63-
// If a config file is found, read it in.
64-
if err := viper.ReadInConfig(); err == nil {
65-
fmt.Println("Using config file:", viper.ConfigFileUsed())
20+
root := cmd.NewTraceCommand(streams)
21+
if err := root.Execute(); err != nil {
22+
os.Exit(1)
6623
}
6724
}

cmd/kubectl-trace/run.go

-113
This file was deleted.

0 commit comments

Comments
 (0)