fix main: Print information about kubectl errors
This commit is contained in:
parent
cb6413bff7
commit
c45e616258
1 changed files with 20 additions and 4 deletions
24
main.go
24
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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue