From bb41a9d56fbf4f09c3a8132b3083d353c479306a Mon Sep 17 00:00:00 2001 From: Guihua Zhu Date: Fri, 7 Dec 2018 15:42:52 +0800 Subject: [PATCH] compare error with error types from k8s.io/apimachinery/pkg/api/errors Signed-off-by: Guihua Zhu --- cmd/nginx/main.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cmd/nginx/main.go b/cmd/nginx/main.go index 8ababca87..295b2f42e 100644 --- a/cmd/nginx/main.go +++ b/cmd/nginx/main.go @@ -24,13 +24,13 @@ import ( "net/http/pprof" "os" "os/signal" - "strings" "syscall" "time" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" + "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/wait" discovery "k8s.io/apimachinery/pkg/version" @@ -94,8 +94,7 @@ func main() { _, err = kubeClient.CoreV1().Services(defSvcNs).Get(defSvcName, metav1.GetOptions{}) if err != nil { - // TODO (antoineco): compare with error types from k8s.io/apimachinery/pkg/api/errors - if strings.Contains(err.Error(), "cannot get services in the namespace") { + if errors.IsUnauthorized(err) || errors.IsForbidden(err) { klog.Fatal("✖ The cluster seems to be running with a restrictive Authorization mode and the Ingress controller does not have the required permissions to operate normally.") } klog.Fatalf("No service with name %v found: %v", conf.DefaultService, err)