Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6acad85bed | ||
|
|
c033c8c45e | ||
|
|
30e1e3b99f | ||
|
|
b93917c857 | ||
|
|
84ac019838 | ||
|
|
9b3616613b | ||
|
|
7e24756ad8 | ||
|
|
a6a2d6e6a3 | ||
|
|
a6b7e06bd2 | ||
|
|
51800c18d7 | ||
|
|
991bbf97b4 | ||
|
|
f3039ee35d | ||
|
|
09e4869b2c | ||
|
|
c641c1a326 | ||
|
|
aa04830600 | ||
|
|
c585d8a22b | ||
|
|
1560c05100 | ||
|
|
e4fa70239e | ||
|
|
c08b2035a8 | ||
|
|
9797f5c8a2 | ||
|
|
173cf374f9 |
@@ -9,8 +9,10 @@ steps:
|
||||
commands:
|
||||
- go test ./cmd/... ./internal/...
|
||||
- go vet ./cmd/... ./internal/...
|
||||
- go get -u golang.org/x/lint/golint
|
||||
- golint ./cmd/... ./internal/...
|
||||
- name: lint
|
||||
image: cytopia/golint
|
||||
commands:
|
||||
- golint -set_exit_status ./cmd/... ./internal/...
|
||||
- name: build
|
||||
image: golang:1.13
|
||||
commands:
|
||||
|
||||
14
README.md
14
README.md
@@ -1,15 +1,3 @@
|
||||
# Drone plugin for Helm 3
|
||||
|
||||
TODO:
|
||||
|
||||
* [x] Make a `.drone.yml` that's sufficient for building an image
|
||||
* [x] Make a `Dockerfile` that's sufficient for launching the built image
|
||||
* [x] Make `cmd/drone-helm/main.go` actually invoke `helm`
|
||||
* [x] Make `golint` part of the build process (and make it pass)
|
||||
* [x] Implement debug output
|
||||
* [x] Flesh out `helm upgrade` until it's capable of working
|
||||
* [ ] Implement config settings for `upgrade`
|
||||
* [ ] Implement `helm lint`
|
||||
* [ ] Implement `helm delete`
|
||||
* [ ] EKS support
|
||||
* [ ] Change `.drone.yml` to use a real docker registry
|
||||
Dissatisfied with this empty README? Consider grabbing [the "put stuff in the README" issue](https://github.com/pelotech/drone-helm3/issues/8)!
|
||||
|
||||
@@ -19,8 +19,8 @@ func main() {
|
||||
// Make the plan
|
||||
plan, err := helm.NewPlan(c)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, err.Error())
|
||||
return
|
||||
fmt.Fprintf(os.Stderr, "%w\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Execute the plan
|
||||
|
||||
@@ -62,7 +62,7 @@ func determineSteps(cfg Config) *func(Config) []Step {
|
||||
case "delete":
|
||||
panic("not implemented")
|
||||
case "lint":
|
||||
panic("not implemented")
|
||||
return &lint
|
||||
case "help":
|
||||
return &help
|
||||
default:
|
||||
@@ -106,6 +106,7 @@ var upgrade = func(cfg Config) []Step {
|
||||
Chart: cfg.Chart,
|
||||
Release: cfg.Release,
|
||||
ChartVersion: cfg.ChartVersion,
|
||||
DryRun: cfg.DryRun,
|
||||
Wait: cfg.Wait,
|
||||
ReuseValues: cfg.ReuseValues,
|
||||
Timeout: cfg.Timeout,
|
||||
@@ -115,6 +116,14 @@ var upgrade = func(cfg Config) []Step {
|
||||
return steps
|
||||
}
|
||||
|
||||
var lint = func(cfg Config) []Step {
|
||||
lint := &run.Lint{
|
||||
Chart: cfg.Chart,
|
||||
}
|
||||
|
||||
return []Step{lint}
|
||||
}
|
||||
|
||||
var help = func(cfg Config) []Step {
|
||||
help := &run.Help{}
|
||||
return []Step{help}
|
||||
|
||||
@@ -93,6 +93,7 @@ func (suite *PlanTestSuite) TestUpgrade() {
|
||||
APIServer: "123.456.78.9",
|
||||
ServiceAccount: "helmet",
|
||||
ChartVersion: "seventeen",
|
||||
DryRun: true,
|
||||
Wait: true,
|
||||
ReuseValues: true,
|
||||
Timeout: "go sit in the corner",
|
||||
@@ -126,6 +127,7 @@ func (suite *PlanTestSuite) TestUpgrade() {
|
||||
Chart: cfg.Chart,
|
||||
Release: cfg.Release,
|
||||
ChartVersion: cfg.ChartVersion,
|
||||
DryRun: true,
|
||||
Wait: cfg.Wait,
|
||||
ReuseValues: cfg.ReuseValues,
|
||||
Timeout: cfg.Timeout,
|
||||
@@ -135,6 +137,20 @@ func (suite *PlanTestSuite) TestUpgrade() {
|
||||
suite.Equal(expected, upgrade)
|
||||
}
|
||||
|
||||
func (suite *PlanTestSuite) TestLint() {
|
||||
cfg := Config{
|
||||
Chart: "./flow",
|
||||
}
|
||||
|
||||
steps := lint(cfg)
|
||||
suite.Equal(1, len(steps))
|
||||
|
||||
want := &run.Lint{
|
||||
Chart: "./flow",
|
||||
}
|
||||
suite.Equal(want, steps[0])
|
||||
}
|
||||
|
||||
func (suite *PlanTestSuite) TestDeterminePlanUpgradeCommand() {
|
||||
cfg := Config{
|
||||
Command: "upgrade",
|
||||
@@ -154,6 +170,15 @@ func (suite *PlanTestSuite) TestDeterminePlanUpgradeFromDroneEvent() {
|
||||
}
|
||||
}
|
||||
|
||||
func (suite *PlanTestSuite) TestDeterminePlanLintCommand() {
|
||||
cfg := Config{
|
||||
Command: "lint",
|
||||
}
|
||||
|
||||
stepsMaker := determineSteps(cfg)
|
||||
suite.Same(&lint, stepsMaker)
|
||||
}
|
||||
|
||||
func (suite *PlanTestSuite) TestDeterminePlanHelpCommand() {
|
||||
cfg := Config{
|
||||
Command: "help",
|
||||
|
||||
56
internal/run/lint.go
Normal file
56
internal/run/lint.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package run
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// Lint is an execution step that calls `helm lint` when executed.
|
||||
type Lint struct {
|
||||
Chart string
|
||||
cmd cmd
|
||||
}
|
||||
|
||||
// Execute executes the `helm lint` command.
|
||||
func (l *Lint) Execute(_ Config) error {
|
||||
return l.cmd.Run()
|
||||
}
|
||||
|
||||
// Prepare gets the Lint ready to execute.
|
||||
func (l *Lint) Prepare(cfg Config) error {
|
||||
if l.Chart == "" {
|
||||
return fmt.Errorf("chart is required")
|
||||
}
|
||||
|
||||
args := make([]string, 0)
|
||||
|
||||
if cfg.Namespace != "" {
|
||||
args = append(args, "--namespace", cfg.Namespace)
|
||||
}
|
||||
if cfg.Debug {
|
||||
args = append(args, "--debug")
|
||||
}
|
||||
|
||||
args = append(args, "lint")
|
||||
|
||||
if cfg.Values != "" {
|
||||
args = append(args, "--set", cfg.Values)
|
||||
}
|
||||
if cfg.StringValues != "" {
|
||||
args = append(args, "--set-string", cfg.StringValues)
|
||||
}
|
||||
for _, vFile := range cfg.ValuesFiles {
|
||||
args = append(args, "--values", vFile)
|
||||
}
|
||||
|
||||
args = append(args, l.Chart)
|
||||
|
||||
l.cmd = command(helmBin, args...)
|
||||
l.cmd.Stdout(cfg.Stdout)
|
||||
l.cmd.Stderr(cfg.Stderr)
|
||||
|
||||
if cfg.Debug {
|
||||
fmt.Fprintf(cfg.Stderr, "Generated command: '%s'\n", l.cmd.String())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
169
internal/run/lint_test.go
Normal file
169
internal/run/lint_test.go
Normal file
@@ -0,0 +1,169 @@
|
||||
package run
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type LintTestSuite struct {
|
||||
suite.Suite
|
||||
ctrl *gomock.Controller
|
||||
mockCmd *Mockcmd
|
||||
originalCommand func(string, ...string) cmd
|
||||
}
|
||||
|
||||
func (suite *LintTestSuite) BeforeTest(_, _ string) {
|
||||
suite.ctrl = gomock.NewController(suite.T())
|
||||
suite.mockCmd = NewMockcmd(suite.ctrl)
|
||||
|
||||
suite.originalCommand = command
|
||||
command = func(path string, args ...string) cmd { return suite.mockCmd }
|
||||
}
|
||||
|
||||
func (suite *LintTestSuite) AfterTest(_, _ string) {
|
||||
command = suite.originalCommand
|
||||
}
|
||||
|
||||
func TestLintTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(LintTestSuite))
|
||||
}
|
||||
|
||||
func (suite *LintTestSuite) TestPrepareAndExecute() {
|
||||
defer suite.ctrl.Finish()
|
||||
|
||||
stdout := strings.Builder{}
|
||||
stderr := strings.Builder{}
|
||||
|
||||
l := Lint{
|
||||
Chart: "./epic/mychart",
|
||||
}
|
||||
cfg := Config{
|
||||
Stdout: &stdout,
|
||||
Stderr: &stderr,
|
||||
}
|
||||
|
||||
command = func(path string, args ...string) cmd {
|
||||
suite.Equal(helmBin, path)
|
||||
suite.Equal([]string{"lint", "./epic/mychart"}, args)
|
||||
|
||||
return suite.mockCmd
|
||||
}
|
||||
|
||||
suite.mockCmd.EXPECT().
|
||||
Stdout(&stdout)
|
||||
suite.mockCmd.EXPECT().
|
||||
Stderr(&stderr)
|
||||
suite.mockCmd.EXPECT().
|
||||
Run().
|
||||
Times(1)
|
||||
|
||||
err := l.Prepare(cfg)
|
||||
suite.Require().Nil(err)
|
||||
l.Execute(cfg)
|
||||
}
|
||||
|
||||
func (suite *LintTestSuite) TestPrepareRequiresChart() {
|
||||
// These aren't really expected, but allowing them gives clearer test-failure messages
|
||||
suite.mockCmd.EXPECT().Stdout(gomock.Any()).AnyTimes()
|
||||
suite.mockCmd.EXPECT().Stderr(gomock.Any()).AnyTimes()
|
||||
|
||||
cfg := Config{}
|
||||
l := Lint{}
|
||||
|
||||
err := l.Prepare(cfg)
|
||||
suite.EqualError(err, "chart is required", "Chart should be mandatory")
|
||||
}
|
||||
|
||||
func (suite *LintTestSuite) TestPrepareWithLintFlags() {
|
||||
defer suite.ctrl.Finish()
|
||||
|
||||
cfg := Config{
|
||||
Values: "width=5",
|
||||
StringValues: "version=2.0",
|
||||
ValuesFiles: []string{"/usr/local/underrides", "/usr/local/overrides"},
|
||||
}
|
||||
|
||||
l := Lint{
|
||||
Chart: "./uk/top_40",
|
||||
}
|
||||
|
||||
command = func(path string, args ...string) cmd {
|
||||
suite.Equal(helmBin, path)
|
||||
suite.Equal([]string{"lint",
|
||||
"--set", "width=5",
|
||||
"--set-string", "version=2.0",
|
||||
"--values", "/usr/local/underrides",
|
||||
"--values", "/usr/local/overrides",
|
||||
"./uk/top_40"}, args)
|
||||
|
||||
return suite.mockCmd
|
||||
}
|
||||
|
||||
suite.mockCmd.EXPECT().Stdout(gomock.Any()).AnyTimes()
|
||||
suite.mockCmd.EXPECT().Stderr(gomock.Any()).AnyTimes()
|
||||
|
||||
err := l.Prepare(cfg)
|
||||
suite.Require().Nil(err)
|
||||
}
|
||||
|
||||
func (suite *LintTestSuite) TestPrepareWithDebugFlag() {
|
||||
defer suite.ctrl.Finish()
|
||||
|
||||
stderr := strings.Builder{}
|
||||
|
||||
cfg := Config{
|
||||
Debug: true,
|
||||
Stderr: &stderr,
|
||||
}
|
||||
|
||||
l := Lint{
|
||||
Chart: "./scotland/top_40",
|
||||
}
|
||||
|
||||
command = func(path string, args ...string) cmd {
|
||||
suite.mockCmd.EXPECT().
|
||||
String().
|
||||
Return(fmt.Sprintf("%s %s", path, strings.Join(args, " ")))
|
||||
|
||||
return suite.mockCmd
|
||||
}
|
||||
|
||||
suite.mockCmd.EXPECT().Stdout(gomock.Any())
|
||||
suite.mockCmd.EXPECT().Stderr(&stderr)
|
||||
|
||||
err := l.Prepare(cfg)
|
||||
suite.Require().Nil(err)
|
||||
|
||||
want := fmt.Sprintf("Generated command: '%s --debug lint ./scotland/top_40'\n", helmBin)
|
||||
suite.Equal(want, stderr.String())
|
||||
}
|
||||
|
||||
func (suite *LintTestSuite) TestPrepareWithNamespaceFlag() {
|
||||
defer suite.ctrl.Finish()
|
||||
|
||||
cfg := Config{
|
||||
Namespace: "table-service",
|
||||
}
|
||||
|
||||
l := Lint{
|
||||
Chart: "./wales/top_40",
|
||||
}
|
||||
|
||||
actual := []string{}
|
||||
command = func(path string, args ...string) cmd {
|
||||
actual = args
|
||||
return suite.mockCmd
|
||||
}
|
||||
|
||||
suite.mockCmd.EXPECT().Stdout(gomock.Any()).AnyTimes()
|
||||
suite.mockCmd.EXPECT().Stderr(gomock.Any()).AnyTimes()
|
||||
|
||||
err := l.Prepare(cfg)
|
||||
suite.Require().Nil(err)
|
||||
|
||||
expected := []string{"--namespace", "table-service", "lint", "./wales/top_40"}
|
||||
suite.Equal(expected, actual)
|
||||
}
|
||||
@@ -10,6 +10,7 @@ type Upgrade struct {
|
||||
Release string
|
||||
|
||||
ChartVersion string
|
||||
DryRun bool
|
||||
Wait bool
|
||||
ReuseValues bool
|
||||
Timeout string
|
||||
@@ -25,18 +26,53 @@ func (u *Upgrade) Execute(_ Config) error {
|
||||
|
||||
// Prepare gets the Upgrade ready to execute.
|
||||
func (u *Upgrade) Prepare(cfg Config) error {
|
||||
if u.Chart == "" {
|
||||
return fmt.Errorf("chart is required")
|
||||
}
|
||||
if u.Release == "" {
|
||||
return fmt.Errorf("release is required")
|
||||
}
|
||||
|
||||
args := []string{"--kubeconfig", cfg.KubeConfig}
|
||||
|
||||
if cfg.Namespace != "" {
|
||||
args = append(args, "--namespace", cfg.Namespace)
|
||||
}
|
||||
|
||||
args = append(args, "upgrade", "--install", u.Release, u.Chart)
|
||||
|
||||
if cfg.Debug {
|
||||
args = append([]string{"--debug"}, args...)
|
||||
args = append(args, "--debug")
|
||||
}
|
||||
|
||||
args = append(args, "upgrade", "--install")
|
||||
|
||||
if u.ChartVersion != "" {
|
||||
args = append(args, "--version", u.ChartVersion)
|
||||
}
|
||||
if u.DryRun {
|
||||
args = append(args, "--dry-run")
|
||||
}
|
||||
if u.Wait {
|
||||
args = append(args, "--wait")
|
||||
}
|
||||
if u.ReuseValues {
|
||||
args = append(args, "--reuse-values")
|
||||
}
|
||||
if u.Timeout != "" {
|
||||
args = append(args, "--timeout", u.Timeout)
|
||||
}
|
||||
if u.Force {
|
||||
args = append(args, "--force")
|
||||
}
|
||||
if cfg.Values != "" {
|
||||
args = append(args, "--set", cfg.Values)
|
||||
}
|
||||
if cfg.StringValues != "" {
|
||||
args = append(args, "--set-string", cfg.StringValues)
|
||||
}
|
||||
for _, vFile := range cfg.ValuesFiles {
|
||||
args = append(args, "--values", vFile)
|
||||
}
|
||||
|
||||
args = append(args, u.Release, u.Chart)
|
||||
u.cmd = command(helmBin, args...)
|
||||
u.cmd.Stdout(cfg.Stdout)
|
||||
u.cmd.Stderr(cfg.Stderr)
|
||||
|
||||
@@ -31,7 +31,7 @@ func TestUpgradeTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(UpgradeTestSuite))
|
||||
}
|
||||
|
||||
func (suite *UpgradeTestSuite) TestPrepare() {
|
||||
func (suite *UpgradeTestSuite) TestPrepareAndExecute() {
|
||||
defer suite.ctrl.Finish()
|
||||
|
||||
u := Upgrade{
|
||||
@@ -79,12 +79,8 @@ func (suite *UpgradeTestSuite) TestPrepareNamespaceFlag() {
|
||||
return suite.mockCmd
|
||||
}
|
||||
|
||||
suite.mockCmd.EXPECT().
|
||||
Stdout(gomock.Any())
|
||||
suite.mockCmd.EXPECT().
|
||||
Stderr(gomock.Any())
|
||||
suite.mockCmd.EXPECT().
|
||||
Run()
|
||||
suite.mockCmd.EXPECT().Stdout(gomock.Any())
|
||||
suite.mockCmd.EXPECT().Stderr(gomock.Any())
|
||||
|
||||
cfg := Config{
|
||||
Namespace: "melt",
|
||||
@@ -92,7 +88,72 @@ func (suite *UpgradeTestSuite) TestPrepareNamespaceFlag() {
|
||||
}
|
||||
err := u.Prepare(cfg)
|
||||
suite.Require().Nil(err)
|
||||
u.Execute(cfg)
|
||||
}
|
||||
|
||||
func (suite *UpgradeTestSuite) TestPrepareWithUpgradeFlags() {
|
||||
defer suite.ctrl.Finish()
|
||||
|
||||
u := Upgrade{
|
||||
Chart: "hot_ac",
|
||||
Release: "maroon_5_memories",
|
||||
ChartVersion: "radio_edit", //-version
|
||||
DryRun: true, //-run
|
||||
Wait: true, //-wait
|
||||
ReuseValues: true, //-values
|
||||
Timeout: "sit_in_the_corner", //-timeout
|
||||
Force: true, //-force
|
||||
}
|
||||
|
||||
cfg := Config{
|
||||
KubeConfig: "/root/.kube/config",
|
||||
Values: "age=35",
|
||||
StringValues: "height=5ft10in",
|
||||
ValuesFiles: []string{"/usr/local/stats", "/usr/local/grades"},
|
||||
}
|
||||
|
||||
command = func(path string, args ...string) cmd {
|
||||
suite.Equal(helmBin, path)
|
||||
suite.Equal([]string{"--kubeconfig", "/root/.kube/config", "upgrade", "--install",
|
||||
"--version", "radio_edit",
|
||||
"--dry-run",
|
||||
"--wait",
|
||||
"--reuse-values",
|
||||
"--timeout", "sit_in_the_corner",
|
||||
"--force",
|
||||
"--set", "age=35",
|
||||
"--set-string", "height=5ft10in",
|
||||
"--values", "/usr/local/stats",
|
||||
"--values", "/usr/local/grades",
|
||||
"maroon_5_memories", "hot_ac"}, args)
|
||||
|
||||
return suite.mockCmd
|
||||
}
|
||||
|
||||
suite.mockCmd.EXPECT().Stdout(gomock.Any())
|
||||
suite.mockCmd.EXPECT().Stderr(gomock.Any())
|
||||
|
||||
err := u.Prepare(cfg)
|
||||
suite.Require().Nil(err)
|
||||
}
|
||||
|
||||
func (suite *UpgradeTestSuite) TestRequiresChartAndRelease() {
|
||||
// These aren't really expected, but allowing them gives clearer test-failure messages
|
||||
suite.mockCmd.EXPECT().Stdout(gomock.Any()).AnyTimes()
|
||||
suite.mockCmd.EXPECT().Stderr(gomock.Any()).AnyTimes()
|
||||
|
||||
u := Upgrade{
|
||||
Release: "seth_everman_unskippable_cutscene",
|
||||
}
|
||||
|
||||
err := u.Prepare(Config{})
|
||||
suite.EqualError(err, "chart is required", "Chart should be mandatory")
|
||||
|
||||
u = Upgrade{
|
||||
Chart: "billboard_top_zero",
|
||||
}
|
||||
|
||||
err = u.Prepare(Config{})
|
||||
suite.EqualError(err, "release is required", "Release should be mandatory")
|
||||
}
|
||||
|
||||
func (suite *UpgradeTestSuite) TestPrepareDebugFlag() {
|
||||
@@ -125,7 +186,7 @@ func (suite *UpgradeTestSuite) TestPrepareDebugFlag() {
|
||||
|
||||
u.Prepare(cfg)
|
||||
|
||||
want := fmt.Sprintf("Generated command: '%s --debug --kubeconfig /root/.kube/config upgrade "+
|
||||
want := fmt.Sprintf("Generated command: '%s --kubeconfig /root/.kube/config --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