|
|
|
@ -28,21 +28,15 @@ import (
|
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
|
|
"github.com/spf13/pflag"
|
|
|
|
|
"k8s.io/cli-runtime/pkg/genericclioptions"
|
|
|
|
|
|
|
|
|
|
"helm.sh/helm/pkg/helmpath"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// EnvSettings describes all of the environment settings.
|
|
|
|
|
type EnvSettings struct {
|
|
|
|
|
// Namespace is the namespace scope.
|
|
|
|
|
Namespace string
|
|
|
|
|
// KubeConfig is the path to the kubeconfig file.
|
|
|
|
|
KubeConfig string
|
|
|
|
|
// KubeContext is the name of the kubeconfig context.
|
|
|
|
|
KubeContext string
|
|
|
|
|
// Debug indicates whether or not Helm is running in Debug mode.
|
|
|
|
|
Debug bool
|
|
|
|
|
|
|
|
|
|
// RegistryConfig is the path to the registry config file.
|
|
|
|
|
RegistryConfig string
|
|
|
|
|
// RepositoryConfig is the path to the repositories file.
|
|
|
|
@ -51,29 +45,29 @@ type EnvSettings struct {
|
|
|
|
|
RepositoryCache string
|
|
|
|
|
// PluginsDirectory is the path to the plugins directory.
|
|
|
|
|
PluginsDirectory string
|
|
|
|
|
|
|
|
|
|
KubeConfig *genericclioptions.ConfigFlags
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func New() *EnvSettings {
|
|
|
|
|
env := EnvSettings{
|
|
|
|
|
Namespace: os.Getenv("HELM_NAMESPACE"),
|
|
|
|
|
return &EnvSettings{
|
|
|
|
|
// Namespace: os.Getenv("HELM_NAMESPACE"),
|
|
|
|
|
Debug: envBool("HELM_DEBUG"),
|
|
|
|
|
PluginsDirectory: envOr("HELM_PLUGINS", helmpath.DataPath("plugins")),
|
|
|
|
|
RegistryConfig: envOr("HELM_REGISTRY_CONFIG", helmpath.ConfigPath("registry.json")),
|
|
|
|
|
RepositoryConfig: envOr("HELM_REPOSITORY_CONFIG", helmpath.ConfigPath("repositories.yaml")),
|
|
|
|
|
RepositoryCache: envOr("HELM_REPOSITORY_CACHE", helmpath.CachePath("repository")),
|
|
|
|
|
KubeConfig: genericclioptions.NewConfigFlags(true),
|
|
|
|
|
}
|
|
|
|
|
env.Debug, _ = strconv.ParseBool(os.Getenv("HELM_DEBUG"))
|
|
|
|
|
return &env
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// AddFlags binds flags to the given flagset.
|
|
|
|
|
func (s *EnvSettings) AddFlags(fs *pflag.FlagSet) {
|
|
|
|
|
fs.StringVarP(&s.Namespace, "namespace", "n", s.Namespace, "namespace scope for this request")
|
|
|
|
|
fs.StringVar(&s.KubeConfig, "kubeconfig", "", "path to the kubeconfig file")
|
|
|
|
|
fs.StringVar(&s.KubeContext, "kube-context", "", "name of the kubeconfig context to use")
|
|
|
|
|
fs.BoolVar(&s.Debug, "debug", s.Debug, "enable verbose output")
|
|
|
|
|
fs.StringVar(&s.RegistryConfig, "registry-config", s.RegistryConfig, "path to the registry config file")
|
|
|
|
|
fs.StringVar(&s.RepositoryConfig, "repository-config", s.RepositoryConfig, "path to the file containing repository names and URLs")
|
|
|
|
|
fs.StringVar(&s.RepositoryCache, "repository-cache", s.RepositoryCache, "path to the file containing cached repository indexes")
|
|
|
|
|
s.KubeConfig.AddFlags(fs)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func envOr(name, def string) string {
|
|
|
|
@ -83,6 +77,22 @@ func envOr(name, def string) string {
|
|
|
|
|
return def
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func envBool(name string) bool {
|
|
|
|
|
var v bool
|
|
|
|
|
v, _ = strconv.ParseBool(os.Getenv(name))
|
|
|
|
|
return v
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *EnvSettings) Namespace() string {
|
|
|
|
|
if ns := os.Getenv("HELM_NAMESPACE"); ns != "" {
|
|
|
|
|
return ns
|
|
|
|
|
}
|
|
|
|
|
if ns, _, err := s.KubeConfig.ToRawKubeConfigLoader().Namespace(); err == nil {
|
|
|
|
|
return ns
|
|
|
|
|
}
|
|
|
|
|
return "default"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *EnvSettings) EnvVars() map[string]string {
|
|
|
|
|
return map[string]string{
|
|
|
|
|
"HELM_BIN": os.Args[0],
|
|
|
|
@ -91,5 +101,6 @@ func (s *EnvSettings) EnvVars() map[string]string {
|
|
|
|
|
"HELM_REGISTRY_CONFIG": s.RegistryConfig,
|
|
|
|
|
"HELM_REPOSITORY_CACHE": s.RepositoryCache,
|
|
|
|
|
"HELM_REPOSITORY_CONFIG": s.RepositoryConfig,
|
|
|
|
|
"HELM_NAMESPACE": s.Namespace(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|