Create AddRepo steps when there are repos to add [#26]
This commit is contained in:
parent
22e30fea56
commit
48b6b3f5b3
|
@ -18,7 +18,7 @@ type Config struct {
|
||||||
Command string `envconfig:"HELM_COMMAND"` // Helm command to run
|
Command string `envconfig:"HELM_COMMAND"` // Helm command to run
|
||||||
DroneEvent string `envconfig:"DRONE_BUILD_EVENT"` // Drone event that invoked this plugin.
|
DroneEvent string `envconfig:"DRONE_BUILD_EVENT"` // Drone event that invoked this plugin.
|
||||||
UpdateDependencies bool `split_words:"true"` // Call `helm dependency update` before the main command
|
UpdateDependencies bool `split_words:"true"` // Call `helm dependency update` before the main command
|
||||||
Repos []string `envconfig:"HELM_REPOS"` // Call `helm repo add` before the main command
|
AddRepos []string `envconfig:"HELM_REPOS"` // Call `helm repo add` before the main command
|
||||||
Prefix string `` // Prefix to use when looking up secret env vars
|
Prefix string `` // Prefix to use when looking up secret env vars
|
||||||
Debug bool `` // Generate debug output and pass --debug to all helm commands
|
Debug bool `` // Generate debug output and pass --debug to all helm commands
|
||||||
Values string `` // Argument to pass to --set in applicable helm commands
|
Values string `` // Argument to pass to --set in applicable helm commands
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/pelotech/drone-helm3/internal/run"
|
"github.com/pelotech/drone-helm3/internal/run"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -96,6 +97,7 @@ func (p *Plan) Execute() error {
|
||||||
|
|
||||||
var upgrade = func(cfg Config) []Step {
|
var upgrade = func(cfg Config) []Step {
|
||||||
steps := initKube(cfg)
|
steps := initKube(cfg)
|
||||||
|
steps = append(steps, addRepos(cfg)...)
|
||||||
if cfg.UpdateDependencies {
|
if cfg.UpdateDependencies {
|
||||||
steps = append(steps, depUpdate(cfg)...)
|
steps = append(steps, depUpdate(cfg)...)
|
||||||
}
|
}
|
||||||
|
@ -127,7 +129,7 @@ var uninstall = func(cfg Config) []Step {
|
||||||
}
|
}
|
||||||
|
|
||||||
var lint = func(cfg Config) []Step {
|
var lint = func(cfg Config) []Step {
|
||||||
steps := make([]Step, 0)
|
steps := addRepos(cfg)
|
||||||
if cfg.UpdateDependencies {
|
if cfg.UpdateDependencies {
|
||||||
steps = append(steps, depUpdate(cfg)...)
|
steps = append(steps, depUpdate(cfg)...)
|
||||||
}
|
}
|
||||||
|
@ -157,6 +159,23 @@ func initKube(cfg Config) []Step {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func addRepos(cfg Config) []Step {
|
||||||
|
steps := make([]Step, 0)
|
||||||
|
for _, repo := range cfg.AddRepos {
|
||||||
|
split := strings.SplitN(repo, "=", 2)
|
||||||
|
if len(split) != 2 {
|
||||||
|
fmt.Fprintf(cfg.Stderr, "Warning: skipping bad repo spec '%s'.\n", repo)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
steps = append(steps, &run.AddRepo{
|
||||||
|
Name: split[0],
|
||||||
|
URL: split[1],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return steps
|
||||||
|
}
|
||||||
|
|
||||||
func depUpdate(cfg Config) []Step {
|
func depUpdate(cfg Config) []Step {
|
||||||
return []Step{
|
return []Step{
|
||||||
&run.DepUpdate{
|
&run.DepUpdate{
|
||||||
|
|
|
@ -177,6 +177,17 @@ func (suite *PlanTestSuite) TestUpgradeWithUpdateDependencies() {
|
||||||
suite.IsType(&run.DepUpdate{}, steps[1])
|
suite.IsType(&run.DepUpdate{}, steps[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (suite *PlanTestSuite) TestUpgradeWithAddRepos() {
|
||||||
|
cfg := Config{
|
||||||
|
AddRepos: []string{
|
||||||
|
"machine=https://github.com/harold_finch/themachine",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
steps := upgrade(cfg)
|
||||||
|
suite.Require().True(len(steps) > 1, "upgrade should generate at least two steps")
|
||||||
|
suite.IsType(&run.AddRepo{}, steps[1])
|
||||||
|
}
|
||||||
|
|
||||||
func (suite *PlanTestSuite) TestUninstall() {
|
func (suite *PlanTestSuite) TestUninstall() {
|
||||||
cfg := Config{
|
cfg := Config{
|
||||||
KubeToken: "b2YgbXkgYWZmZWN0aW9u",
|
KubeToken: "b2YgbXkgYWZmZWN0aW9u",
|
||||||
|
@ -268,6 +279,61 @@ func (suite *PlanTestSuite) TestDepUpdate() {
|
||||||
suite.Equal(expected, update)
|
suite.Equal(expected, update)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (suite *PlanTestSuite) TestAddRepos() {
|
||||||
|
cfg := Config{
|
||||||
|
AddRepos: []string{
|
||||||
|
"first=https://add.repos/one",
|
||||||
|
"second=https://add.repos/two",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
steps := addRepos(cfg)
|
||||||
|
suite.Require().Equal(2, len(steps), "addRepos should add one step per repo")
|
||||||
|
suite.Require().IsType(&run.AddRepo{}, steps[0])
|
||||||
|
suite.Require().IsType(&run.AddRepo{}, steps[1])
|
||||||
|
first := steps[0].(*run.AddRepo)
|
||||||
|
second := steps[1].(*run.AddRepo)
|
||||||
|
|
||||||
|
suite.Equal(first.Name, "first")
|
||||||
|
suite.Equal(first.URL, "https://add.repos/one")
|
||||||
|
suite.Equal(second.Name, "second")
|
||||||
|
suite.Equal(second.URL, "https://add.repos/two")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (suite *PlanTestSuite) TestAddNoRepos() {
|
||||||
|
cfg := Config{
|
||||||
|
AddRepos: []string{},
|
||||||
|
}
|
||||||
|
steps := addRepos(cfg)
|
||||||
|
suite.Equal(0, len(steps), "adding no repos should take zero steps")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (suite *PlanTestSuite) TestAddReposWithMalformedRepoSpec() {
|
||||||
|
stderr := strings.Builder{}
|
||||||
|
cfg := Config{
|
||||||
|
AddRepos: []string{
|
||||||
|
"dwim",
|
||||||
|
},
|
||||||
|
Stderr: &stderr,
|
||||||
|
}
|
||||||
|
steps := addRepos(cfg)
|
||||||
|
suite.Equal(len(steps), 0)
|
||||||
|
suite.Equal("Warning: skipping bad repo spec 'dwim'.\n", stderr.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (suite *PlanTestSuite) TestAddReposWithEqualsInURL() {
|
||||||
|
cfg := Config{
|
||||||
|
AddRepos: []string{
|
||||||
|
"samaritan=https://github.com/arthur_claypool/samaritan?version=2.1",
|
||||||
|
},
|
||||||
|
Stderr: &strings.Builder{},
|
||||||
|
}
|
||||||
|
steps := addRepos(cfg)
|
||||||
|
suite.Require().Equal(1, len(steps))
|
||||||
|
suite.Require().IsType(&run.AddRepo{}, steps[0])
|
||||||
|
addRepo := steps[0].(*run.AddRepo)
|
||||||
|
suite.Equal("https://github.com/arthur_claypool/samaritan?version=2.1", addRepo.URL)
|
||||||
|
}
|
||||||
|
|
||||||
func (suite *PlanTestSuite) TestLint() {
|
func (suite *PlanTestSuite) TestLint() {
|
||||||
cfg := Config{
|
cfg := Config{
|
||||||
Chart: "./flow",
|
Chart: "./flow",
|
||||||
|
@ -291,6 +357,15 @@ func (suite *PlanTestSuite) TestLintWithUpdateDependencies() {
|
||||||
suite.IsType(&run.DepUpdate{}, steps[0])
|
suite.IsType(&run.DepUpdate{}, steps[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (suite *PlanTestSuite) TestLintWithAddRepos() {
|
||||||
|
cfg := Config{
|
||||||
|
AddRepos: []string{"friendczar=https://github.com/logan_pierce/friendczar"},
|
||||||
|
}
|
||||||
|
steps := lint(cfg)
|
||||||
|
suite.Require().True(len(steps) > 0, "lint should return at least one step")
|
||||||
|
suite.IsType(&run.AddRepo{}, steps[0])
|
||||||
|
}
|
||||||
|
|
||||||
func (suite *PlanTestSuite) TestDeterminePlanUpgradeCommand() {
|
func (suite *PlanTestSuite) TestDeterminePlanUpgradeCommand() {
|
||||||
cfg := Config{
|
cfg := Config{
|
||||||
Command: "upgrade",
|
Command: "upgrade",
|
||||||
|
|
Loading…
Reference in a new issue