ingress2gateway

repository·main·Indexed 21 days ago

https://github.com/kubernetes-sigs/ingress2gateway

A tool designed to translate Kubernetes Ingress resources and provider-specific CRDs into standard Gateway API resources. It supports translation for providers including Apache APISIX, Cilium, GCE, and ingress-nginx, mapping provider-specific annotations (such as canary routing, HTTPS redirection, and rewrite rules) to Gateway API filters and resources.

Tokens
12.9K
Snippets
30
Records
65
Agent score
77%

What's inside ingress2gateway

  1. Implement NGINX Ingress Annotations for ingress2gateway

    main

    This provider implementation handles annotations specifically for the NGINX Ingress Controller.

    Warning: This is NOT for the community ingress-nginx controller.

    Supported Annotation Features

    The following features are implemented to convert NGINX annotations into Gateway API equivalents:

    • SSL Backend Services: SSLServicesFeature (via ssl_services.go)
    • gRPC Backend Services: GRPCServicesFeature (via grpc_services.go)
    • WebSocket Backend Services: WebSocketServicesFeature (via websocket_services.go)
    • Header Manipulation: HeaderManipulationFeature (handles hide-headers, proxy-set-headers, etc.)
    • HSTS: HSTSFeature (via hsts.go)
    • Custom Port Listeners: ListenPortsFeature (handles listen-ports, listen-ports-ssl)
    • Path Regex Matching: PathRegexFeature (via path_matching.go)
    • URL Rewriting: RewriteTargetFeature (via path_rewrite.go)
    • SSL/HTTPS Redirects: SSLRedirectFeature (via ssl_redirect.go)
  2. Understand Istio Gateway to K8S Gateway Listener translation

    main

    The provider generates a K8S API Gateway Listener for every host in every server defined in istio.Gateway.spec.Server.

    Listener Naming Convention: To ensure uniqueness within the Gateway, listener names follow the format: $PROTOCOL_NAME-protocol-$NAMESPACE-ns-$HOSTNAME

    Protocol Mapping:

    Istio ProtocolK8S Gateway Listener Protocol
    HTTP, HTTPS, TCP, TLSConverted as is
    HTTP2, GRPCHTTPS (if tls is set) or HTTP
    MONGOTCP

    TLS Mode Mapping:

    Istio TLS ModeK8S Gateway TLS Mode
    PASSTHROUGH, AUTO_PASSTHROUGHgw.TLSModePassthrough
    SIMPLE, MUTUALgw.TLSModeTerminate
    Other modesNot translated
  3. How ReferenceGrants and parentRefs are generated for cross-namespace Istio resources

    main

    The translator automatically manages connectivity between the Gateway and VirtualServices, especially when they reside in different namespaces.

    ParentRef Generation: parentRefs for an xRoute are generated if:

    1. The VirtualService can be exported to the Gateway's namespace (based on virtualService.Spec.ExportTo).
    2. There is an overlap between the Gateway's Server.Hosts and the virtualService.Spec.Hosts.

    ReferenceGrant Creation: If the Gateway and the VirtualService are in different namespaces, the translator creates a ReferenceGrant to allow the translated xRoute to successfully reference the translated Gateway.

  4. How Providers and Emitters work together in Ingress2gateway

    main

    Ingress2gateway uses a two-stage pipeline to translate resources:

    1. Providers: These components read Ingress resources and provider-specific Custom Resource Definitions (CRDs), then convert them into a generic intermediate representation (IR).
    2. Emitters: These components take the IR and produce the final Gateway API output.

    By default, the standard emitter produces core Gateway API resources like Gateway and HTTPRoute. Other emitters can produce resources tailored to specific projects, such as EnvoyGateway BackendTrafficPolicy or GKE HealthCheckPolicy.

  5. Understand Istio VirtualService to TLSRoute and TCPRoute translation

    main

    The provider translates non-HTTP Istio VirtualService configurations into specialized Gateway API routes:

    TLS Translation (TLSRoute):

    • match.sniHosts $\rightarrow$ TLSRouteSpec.Hostnames
    • route []RouteDestination $\rightarrow$ []gw.BackendRef

    TCP Translation (TCPRoute):

    • route []RouteDestination $\rightarrow$ []gw.BackendRef
  6. Understand Istio VirtualService to HTTPRoute translation

    main

    The provider maps istio.VirtualService.Http fields to gw.HTTPRoute equivalents as follows:

    Istio FieldK8S Gateway API Equivalent
    match []HTTPMatchRequest[]gw.HTTPRouteMatch
    route []HTTPRouteDestination[]gw.HTTPBackendRef
    redirect HTTPRedirectgw.HTTPRequestRedirectFilter
    rewrite HTTPRewritegw.HTTPURLRewriteFilter
    timeout Durationgw.HTTPRouteTimeouts.Request
    mirror and mirrors[]gw.HTTPRequestMirrorFilters
    headers.requestrequestHeaderModifier (gw.HTTPHeaderFilter)
    headers.responseresponseHeaderModifier (gw.HTTPHeaderFilter)

    HTTP Rewrite Logic

    Because the K8S Gateway API only allows one HTTPRouteFilterURLRewrite per HTTPRouteRule, the translator handles Istio's different rewrite behaviors by aggregating matches:

    1. Prefix Matches: Rewrites the matched prefix to the given value.
    2. Exact/Regex Matches: Rewrites the full URI path to the given value.

    Resulting Behavior: The translator may generate up to two HTTPRoutes:

    • One for prefix matches using the ReplacePrefixMatch filter.
    • One for non-prefix matches (exact/regex) using the ReplaceFullPath filter.

    If a match group is empty, that specific HTTPRoute is not generated. If all URI matches are empty, an HTTPRoute with a ReplacePrefixMatch filter is generated.

  7. How Ingress to Gateway conversion handles processing order and conflicts

    main

    To ensure deterministic generated Gateway API configurations, ingress2gateway processes Ingress resources using a specific sorting order. This order also determines precedence when Ingress resources or routes conflict.

    Precedence Rules:

    1. Creation Timestamp: Ingress resources with the oldest creation timestamp are processed first and given precedence.
    2. Namespace/Name: If creation timestamps are identical, resources are sorted by their namespace/name.

    Conflict Handling: If an Ingress rule conflicts with another (for example, having the same path match but different backends), an error is reported for the resource that sorted later in the sequence. This logic follows the Gateway API conflict resolution guidelines.

  8. How the Istio Provider translates Istio resources to K8S Gateway API

    main

    The Istio Provider acts as a translator that converts Istio API entities into Kubernetes Gateway API resources.

    Supported Translations:

    • Istio Gateway $\rightarrow$ K8S API Gateway
    • Istio VirtualService $\rightarrow$ HTTPRoute, TLSRoute, or TCPRoute (depending on the protocol)
    • Cross-namespace references $\rightarrow$ ReferenceGrant and xRoute.parentRefs generation

    Translation Logic:

    • Fields with direct equivalents are translated.
    • Fields that cannot be translated directly are logged and ignored. Users are responsible for handling these edge cases manually.