Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

Commit

Permalink
fix: Get target frontend from ingresses (#48)
Browse files Browse the repository at this point in the history
* fix: get target service from ingress

* print stack trace

* fix check correct ingress ref
  • Loading branch information
lostbean authored Sep 26, 2024
1 parent 0ccbbf4 commit b4ad5a3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
26 changes: 23 additions & 3 deletions kontrol-service/engine/flow/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -517,7 +537,7 @@ func getHTTPRoutes(
func getEnvoyFilters(
allServices []*resolved.Service,
namespace string,
targetHttpRouteServices []string,
targetServices []string,
) []istioclient.EnvoyFilter {
filters := []istioclient.EnvoyFilter{}
traceIdEnforcerLuaScript := generateTraceIDEnforcerLuaScript()
Expand All @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion kontrol-service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit b4ad5a3

Please sign in to comment.