Skip to content

Commit

Permalink
Merge pull request #112 from alfadb/release-0.0.12
Browse files Browse the repository at this point in the history
dump2hosts改为输入namespace列表,用逗号分隔
  • Loading branch information
yunlzheng authored Apr 3, 2020
2 parents 11ef7c8 + 8420380 commit 0069dc1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
25 changes: 25 additions & 0 deletions pkg/kt/command/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ func newConnectCommand(options *options.DaemonOptions, action ActionInterface) c
Usage: "Auto write service to local hosts file",
Destination: &options.ConnectOptions.Dump2Hosts,
},
cli.StringSliceFlag{
Name: "dump2hostsNS",
Usage: "Which namespaces service to local hosts file, support multiple namespaces.",
Value: &options.ConnectOptions.Dump2HostsNamespaces,
},
},
Action: func(c *cli.Context) error {
if options.Debug {
Expand Down Expand Up @@ -101,7 +106,27 @@ func (action *Action) Connect(options *options.DaemonOptions) (err error) {
func connectToCluster(shadow connect.ShadowInterface, kubernetes cluster.KubernetesInterface, options *options.DaemonOptions) (err error) {

if options.ConnectOptions.Dump2Hosts {
log.Debug().Msgf("Serach service in %s namespace...", options.Namespace)
hosts := kubernetes.ServiceHosts(options.Namespace)
for k, v := range hosts {
log.Debug().Msgf("Service found: %s %s", k, v)
}
if options.ConnectOptions.Dump2HostsNamespaces != nil {
for _, namespace := range options.ConnectOptions.Dump2HostsNamespaces {
if namespace == options.Namespace {
continue
}
log.Debug().Msgf("Serach service in %s namespace...", namespace)
singleHosts := kubernetes.ServiceHosts(namespace)
for k, v := range singleHosts {
if v == "" || v == "None" {
continue
}
log.Debug().Msgf("Service found: %s.%s %s", k, namespace, v)
hosts[k+"."+namespace] = v
}
}
}
util.DumpHosts(hosts)
options.ConnectOptions.Hosts = hosts
}
Expand Down
16 changes: 9 additions & 7 deletions pkg/kt/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

"github.com/alibaba/kt-connect/pkg/kt/util"
"github.com/urfave/cli"
)

type runOptions struct {
Expand All @@ -12,13 +13,14 @@ type runOptions struct {
}

type connectOptions struct {
DisableDNS bool
SSHPort int
Socke5Proxy int
CIDR string
Method string
Dump2Hosts bool
Hosts map[string]string
DisableDNS bool
SSHPort int
Socke5Proxy int
CIDR string
Method string
Dump2Hosts bool
Dump2HostsNamespaces cli.StringSlice
Hosts map[string]string
}

type exchangeOptions struct {
Expand Down

0 comments on commit 0069dc1

Please # to comment.