func()

in pkg/appgw/requestroutingrules.go [169:235]


func (c *appGwConfigBuilder) getPathMaps(cbCtx *ConfigBuilderContext) map[listenerIdentifier]*n.ApplicationGatewayURLPathMap {
	urlPathMaps := make(map[listenerIdentifier]*n.ApplicationGatewayURLPathMap)
	for ingressIdx := range cbCtx.IngressList {
		ingress := cbCtx.IngressList[ingressIdx]

		if len(ingress.Spec.Rules) == 0 {
			c.noRulesIngress(cbCtx, ingress, &urlPathMaps)
		}

		for ruleIdx := range ingress.Spec.Rules {
			rule := &ingress.Spec.Rules[ruleIdx]
			// skip no http rule
			if rule.HTTP == nil {
				continue
			}

			_, azListenerConfig := c.processIngressRuleWithTLS(rule, ingress, cbCtx.EnvVariables)

			for listenerID, listenerAzConfig := range azListenerConfig {
				if _, exists := urlPathMaps[listenerID]; !exists {
					pathMapName := generateURLPathMapName(listenerID)
					urlPathMaps[listenerID] = &n.ApplicationGatewayURLPathMap{
						Etag: to.StringPtr("*"),
						Name: to.StringPtr(pathMapName),
						ID:   to.StringPtr(c.appGwIdentifier.urlPathMapID(pathMapName)),
						ApplicationGatewayURLPathMapPropertiesFormat: &n.ApplicationGatewayURLPathMapPropertiesFormat{
							DefaultBackendAddressPool:  &n.SubResource{ID: cbCtx.DefaultAddressPoolID},
							DefaultBackendHTTPSettings: &n.SubResource{ID: cbCtx.DefaultHTTPSettingsID},
						},
					}
				}

				pathMap := c.getPathMap(cbCtx, listenerID, listenerAzConfig, ingress, rule, ruleIdx)
				urlPathMaps[listenerID] = c.mergePathMap(urlPathMaps[listenerID], pathMap, cbCtx)
			}
		}
	}

	// if no url pathmaps were created, then add a default path map since this will be translated to
	// a basic request routing rule which is needed on Application Gateway to avoid validation error.
	if len(urlPathMaps) == 0 {
		defaultAddressPoolID := c.appGwIdentifier.AddressPoolID(DefaultBackendAddressPoolName)
		defaultHTTPSettingsID := c.appGwIdentifier.HTTPSettingsID(DefaultBackendHTTPSettingsName)
		listenerID := defaultFrontendListenerIdentifier(c.appGw, cbCtx.EnvVariables)
		pathMapName := generateURLPathMapName(listenerID)
		urlPathMaps[listenerID] = &n.ApplicationGatewayURLPathMap{
			Etag: to.StringPtr("*"),
			Name: to.StringPtr(pathMapName),
			ID:   to.StringPtr(c.appGwIdentifier.urlPathMapID(pathMapName)),
			ApplicationGatewayURLPathMapPropertiesFormat: &n.ApplicationGatewayURLPathMapPropertiesFormat{
				DefaultBackendAddressPool:  &n.SubResource{ID: &defaultAddressPoolID},
				DefaultBackendHTTPSettings: &n.SubResource{ID: &defaultHTTPSettingsID},
				PathRules:                  &[]n.ApplicationGatewayPathRule{},
			},
		}
	}

	if cbCtx.EnvVariables.EnableIstioIntegration {
		for listenerID, pathMap := range c.getIstioPathMaps(cbCtx) {
			if _, exists := urlPathMaps[listenerID]; !exists {
				urlPathMaps[listenerID] = pathMap
			}
		}
	}

	return urlPathMaps
}