Skip to content

Commit

Permalink
feat(kubectl-trace): removed old command and some cleanup
Browse files Browse the repository at this point in the history
Co-authored-by: Leonardo Di Donato <[email protected]>
Signed-off-by: Lorenzo Fontana <[email protected]>
  • Loading branch information
fntlnz and leodido committed Nov 25, 2018
1 parent eb190ff commit f882d63
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 396 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ kubectl_trace ?= _output/bin/kubectl-trace
build: clean ${kubectl_trace}

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

.PHONY: clean
clean:
Expand Down
68 changes: 0 additions & 68 deletions cmd/kubectl-trace/delete.go

This file was deleted.

103 changes: 0 additions & 103 deletions cmd/kubectl-trace/get.go

This file was deleted.

5 changes: 0 additions & 5 deletions cmd/kubectl-trace/main.go

This file was deleted.

69 changes: 13 additions & 56 deletions cmd/kubectl-trace/root.go
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)
}
}
113 changes: 0 additions & 113 deletions cmd/kubectl-trace/run.go

This file was deleted.

Loading

0 comments on commit f882d63

Please sign in to comment.