in pkg/appgw/backendhttpsettings.go [225:336]
func (c *appGwConfigBuilder) generateHTTPSettings(backendID backendIdentifier, port Port, cbCtx *ConfigBuilderContext) n.ApplicationGatewayBackendHTTPSettings {
httpSettingsName := generateHTTPSettingsName(backendID.serviceFullName(), serviceBackendPortToStr(backendID.Backend.Service.Port), port, backendID.Ingress.Name)
httpSettings := n.ApplicationGatewayBackendHTTPSettings{
Etag: to.StringPtr("*"),
Name: &httpSettingsName,
ID: to.StringPtr(c.appGwIdentifier.HTTPSettingsID(httpSettingsName)),
ApplicationGatewayBackendHTTPSettingsPropertiesFormat: &n.ApplicationGatewayBackendHTTPSettingsPropertiesFormat{
Protocol: n.ApplicationGatewayProtocolHTTP,
Port: to.Int32Ptr(int32(port)),
// setting to default
PickHostNameFromBackendAddress: to.BoolPtr(false),
CookieBasedAffinity: n.ApplicationGatewayCookieBasedAffinityDisabled,
RequestTimeout: to.Int32Ptr(30),
},
}
_, probesMap := c.newProbesMap(cbCtx)
if probesMap[backendID] != nil {
probeName := probesMap[backendID].Name
probeID := c.appGwIdentifier.probeID(*probeName)
httpSettings.ApplicationGatewayBackendHTTPSettingsPropertiesFormat.Probe = resourceRef(probeID)
}
if pathPrefix, err := annotations.BackendPathPrefix(backendID.Ingress); err == nil {
httpSettings.Path = to.StringPtr(pathPrefix)
} else if !controllererrors.IsErrorCode(err, controllererrors.ErrorMissingAnnotation) {
c.recorder.Event(backendID.Ingress, v1.EventTypeWarning, events.ReasonInvalidAnnotation, err.Error())
}
if hostName, err := annotations.BackendHostName(backendID.Ingress); err == nil {
httpSettings.HostName = to.StringPtr(hostName)
} else if !controllererrors.IsErrorCode(err, controllererrors.ErrorMissingAnnotation) {
c.recorder.Event(backendID.Ingress, v1.EventTypeWarning, events.ReasonInvalidAnnotation, err.Error())
}
if isConnDrain, err := annotations.IsConnectionDraining(backendID.Ingress); err == nil && isConnDrain {
httpSettings.ConnectionDraining = &n.ApplicationGatewayConnectionDraining{
Enabled: to.BoolPtr(true),
}
if connDrainTimeout, err := annotations.ConnectionDrainingTimeout(backendID.Ingress); err == nil {
httpSettings.ConnectionDraining.DrainTimeoutInSec = to.Int32Ptr(connDrainTimeout)
} else {
httpSettings.ConnectionDraining.DrainTimeoutInSec = to.Int32Ptr(DefaultConnDrainTimeoutInSec)
}
} else if err != nil && !controllererrors.IsErrorCode(err, controllererrors.ErrorMissingAnnotation) {
c.recorder.Event(backendID.Ingress, v1.EventTypeWarning, events.ReasonInvalidAnnotation, err.Error())
}
if affinity, err := annotations.IsCookieBasedAffinity(backendID.Ingress); err == nil && affinity {
httpSettings.CookieBasedAffinity = n.ApplicationGatewayCookieBasedAffinityEnabled
} else if err != nil && !controllererrors.IsErrorCode(err, controllererrors.ErrorMissingAnnotation) {
c.recorder.Event(backendID.Ingress, v1.EventTypeWarning, events.ReasonInvalidAnnotation, err.Error())
}
if distinctName, err := annotations.IsCookieBasedAffinityDistinctName(backendID.Ingress); err == nil && distinctName {
httpSettings.AffinityCookieName = to.StringPtr(fmt.Sprintf("%s%s", "appgw-affinity-", backendID.serviceFullNameHash()))
} else if err != nil && !controllererrors.IsErrorCode(err, controllererrors.ErrorMissingAnnotation) {
c.recorder.Event(backendID.Ingress, v1.EventTypeWarning, events.ReasonInvalidAnnotation, err.Error())
}
if reqTimeout, err := annotations.RequestTimeout(backendID.Ingress); err == nil {
httpSettings.RequestTimeout = to.Int32Ptr(reqTimeout)
} else if !controllererrors.IsErrorCode(err, controllererrors.ErrorMissingAnnotation) {
c.recorder.Event(backendID.Ingress, v1.EventTypeWarning, events.ReasonInvalidAnnotation, err.Error())
}
// when ingress is defined with backend at port 443 but without annotation backend-protocol set to https.
if int32(port) == 443 {
httpSettings.Protocol = n.ApplicationGatewayProtocolHTTPS
}
// backend protocol take precedence over port
backendProtocol, err := annotations.BackendProtocol(backendID.Ingress)
if err == nil && backendProtocol == annotations.HTTPS {
httpSettings.Protocol = n.ApplicationGatewayProtocolHTTPS
} else if err == nil && backendProtocol == annotations.HTTP {
httpSettings.Protocol = n.ApplicationGatewayProtocolHTTP
} else if err != nil && !controllererrors.IsErrorCode(err, controllererrors.ErrorMissingAnnotation) {
c.recorder.Event(backendID.Ingress, v1.EventTypeWarning, events.ReasonInvalidAnnotation, err.Error())
}
if trustedRootCertificates, err := annotations.GetAppGwTrustedRootCertificate(backendID.Ingress); err == nil {
certificateNames := strings.TrimRight(trustedRootCertificates, ",")
certificateNameList := strings.Split(certificateNames, ",")
var certs []n.SubResource
for _, certName := range certificateNameList {
trustCertID := c.appGwIdentifier.trustedRootCertificateID(certName)
certs = append(certs, *resourceRef(trustCertID))
}
httpSettings.TrustedRootCertificates = &certs
klog.V(3).Infof("Found trusted root certificate(s): %s from ingress: %s/%s", certificateNames, backendID.Ingress.Namespace, backendID.Ingress.Name)
} else if err != nil && !controllererrors.IsErrorCode(err, controllererrors.ErrorMissingAnnotation) {
c.recorder.Event(backendID.Ingress, v1.EventTypeWarning, events.ReasonInvalidAnnotation, err.Error())
}
// 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".
if httpSettings.TrustedRootCertificates != nil {
if httpSettings.Protocol == n.ApplicationGatewayProtocolHTTPS && len(*httpSettings.TrustedRootCertificates) > 0 {
if httpSettings.HostName != nil && len(*httpSettings.HostName) > 0 {
httpSettings.PickHostNameFromBackendAddress = to.BoolPtr(false)
} else {
httpSettings.PickHostNameFromBackendAddress = to.BoolPtr(true)
}
}
}
return httpSettings
}