diff --git a/.gitignore b/.gitignore index 2a5ed0a1..0c25d58d 100644 --- a/.gitignore +++ b/.gitignore @@ -9,5 +9,6 @@ node_modules/ note/ .jvmrc +.envrc .DS_Store vendor/ \ No newline at end of file diff --git a/pkg/kt/command/util.go b/pkg/kt/command/util.go index ff615c57..3e8522cf 100644 --- a/pkg/kt/command/util.go +++ b/pkg/kt/command/util.go @@ -63,6 +63,13 @@ func CleanupWorkspace(options *options.DaemonOptions) { } } + if _, err := os.Stat(".envrc"); err == nil { + log.Info().Msgf("- Remove .envrc %s", options.RuntimeOptions.PidFile) + if err = os.Remove(".envrc"); err != nil { + log.Error().Err(err).Msg("delete .envrc failed") + } + } + util.DropHosts(options.ConnectOptions.Hosts) client, err := cluster.GetKubernetesClient(options.KubeConfig) if err != nil { diff --git a/pkg/kt/connect/outbound.go b/pkg/kt/connect/outbound.go index 516165d9..c6e45584 100644 --- a/pkg/kt/connect/outbound.go +++ b/pkg/kt/connect/outbound.go @@ -37,6 +37,7 @@ func (s *Shadow) Outbound(name, podIP string, cidrs []string) (err error) { log.Info().Msgf("Start SOCKS5 Proxy: export http_proxy=socks5://127.0.0.1:%d", options.ConnectOptions.Socke5Proxy) log.Info().Msgf("==============================================================") _ = ioutil.WriteFile(".jvmrc", []byte(fmt.Sprintf("-DsocksProxyHost=127.0.0.1\n-DsocksProxyPort=%d", options.ConnectOptions.Socke5Proxy)), 0644) + _ = ioutil.WriteFile(".envrc", []byte(fmt.Sprintf("KUBERNETES_NAMESPACE=%s", options.Namespace)), 0644) err = exec.BackgroundRun(ssh.DynamicForwardLocalRequestToRemote("127.0.0.1", options.ConnectOptions.SSHPort, options.ConnectOptions.Socke5Proxy), "vpn(ssh)", options.Debug) } else { err = exec.BackgroundRun(sshuttle.SSHUttle("127.0.0.1", options.ConnectOptions.SSHPort, podIP, options.ConnectOptions.DisableDNS, cidrs, options.Debug), "vpn(sshuttle)", options.Debug)