in pkg/appgw/frontend_listeners.go [21:100]
func (c *appGwConfigBuilder) getListeners(cbCtx *ConfigBuilderContext) (*[]n.ApplicationGatewayHTTPListener, *[]n.ApplicationGatewayFrontendPort) {
if c.mem.listeners != nil && c.mem.ports != nil {
return c.mem.listeners, c.mem.ports
}
portsByNumber := cbCtx.ExistingPortsByNumber
var listeners []n.ApplicationGatewayHTTPListener
if portsByNumber == nil {
portsByNumber = make(map[Port]n.ApplicationGatewayFrontendPort)
}
if cbCtx.EnvVariables.EnableIstioIntegration {
listeners, portsByNumber = c.getIstioListenersPorts(cbCtx)
}
for listenerID, config := range c.getListenerConfigs(cbCtx) {
listener, port, err := c.newListener(cbCtx, listenerID, config.Protocol, portsByNumber)
if err != nil {
klog.Errorf("Failed creating listener %+v: %s", listenerID, err)
continue
}
// newlistener created a new port; Add it to the set
if _, exists := portsByNumber[Port(*port.Port)]; !exists {
portsByNumber[Port(*port.Port)] = *port
}
if config.Protocol == n.ApplicationGatewayProtocolHTTPS {
sslCertificateID := c.appGwIdentifier.sslCertificateID(config.Secret.secretFullName())
listener.SslCertificate = resourceRef(sslCertificateID)
if config.SslProfile != "" {
sslProfileID := c.appGwIdentifier.sslProfileID(config.SslProfile)
listener.SslProfile = resourceRef(sslProfileID)
}
}
if config.FirewallPolicy != "" {
listener.FirewallPolicy = &n.SubResource{ID: to.StringPtr(config.FirewallPolicy)}
}
listeners = append(listeners, *listener)
}
if cbCtx.EnvVariables.EnableBrownfieldDeployment {
er := brownfield.NewExistingResources(c.appGw, cbCtx.ProhibitedTargets, nil)
// Listeners we obtained from App Gateway - we segment them into ones AGIC is and is not allowed to change.
existingBlacklisted, existingNonBlacklisted := er.GetBlacklistedListeners()
brownfield.LogListeners(existingBlacklisted, existingNonBlacklisted, listeners)
// MergeListeners would produce unique list of listeners based on Name. Blacklisted listeners,
// which have the same name as a managed listeners would be overwritten.
listeners = brownfield.MergeListeners(existingBlacklisted, listeners)
}
portIDs := make(map[string]interface{})
// Cleanup unused ports
for _, listener := range listeners {
if listener.FrontendPort != nil && listener.FrontendPort.ID != nil {
portIDs[*listener.FrontendPort.ID] = nil
}
}
var ports []n.ApplicationGatewayFrontendPort
for _, port := range portsByNumber {
if _, exists := portIDs[*port.ID]; exists {
ports = append(ports, port)
}
}
sort.Sort(sorter.ByListenerName(listeners))
sort.Sort(sorter.ByFrontendPortName(ports))
// Since getListeners() would be called multiple times within the life cycle of a MutateAppGateway(Event)
// we cache the results of this function in what would be final place to store the Listeners.
c.mem.listeners = &listeners
c.mem.ports = &ports
return &listeners, &ports
}