diff --git a/kontrol-service/engine/flow/render.go b/kontrol-service/engine/flow/render.go index 94aea21..6728f23 100644 --- a/kontrol-service/engine/flow/render.go +++ b/kontrol-service/engine/flow/render.go @@ -53,6 +53,26 @@ func RenderClusterResources(clusterTopology *resolved.ClusterTopology, namespace }) })) + targeIngressServices := lo.Uniq( + lo.FlatMap(clusterTopology.Ingress.Ingresses, func(ing net.Ingress, _ int) []string { + return lo.FlatMap(ing.Spec.Rules, func(rule net.IngressRule, _ int) []string { + return lo.FilterMap(rule.HTTP.Paths, func(path net.HTTPIngressPath, _ int) (string, bool) { + // TODO: we are ignoring the namespace from the path, should we? + targetNS := namespace + if ing.Namespace != "" { + targetNS = string(ing.Namespace) + } + if path.Backend.Service == nil { + logrus.Errorf("Ingress %v has a nil backend service", ing.Name) + return "", false + } + return fmt.Sprintf("%s/%s", targetNS, string(path.Backend.Service.Name)), true + }) + }) + })) + + targetServices := lo.Uniq(append(targetHttpRouteServices, targeIngressServices...)) + groupedServices := lo.GroupBy(clusterTopology.Services, func(item *resolved.Service) string { return item.ServiceID }) for serviceID, services := range groupedServices { logrus.Infof("Rendering service with id: '%v'.", serviceID) @@ -79,7 +99,7 @@ func RenderClusterResources(clusterTopology *resolved.ClusterTopology, namespace } } - envoyFiltersForService := getEnvoyFilters(clusterTopology.Services, namespace, targetHttpRouteServices) + envoyFiltersForService := getEnvoyFilters(clusterTopology.Services, namespace, targetServices) envoyFilters = append(envoyFilters, envoyFiltersForService...) routes, frontServices, inboundFrontFilters := getHTTPRoutes(clusterTopology.GatewayAndRoutes, clusterTopology.Services, namespace) @@ -517,7 +537,7 @@ func getHTTPRoutes( func getEnvoyFilters( allServices []*resolved.Service, namespace string, - targetHttpRouteServices []string, + targetServices []string, ) []istioclient.EnvoyFilter { filters := []istioclient.EnvoyFilter{} traceIdEnforcerLuaScript := generateTraceIDEnforcerLuaScript() @@ -537,7 +557,7 @@ func getEnvoyFilters( continue } - isTargertService := slices.Contains(targetHttpRouteServices, fmt.Sprintf("%s/%s", namespace, serviceID)) + isTargertService := slices.Contains(targetServices, fmt.Sprintf("%s/%s", namespace, serviceID)) // more inbound EnvoyFilters for routing routing traffic on frontend services are added by the getHTTPRoutes function if isTargertService { diff --git a/kontrol-service/main.go b/kontrol-service/main.go index 9261c71..87f11df 100644 --- a/kontrol-service/main.go +++ b/kontrol-service/main.go @@ -4,6 +4,7 @@ import ( "flag" "net/http" "os" + "runtime/debug" "strconv" cli_api "github.com/kurtosis-tech/kardinal/libs/cli-kontrol-api/api/golang/server" @@ -35,7 +36,6 @@ func main() { } func startServer(isDevMode bool) { - dbHostname := os.Getenv("DB_HOSTNAME") dbUsername := os.Getenv("DB_USERNAME") dbPassword := os.Getenv("DB_PASSWORD") @@ -121,6 +121,9 @@ func startServer(isDevMode bool) { debugMsg = "recover didn't get error msg" } logrus.Errorf("HTTP server handled this internal panic: %s", debugMsg) + // Log the error message along with the stack trace + stackTrace := string(debug.Stack()) + logrus.Errorf("HTTP server handled this internal panic: %s\nStack trace: %s", debugMsg, stackTrace) } }() return next(c)