Merge remote-tracking branch 'origin/master' into help-by-default
This commit is contained in:
@@ -8,7 +8,6 @@ import (
|
||||
type Config struct {
|
||||
HelmCommand string
|
||||
Debug bool
|
||||
KubeConfig string
|
||||
Values string
|
||||
StringValues string
|
||||
ValuesFiles []string
|
||||
|
||||
@@ -16,6 +16,7 @@ type InitKube struct {
|
||||
ServiceAccount string
|
||||
Token string
|
||||
TemplateFile string
|
||||
ConfigFile string
|
||||
|
||||
template *template.Template
|
||||
configFile io.WriteCloser
|
||||
@@ -34,7 +35,7 @@ type kubeValues struct {
|
||||
// Execute generates a kubernetes config file from drone-helm3's template.
|
||||
func (i *InitKube) Execute(cfg Config) error {
|
||||
if cfg.Debug {
|
||||
fmt.Fprintf(cfg.Stderr, "writing kubeconfig file to %s\n", cfg.KubeConfig)
|
||||
fmt.Fprintf(cfg.Stderr, "writing kubeconfig file to %s\n", i.ConfigFile)
|
||||
}
|
||||
defer i.configFile.Close()
|
||||
return i.template.Execute(i.configFile, i.values)
|
||||
@@ -50,9 +51,6 @@ func (i *InitKube) Prepare(cfg Config) error {
|
||||
if i.Token == "" {
|
||||
return errors.New("token is needed to deploy")
|
||||
}
|
||||
if i.Certificate == "" && !i.SkipTLSVerify {
|
||||
return errors.New("certificate is needed to deploy")
|
||||
}
|
||||
|
||||
if i.ServiceAccount == "" {
|
||||
i.ServiceAccount = "helm"
|
||||
@@ -76,16 +74,16 @@ func (i *InitKube) Prepare(cfg Config) error {
|
||||
}
|
||||
|
||||
if cfg.Debug {
|
||||
if _, err := os.Stat(cfg.KubeConfig); err != nil {
|
||||
if _, err := os.Stat(i.ConfigFile); err != nil {
|
||||
// non-nil err here isn't an actual error state; the kubeconfig just doesn't exist
|
||||
fmt.Fprint(cfg.Stderr, "creating ")
|
||||
} else {
|
||||
fmt.Fprint(cfg.Stderr, "truncating ")
|
||||
}
|
||||
fmt.Fprintf(cfg.Stderr, "kubeconfig file at %s\n", cfg.KubeConfig)
|
||||
fmt.Fprintf(cfg.Stderr, "kubeconfig file at %s\n", i.ConfigFile)
|
||||
}
|
||||
|
||||
i.configFile, err = os.Create(cfg.KubeConfig)
|
||||
i.configFile, err = os.Create(i.ConfigFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not open kubeconfig file for writing: %w", err)
|
||||
}
|
||||
|
||||
@@ -34,10 +34,10 @@ namespace: {{ .Namespace }}
|
||||
Certificate: "CCNA",
|
||||
Token: "Aspire virtual currency",
|
||||
TemplateFile: templateFile.Name(),
|
||||
ConfigFile: configFile.Name(),
|
||||
}
|
||||
cfg := Config{
|
||||
Namespace: "Cisco",
|
||||
KubeConfig: configFile.Name(),
|
||||
Namespace: "Cisco",
|
||||
}
|
||||
err = init.Prepare(cfg)
|
||||
suite.Require().Nil(err)
|
||||
@@ -95,11 +95,10 @@ func (suite *InitKubeTestSuite) TestPrepareCannotOpenDestinationFile() {
|
||||
Certificate: "CCNA",
|
||||
Token: "Aspire virtual currency",
|
||||
TemplateFile: templateFile.Name(),
|
||||
ConfigFile: "/usr/foreign/exclude/kubeprofig",
|
||||
}
|
||||
|
||||
cfg := Config{
|
||||
KubeConfig: "/usr/foreign/exclude/kubeprofig",
|
||||
}
|
||||
cfg := Config{}
|
||||
err = init.Prepare(cfg)
|
||||
suite.Error(err)
|
||||
suite.Regexp("could not open .* for writing: .* no such file or directory", err)
|
||||
@@ -120,11 +119,10 @@ func (suite *InitKubeTestSuite) TestPrepareRequiredConfig() {
|
||||
Certificate: "CCNA",
|
||||
Token: "Aspire virtual currency",
|
||||
TemplateFile: templateFile.Name(),
|
||||
ConfigFile: configFile.Name(),
|
||||
}
|
||||
|
||||
cfg := Config{
|
||||
KubeConfig: configFile.Name(),
|
||||
}
|
||||
cfg := Config{}
|
||||
|
||||
suite.NoError(init.Prepare(cfg)) // consistency check; we should be starting in a happy state
|
||||
|
||||
@@ -134,13 +132,6 @@ func (suite *InitKubeTestSuite) TestPrepareRequiredConfig() {
|
||||
init.APIServer = "Sysadmin"
|
||||
init.Token = ""
|
||||
suite.Error(init.Prepare(cfg), "Token should be required.")
|
||||
|
||||
init.Token = "Aspire virtual currency"
|
||||
init.Certificate = ""
|
||||
suite.Error(init.Prepare(cfg), "Certificate should be required.")
|
||||
|
||||
init.SkipTLSVerify = true
|
||||
suite.NoError(init.Prepare(cfg), "Certificate should not be required if SkipTLSVerify is true")
|
||||
}
|
||||
|
||||
func (suite *InitKubeTestSuite) TestPrepareDefaultsServiceAccount() {
|
||||
@@ -157,11 +148,10 @@ func (suite *InitKubeTestSuite) TestPrepareDefaultsServiceAccount() {
|
||||
Certificate: "CCNA",
|
||||
Token: "Aspire virtual currency",
|
||||
TemplateFile: templateFile.Name(),
|
||||
ConfigFile: configFile.Name(),
|
||||
}
|
||||
|
||||
cfg := Config{
|
||||
KubeConfig: configFile.Name(),
|
||||
}
|
||||
cfg := Config{}
|
||||
|
||||
init.Prepare(cfg)
|
||||
suite.Equal("helm", init.ServiceAccount)
|
||||
|
||||
@@ -16,6 +16,8 @@ func (l *Lint) Execute(_ Config) error {
|
||||
}
|
||||
|
||||
// Prepare gets the Lint ready to execute.
|
||||
// Note: mandatory settings are documented in README.md, and the full list of settings is in docs/lint_settings.yml.
|
||||
// Any additions or deletions here should be reflected there.
|
||||
func (l *Lint) Prepare(cfg Config) error {
|
||||
if l.Chart == "" {
|
||||
return fmt.Errorf("chart is required")
|
||||
|
||||
@@ -22,7 +22,7 @@ func (u *Uninstall) Prepare(cfg Config) error {
|
||||
return fmt.Errorf("release is required")
|
||||
}
|
||||
|
||||
args := []string{"--kubeconfig", cfg.KubeConfig}
|
||||
args := make([]string, 0)
|
||||
|
||||
if cfg.Namespace != "" {
|
||||
args = append(args, "--namespace", cfg.Namespace)
|
||||
|
||||
@@ -58,11 +58,9 @@ func (suite *UninstallTestSuite) TestPrepareAndExecute() {
|
||||
Run().
|
||||
Times(1)
|
||||
|
||||
cfg := Config{
|
||||
KubeConfig: "/root/.kube/config",
|
||||
}
|
||||
cfg := Config{}
|
||||
suite.NoError(u.Prepare(cfg))
|
||||
expected := []string{"--kubeconfig", "/root/.kube/config", "uninstall", "zayde_wølf_king"}
|
||||
expected := []string{"uninstall", "zayde_wølf_king"}
|
||||
suite.Equal(expected, actual)
|
||||
|
||||
u.Execute(cfg)
|
||||
@@ -73,15 +71,13 @@ func (suite *UninstallTestSuite) TestPrepareDryRunFlag() {
|
||||
Release: "firefox_ak_wildfire",
|
||||
DryRun: true,
|
||||
}
|
||||
cfg := Config{
|
||||
KubeConfig: "/root/.kube/config",
|
||||
}
|
||||
cfg := Config{}
|
||||
|
||||
suite.mockCmd.EXPECT().Stdout(gomock.Any()).AnyTimes()
|
||||
suite.mockCmd.EXPECT().Stderr(gomock.Any()).AnyTimes()
|
||||
|
||||
suite.NoError(u.Prepare(cfg))
|
||||
expected := []string{"--kubeconfig", "/root/.kube/config", "uninstall", "--dry-run", "firefox_ak_wildfire"}
|
||||
expected := []string{"uninstall", "--dry-run", "firefox_ak_wildfire"}
|
||||
suite.Equal(expected, suite.actualArgs)
|
||||
}
|
||||
|
||||
@@ -90,16 +86,14 @@ func (suite *UninstallTestSuite) TestPrepareNamespaceFlag() {
|
||||
Release: "carly_simon_run_away_with_me",
|
||||
}
|
||||
cfg := Config{
|
||||
KubeConfig: "/root/.kube/config",
|
||||
Namespace: "emotion",
|
||||
Namespace: "emotion",
|
||||
}
|
||||
|
||||
suite.mockCmd.EXPECT().Stdout(gomock.Any()).AnyTimes()
|
||||
suite.mockCmd.EXPECT().Stderr(gomock.Any()).AnyTimes()
|
||||
|
||||
suite.NoError(u.Prepare(cfg))
|
||||
expected := []string{"--kubeconfig", "/root/.kube/config",
|
||||
"--namespace", "emotion", "uninstall", "carly_simon_run_away_with_me"}
|
||||
expected := []string{"--namespace", "emotion", "uninstall", "carly_simon_run_away_with_me"}
|
||||
suite.Equal(expected, suite.actualArgs)
|
||||
}
|
||||
|
||||
@@ -109,9 +103,8 @@ func (suite *UninstallTestSuite) TestPrepareDebugFlag() {
|
||||
}
|
||||
stderr := strings.Builder{}
|
||||
cfg := Config{
|
||||
KubeConfig: "/root/.kube/config",
|
||||
Debug: true,
|
||||
Stderr: &stderr,
|
||||
Debug: true,
|
||||
Stderr: &stderr,
|
||||
}
|
||||
|
||||
command = func(path string, args ...string) cmd {
|
||||
@@ -126,8 +119,8 @@ func (suite *UninstallTestSuite) TestPrepareDebugFlag() {
|
||||
suite.mockCmd.EXPECT().Stderr(&stderr).AnyTimes()
|
||||
|
||||
suite.NoError(u.Prepare(cfg))
|
||||
suite.Equal(fmt.Sprintf("Generated command: '%s --kubeconfig /root/.kube/config "+
|
||||
"--debug uninstall just_a_band_huff_and_puff'\n", helmBin), stderr.String())
|
||||
suite.Equal(fmt.Sprintf("Generated command: '%s --debug "+
|
||||
"uninstall just_a_band_huff_and_puff'\n", helmBin), stderr.String())
|
||||
}
|
||||
|
||||
func (suite *UninstallTestSuite) TestPrepareRequiresRelease() {
|
||||
|
||||
@@ -25,6 +25,8 @@ func (u *Upgrade) Execute(_ Config) error {
|
||||
}
|
||||
|
||||
// Prepare gets the Upgrade ready to execute.
|
||||
// Note: mandatory settings are documented in README.md, and the full list of settings is in docs/upgrade_settings.yml.
|
||||
// Any additions or deletions here should be reflected there.
|
||||
func (u *Upgrade) Prepare(cfg Config) error {
|
||||
if u.Chart == "" {
|
||||
return fmt.Errorf("chart is required")
|
||||
@@ -33,7 +35,7 @@ func (u *Upgrade) Prepare(cfg Config) error {
|
||||
return fmt.Errorf("release is required")
|
||||
}
|
||||
|
||||
args := []string{"--kubeconfig", cfg.KubeConfig}
|
||||
args := make([]string, 0)
|
||||
|
||||
if cfg.Namespace != "" {
|
||||
args = append(args, "--namespace", cfg.Namespace)
|
||||
|
||||
@@ -41,8 +41,7 @@ func (suite *UpgradeTestSuite) TestPrepareAndExecute() {
|
||||
|
||||
command = func(path string, args ...string) cmd {
|
||||
suite.Equal(helmBin, path)
|
||||
suite.Equal([]string{"--kubeconfig", "/root/.kube/config", "upgrade", "--install",
|
||||
"jonas_brothers_only_human", "at40"}, args)
|
||||
suite.Equal([]string{"upgrade", "--install", "jonas_brothers_only_human", "at40"}, args)
|
||||
|
||||
return suite.mockCmd
|
||||
}
|
||||
@@ -55,9 +54,7 @@ func (suite *UpgradeTestSuite) TestPrepareAndExecute() {
|
||||
Run().
|
||||
Times(1)
|
||||
|
||||
cfg := Config{
|
||||
KubeConfig: "/root/.kube/config",
|
||||
}
|
||||
cfg := Config{}
|
||||
err := u.Prepare(cfg)
|
||||
suite.Require().Nil(err)
|
||||
u.Execute(cfg)
|
||||
@@ -73,8 +70,7 @@ func (suite *UpgradeTestSuite) TestPrepareNamespaceFlag() {
|
||||
|
||||
command = func(path string, args ...string) cmd {
|
||||
suite.Equal(helmBin, path)
|
||||
suite.Equal([]string{"--kubeconfig", "/root/.kube/config", "--namespace", "melt", "upgrade",
|
||||
"--install", "shaed_trampoline", "at40"}, args)
|
||||
suite.Equal([]string{"--namespace", "melt", "upgrade", "--install", "shaed_trampoline", "at40"}, args)
|
||||
|
||||
return suite.mockCmd
|
||||
}
|
||||
@@ -83,8 +79,7 @@ func (suite *UpgradeTestSuite) TestPrepareNamespaceFlag() {
|
||||
suite.mockCmd.EXPECT().Stderr(gomock.Any())
|
||||
|
||||
cfg := Config{
|
||||
Namespace: "melt",
|
||||
KubeConfig: "/root/.kube/config",
|
||||
Namespace: "melt",
|
||||
}
|
||||
err := u.Prepare(cfg)
|
||||
suite.Require().Nil(err)
|
||||
@@ -105,7 +100,6 @@ func (suite *UpgradeTestSuite) TestPrepareWithUpgradeFlags() {
|
||||
}
|
||||
|
||||
cfg := Config{
|
||||
KubeConfig: "/root/.kube/config",
|
||||
Values: "age=35",
|
||||
StringValues: "height=5ft10in",
|
||||
ValuesFiles: []string{"/usr/local/stats", "/usr/local/grades"},
|
||||
@@ -113,7 +107,7 @@ func (suite *UpgradeTestSuite) TestPrepareWithUpgradeFlags() {
|
||||
|
||||
command = func(path string, args ...string) cmd {
|
||||
suite.Equal(helmBin, path)
|
||||
suite.Equal([]string{"--kubeconfig", "/root/.kube/config", "upgrade", "--install",
|
||||
suite.Equal([]string{"upgrade", "--install",
|
||||
"--version", "radio_edit",
|
||||
"--dry-run",
|
||||
"--wait",
|
||||
@@ -165,10 +159,9 @@ func (suite *UpgradeTestSuite) TestPrepareDebugFlag() {
|
||||
stdout := strings.Builder{}
|
||||
stderr := strings.Builder{}
|
||||
cfg := Config{
|
||||
Debug: true,
|
||||
KubeConfig: "/root/.kube/config",
|
||||
Stdout: &stdout,
|
||||
Stderr: &stderr,
|
||||
Debug: true,
|
||||
Stdout: &stdout,
|
||||
Stderr: &stderr,
|
||||
}
|
||||
|
||||
command = func(path string, args ...string) cmd {
|
||||
@@ -186,7 +179,7 @@ func (suite *UpgradeTestSuite) TestPrepareDebugFlag() {
|
||||
|
||||
u.Prepare(cfg)
|
||||
|
||||
want := fmt.Sprintf("Generated command: '%s --kubeconfig /root/.kube/config --debug upgrade "+
|
||||
want := fmt.Sprintf("Generated command: '%s --debug upgrade "+
|
||||
"--install lewis_capaldi_someone_you_loved at40'\n", helmBin)
|
||||
suite.Equal(want, stderr.String())
|
||||
suite.Equal("", stdout.String())
|
||||
|
||||
Reference in New Issue
Block a user