Initialize Steps with a NewSTEPNAME function [#67]
This seems to be be a more natural separation of concerns--the knowledge of which config fields map to which parts of a Step belong to the Step, not to the Plan.
This commit is contained in:
parent
16117eea2f
commit
588c7cb9f7
|
@ -98,21 +98,7 @@ var upgrade = func(cfg env.Config) []Step {
|
||||||
if cfg.UpdateDependencies {
|
if cfg.UpdateDependencies {
|
||||||
steps = append(steps, depUpdate(cfg)...)
|
steps = append(steps, depUpdate(cfg)...)
|
||||||
}
|
}
|
||||||
steps = append(steps, &run.Upgrade{
|
steps = append(steps, run.NewUpgrade(cfg))
|
||||||
Chart: cfg.Chart,
|
|
||||||
Release: cfg.Release,
|
|
||||||
ChartVersion: cfg.ChartVersion,
|
|
||||||
DryRun: cfg.DryRun,
|
|
||||||
Wait: cfg.Wait,
|
|
||||||
Values: cfg.Values,
|
|
||||||
StringValues: cfg.StringValues,
|
|
||||||
ValuesFiles: cfg.ValuesFiles,
|
|
||||||
ReuseValues: cfg.ReuseValues,
|
|
||||||
Timeout: cfg.Timeout,
|
|
||||||
Force: cfg.Force,
|
|
||||||
Atomic: cfg.AtomicUpgrade,
|
|
||||||
CleanupOnFail: cfg.CleanupOnFail,
|
|
||||||
})
|
|
||||||
|
|
||||||
return steps
|
return steps
|
||||||
}
|
}
|
||||||
|
@ -122,11 +108,7 @@ var uninstall = func(cfg env.Config) []Step {
|
||||||
if cfg.UpdateDependencies {
|
if cfg.UpdateDependencies {
|
||||||
steps = append(steps, depUpdate(cfg)...)
|
steps = append(steps, depUpdate(cfg)...)
|
||||||
}
|
}
|
||||||
steps = append(steps, &run.Uninstall{
|
steps = append(steps, run.NewUninstall(cfg))
|
||||||
Release: cfg.Release,
|
|
||||||
DryRun: cfg.DryRun,
|
|
||||||
KeepHistory: cfg.KeepHistory,
|
|
||||||
})
|
|
||||||
|
|
||||||
return steps
|
return steps
|
||||||
}
|
}
|
||||||
|
@ -136,53 +118,27 @@ var lint = func(cfg env.Config) []Step {
|
||||||
if cfg.UpdateDependencies {
|
if cfg.UpdateDependencies {
|
||||||
steps = append(steps, depUpdate(cfg)...)
|
steps = append(steps, depUpdate(cfg)...)
|
||||||
}
|
}
|
||||||
steps = append(steps, &run.Lint{
|
steps = append(steps, run.NewLint(cfg))
|
||||||
Chart: cfg.Chart,
|
|
||||||
Values: cfg.Values,
|
|
||||||
StringValues: cfg.StringValues,
|
|
||||||
ValuesFiles: cfg.ValuesFiles,
|
|
||||||
Strict: cfg.LintStrictly,
|
|
||||||
})
|
|
||||||
|
|
||||||
return steps
|
return steps
|
||||||
}
|
}
|
||||||
|
|
||||||
var help = func(cfg env.Config) []Step {
|
var help = func(cfg env.Config) []Step {
|
||||||
help := &run.Help{
|
return []Step{run.NewHelp(cfg)}
|
||||||
HelmCommand: cfg.Command,
|
|
||||||
}
|
|
||||||
return []Step{help}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func initKube(cfg env.Config) []Step {
|
func initKube(cfg env.Config) []Step {
|
||||||
return []Step{
|
return []Step{run.NewInitKube(cfg, kubeConfigTemplate, kubeConfigFile)}
|
||||||
&run.InitKube{
|
|
||||||
SkipTLSVerify: cfg.SkipTLSVerify,
|
|
||||||
Certificate: cfg.Certificate,
|
|
||||||
APIServer: cfg.APIServer,
|
|
||||||
ServiceAccount: cfg.ServiceAccount,
|
|
||||||
Token: cfg.KubeToken,
|
|
||||||
TemplateFile: kubeConfigTemplate,
|
|
||||||
ConfigFile: kubeConfigFile,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func addRepos(cfg env.Config) []Step {
|
func addRepos(cfg env.Config) []Step {
|
||||||
steps := make([]Step, 0)
|
steps := make([]Step, 0)
|
||||||
for _, repo := range cfg.AddRepos {
|
for _, repo := range cfg.AddRepos {
|
||||||
steps = append(steps, &run.AddRepo{
|
steps = append(steps, run.NewAddRepo(repo))
|
||||||
Repo: repo,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return steps
|
return steps
|
||||||
}
|
}
|
||||||
|
|
||||||
func depUpdate(cfg env.Config) []Step {
|
func depUpdate(cfg env.Config) []Step {
|
||||||
return []Step{
|
return []Step{run.NewDepUpdate(cfg)}
|
||||||
&run.DepUpdate{
|
|
||||||
Chart: cfg.Chart,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,46 +130,10 @@ func (suite *PlanTestSuite) TestExecuteAbortsOnError() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *PlanTestSuite) TestUpgrade() {
|
func (suite *PlanTestSuite) TestUpgrade() {
|
||||||
cfg := env.Config{
|
steps := upgrade(env.Config{})
|
||||||
ChartVersion: "seventeen",
|
|
||||||
DryRun: true,
|
|
||||||
Wait: true,
|
|
||||||
Values: "steadfastness,forthrightness",
|
|
||||||
StringValues: "tensile_strength,flexibility",
|
|
||||||
ValuesFiles: []string{"/root/price_inventory.yml"},
|
|
||||||
ReuseValues: true,
|
|
||||||
Timeout: "go sit in the corner",
|
|
||||||
Chart: "billboard_top_100",
|
|
||||||
Release: "post_malone_circles",
|
|
||||||
Force: true,
|
|
||||||
AtomicUpgrade: true,
|
|
||||||
CleanupOnFail: true,
|
|
||||||
}
|
|
||||||
|
|
||||||
steps := upgrade(cfg)
|
|
||||||
suite.Require().Equal(2, len(steps), "upgrade should return 2 steps")
|
suite.Require().Equal(2, len(steps), "upgrade should return 2 steps")
|
||||||
suite.Require().IsType(&run.InitKube{}, steps[0])
|
suite.IsType(&run.InitKube{}, steps[0])
|
||||||
|
suite.IsType(&run.Upgrade{}, steps[1])
|
||||||
suite.Require().IsType(&run.Upgrade{}, steps[1])
|
|
||||||
upgrade, _ := steps[1].(*run.Upgrade)
|
|
||||||
|
|
||||||
expected := &run.Upgrade{
|
|
||||||
Chart: cfg.Chart,
|
|
||||||
Release: cfg.Release,
|
|
||||||
ChartVersion: cfg.ChartVersion,
|
|
||||||
DryRun: true,
|
|
||||||
Wait: cfg.Wait,
|
|
||||||
Values: "steadfastness,forthrightness",
|
|
||||||
StringValues: "tensile_strength,flexibility",
|
|
||||||
ValuesFiles: []string{"/root/price_inventory.yml"},
|
|
||||||
ReuseValues: cfg.ReuseValues,
|
|
||||||
Timeout: cfg.Timeout,
|
|
||||||
Force: cfg.Force,
|
|
||||||
Atomic: true,
|
|
||||||
CleanupOnFail: true,
|
|
||||||
}
|
|
||||||
|
|
||||||
suite.Equal(expected, upgrade)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *PlanTestSuite) TestUpgradeWithUpdateDependencies() {
|
func (suite *PlanTestSuite) TestUpgradeWithUpdateDependencies() {
|
||||||
|
@ -194,43 +158,11 @@ func (suite *PlanTestSuite) TestUpgradeWithAddRepos() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *PlanTestSuite) TestUninstall() {
|
func (suite *PlanTestSuite) TestUninstall() {
|
||||||
cfg := env.Config{
|
steps := uninstall(env.Config{})
|
||||||
KubeToken: "b2YgbXkgYWZmZWN0aW9u",
|
|
||||||
SkipTLSVerify: true,
|
|
||||||
Certificate: "cHJvY2xhaW1zIHdvbmRlcmZ1bCBmcmllbmRzaGlw",
|
|
||||||
APIServer: "98.765.43.21",
|
|
||||||
ServiceAccount: "greathelm",
|
|
||||||
DryRun: true,
|
|
||||||
Timeout: "think about what you did",
|
|
||||||
Release: "jetta_id_love_to_change_the_world",
|
|
||||||
KeepHistory: true,
|
|
||||||
}
|
|
||||||
|
|
||||||
steps := uninstall(cfg)
|
|
||||||
suite.Require().Equal(2, len(steps), "uninstall should return 2 steps")
|
suite.Require().Equal(2, len(steps), "uninstall should return 2 steps")
|
||||||
|
|
||||||
suite.Require().IsType(&run.InitKube{}, steps[0])
|
suite.IsType(&run.InitKube{}, steps[0])
|
||||||
init, _ := steps[0].(*run.InitKube)
|
suite.IsType(&run.Uninstall{}, steps[1])
|
||||||
var expected Step = &run.InitKube{
|
|
||||||
SkipTLSVerify: true,
|
|
||||||
Certificate: "cHJvY2xhaW1zIHdvbmRlcmZ1bCBmcmllbmRzaGlw",
|
|
||||||
APIServer: "98.765.43.21",
|
|
||||||
ServiceAccount: "greathelm",
|
|
||||||
Token: "b2YgbXkgYWZmZWN0aW9u",
|
|
||||||
TemplateFile: kubeConfigTemplate,
|
|
||||||
ConfigFile: kubeConfigFile,
|
|
||||||
}
|
|
||||||
|
|
||||||
suite.Equal(expected, init)
|
|
||||||
|
|
||||||
suite.Require().IsType(&run.Uninstall{}, steps[1])
|
|
||||||
actual, _ := steps[1].(*run.Uninstall)
|
|
||||||
expected = &run.Uninstall{
|
|
||||||
Release: "jetta_id_love_to_change_the_world",
|
|
||||||
DryRun: true,
|
|
||||||
KeepHistory: true,
|
|
||||||
}
|
|
||||||
suite.Equal(expected, actual)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *PlanTestSuite) TestUninstallWithUpdateDependencies() {
|
func (suite *PlanTestSuite) TestUninstallWithUpdateDependencies() {
|
||||||
|
@ -244,46 +176,21 @@ func (suite *PlanTestSuite) TestUninstallWithUpdateDependencies() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *PlanTestSuite) TestInitKube() {
|
func (suite *PlanTestSuite) TestInitKube() {
|
||||||
cfg := env.Config{
|
cfg := env.Config{}
|
||||||
KubeToken: "cXVlZXIgY2hhcmFjdGVyCg==",
|
|
||||||
SkipTLSVerify: true,
|
|
||||||
Certificate: "b2Ygd29rZW5lc3MK",
|
|
||||||
APIServer: "123.456.78.9",
|
|
||||||
ServiceAccount: "helmet",
|
|
||||||
}
|
|
||||||
|
|
||||||
steps := initKube(cfg)
|
steps := initKube(cfg)
|
||||||
suite.Require().Equal(1, len(steps), "initKube should return one step")
|
suite.Require().Equal(1, len(steps), "initKube should return one step")
|
||||||
suite.Require().IsType(&run.InitKube{}, steps[0])
|
suite.IsType(&run.InitKube{}, steps[0])
|
||||||
init, _ := steps[0].(*run.InitKube)
|
|
||||||
|
|
||||||
expected := &run.InitKube{
|
|
||||||
SkipTLSVerify: true,
|
|
||||||
Certificate: "b2Ygd29rZW5lc3MK",
|
|
||||||
APIServer: "123.456.78.9",
|
|
||||||
ServiceAccount: "helmet",
|
|
||||||
Token: "cXVlZXIgY2hhcmFjdGVyCg==",
|
|
||||||
TemplateFile: kubeConfigTemplate,
|
|
||||||
ConfigFile: kubeConfigFile,
|
|
||||||
}
|
|
||||||
suite.Equal(expected, init)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *PlanTestSuite) TestDepUpdate() {
|
func (suite *PlanTestSuite) TestDepUpdate() {
|
||||||
cfg := env.Config{
|
cfg := env.Config{
|
||||||
UpdateDependencies: true,
|
UpdateDependencies: true,
|
||||||
Chart: "scatterplot",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
steps := depUpdate(cfg)
|
steps := depUpdate(cfg)
|
||||||
suite.Require().Equal(1, len(steps), "depUpdate should return one step")
|
suite.Require().Equal(1, len(steps), "depUpdate should return one step")
|
||||||
suite.Require().IsType(&run.DepUpdate{}, steps[0])
|
suite.IsType(&run.DepUpdate{}, steps[0])
|
||||||
update, _ := steps[0].(*run.DepUpdate)
|
|
||||||
|
|
||||||
expected := &run.DepUpdate{
|
|
||||||
Chart: "scatterplot",
|
|
||||||
}
|
|
||||||
suite.Equal(expected, update)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *PlanTestSuite) TestAddRepos() {
|
func (suite *PlanTestSuite) TestAddRepos() {
|
||||||
|
@ -295,35 +202,14 @@ func (suite *PlanTestSuite) TestAddRepos() {
|
||||||
}
|
}
|
||||||
steps := addRepos(cfg)
|
steps := addRepos(cfg)
|
||||||
suite.Require().Equal(2, len(steps), "addRepos should add one step per repo")
|
suite.Require().Equal(2, len(steps), "addRepos should add one step per repo")
|
||||||
suite.Require().IsType(&run.AddRepo{}, steps[0])
|
suite.IsType(&run.AddRepo{}, steps[0])
|
||||||
suite.Require().IsType(&run.AddRepo{}, steps[1])
|
suite.IsType(&run.AddRepo{}, steps[1])
|
||||||
first := steps[0].(*run.AddRepo)
|
|
||||||
second := steps[1].(*run.AddRepo)
|
|
||||||
|
|
||||||
suite.Equal(first.Repo, "first=https://add.repos/one")
|
|
||||||
suite.Equal(second.Repo, "second=https://add.repos/two")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *PlanTestSuite) TestLint() {
|
func (suite *PlanTestSuite) TestLint() {
|
||||||
cfg := env.Config{
|
steps := lint(env.Config{})
|
||||||
Chart: "./flow",
|
suite.Require().Equal(1, len(steps))
|
||||||
Values: "steadfastness,forthrightness",
|
suite.IsType(&run.Lint{}, steps[0])
|
||||||
StringValues: "tensile_strength,flexibility",
|
|
||||||
ValuesFiles: []string{"/root/price_inventory.yml"},
|
|
||||||
LintStrictly: true,
|
|
||||||
}
|
|
||||||
|
|
||||||
steps := lint(cfg)
|
|
||||||
suite.Equal(1, len(steps))
|
|
||||||
|
|
||||||
want := &run.Lint{
|
|
||||||
Chart: "./flow",
|
|
||||||
Values: "steadfastness,forthrightness",
|
|
||||||
StringValues: "tensile_strength,flexibility",
|
|
||||||
ValuesFiles: []string{"/root/price_inventory.yml"},
|
|
||||||
Strict: true,
|
|
||||||
}
|
|
||||||
suite.Equal(want, steps[0])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *PlanTestSuite) TestLintWithUpdateDependencies() {
|
func (suite *PlanTestSuite) TestLintWithUpdateDependencies() {
|
||||||
|
|
|
@ -11,6 +11,13 @@ type AddRepo struct {
|
||||||
cmd cmd
|
cmd cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewAddRepo creates an AddRepo for the given repo-spec. No validation is performed at this time.
|
||||||
|
func NewAddRepo(repo string) *AddRepo {
|
||||||
|
return &AddRepo{
|
||||||
|
Repo: repo,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Execute executes the `helm repo add` command.
|
// Execute executes the `helm repo add` command.
|
||||||
func (a *AddRepo) Execute(_ Config) error {
|
func (a *AddRepo) Execute(_ Config) error {
|
||||||
return a.cmd.Run()
|
return a.cmd.Run()
|
||||||
|
|
|
@ -38,6 +38,12 @@ func TestAddRepoTestSuite(t *testing.T) {
|
||||||
suite.Run(t, new(AddRepoTestSuite))
|
suite.Run(t, new(AddRepoTestSuite))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (suite *AddRepoTestSuite) TestNewAddRepo() {
|
||||||
|
repo := NewAddRepo("picompress=https://github.com/caleb_phipps/picompress")
|
||||||
|
suite.Require().NotNil(repo)
|
||||||
|
suite.Equal("picompress=https://github.com/caleb_phipps/picompress", repo.Repo)
|
||||||
|
}
|
||||||
|
|
||||||
func (suite *AddRepoTestSuite) TestPrepareAndExecute() {
|
func (suite *AddRepoTestSuite) TestPrepareAndExecute() {
|
||||||
stdout := strings.Builder{}
|
stdout := strings.Builder{}
|
||||||
stderr := strings.Builder{}
|
stderr := strings.Builder{}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package run
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/pelotech/drone-helm3/internal/env"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DepUpdate is an execution step that calls `helm dependency update` when executed.
|
// DepUpdate is an execution step that calls `helm dependency update` when executed.
|
||||||
|
@ -10,6 +11,13 @@ type DepUpdate struct {
|
||||||
cmd cmd
|
cmd cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewDepUpdate creates a DepUpdate using fields from the given Config. No validation is performed at this time.
|
||||||
|
func NewDepUpdate(cfg env.Config) *DepUpdate {
|
||||||
|
return &DepUpdate{
|
||||||
|
Chart: cfg.Chart,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Execute executes the `helm upgrade` command.
|
// Execute executes the `helm upgrade` command.
|
||||||
func (d *DepUpdate) Execute(_ Config) error {
|
func (d *DepUpdate) Execute(_ Config) error {
|
||||||
return d.cmd.Run()
|
return d.cmd.Run()
|
||||||
|
|
|
@ -3,6 +3,7 @@ package run
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/golang/mock/gomock"
|
"github.com/golang/mock/gomock"
|
||||||
|
"github.com/pelotech/drone-helm3/internal/env"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -31,6 +32,14 @@ func TestDepUpdateTestSuite(t *testing.T) {
|
||||||
suite.Run(t, new(DepUpdateTestSuite))
|
suite.Run(t, new(DepUpdateTestSuite))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (suite *DepUpdateTestSuite) TestNewDepUpdate() {
|
||||||
|
cfg := env.Config{
|
||||||
|
Chart: "scatterplot",
|
||||||
|
}
|
||||||
|
d := NewDepUpdate(cfg)
|
||||||
|
suite.Equal("scatterplot", d.Chart)
|
||||||
|
}
|
||||||
|
|
||||||
func (suite *DepUpdateTestSuite) TestPrepareAndExecute() {
|
func (suite *DepUpdateTestSuite) TestPrepareAndExecute() {
|
||||||
defer suite.ctrl.Finish()
|
defer suite.ctrl.Finish()
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package run
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/pelotech/drone-helm3/internal/env"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Help is a step in a helm Plan that calls `helm help`.
|
// Help is a step in a helm Plan that calls `helm help`.
|
||||||
|
@ -10,6 +11,13 @@ type Help struct {
|
||||||
cmd cmd
|
cmd cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewHelp creates a Help using fields from the given Config. No validation is performed at this time.
|
||||||
|
func NewHelp(cfg env.Config) *Help {
|
||||||
|
return &Help{
|
||||||
|
HelmCommand: cfg.Command,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Execute executes the `helm help` command.
|
// Execute executes the `helm help` command.
|
||||||
func (h *Help) Execute(cfg Config) error {
|
func (h *Help) Execute(cfg Config) error {
|
||||||
if err := h.cmd.Run(); err != nil {
|
if err := h.cmd.Run(); err != nil {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package run
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/golang/mock/gomock"
|
"github.com/golang/mock/gomock"
|
||||||
|
"github.com/pelotech/drone-helm3/internal/env"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -17,6 +18,15 @@ func TestHelpTestSuite(t *testing.T) {
|
||||||
suite.Run(t, new(HelpTestSuite))
|
suite.Run(t, new(HelpTestSuite))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (suite *HelpTestSuite) TestNewHelp() {
|
||||||
|
cfg := env.Config{
|
||||||
|
Command: "everybody dance NOW!!",
|
||||||
|
}
|
||||||
|
help := NewHelp(cfg)
|
||||||
|
suite.Require().NotNil(help)
|
||||||
|
suite.Equal("everybody dance NOW!!", help.HelmCommand)
|
||||||
|
}
|
||||||
|
|
||||||
func (suite *HelpTestSuite) TestPrepare() {
|
func (suite *HelpTestSuite) TestPrepare() {
|
||||||
ctrl := gomock.NewController(suite.T())
|
ctrl := gomock.NewController(suite.T())
|
||||||
defer ctrl.Finish()
|
defer ctrl.Finish()
|
||||||
|
|
|
@ -3,6 +3,7 @@ package run
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/pelotech/drone-helm3/internal/env"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
@ -32,6 +33,19 @@ type kubeValues struct {
|
||||||
Token string
|
Token string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewInitKube creates a InitKube using the given Config and filepaths. No validation is performed at this time.
|
||||||
|
func NewInitKube(cfg env.Config, templateFile, configFile string) *InitKube {
|
||||||
|
return &InitKube{
|
||||||
|
SkipTLSVerify: cfg.SkipTLSVerify,
|
||||||
|
Certificate: cfg.Certificate,
|
||||||
|
APIServer: cfg.APIServer,
|
||||||
|
ServiceAccount: cfg.ServiceAccount,
|
||||||
|
Token: cfg.KubeToken,
|
||||||
|
TemplateFile: templateFile,
|
||||||
|
ConfigFile: configFile,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Execute generates a kubernetes config file from drone-helm3's template.
|
// Execute generates a kubernetes config file from drone-helm3's template.
|
||||||
func (i *InitKube) Execute(cfg Config) error {
|
func (i *InitKube) Execute(cfg Config) error {
|
||||||
if cfg.Debug {
|
if cfg.Debug {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package run
|
package run
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/pelotech/drone-helm3/internal/env"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
yaml "gopkg.in/yaml.v2"
|
yaml "gopkg.in/yaml.v2"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
@ -17,6 +18,27 @@ func TestInitKubeTestSuite(t *testing.T) {
|
||||||
suite.Run(t, new(InitKubeTestSuite))
|
suite.Run(t, new(InitKubeTestSuite))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (suite *InitKubeTestSuite) TestNewInitKube() {
|
||||||
|
cfg := env.Config{
|
||||||
|
SkipTLSVerify: true,
|
||||||
|
Certificate: "cHJvY2xhaW1zIHdvbmRlcmZ1bCBmcmllbmRzaGlw",
|
||||||
|
APIServer: "98.765.43.21",
|
||||||
|
ServiceAccount: "greathelm",
|
||||||
|
KubeToken: "b2YgbXkgYWZmZWN0aW9u",
|
||||||
|
}
|
||||||
|
|
||||||
|
init := NewInitKube(cfg, "conf.tpl", "conf.yml")
|
||||||
|
suite.Equal(&InitKube{
|
||||||
|
SkipTLSVerify: true,
|
||||||
|
Certificate: "cHJvY2xhaW1zIHdvbmRlcmZ1bCBmcmllbmRzaGlw",
|
||||||
|
APIServer: "98.765.43.21",
|
||||||
|
ServiceAccount: "greathelm",
|
||||||
|
Token: "b2YgbXkgYWZmZWN0aW9u",
|
||||||
|
TemplateFile: "conf.tpl",
|
||||||
|
ConfigFile: "conf.yml",
|
||||||
|
}, init)
|
||||||
|
}
|
||||||
|
|
||||||
func (suite *InitKubeTestSuite) TestPrepareExecute() {
|
func (suite *InitKubeTestSuite) TestPrepareExecute() {
|
||||||
templateFile, err := tempfile("kubeconfig********.yml.tpl", `
|
templateFile, err := tempfile("kubeconfig********.yml.tpl", `
|
||||||
certificate: {{ .Certificate }}
|
certificate: {{ .Certificate }}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package run
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/pelotech/drone-helm3/internal/env"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Lint is an execution step that calls `helm lint` when executed.
|
// Lint is an execution step that calls `helm lint` when executed.
|
||||||
|
@ -14,6 +15,17 @@ type Lint struct {
|
||||||
cmd cmd
|
cmd cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewLint creates a Lint using fields from the given Config. No validation is performed at this time.
|
||||||
|
func NewLint(cfg env.Config) *Lint {
|
||||||
|
return &Lint{
|
||||||
|
Chart: cfg.Chart,
|
||||||
|
Values: cfg.Values,
|
||||||
|
StringValues: cfg.StringValues,
|
||||||
|
ValuesFiles: cfg.ValuesFiles,
|
||||||
|
Strict: cfg.LintStrictly,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Execute executes the `helm lint` command.
|
// Execute executes the `helm lint` command.
|
||||||
func (l *Lint) Execute(_ Config) error {
|
func (l *Lint) Execute(_ Config) error {
|
||||||
return l.cmd.Run()
|
return l.cmd.Run()
|
||||||
|
|
|
@ -3,6 +3,7 @@ package run
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/golang/mock/gomock"
|
"github.com/golang/mock/gomock"
|
||||||
|
"github.com/pelotech/drone-helm3/internal/env"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -31,6 +32,25 @@ func TestLintTestSuite(t *testing.T) {
|
||||||
suite.Run(t, new(LintTestSuite))
|
suite.Run(t, new(LintTestSuite))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (suite *LintTestSuite) TestNewLint() {
|
||||||
|
cfg := env.Config{
|
||||||
|
Chart: "./flow",
|
||||||
|
Values: "steadfastness,forthrightness",
|
||||||
|
StringValues: "tensile_strength,flexibility",
|
||||||
|
ValuesFiles: []string{"/root/price_inventory.yml"},
|
||||||
|
LintStrictly: true,
|
||||||
|
}
|
||||||
|
lint := NewLint(cfg)
|
||||||
|
suite.Require().NotNil(lint)
|
||||||
|
suite.Equal(&Lint{
|
||||||
|
Chart: "./flow",
|
||||||
|
Values: "steadfastness,forthrightness",
|
||||||
|
StringValues: "tensile_strength,flexibility",
|
||||||
|
ValuesFiles: []string{"/root/price_inventory.yml"},
|
||||||
|
Strict: true,
|
||||||
|
}, lint)
|
||||||
|
}
|
||||||
|
|
||||||
func (suite *LintTestSuite) TestPrepareAndExecute() {
|
func (suite *LintTestSuite) TestPrepareAndExecute() {
|
||||||
defer suite.ctrl.Finish()
|
defer suite.ctrl.Finish()
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package run
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/pelotech/drone-helm3/internal/env"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Uninstall is an execution step that calls `helm uninstall` when executed.
|
// Uninstall is an execution step that calls `helm uninstall` when executed.
|
||||||
|
@ -12,6 +13,15 @@ type Uninstall struct {
|
||||||
cmd cmd
|
cmd cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewUninstall creates an Uninstall using fields from the given Config. No validation is performed at this time.
|
||||||
|
func NewUninstall(cfg env.Config) *Uninstall {
|
||||||
|
return &Uninstall{
|
||||||
|
Release: cfg.Release,
|
||||||
|
DryRun: cfg.DryRun,
|
||||||
|
KeepHistory: cfg.KeepHistory,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Execute executes the `helm uninstall` command.
|
// Execute executes the `helm uninstall` command.
|
||||||
func (u *Uninstall) Execute(_ Config) error {
|
func (u *Uninstall) Execute(_ Config) error {
|
||||||
return u.cmd.Run()
|
return u.cmd.Run()
|
||||||
|
|
|
@ -3,6 +3,7 @@ package run
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/golang/mock/gomock"
|
"github.com/golang/mock/gomock"
|
||||||
|
"github.com/pelotech/drone-helm3/internal/env"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -35,6 +36,20 @@ func TestUninstallTestSuite(t *testing.T) {
|
||||||
suite.Run(t, new(UninstallTestSuite))
|
suite.Run(t, new(UninstallTestSuite))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (suite *UninstallTestSuite) TestNewUninstall() {
|
||||||
|
cfg := env.Config{
|
||||||
|
DryRun: true,
|
||||||
|
Release: "jetta_id_love_to_change_the_world",
|
||||||
|
KeepHistory: true,
|
||||||
|
}
|
||||||
|
u := NewUninstall(cfg)
|
||||||
|
suite.Equal(&Uninstall{
|
||||||
|
Release: "jetta_id_love_to_change_the_world",
|
||||||
|
DryRun: true,
|
||||||
|
KeepHistory: true,
|
||||||
|
}, u)
|
||||||
|
}
|
||||||
|
|
||||||
func (suite *UninstallTestSuite) TestPrepareAndExecute() {
|
func (suite *UninstallTestSuite) TestPrepareAndExecute() {
|
||||||
defer suite.ctrl.Finish()
|
defer suite.ctrl.Finish()
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package run
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/pelotech/drone-helm3/internal/env"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Upgrade is an execution step that calls `helm upgrade` when executed.
|
// Upgrade is an execution step that calls `helm upgrade` when executed.
|
||||||
|
@ -24,6 +25,25 @@ type Upgrade struct {
|
||||||
cmd cmd
|
cmd cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewUpgrade creates an Upgrade using fields from the given Config. No validation is performed at this time.
|
||||||
|
func NewUpgrade(cfg env.Config) *Upgrade {
|
||||||
|
return &Upgrade{
|
||||||
|
Chart: cfg.Chart,
|
||||||
|
Release: cfg.Release,
|
||||||
|
ChartVersion: cfg.ChartVersion,
|
||||||
|
DryRun: cfg.DryRun,
|
||||||
|
Wait: cfg.Wait,
|
||||||
|
Values: cfg.Values,
|
||||||
|
StringValues: cfg.StringValues,
|
||||||
|
ValuesFiles: cfg.ValuesFiles,
|
||||||
|
ReuseValues: cfg.ReuseValues,
|
||||||
|
Timeout: cfg.Timeout,
|
||||||
|
Force: cfg.Force,
|
||||||
|
Atomic: cfg.AtomicUpgrade,
|
||||||
|
CleanupOnFail: cfg.CleanupOnFail,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Execute executes the `helm upgrade` command.
|
// Execute executes the `helm upgrade` command.
|
||||||
func (u *Upgrade) Execute(_ Config) error {
|
func (u *Upgrade) Execute(_ Config) error {
|
||||||
return u.cmd.Run()
|
return u.cmd.Run()
|
||||||
|
|
|
@ -3,6 +3,7 @@ package run
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/golang/mock/gomock"
|
"github.com/golang/mock/gomock"
|
||||||
|
"github.com/pelotech/drone-helm3/internal/env"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -31,6 +32,41 @@ func TestUpgradeTestSuite(t *testing.T) {
|
||||||
suite.Run(t, new(UpgradeTestSuite))
|
suite.Run(t, new(UpgradeTestSuite))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (suite *UpgradeTestSuite) TestNewUpgrade() {
|
||||||
|
cfg := env.Config{
|
||||||
|
ChartVersion: "seventeen",
|
||||||
|
DryRun: true,
|
||||||
|
Wait: true,
|
||||||
|
Values: "steadfastness,forthrightness",
|
||||||
|
StringValues: "tensile_strength,flexibility",
|
||||||
|
ValuesFiles: []string{"/root/price_inventory.yml"},
|
||||||
|
ReuseValues: true,
|
||||||
|
Timeout: "go sit in the corner",
|
||||||
|
Chart: "billboard_top_100",
|
||||||
|
Release: "post_malone_circles",
|
||||||
|
Force: true,
|
||||||
|
AtomicUpgrade: true,
|
||||||
|
CleanupOnFail: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
up := NewUpgrade(cfg)
|
||||||
|
suite.Equal(&Upgrade{
|
||||||
|
Chart: cfg.Chart,
|
||||||
|
Release: cfg.Release,
|
||||||
|
ChartVersion: cfg.ChartVersion,
|
||||||
|
DryRun: true,
|
||||||
|
Wait: cfg.Wait,
|
||||||
|
Values: "steadfastness,forthrightness",
|
||||||
|
StringValues: "tensile_strength,flexibility",
|
||||||
|
ValuesFiles: []string{"/root/price_inventory.yml"},
|
||||||
|
ReuseValues: cfg.ReuseValues,
|
||||||
|
Timeout: cfg.Timeout,
|
||||||
|
Force: cfg.Force,
|
||||||
|
Atomic: true,
|
||||||
|
CleanupOnFail: true,
|
||||||
|
}, up)
|
||||||
|
}
|
||||||
|
|
||||||
func (suite *UpgradeTestSuite) TestPrepareAndExecute() {
|
func (suite *UpgradeTestSuite) TestPrepareAndExecute() {
|
||||||
defer suite.ctrl.Finish()
|
defer suite.ctrl.Finish()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue