Fixes #501: prioritize kube.endpoint passed via cli
This commit is contained in:
parent
8f8f72fa76
commit
40c0ed092e
2 changed files with 9 additions and 2 deletions
|
@ -272,7 +272,7 @@ func NewTraefikDefaultPointersConfiguration() *TraefikConfiguration {
|
|||
//default Kubernetes
|
||||
var defaultKubernetes provider.Kubernetes
|
||||
defaultKubernetes.Watch = true
|
||||
defaultKubernetes.Endpoint = "http://127.0.0.1:8080"
|
||||
defaultKubernetes.Endpoint = ""
|
||||
defaultKubernetes.Constraints = []types.Constraint{}
|
||||
|
||||
defaultConfiguration := GlobalConfiguration{
|
||||
|
|
|
@ -20,6 +20,7 @@ import (
|
|||
const (
|
||||
serviceAccountToken = "/var/run/secrets/kubernetes.io/serviceaccount/token"
|
||||
serviceAccountCACert = "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt"
|
||||
defaultKubeEndpoint = "http://127.0.0.1:8080"
|
||||
)
|
||||
|
||||
// Namespaces holds kubernetes namespaces
|
||||
|
@ -74,9 +75,15 @@ func (provider *Kubernetes) createClient() (k8s.Client, error) {
|
|||
}
|
||||
kubernetesHost := os.Getenv("KUBERNETES_SERVICE_HOST")
|
||||
kubernetesPort := os.Getenv("KUBERNETES_SERVICE_PORT_HTTPS")
|
||||
if len(kubernetesPort) > 0 && len(kubernetesHost) > 0 {
|
||||
// Prioritize user provided kubernetes endpoint since kube container runtime will almost always have it
|
||||
if provider.Endpoint == "" && len(kubernetesPort) > 0 && len(kubernetesHost) > 0 {
|
||||
log.Debugf("Using environment provided kubernetes endpoint")
|
||||
provider.Endpoint = "https://" + kubernetesHost + ":" + kubernetesPort
|
||||
}
|
||||
if provider.Endpoint == "" {
|
||||
log.Debugf("Using default kubernetes api endpoint")
|
||||
provider.Endpoint = defaultKubeEndpoint
|
||||
}
|
||||
log.Debugf("Kubernetes endpoint: %s", provider.Endpoint)
|
||||
return k8s.NewClient(provider.Endpoint, caCert, token)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue