Skip to content
This repository has been archived by the owner on Dec 21, 2019. It is now read-only.

Commit

Permalink
fix main: Print information about kubectl errors
Browse files Browse the repository at this point in the history
  • Loading branch information
tazjin committed May 8, 2017
1 parent cb6413b commit c45e616
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}

0 comments on commit c45e616

Please sign in to comment.