From 0e58dde5919ae2fd6f7dd77297b06ac1d6f3dee9 Mon Sep 17 00:00:00 2001 From: minhdanh Date: Fri, 21 Aug 2020 15:30:22 +0700 Subject: [PATCH 1/2] Support skipping kubeconfig creation --- .gitignore | 1 + internal/env/config.go | 1 + internal/helm/plan.go | 8 ++++++-- internal/helm/plan_test.go | 6 ++++++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 368aae7..2ee9527 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ *.dll *.so *.dylib +*.swp .idea diff --git a/internal/env/config.go b/internal/env/config.go index 6751be9..4cd5471 100644 --- a/internal/env/config.go +++ b/internal/env/config.go @@ -33,6 +33,7 @@ type Config struct { StringValues string `split_words:"true"` // Argument to pass to --set-string in applicable helm commands ValuesFiles []string `split_words:"true"` // Arguments to pass to --values in applicable helm commands Namespace string `` // Kubernetes namespace for all helm commands + KubeInitSkip bool `envconfig:"kube_init_skip"` // Skip kubeconfig creation KubeToken string `split_words:"true"` // Kubernetes authentication token to put in .kube/config SkipTLSVerify bool `envconfig:"skip_tls_verify"` // Put insecure-skip-tls-verify in .kube/config Certificate string `envconfig:"kube_certificate"` // The Kubernetes cluster CA's self-signed certificate (must be base64-encoded) diff --git a/internal/helm/plan.go b/internal/helm/plan.go index 4f62162..50cb17b 100644 --- a/internal/helm/plan.go +++ b/internal/helm/plan.go @@ -92,7 +92,9 @@ func (p *Plan) Execute() error { var upgrade = func(cfg env.Config) []Step { var steps []Step - steps = append(steps, run.NewInitKube(cfg, kubeConfigTemplate, kubeConfigFile)) + if !cfg.KubeInitSkip { + steps = append(steps, run.NewInitKube(cfg, kubeConfigTemplate, kubeConfigFile)) + } for _, repo := range cfg.AddRepos { steps = append(steps, run.NewAddRepo(cfg, repo)) } @@ -112,7 +114,9 @@ var upgrade = func(cfg env.Config) []Step { var uninstall = func(cfg env.Config) []Step { var steps []Step - steps = append(steps, run.NewInitKube(cfg, kubeConfigTemplate, kubeConfigFile)) + if !cfg.KubeInitSkip { + steps = append(steps, run.NewInitKube(cfg, kubeConfigTemplate, kubeConfigFile)) + } if cfg.UpdateDependencies { steps = append(steps, run.NewDepUpdate(cfg)) } diff --git a/internal/helm/plan_test.go b/internal/helm/plan_test.go index 77e913c..3f8a9a3 100644 --- a/internal/helm/plan_test.go +++ b/internal/helm/plan_test.go @@ -122,6 +122,12 @@ func (suite *PlanTestSuite) TestUpgrade() { suite.IsType(&run.Upgrade{}, steps[1]) } +func (suite *PlanTestSuite) TestUpgradeWithKubeInitSkip() { + steps := upgrade(env.Config{KubeInitSkip: true}) + suite.Require().Equal(1, len(steps), "upgrade should return 1 step") + suite.IsType(&run.Upgrade{}, steps[0]) +} + func (suite *PlanTestSuite) TestUpgradeWithUpdateDependencies() { cfg := env.Config{ UpdateDependencies: true, From 5b4e3ab2eabae41dd59931590460502928cad361 Mon Sep 17 00:00:00 2001 From: minhdanh Date: Tue, 25 Aug 2020 09:59:06 +0700 Subject: [PATCH 2/2] Rename kube_init_skip to skip_kubeconfig --- docs/parameter_reference.md | 22 ++++++++++++---------- internal/env/config.go | 8 +++++++- internal/helm/plan.go | 4 ++-- internal/helm/plan_test.go | 4 ++-- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/docs/parameter_reference.md b/docs/parameter_reference.md index ad28ae6..489db21 100644 --- a/docs/parameter_reference.md +++ b/docs/parameter_reference.md @@ -31,10 +31,11 @@ Installations are triggered when the `mode` setting is "upgrade." They can also |------------------------|----------------|----------|------------------------|---------| | chart | string | yes | | The chart to use for this installation. | | release | string | yes | | The release name for helm to use. | -| kube_api_server | string | yes | api_server | API endpoint for the Kubernetes cluster. | -| kube_token | string | yes | kubernetes_token | Token for authenticating to Kubernetes. | -| kube_service_account | string | | service_account | Service account for authenticating to Kubernetes. Default is `helm`. | -| kube_certificate | string | | kubernetes_certificate | Base64 encoded TLS certificate used by the Kubernetes cluster's certificate authority. | +| skip_kubeconfig | boolean | | | Whether to skip kubeconfig file creation. | +| kube_api_server | string | yes | api_server | API endpoint for the Kubernetes cluster. This is ignored if `skip_kubeconfig` is `true`. | +| kube_token | string | yes | kubernetes_token | Token for authenticating to Kubernetes. This is ignored if `skip_kubeconfig` is `true`. | +| kube_service_account | string | | service_account | Service account for authenticating to Kubernetes. Default is `helm`. This is ignored if `skip_kubeconfig` is `true`. | +| kube_certificate | string | | kubernetes_certificate | Base64 encoded TLS certificate used by the Kubernetes cluster's certificate authority. This is ignored if `skip_kubeconfig` is `true`. | | chart_version | string | | | Specific chart version to install. | | dry_run | boolean | | | Pass `--dry-run` to `helm upgrade`. | | dependencies_action | string | | | Calls `helm dependency build` OR `helm dependency update` before running the main command. Possible values: `build`, `update`. | @@ -47,7 +48,7 @@ Installations are triggered when the `mode` setting is "upgrade." They can also | string_values | list\ | | | Chart values to use as the `--set-string` argument to `helm upgrade`. | | values_files | list\ | | | Values to use as `--values` arguments to `helm upgrade`. | | reuse_values | boolean | | | Reuse the values from a previous release. | -| skip_tls_verify | boolean | | | Connect to the Kubernetes cluster without checking for a valid TLS certificate. Not recommended in production. | +| skip_tls_verify | boolean | | | Connect to the Kubernetes cluster without checking for a valid TLS certificate. Not recommended in production. This is ignored if `skip_kubeconfig` is `true`. | ## Uninstallation @@ -56,14 +57,15 @@ Uninstallations are triggered when the `mode` setting is "uninstall" or "delete. | Param name | Type | Required | Alias | Purpose | |------------------------|----------|----------|------------------------|---------| | release | string | yes | | The release name for helm to use. | -| kube_api_server | string | yes | api_server | API endpoint for the Kubernetes cluster. | -| kube_token | string | yes | kubernetes_token | Token for authenticating to Kubernetes. | -| kube_service_account | string | | service_account | Service account for authenticating to Kubernetes. Default is `helm`. | -| kube_certificate | string | | kubernetes_certificate | Base64 encoded TLS certificate used by the Kubernetes cluster's certificate authority. | +| skip_kubeconfig | boolean | | | Whether to skip kubeconfig file creation. | +| kube_api_server | string | yes | api_server | API endpoint for the Kubernetes cluster. This is ignored if `skip_kubeconfig` is `true`. | +| kube_token | string | yes | kubernetes_token | Token for authenticating to Kubernetes. This is ignored if `skip_kubeconfig` is `true`. | +| kube_service_account | string | | service_account | Service account for authenticating to Kubernetes. Default is `helm`. This is ignored if `skip_kubeconfig` is `true`. | +| kube_certificate | string | | kubernetes_certificate | Base64 encoded TLS certificate used by the Kubernetes cluster's certificate authority. This is ignored if `skip_kubeconfig` is `true`. | | keep_history | boolean | | | Pass `--keep-history` to `helm uninstall`, to retain the release history. | | dry_run | boolean | | | Pass `--dry-run` to `helm uninstall`. | | timeout | duration | | | Timeout for any *individual* Kubernetes operation. The uninstallation's full runtime may exceed this duration. | -| skip_tls_verify | boolean | | | Connect to the Kubernetes cluster without checking for a valid TLS certificate. Not recommended in production. | +| skip_tls_verify | boolean | | | Connect to the Kubernetes cluster without checking for a valid TLS certificate. Not recommended in production. This is ignored if `skip_kubeconfig` is `true`. | | chart | string | | | Required when the global `update_dependencies` parameter is true. No effect otherwise. | ### Where to put settings diff --git a/internal/env/config.go b/internal/env/config.go index 4cd5471..3bd43ae 100644 --- a/internal/env/config.go +++ b/internal/env/config.go @@ -33,8 +33,8 @@ type Config struct { StringValues string `split_words:"true"` // Argument to pass to --set-string in applicable helm commands ValuesFiles []string `split_words:"true"` // Arguments to pass to --values in applicable helm commands Namespace string `` // Kubernetes namespace for all helm commands - KubeInitSkip bool `envconfig:"kube_init_skip"` // Skip kubeconfig creation KubeToken string `split_words:"true"` // Kubernetes authentication token to put in .kube/config + SkipKubeconfig bool `envconfig:"skip_kubeconfig"` // Skip kubeconfig creation SkipTLSVerify bool `envconfig:"skip_tls_verify"` // Put insecure-skip-tls-verify in .kube/config Certificate string `envconfig:"kube_certificate"` // The Kubernetes cluster CA's self-signed certificate (must be base64-encoded) APIServer string `envconfig:"kube_api_server"` // The Kubernetes cluster's API endpoint @@ -88,6 +88,12 @@ func NewConfig(stdout, stderr io.Writer) (*Config, error) { return nil, err } + if cfg.SkipKubeconfig { + if cfg.KubeToken != "" || cfg.Certificate != "" || cfg.APIServer != "" || cfg.ServiceAccount != "" || cfg.SkipTLSVerify { + fmt.Fprintf(cfg.Stderr, "Warning: skip_kubeconfig is set. The following kubeconfig-related settings will be ignored: kube_config, kube_certificate, kube_api_server, kube_service_account, skip_tls_verify.") + } + } + if justNumbers.MatchString(cfg.Timeout) { cfg.Timeout = fmt.Sprintf("%ss", cfg.Timeout) } diff --git a/internal/helm/plan.go b/internal/helm/plan.go index 50cb17b..f2145ed 100644 --- a/internal/helm/plan.go +++ b/internal/helm/plan.go @@ -92,7 +92,7 @@ func (p *Plan) Execute() error { var upgrade = func(cfg env.Config) []Step { var steps []Step - if !cfg.KubeInitSkip { + if !cfg.SkipKubeconfig { steps = append(steps, run.NewInitKube(cfg, kubeConfigTemplate, kubeConfigFile)) } for _, repo := range cfg.AddRepos { @@ -114,7 +114,7 @@ var upgrade = func(cfg env.Config) []Step { var uninstall = func(cfg env.Config) []Step { var steps []Step - if !cfg.KubeInitSkip { + if !cfg.SkipKubeconfig { steps = append(steps, run.NewInitKube(cfg, kubeConfigTemplate, kubeConfigFile)) } if cfg.UpdateDependencies { diff --git a/internal/helm/plan_test.go b/internal/helm/plan_test.go index 3f8a9a3..9c7b5f1 100644 --- a/internal/helm/plan_test.go +++ b/internal/helm/plan_test.go @@ -122,8 +122,8 @@ func (suite *PlanTestSuite) TestUpgrade() { suite.IsType(&run.Upgrade{}, steps[1]) } -func (suite *PlanTestSuite) TestUpgradeWithKubeInitSkip() { - steps := upgrade(env.Config{KubeInitSkip: true}) +func (suite *PlanTestSuite) TestUpgradeWithSkipKubeconfig() { + steps := upgrade(env.Config{SkipKubeconfig: true}) suite.Require().Equal(1, len(steps), "upgrade should return 1 step") suite.IsType(&run.Upgrade{}, steps[0]) }