Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding option to ignore default KUBECONFIG (new switch "-i") #10

Merged
merged 2 commits into from
Sep 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 26 additions & 21 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,20 @@ import (
)

var (
PortFlag string
NamespaceFlag string
ContainerFlag string
PodFlag string
ServerIpAddressFlag string
ServerFullAddressGlobal string
PodUidFlag string
KubeConfigFlag string
ProtocolScheme string
caFlag string
certFlag string
keyFlag string
HttpFlag bool
PortFlag string
NamespaceFlag string
ContainerFlag string
PodFlag string
ServerIpAddressFlag string
ServerFullAddressGlobal string
PodUidFlag string
KubeConfigFlag string
ProtocolScheme string
caFlag string
certFlag string
keyFlag string
HttpFlag bool
IgnoreDefaultKubeConfigFlag bool
//BodyContentFlag string
RawFlag bool
)
Expand Down Expand Up @@ -61,6 +62,7 @@ var RootCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
// Do Stuff Here
printLogo()
cmd.Help()
},
}

Expand All @@ -86,6 +88,7 @@ func init() {
RootCmd.PersistentFlags().StringVarP(&KubeConfigFlag, "config", "k", "", "KubeConfig file")
RootCmd.PersistentFlags().BoolVarP(&RawFlag, "raw", "r", false, "Prints raw data")
RootCmd.PersistentFlags().BoolVarP(&HttpFlag, "http", "", false, "Use HTTP (default is HTTPS)")
RootCmd.PersistentFlags().BoolVarP(&IgnoreDefaultKubeConfigFlag, "ignoreconfig", "i", false, "Ignore the default KUBECONFIG environment variable or location ~/.kube")
//RootCmd.PersistentFlags().StringVarP(&BodyContentFlag, "body", "b", "", "This is the body message. Should be used in POST or PUT requests.")

RootCmd.PersistentFlags().StringVarP(&caFlag, "cacert", "", "", "CA certificate (example: /etc/kubernetes/pki/ca.crt )")
Expand Down Expand Up @@ -125,14 +128,16 @@ func initConfig() {
},
}
} else {
kubeConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
clientcmd.NewDefaultClientConfigLoadingRules(),
&clientcmd.ConfigOverrides{},
)
config, err = kubeConfig.ClientConfig()
if err != nil && len(os.Getenv(clientcmd.RecommendedConfigPathEnvVar)) > 0 {
fmt.Fprintln(os.Stderr, "[*] There is a problem with the file in KUBECONFIG environment variable")
panic(err.Error())
if !IgnoreDefaultKubeConfigFlag {
kubeConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
clientcmd.NewDefaultClientConfigLoadingRules(),
&clientcmd.ConfigOverrides{},
)
config, err = kubeConfig.ClientConfig()
if err != nil && len(os.Getenv(clientcmd.RecommendedConfigPathEnvVar)) > 0 {
fmt.Fprintln(os.Stderr, "[*] There is a problem with the file in KUBECONFIG environment variable\n[*] You can ignore it by modifying the KUBECONFIG environment variable, file \"~/.kube/config\" or use the \"-i\" switch")
panic(err.Error())
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/api/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func InitHttpClient(config *restclient.Config) {
var tr *http.Transport

if config != nil {
fmt.Fprintln(os.Stderr, "[*] Using KUBECONFIG environment variable")
fmt.Fprintln(os.Stderr, "[*] Using KUBECONFIG environment variable\n[*] You can ignore it by modifying the KUBECONFIG environment variable, file \"~/.kube/config\" or use the \"-i\" switch")
tr = getHttpTransportWithCertificates(config, insecure)
} else {
tr = &http.Transport{
Expand Down