in pkg/providers/apisix/translation/apisix_route.go [433:510]
func (t *translator) generateHTTPRouteV2DeleteMark(ctx *translation.TranslateContext, ar *configv2.ApisixRoute) error {
for _, part := range ar.Spec.HTTP {
pluginMap := make(apisixv1.Plugins)
// add route plugins
for _, plugin := range part.Plugins {
if !plugin.Enable {
continue
}
if plugin.Config != nil {
pluginMap[plugin.Name] = plugin.Config
} else {
pluginMap[plugin.Name] = make(map[string]interface{})
}
}
// add KeyAuth and basicAuth plugin
if part.Authentication.Enable {
switch part.Authentication.Type {
case "keyAuth":
pluginMap["key-auth"] = part.Authentication.KeyAuth
case "basicAuth":
pluginMap["basic-auth"] = make(map[string]interface{})
case "wolfRBAC":
pluginMap["wolf-rbac"] = make(map[string]interface{})
case "jwtAuth":
pluginMap["jwt-auth"] = part.Authentication.JwtAuth
case "hmacAuth":
pluginMap["hmac-auth"] = make(map[string]interface{})
case "ldapAuth":
pluginMap["ldap-auth"] = part.Authentication.LDAPAuth
default:
pluginMap["basic-auth"] = make(map[string]interface{})
}
}
route := apisixv1.NewDefaultRoute()
route.Name = apisixv1.ComposeRouteName(ar.Namespace, ar.Name, part.Name)
route.ID = id.GenID(route.Name)
if part.PluginConfigName != "" {
ns := ar.Namespace
if part.PluginConfigNamespace != "" {
ns = part.PluginConfigNamespace
}
route.PluginConfigId = id.GenID(apisixv1.ComposePluginConfigName(ns, part.PluginConfigName))
}
ctx.AddRoute(route)
if len(part.Backends) > 0 {
backends := part.Backends
// Use the first backend as the default backend in Route,
// others will be configured in traffic-split plugin.
backend := backends[0]
upstreamName := apisixv1.ComposeUpstreamName(ar.Namespace, backend.ServiceName, backend.Subset, backend.ServicePort.IntVal, backend.ResolveGranularity)
if !ctx.CheckUpstreamExist(upstreamName) {
ups, err := t.generateUpstreamDeleteMark(ar.Namespace, backend.ServiceName, backend.Subset, backend.ServicePort.IntVal, backend.ResolveGranularity)
if err != nil {
return err
}
ctx.AddUpstream(ups)
}
}
if len(part.Upstreams) > 0 {
upstreams := part.Upstreams
for _, upstream := range upstreams {
upstreamName := apisixv1.ComposeExternalUpstreamName(ar.Namespace, upstream.Name)
if !ctx.CheckUpstreamExist(upstreamName) {
ups := &apisixv1.Upstream{}
ups.Name = upstreamName
ups.ID = id.GenID(ups.Name)
ctx.AddUpstream(ups)
}
}
}
}
return nil
}