8 Commits

Author SHA1 Message Date
Erin Call
09e4869b2c Merge pull request #2 from pelotech/flesh-out-upgrade
Build out the rest of the upgrade Step
2019-12-17 15:34:08 -08:00
Erin Call
aa04830600 Populate DryRun when building an Upgrade step 2019-12-17 09:23:44 -08:00
Erin Call
c585d8a22b More TODOs in the README 2019-12-16 17:07:33 -08:00
Erin Call
1560c05100 Fail early if chart or release is missing 2019-12-16 17:02:56 -08:00
Erin Call
e4fa70239e Implement config flags for helm upgrade 2019-12-16 16:55:05 -08:00
Erin Call
c08b2035a8 Merge pull request #1 from pelotech/assorted-cleanups
Assorted cleanups
2019-12-16 15:48:27 -08:00
Erin Call
9797f5c8a2 Non-0 exit status on error 2019-12-16 15:46:37 -08:00
Erin Call
173cf374f9 Run linting on an image with golint preinstalled
Running `go get` adds a line to `go.mod` every time, so using a
preinstalled golint avoids churn.
2019-12-16 15:44:46 -08:00
7 changed files with 130 additions and 18 deletions

View File

@@ -9,8 +9,10 @@ steps:
commands: commands:
- go test ./cmd/... ./internal/... - go test ./cmd/... ./internal/...
- go vet ./cmd/... ./internal/... - go vet ./cmd/... ./internal/...
- go get -u golang.org/x/lint/golint - name: lint
- golint ./cmd/... ./internal/... image: cytopia/golint
commands:
- golint -set_exit_status ./cmd/... ./internal/...
- name: build - name: build
image: golang:1.13 image: golang:1.13
commands: commands:

View File

@@ -8,8 +8,18 @@ TODO:
* [x] Make `golint` part of the build process (and make it pass) * [x] Make `golint` part of the build process (and make it pass)
* [x] Implement debug output * [x] Implement debug output
* [x] Flesh out `helm upgrade` until it's capable of working * [x] Flesh out `helm upgrade` until it's capable of working
* [ ] Implement config settings for `upgrade` * [x] Implement config settings for `upgrade`
* [ ] Implement `helm lint` * [ ] Implement `helm lint`
* [ ] Implement `helm delete` * [ ] Implement `helm delete`
* [ ] Look for command-line flags added in helm3; implement them
* [ ] EKS support * [ ] EKS support
* [ ] Dotenv support
* [ ] Example drone config in this README
* [ ] Change `.drone.yml` to use a real docker registry * [ ] Change `.drone.yml` to use a real docker registry
Nice-to-haves:
* [ ] Cleanup() method on Steps to close open filehandles, etc.
* [ ] Replace `fmt.Printf` with an actual logger
* [ ] Replace `fmt.Errorf` with `github.com/pkg/errors.Wrap`, since the built-in `Unwrap` doesn't work the way `Cause` does
* [ ] Deprecation warnings if there are environment variables that aren't applicable in helm3

View File

@@ -19,8 +19,8 @@ func main() {
// Make the plan // Make the plan
plan, err := helm.NewPlan(c) plan, err := helm.NewPlan(c)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, err.Error()) fmt.Fprintf(os.Stderr, "%w\n", err)
return os.Exit(1)
} }
// Execute the plan // Execute the plan

View File

@@ -106,6 +106,7 @@ var upgrade = func(cfg Config) []Step {
Chart: cfg.Chart, Chart: cfg.Chart,
Release: cfg.Release, Release: cfg.Release,
ChartVersion: cfg.ChartVersion, ChartVersion: cfg.ChartVersion,
DryRun: cfg.DryRun,
Wait: cfg.Wait, Wait: cfg.Wait,
ReuseValues: cfg.ReuseValues, ReuseValues: cfg.ReuseValues,
Timeout: cfg.Timeout, Timeout: cfg.Timeout,

View File

@@ -93,6 +93,7 @@ func (suite *PlanTestSuite) TestUpgrade() {
APIServer: "123.456.78.9", APIServer: "123.456.78.9",
ServiceAccount: "helmet", ServiceAccount: "helmet",
ChartVersion: "seventeen", ChartVersion: "seventeen",
DryRun: true,
Wait: true, Wait: true,
ReuseValues: true, ReuseValues: true,
Timeout: "go sit in the corner", Timeout: "go sit in the corner",
@@ -126,6 +127,7 @@ func (suite *PlanTestSuite) TestUpgrade() {
Chart: cfg.Chart, Chart: cfg.Chart,
Release: cfg.Release, Release: cfg.Release,
ChartVersion: cfg.ChartVersion, ChartVersion: cfg.ChartVersion,
DryRun: true,
Wait: cfg.Wait, Wait: cfg.Wait,
ReuseValues: cfg.ReuseValues, ReuseValues: cfg.ReuseValues,
Timeout: cfg.Timeout, Timeout: cfg.Timeout,

View File

@@ -10,6 +10,7 @@ type Upgrade struct {
Release string Release string
ChartVersion string ChartVersion string
DryRun bool
Wait bool Wait bool
ReuseValues bool ReuseValues bool
Timeout string Timeout string
@@ -25,18 +26,53 @@ func (u *Upgrade) Execute(_ Config) error {
// Prepare gets the Upgrade ready to execute. // Prepare gets the Upgrade ready to execute.
func (u *Upgrade) Prepare(cfg Config) error { 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} args := []string{"--kubeconfig", cfg.KubeConfig}
if cfg.Namespace != "" { if cfg.Namespace != "" {
args = append(args, "--namespace", cfg.Namespace) args = append(args, "--namespace", cfg.Namespace)
} }
args = append(args, "upgrade", "--install", u.Release, u.Chart)
if cfg.Debug { 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 = command(helmBin, args...)
u.cmd.Stdout(cfg.Stdout) u.cmd.Stdout(cfg.Stdout)
u.cmd.Stderr(cfg.Stderr) u.cmd.Stderr(cfg.Stderr)

View File

@@ -31,7 +31,7 @@ func TestUpgradeTestSuite(t *testing.T) {
suite.Run(t, new(UpgradeTestSuite)) suite.Run(t, new(UpgradeTestSuite))
} }
func (suite *UpgradeTestSuite) TestPrepare() { func (suite *UpgradeTestSuite) TestPrepareAndExecute() {
defer suite.ctrl.Finish() defer suite.ctrl.Finish()
u := Upgrade{ u := Upgrade{
@@ -79,12 +79,8 @@ func (suite *UpgradeTestSuite) TestPrepareNamespaceFlag() {
return suite.mockCmd return suite.mockCmd
} }
suite.mockCmd.EXPECT(). suite.mockCmd.EXPECT().Stdout(gomock.Any())
Stdout(gomock.Any()) suite.mockCmd.EXPECT().Stderr(gomock.Any())
suite.mockCmd.EXPECT().
Stderr(gomock.Any())
suite.mockCmd.EXPECT().
Run()
cfg := Config{ cfg := Config{
Namespace: "melt", Namespace: "melt",
@@ -92,7 +88,72 @@ func (suite *UpgradeTestSuite) TestPrepareNamespaceFlag() {
} }
err := u.Prepare(cfg) err := u.Prepare(cfg)
suite.Require().Nil(err) 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() { func (suite *UpgradeTestSuite) TestPrepareDebugFlag() {
@@ -125,7 +186,7 @@ func (suite *UpgradeTestSuite) TestPrepareDebugFlag() {
u.Prepare(cfg) 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) "--install lewis_capaldi_someone_you_loved at40'\n", helmBin)
suite.Equal(want, stderr.String()) suite.Equal(want, stderr.String())
suite.Equal("", stdout.String()) suite.Equal("", stdout.String())