Skip to content

Commit

Permalink
feat(helm): add cleanup flag to test command
Browse files Browse the repository at this point in the history
  • Loading branch information
Vaughn Dice committed Feb 13, 2017
1 parent eadd830 commit 4a57b01
Show file tree
Hide file tree
Showing 9 changed files with 240 additions and 107 deletions.
2 changes: 2 additions & 0 deletions _proto/hapi/services/tiller.proto
Expand Up @@ -317,6 +317,8 @@ message TestReleaseRequest {
string name = 1;
// timeout specifies the max amount of time any kubernetes client command can run.
int64 timeout = 2;
// cleanup specifies whether or not to attempt pod deletion after test completes
bool cleanup = 3;
}

// TestReleaseResponse represents a message from executing a test
Expand Down
8 changes: 7 additions & 1 deletion cmd/helm/release_testing.go
Expand Up @@ -37,6 +37,7 @@ type releaseTestCmd struct {
out io.Writer
client helm.Interface
timeout int64
cleanup bool
}

func newReleaseTestCmd(c helm.Interface, out io.Writer) *cobra.Command {
Expand All @@ -63,12 +64,17 @@ func newReleaseTestCmd(c helm.Interface, out io.Writer) *cobra.Command {

f := cmd.Flags()
f.Int64Var(&rlsTest.timeout, "timeout", 300, "time in seconds to wait for any individual kubernetes operation (like Jobs for hooks)")
f.BoolVar(&rlsTest.cleanup, "cleanup", false, "delete test pods upon completion")

return cmd
}

func (t *releaseTestCmd) run() (err error) {
c, errc := t.client.RunReleaseTest(t.name, helm.ReleaseTestTimeout(t.timeout))
c, errc := t.client.RunReleaseTest(
t.name,
helm.ReleaseTestTimeout(t.timeout),
helm.ReleaseTestCleanup(t.cleanup),
)

for {
select {
Expand Down
7 changes: 7 additions & 0 deletions pkg/helm/option.go
Expand Up @@ -190,6 +190,13 @@ func ReleaseTestTimeout(timeout int64) ReleaseTestOption {
}
}

// ReleaseTestCleanup is a boolean value representing whether to cleanup test pods
func ReleaseTestCleanup(cleanup bool) ReleaseTestOption {
return func(opts *options) {
opts.testReq.Cleanup = cleanup
}
}

// RollbackTimeout specifies the number of seconds before kubernetes calls timeout
func RollbackTimeout(timeout int64) RollbackOption {
return func(opts *options) {
Expand Down
149 changes: 76 additions & 73 deletions pkg/proto/hapi/services/tiller.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 24 additions & 19 deletions pkg/releasetesting/environment.go
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package releasetesting

import (
"bytes"
"fmt"

"k8s.io/helm/pkg/proto/hapi/services"
Expand All @@ -31,38 +32,42 @@ type Environment struct {
Timeout int64
}

func streamRunning(name string, stream services.ReleaseService_RunReleaseTestServer) error {
func (env *Environment) streamRunning(name string) error {
msg := "RUNNING: " + name
err := streamMessage(msg, stream)
return err
return env.streamMessage(msg)
}

func streamError(info string, stream services.ReleaseService_RunReleaseTestServer) error {
func (env *Environment) streamError(info string) error {
msg := "ERROR: " + info
err := streamMessage(msg, stream)
return err
return env.streamMessage(msg)
}

func streamFailed(name, namespace string, stream services.ReleaseService_RunReleaseTestServer) error {
msg := fmt.Sprintf("FAILED: %s, run `kubectl logs %s --namespace %s` for more info", name, name, namespace)
err := streamMessage(msg, stream)
return err
func (env *Environment) streamFailed(name string) error {
msg := fmt.Sprintf("FAILED: %s, run `kubectl logs %s --namespace %s` for more info", name, name, env.Namespace)
return env.streamMessage(msg)
}

func streamSuccess(name string, stream services.ReleaseService_RunReleaseTestServer) error {
func (env *Environment) streamSuccess(name string) error {
msg := fmt.Sprintf("PASSED: %s", name)
err := streamMessage(msg, stream)
return err
return env.streamMessage(msg)
}

func streamUnknown(name, info string, stream services.ReleaseService_RunReleaseTestServer) error {
func (env *Environment) streamUnknown(name, info string) error {
msg := fmt.Sprintf("UNKNOWN: %s: %s", name, info)
err := streamMessage(msg, stream)
return err
return env.streamMessage(msg)
}

func streamMessage(msg string, stream services.ReleaseService_RunReleaseTestServer) error {
func (env *Environment) streamMessage(msg string) error {
resp := &services.TestReleaseResponse{Msg: msg}
err := stream.Send(resp)
return err
return env.Stream.Send(resp)
}

// DeleteTestPods deletes resources given in testManifests
func (env *Environment) DeleteTestPods(testManifests []string) {
for _, testManifest := range testManifests {
err := env.KubeClient.Delete(env.Namespace, bytes.NewBufferString(testManifest))
if err != nil {
env.streamError(err.Error())
}
}
}

0 comments on commit 4a57b01

Please sign in to comment.