Skip to content

Commit

Permalink
Return an error on invalid ingress frontend configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
skmatti committed Nov 19, 2019
1 parent a2e96e0 commit f9bc672
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
16 changes: 6 additions & 10 deletions pkg/loadbalancers/l7.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ const (
// DefaultPath is the path used if none is specified. It is a valid path
// recognized by GCE.
DefaultPath = "/*"

invalidConfigErrorMessage = "error invalid ingress frontend configuration"
)

// L7RuntimeInfo is info passed to this module from the controller runtime.
Expand Down Expand Up @@ -152,10 +154,11 @@ func (l *L7) UrlMap() *composite.UrlMap {
}

func (l *L7) edgeHop() error {
// Keeps track if we will "try" to setup frontend resources based on user configuration.
// If user configuration dictates we do not, then we emit an event.
willConfigureFrontend := false
sslConfigured := l.runtimeInfo.TLS != nil || l.runtimeInfo.TLSName != ""
// Return an error if user configuration species that both HTTP & HTTPS are not to be configured.
if !l.runtimeInfo.AllowHTTP && !sslConfigured {
return fmt.Errorf(invalidConfigErrorMessage)
}

// Check for invalid L7-ILB HTTPS config before attempting sync
if flags.F.EnableL7Ilb && utils.IsGCEL7ILBIngress(l.runtimeInfo.Ingress) && sslConfigured && l.runtimeInfo.AllowHTTP {
Expand All @@ -167,7 +170,6 @@ func (l *L7) edgeHop() error {
return err
}
if l.runtimeInfo.AllowHTTP {
willConfigureFrontend = true
if err := l.edgeHopHttp(); err != nil {
return err
}
Expand All @@ -185,7 +187,6 @@ func (l *L7) edgeHop() error {
}
}
if sslConfigured {
willConfigureFrontend = true
klog.V(3).Infof("validating https for %v", l)
if err := l.edgeHopHttps(); err != nil {
return err
Expand All @@ -196,11 +197,6 @@ func (l *L7) edgeHop() error {
}
klog.V(2).Infof("Successfully deleted unused HTTPS frontend resources for load-balancer %s", l)
}

if !willConfigureFrontend {
l.recorder.Eventf(l.runtimeInfo.Ingress, corev1.EventTypeNormal, "WillNotConfigureFrontend", "Will not configure frontend based on Ingress specification. Please check your usage of the 'kubernetes.io/ingress.allow-http' annotation.")
}

return nil
}

Expand Down
10 changes: 9 additions & 1 deletion pkg/loadbalancers/loadbalancers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1543,7 +1543,15 @@ func TestResourceDeletionWithProtocol(t *testing.T) {
delete(expectCerts, certName1)
}

if lb, err = j.pool.Ensure(lbInfo); err != nil {
lb, err = j.pool.Ensure(lbInfo)
if tc.disableHTTP && tc.disableHTTPS {
// we expect an invalid ingress configuration error here.
if err == nil || !strings.Contains(err.Error(), invalidConfigErrorMessage) {
t.Fatalf("pool.Ensure(%+v) = %v, want %v", lbInfo, err, fmt.Errorf(invalidConfigErrorMessage))
}
return
}
if err != nil {
t.Fatalf("pool.Ensure(%+v) = %v, want nil", lbInfo, err)
}
// Update ingress annotations
Expand Down

0 comments on commit f9bc672

Please sign in to comment.