do not require --default-backend-service

This commit is contained in:
Elvin Efendi 2018-09-24 23:33:13 -04:00
parent 5ce3809457
commit b3a22f7fc0
9 changed files with 97 additions and 143 deletions

View file

@ -31,10 +31,10 @@ func resetForTesting(usage func()) {
flag.Usage = usage
}
func TestMandatoryFlag(t *testing.T) {
func TestNoMandatoryFlag(t *testing.T) {
_, _, err := parseFlags()
if err == nil {
t.Fatalf("Expected an error about default backend service")
if err != nil {
t.Fatalf("Expected no error but got: %s", err)
}
}

View file

@ -176,10 +176,6 @@ Feature backed by OpenResty Lua libraries. Requires that OCSP stapling is not en
return true, nil, nil
}
if *defaultSvc == "" {
return false, nil, fmt.Errorf("Please specify --default-backend-service")
}
if *ingressClass != "" {
glog.Infof("Watching for Ingress class: %s", *ingressClass)

View file

@ -84,20 +84,22 @@ func main() {
handleFatalInitError(err)
}
defSvcNs, defSvcName, err := k8s.ParseNameNS(conf.DefaultService)
if err != nil {
glog.Fatal(err)
}
_, 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") {
glog.Fatalf("✖ The cluster seems to be running with a restrictive Authorization mode and the Ingress controller does not have the required permissions to operate normally.")
if len(conf.DefaultService) > 0 {
defSvcNs, defSvcName, err := k8s.ParseNameNS(conf.DefaultService)
if err != nil {
glog.Fatal(err)
}
glog.Fatalf("No service with name %v found: %v", conf.DefaultService, err)
_, 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") {
glog.Fatalf("✖ The cluster seems to be running with a restrictive Authorization mode and the Ingress controller does not have the required permissions to operate normally.")
}
glog.Fatalf("No service with name %v found: %v", conf.DefaultService, err)
}
glog.Infof("Validated %v as the default backend.", conf.DefaultService)
}
glog.Infof("Validated %v as the default backend.", conf.DefaultService)
if conf.Namespace != "" {
_, err = kubeClient.CoreV1().Namespaces().Get(conf.Namespace, metav1.GetOptions{})