-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(kubectl-trace): removed old command and some cleanup
Co-authored-by: Leonardo Di Donato <[email protected]> Signed-off-by: Lorenzo Fontana <[email protected]>
- Loading branch information
Showing
12 changed files
with
63 additions
and
396 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,24 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
homedir "github.com/mitchellh/go-homedir" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
apiv1 "k8s.io/api/core/v1" | ||
//"k8s.io/cli-runtime/pkg/genericclioptions" | ||
"github.com/fntlnz/kubectl-trace/pkg/cmd" | ||
"github.com/spf13/pflag" | ||
"k8s.io/cli-runtime/pkg/genericclioptions" | ||
) | ||
|
||
var cfgFile string | ||
func main() { | ||
flags := pflag.NewFlagSet("kubectl-trace", pflag.ExitOnError) | ||
pflag.CommandLine = flags | ||
|
||
var rootCmd = &cobra.Command{ | ||
Use: "trace", | ||
Short: "Execute and manage bpftrace programs on your kubernetes cluster", | ||
} | ||
|
||
func Execute() { | ||
if err := rootCmd.Execute(); err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
streams := genericclioptions.IOStreams{ | ||
In: os.Stdin, | ||
Out: os.Stdout, | ||
ErrOut: os.Stderr, | ||
} | ||
} | ||
|
||
func init() { | ||
cobra.OnInitialize(initConfig) | ||
|
||
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.kubectl-trace.yaml)") | ||
|
||
rootCmd.PersistentFlags().String("kubeconfig", "", "Path to the kubeconfig file to use for CLI requests.") | ||
viper.BindPFlag("kubeconfig", rootCmd.PersistentFlags().Lookup("kubeconfig")) | ||
viper.BindEnv("kubeconfig", "KUBECONFIG") | ||
|
||
rootCmd.PersistentFlags().StringP("namespace", "n", apiv1.NamespaceDefault, "If present, the namespace scope for this CLI request") | ||
viper.BindPFlag("namespace", rootCmd.PersistentFlags().Lookup("namespace")) | ||
|
||
rootCmd.AddCommand(runCmd) | ||
rootCmd.AddCommand(deleteCmd) | ||
rootCmd.AddCommand(getCmd) | ||
} | ||
|
||
// initConfig reads in config file and ENV variables if set. | ||
func initConfig() { | ||
if cfgFile != "" { | ||
// Use config file from the flag. | ||
viper.SetConfigFile(cfgFile) | ||
} else { | ||
// Find home directory. | ||
home, err := homedir.Dir() | ||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
|
||
// Search config in home directory with name ".kubectl-trace" (without extension). | ||
viper.AddConfigPath(home) | ||
viper.SetConfigName(".kubectl-trace") | ||
} | ||
|
||
// If a config file is found, read it in. | ||
if err := viper.ReadInConfig(); err == nil { | ||
fmt.Println("Using config file:", viper.ConfigFileUsed()) | ||
root := cmd.NewTraceCommand(streams) | ||
if err := root.Execute(); err != nil { | ||
os.Exit(1) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.