[goldpushk] Goldpushk.pushConfigMap(): Detect kubectl exit code in a less brittle way.
Change-Id: I1bea18bc26144d9a68a9df99897b936abea9bb99
Reviewed-on: https://skia-review.googlesource.com/c/buildbot/+/325898
Reviewed-by: Eric Boren <borenet@google.com>
Commit-Queue: Leandro Lovisolo <lovisolo@google.com>
diff --git a/golden/cmd/goldpushk/goldpushk/goldpushk.go b/golden/cmd/goldpushk/goldpushk/goldpushk.go
index 1029642..8a4d85a 100644
--- a/golden/cmd/goldpushk/goldpushk/goldpushk.go
+++ b/golden/cmd/goldpushk/goldpushk/goldpushk.go
@@ -14,9 +14,11 @@
import (
"context"
+ "errors"
"fmt"
"io/ioutil"
"os"
+ osexec "os/exec"
"path/filepath"
"regexp"
"strings"
@@ -534,8 +536,10 @@
func (g *Goldpushk) pushConfigMap(ctx context.Context, path, configMapName string) error {
// Delete existing ConfigMap.
if err := g.execCmd(ctx, "kubectl", []string{"delete", "configmap", configMapName}); err != nil {
- // TODO(lovisolo): Figure out a less brittle way to detect exit status 1.
- if strings.Contains(err.Error(), "Command exited with exit status 1") {
+ // Command "kubectl delete configmap" returns exit code 1 when the ConfigMap does not exist on
+ // the cluster.
+ var exitError *osexec.ExitError
+ if errors.As(err, &exitError) && exitError.ExitCode() == 1 {
sklog.Infof("Did not delete ConfigMap %s as it does not exist on the cluster.", configMapName)
} else {
return skerr.Wrap(err)