|
|
|
@ -26,23 +26,26 @@ import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"os"
|
|
|
|
|
"strconv"
|
|
|
|
|
"sync"
|
|
|
|
|
|
|
|
|
|
"github.com/spf13/pflag"
|
|
|
|
|
|
|
|
|
|
"k8s.io/cli-runtime/pkg/genericclioptions"
|
|
|
|
|
|
|
|
|
|
"helm.sh/helm/v3/pkg/helmpath"
|
|
|
|
|
"helm.sh/helm/v3/pkg/kube"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
namespace string
|
|
|
|
|
kubeConfig string
|
|
|
|
|
config genericclioptions.RESTClientGetter
|
|
|
|
|
configOnce sync.Once
|
|
|
|
|
// 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.
|
|
|
|
@ -54,8 +57,9 @@ type EnvSettings struct {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func New() *EnvSettings {
|
|
|
|
|
|
|
|
|
|
env := EnvSettings{
|
|
|
|
|
Namespace: os.Getenv("HELM_NAMESPACE"),
|
|
|
|
|
namespace: os.Getenv("HELM_NAMESPACE"),
|
|
|
|
|
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")),
|
|
|
|
@ -67,8 +71,8 @@ func New() *EnvSettings {
|
|
|
|
|
|
|
|
|
|
// 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.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")
|
|
|
|
@ -93,3 +97,23 @@ func (s *EnvSettings) EnvVars() map[string]string {
|
|
|
|
|
"HELM_REPOSITORY_CONFIG": s.RepositoryConfig,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Namespace gets the namespace from the configuration
|
|
|
|
|
func (s *EnvSettings) Namespace() string {
|
|
|
|
|
if s.namespace != "" {
|
|
|
|
|
return s.namespace
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ns, _, err := s.KubeConfig().ToRawKubeConfigLoader().Namespace(); err == nil {
|
|
|
|
|
return ns
|
|
|
|
|
}
|
|
|
|
|
return "default"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//KubeConfig gets the kubeconfig from EnvSettings
|
|
|
|
|
func (s *EnvSettings) KubeConfig() genericclioptions.RESTClientGetter {
|
|
|
|
|
s.configOnce.Do(func() {
|
|
|
|
|
s.config = kube.GetConfig(s.kubeConfig, s.KubeContext, s.namespace)
|
|
|
|
|
})
|
|
|
|
|
return s.config
|
|
|
|
|
}
|
|
|
|
|