Skip to content

Commit 560dcd4

Browse files
committed
Support in-cluster config with --master
If --master is specified, but --kubeconfig is not, use in-cluster config and override the host. Previous behaviour was to use out-of-cluster config anyway (and fail).
1 parent b9d5cb5 commit 560dcd4

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

pkg/cmd/.kube-router.go.kate-swp

94 Bytes
Binary file not shown.

pkg/cmd/kube-router.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,29 @@ func NewKubeRouterDefault(config *options.KubeRouterConfig) (*KubeRouter, error)
4141
var err error
4242
version.PrintVersion(true)
4343
version.PrintVersionMessages(true)
44-
// Use out of cluster config if the URL or kubeconfig have been specified. Otherwise use incluster config.
45-
if len(config.Master) != 0 || len(config.Kubeconfig) != 0 {
44+
// Use out of cluster config if the kubeconfig has been specified. Otherwise use incluster config.
45+
if len(config.Kubeconfig) != 0 {
4646
clientconfig, err = clientcmd.BuildConfigFromFlags(config.Master, config.Kubeconfig)
4747
if err != nil {
4848
return nil, fmt.Errorf("failed to build configuration from CLI: %v", err)
4949
}
50+
} else if len(config.Master) != 0 {
51+
// InClusterConfig() fails with ErrNotInCluster if these are unset.
52+
os.Setenv("KUBERNETES_SERVICE_HOST", " ")
53+
os.Setenv("KUBERNETES_SERVICE_PORT", " ")
54+
55+
clientconfig, err = rest.InClusterConfig()
56+
if err != nil {
57+
return nil, fmt.Errorf("unable to initialize inclusterconfig: %v", err)
58+
}
59+
60+
os.Setenv("KUBERNETES_SERVICE_HOST", "")
61+
os.Setenv("KUBERNETES_SERVICE_PORT", "")
62+
63+
clientconfig.Host = config.Master
64+
65+
66+
5067
} else {
5168
clientconfig, err = rest.InClusterConfig()
5269
if err != nil {

0 commit comments

Comments
 (0)