From c45e616258f4187dca19964508b97a94d2893430 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Mon, 8 May 2017 14:29:47 +0200 Subject: fix main: Print information about kubectl errors --- main.go | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 0fcf93d66e..3a0febbb0a 100644 --- a/main.go +++ b/main.go @@ -98,25 +98,36 @@ func applyCommand() { kubectlArgs = []string{"apply", "-f", "-"} } - runKubectlWithResources(ctx, &kubectlArgs, resources) + if err := runKubectlWithResources(ctx, &kubectlArgs, resources); err != nil { + failWithKubectlError(err) + } } func replaceCommand() { ctx, resources := loadContextAndResources(replaceFile) args := []string{"replace", "--save-config=true", "-f", "-"} - runKubectlWithResources(ctx, &args, resources) + + if err := runKubectlWithResources(ctx, &args, resources); err != nil { + failWithKubectlError(err) + } } func deleteCommand() { ctx, resources := loadContextAndResources(deleteFile) args := []string{"delete", "-f", "-"} - runKubectlWithResources(ctx, &args, resources) + + if err := runKubectlWithResources(ctx, &args, resources); err != nil { + failWithKubectlError(err) + } } func createCommand() { ctx, resources := loadContextAndResources(createFile) args := []string{"create", "--save-config=true", "-f", "-"} - runKubectlWithResources(ctx, &args, resources) + + if err := runKubectlWithResources(ctx, &args, resources); err != nil { + failWithKubectlError(err) + } } func loadContextAndResources(file *string) (*context.Context, *[]string) { @@ -157,3 +168,8 @@ func runKubectlWithResources(c *context.Context, kubectlArgs *[]string, resource return kubectl.Wait() } + +func failWithKubectlError(err error) { + fmt.Errorf("Kubectl error: %v\n", err) + os.Exit(1) +} -- cgit 1.4.1