Skip to content

Commit 942282e

Browse files
committed
Handle when new annotation is set
1 parent 4110a22 commit 942282e

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

pkg/appgw/backendhttpsettings.go

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -321,16 +321,29 @@ func (c *appGwConfigBuilder) generateHTTPSettings(backendID backendIdentifier, p
321321
c.recorder.Event(backendID.Ingress, v1.EventTypeWarning, events.ReasonInvalidAnnotation, err.Error())
322322
}
323323

324-
// To use an HTTP setting with a trusted root certificate, we must either override with a specific domain name or choose "Pick host name from backend target".
325-
if httpSettings.TrustedRootCertificates != nil {
326-
if httpSettings.Protocol == n.ApplicationGatewayProtocolHTTPS && len(*httpSettings.TrustedRootCertificates) > 0 {
327-
if httpSettings.HostName != nil && len(*httpSettings.HostName) > 0 {
328-
httpSettings.PickHostNameFromBackendAddress = to.BoolPtr(false)
329-
} else {
330-
httpSettings.PickHostNameFromBackendAddress = to.BoolPtr(true)
324+
if overrideBackendHostName, err := annotations.OverrideBackendHostName(backendID.Ingress); err == nil {
325+
if httpSettings.HostName != nil && !overrideBackendHostName {
326+
// TODO Warn about pointless setting of hostname
327+
} else if httpSettings.HostName != nil && overrideBackendHostName {
328+
httpSettings.PickHostNameFromBackendAddress = to.BoolPtr(false)
329+
} else if httpSettings.HostName == nil && overrideBackendHostName {
330+
httpSettings.PickHostNameFromBackendAddress = to.BoolPtr(true)
331+
}
332+
} else if err != nil && !controllererrors.IsErrorCode(err, controllererrors.ErrorMissingAnnotation) {
333+
c.recorder.Event(backendID.Ingress, v1.EventTypeWarning, events.ReasonInvalidAnnotation, err.Error())
334+
} else if err != nil && controllererrors.IsErrorCode(err, controllererrors.ErrorMissingAnnotation) {
335+
// When overrideBackendHostName is unset, fallback to original behaviour:
336+
337+
// To use an HTTP setting with a trusted root certificate, we must either override with a specific domain name or choose "Pick host name from backend target".
338+
if httpSettings.TrustedRootCertificates != nil {
339+
if httpSettings.Protocol == n.ApplicationGatewayProtocolHTTPS && len(*httpSettings.TrustedRootCertificates) > 0 {
340+
if httpSettings.HostName != nil && len(*httpSettings.HostName) > 0 {
341+
httpSettings.PickHostNameFromBackendAddress = to.BoolPtr(false)
342+
} else {
343+
httpSettings.PickHostNameFromBackendAddress = to.BoolPtr(true)
344+
}
331345
}
332346
}
333347
}
334-
335348
return httpSettings
336349
}

0 commit comments

Comments
 (0)