Skip to content
Snippets Groups Projects
Unverified Commit dfe8aafc authored by Alex Clemmer's avatar Alex Clemmer Committed by GitHub
Browse files

Merge pull request #60 from jessicayuen/env-context-fix

Pass context & overrides by reference when initiating client
parents 06c4cc80 beddf415
No related branches found
No related tags found
No related merge requests found
...@@ -270,10 +270,10 @@ func initDiffRemoteCmd(localEnv, remoteEnv, diffStrategy string, cmd *cobra.Comm ...@@ -270,10 +270,10 @@ func initDiffRemoteCmd(localEnv, remoteEnv, diffStrategy string, cmd *cobra.Comm
} }
func setupClientConfig(env *string, cmd *cobra.Command) (dynamic.ClientPool, discovery.DiscoveryInterface, string, error) { func setupClientConfig(env *string, cmd *cobra.Command) (dynamic.ClientPool, discovery.DiscoveryInterface, string, error) {
overrides := clientcmd.ConfigOverrides{} overrides := &clientcmd.ConfigOverrides{}
loadingRules := *clientcmd.NewDefaultClientConfigLoadingRules() loadingRules := *clientcmd.NewDefaultClientConfigLoadingRules()
loadingRules.DefaultClientConfig = &clientcmd.DefaultClientConfig loadingRules.DefaultClientConfig = &clientcmd.DefaultClientConfig
config := clientcmd.NewInteractiveDeferredLoadingClientConfig(&loadingRules, &overrides, os.Stdin) config := clientcmd.NewInteractiveDeferredLoadingClientConfig(&loadingRules, overrides, os.Stdin)
clientPool, discovery, err := restClient(cmd, env, config, overrides) clientPool, discovery, err := restClient(cmd, env, config, overrides)
if err != nil { if err != nil {
......
...@@ -121,10 +121,10 @@ var RootCmd = &cobra.Command{ ...@@ -121,10 +121,10 @@ var RootCmd = &cobra.Command{
// clientConfig.Namespace() is broken in client-go 3.0: // clientConfig.Namespace() is broken in client-go 3.0:
// namespace in config erroneously overrides explicit --namespace // namespace in config erroneously overrides explicit --namespace
func namespace() (string, error) { func namespace() (string, error) {
return namespaceFor(clientConfig, overrides) return namespaceFor(clientConfig, &overrides)
} }
func namespaceFor(c clientcmd.ClientConfig, overrides clientcmd.ConfigOverrides) (string, error) { func namespaceFor(c clientcmd.ClientConfig, overrides *clientcmd.ConfigOverrides) (string, error) {
if overrides.Context.Namespace != "" { if overrides.Context.Namespace != "" {
return overrides.Context.Namespace, nil return overrides.Context.Namespace, nil
} }
...@@ -260,7 +260,7 @@ func dumpJSON(v interface{}) string { ...@@ -260,7 +260,7 @@ func dumpJSON(v interface{}) string {
return string(buf.Bytes()) return string(buf.Bytes())
} }
func restClient(cmd *cobra.Command, envName *string, config clientcmd.ClientConfig, overrides clientcmd.ConfigOverrides) (dynamic.ClientPool, discovery.DiscoveryInterface, error) { func restClient(cmd *cobra.Command, envName *string, config clientcmd.ClientConfig, overrides *clientcmd.ConfigOverrides) (dynamic.ClientPool, discovery.DiscoveryInterface, error) {
if envName != nil { if envName != nil {
err := overrideCluster(*envName, config, overrides) err := overrideCluster(*envName, config, overrides)
if err != nil { if err != nil {
...@@ -287,7 +287,7 @@ func restClient(cmd *cobra.Command, envName *string, config clientcmd.ClientConf ...@@ -287,7 +287,7 @@ func restClient(cmd *cobra.Command, envName *string, config clientcmd.ClientConf
} }
func restClientPool(cmd *cobra.Command, envName *string) (dynamic.ClientPool, discovery.DiscoveryInterface, error) { func restClientPool(cmd *cobra.Command, envName *string) (dynamic.ClientPool, discovery.DiscoveryInterface, error) {
return restClient(cmd, envName, clientConfig, overrides) return restClient(cmd, envName, clientConfig, &overrides)
} }
type envSpec struct { type envSpec struct {
...@@ -326,7 +326,7 @@ func parseEnvCmd(cmd *cobra.Command, args []string) (*envSpec, error) { ...@@ -326,7 +326,7 @@ func parseEnvCmd(cmd *cobra.Command, args []string) (*envSpec, error) {
// If the environment server the user is attempting to deploy to is not the current // If the environment server the user is attempting to deploy to is not the current
// kubeconfig context, we must manually override the client-go --cluster flag // kubeconfig context, we must manually override the client-go --cluster flag
// to ensure we are deploying to the correct cluster. // to ensure we are deploying to the correct cluster.
func overrideCluster(envName string, clientConfig clientcmd.ClientConfig, overrides clientcmd.ConfigOverrides) error { func overrideCluster(envName string, clientConfig clientcmd.ClientConfig, overrides *clientcmd.ConfigOverrides) error {
cwd, err := os.Getwd() cwd, err := os.Getwd()
if err != nil { if err != nil {
return err return err
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment