Commit bb4c7e56 authored by 金戟's avatar 金戟
Browse files

feat: also dump full cluster domain of service

parent 40625973
Showing with 24 additions and 17 deletions
+24 -17
......@@ -116,24 +116,24 @@ func getOrCreateShadow(options *options.DaemonOptions, err error, kubernetes clu
}
func setupDump2Host(options *options.DaemonOptions, kubernetes cluster.KubernetesInterface) {
hosts := kubernetes.ServiceHosts(options.Namespace)
for k, v := range hosts {
log.Info().Msgf("Service found: %s %s", k, v)
}
if len(options.ConnectOptions.Dump2HostsNamespaces) > 0 {
for _, namespace := range options.ConnectOptions.Dump2HostsNamespaces {
if namespace == options.Namespace {
continue
var namespaceToDump = options.ConnectOptions.Dump2HostsNamespaces
if len(namespaceToDump) == 0 {
namespaceToDump = append(namespaceToDump, options.Namespace)
}
hosts := map[string]string{}
for _, namespace := range namespaceToDump {
log.Debug().Msgf("Search service in %s namespace...", namespace)
singleHosts := kubernetes.ServiceHosts(namespace)
for svc, ip := range singleHosts {
if ip == "" || ip == "None" {
continue
}
log.Info().Msgf("Service found: %s.%s %s", svc, namespace, ip)
hosts[svc+"."+namespace] = ip
log.Debug().Msgf("Service found: %s.%s %s", svc, namespace, ip)
if namespace == options.Namespace {
hosts[svc] = ip
}
hosts[svc+"."+namespace] = ip
hosts[svc+"."+namespace+"."+options.ConnectOptions.ClusterDomain] = ip
}
}
util.DumpHosts(hosts)
......
......@@ -70,13 +70,13 @@ func ConnectActionFlag(options *options.DaemonOptions) []cli.Flag {
Destination: &options.ConnectOptions.Method,
},
cli.IntFlag{
Name: "proxy",
Name: "proxyPort",
Value: 2223,
Usage: "when should method socks5, you can choice which port to proxy",
Destination: &options.ConnectOptions.SocksPort,
},
cli.IntFlag{
Name: "port",
Name: "sshPort",
Value: 2222,
Usage: "Local SSH Proxy port",
Destination: &options.ConnectOptions.SSHPort,
......@@ -106,6 +106,12 @@ func ConnectActionFlag(options *options.DaemonOptions) []cli.Flag {
Usage: "Set local domain suffix to help dns resolve properly",
Destination: &options.ConnectOptions.LocalDomain,
},
cli.StringFlag{
Name: "clusterDomain",
Usage: "The cluster domain provided to kubernetes api-server",
Value: "cluster.local",
Destination: &options.ConnectOptions.ClusterDomain,
},
}
}
......
......@@ -26,6 +26,7 @@ type ConnectOptions struct {
Dump2HostsNamespaces cli.StringSlice
ShareShadow bool
LocalDomain string
ClusterDomain string
}
// ExchangeOptions ...
......
Supports Markdown
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