in cmd/hbone/hbone.go [49:102]
func main() {
// WIP - multiple ports
//flag.Var(&localForwards, "LocalForward", "SSH-style local forward")
flag.Parse()
kr := mesh.New()
ctx, cf := context.WithTimeout(context.Background(), 10000*time.Second)
defer cf()
gcp.InitGCP(ctx, kr)
// Use kubeconfig or gcp to find the cluster
err := kr.LoadConfig(ctx)
if err != nil {
log.Fatal("Failed to connect to K8S ", time.Since(kr.StartTime), kr, os.Environ(), err)
}
// Not calling RefreshAndSaveTokens - hbone is not creating files, jwts and certs in memory only.
// Also not initializing pilot-agent or envoy - this is just using k8s to configure the hbone tunnel
tokenProvider, err := sts.NewSTS(kr)
if kr.MeshConnectorAddr == "" {
log.Fatal("Failed to find in-cluster, missing 'hgate' service in mesh env")
}
kr.XDSAddr = kr.MeshConnectorAddr + ":15012"
hb := hbone.New()
tcache := sts.NewTokenCache(kr, tokenProvider)
hb.TokenCallback = tcache.Token
if *localForward != "" {
go localForwardPort(hb, kr.MeshConnectorAddr)
}
if len(flag.Args()) == 0 && *localForward == "" {
flag.Usage()
os.Exit(1)
}
if len(flag.Args()) > 0 {
dest := flag.Arg(0)
err := forward(dest, hb, kr.MeshConnectorAddr, os.Stdin, os.Stdout)
if err != nil {
fmt.Fprintln(os.Stderr, "Error forwarding ", err)
log.Fatal(err)
}
} else {
select {}
}
}