fix main: Print information about kubectl errors

This commit is contained in:
Vincent Ambo 2017-05-08 14:29:47 +02:00
parent cb6413bff7
commit c45e616258

24
main.go
View file

@ -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)
}