feat: Adding kube-context flag + env var for tiller

This allows the kube-context for tiller's kube client to be set
at runtime via an env var (TILLER_KUBE_CONTEXT) or
CLI flag (--kube-context).

This can be useful when running tiller locally rather than inside the
cluster.

Signed-off-by: Adam Setters <9741640+asetty@users.noreply.github.com>
pull/8803/head
Adam Setters 7 years ago committed by Adam Setters
parent 0d9779c4f1
commit 2a5f5e91a8
No known key found for this signature in database
GPG Key ID: 6A6A84227E2B0C4E

@ -41,6 +41,7 @@ import (
// Import to initialize client auth plugins. // Import to initialize client auth plugins.
_ "k8s.io/client-go/plugin/pkg/client/auth" _ "k8s.io/client-go/plugin/pkg/client/auth"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/helm/pkg/kube" "k8s.io/helm/pkg/kube"
"k8s.io/helm/pkg/proto/hapi/services" "k8s.io/helm/pkg/proto/hapi/services"
"k8s.io/helm/pkg/storage" "k8s.io/helm/pkg/storage"
@ -62,6 +63,8 @@ const (
tlsCertsEnvVar = "TILLER_TLS_CERTS" tlsCertsEnvVar = "TILLER_TLS_CERTS"
// historyMaxEnvVar is the name of the env var for setting max history. // historyMaxEnvVar is the name of the env var for setting max history.
historyMaxEnvVar = "TILLER_HISTORY_MAX" historyMaxEnvVar = "TILLER_HISTORY_MAX"
// k8sContextEnvVar is the name of the env var for the k8s context for tiller to use
kubeContextEnvVar = "TILLER_KUBE_CONTEXT"
storageMemory = "memory" storageMemory = "memory"
storageConfigMap = "configmap" storageConfigMap = "configmap"
@ -79,6 +82,7 @@ var (
probeAddr = flag.String("probe-listen", fmt.Sprintf(":%v", environment.DefaultTillerProbePort), "address:port to listen on for probes") probeAddr = flag.String("probe-listen", fmt.Sprintf(":%v", environment.DefaultTillerProbePort), "address:port to listen on for probes")
enableProbing = flag.Bool("probe", true, "enable probing over http") enableProbing = flag.Bool("probe", true, "enable probing over http")
enableTracing = flag.Bool("trace", false, "enable rpc tracing") enableTracing = flag.Bool("trace", false, "enable rpc tracing")
kubeContext = flag.String("kube-context", kubeContextFromEnv(), "kube context for tiller")
store = flag.String("storage", storageConfigMap, "storage driver to use. One of 'configmap', 'memory', 'sql' or 'secret'") store = flag.String("storage", storageConfigMap, "storage driver to use. One of 'configmap', 'memory', 'sql' or 'secret'")
sqlDialect = flag.String("sql-dialect", "postgres", "SQL dialect to use (only postgres is supported for now") sqlDialect = flag.String("sql-dialect", "postgres", "SQL dialect to use (only postgres is supported for now")
@ -130,7 +134,12 @@ func start() {
healthSrv := health.NewServer() healthSrv := health.NewServer()
healthSrv.SetServingStatus("Tiller", healthpb.HealthCheckResponse_NOT_SERVING) healthSrv.SetServingStatus("Tiller", healthpb.HealthCheckResponse_NOT_SERVING)
clientset, err := kube.New(nil).KubernetesClientSet() var clientArgs *genericclioptions.ConfigFlags = nil
if *kubeContext != "" {
clientArgs = genericclioptions.NewConfigFlags(false)
clientArgs.Context = kubeContext
}
clientset, err := kube.New(clientArgs).KubernetesClientSet()
if err != nil { if err != nil {
logger.Fatalf("Cannot initialize Kubernetes connection: %s", err) logger.Fatalf("Cannot initialize Kubernetes connection: %s", err)
} }
@ -168,7 +177,7 @@ func start() {
env.Releases.MaxHistory = *maxHistory env.Releases.MaxHistory = *maxHistory
} }
kubeClient := kube.New(nil) kubeClient := kube.New(clientArgs)
kubeClient.Log = newLogger("kube").Printf kubeClient.Log = newLogger("kube").Printf
env.KubeClient = kubeClient env.KubeClient = kubeClient
@ -276,6 +285,10 @@ func namespace() string {
return environment.DefaultTillerNamespace return environment.DefaultTillerNamespace
} }
func kubeContextFromEnv() string {
return os.Getenv(kubeContextEnvVar)
}
func tlsOptions() tlsutil.Options { func tlsOptions() tlsutil.Options {
opts := tlsutil.Options{CertFile: *certFile, KeyFile: *keyFile} opts := tlsutil.Options{CertFile: *certFile, KeyFile: *keyFile}
if *tlsVerify { if *tlsVerify {

Loading…
Cancel
Save