Skip to content

egctl x translate requires gateway/gatewayclass resources #1648

@seankhliao

Description

@seankhliao

Description:
egctl x translate panics when only given an httproute resource.

Repro steps:

Just httproute
» cat httproute.yaml      
apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
  name: app
spec:
  parentRefs:
    - name: default
      namespace: envoy-gateway-system
  hostnames:
    - test-auth.ihwa.liao.dev
  rules:
    - matches:
        - path:
            type: PathPrefix
            value: /
          headers:
            - name: authorization
              type: RegularExpression
              value: "Bearer .*"
      backendRefs:
        - name: web-app
          port: 80
    - matches:
        - path:
            type: PathPrefix
            value: /
      backendRefs:
        - name: auth-app
          port: 80

» ~/third_party/envoyproxy-gateway/default/egctl x translate --from gateway-api --to xds --type route --add-missing-resources --file httproute.yaml
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x40 pc=0x1dabd3a]

goroutine 1 [running]:
github.com/envoyproxy/gateway/internal/cmd/egctl.addDefaultEnvoyProxy(0xc0007bdc80)
	github.com/envoyproxy/gateway/internal/cmd/egctl/translate.go:812 +0x1a
github.com/envoyproxy/gateway/internal/cmd/egctl.kubernetesYAMLToResources({0xc00083e500, 0x271}, 0x1)
	github.com/envoyproxy/gateway/internal/cmd/egctl/translate.go:801 +0x2334
github.com/envoyproxy/gateway/internal/cmd/egctl.translate({0x2750d40, 0xc0000b6030}, {0x7ffd4703fb68, 0xe}, {0x7ffd4703fb27, 0xb}, {0xc00037a270, 0x1, 0x1}, {0x24518dc, ...}, ...)
	github.com/envoyproxy/gateway/internal/cmd/egctl/translate.go:224 +0x159
github.com/envoyproxy/gateway/internal/cmd/egctl.NewTranslateCommand.func1(0xc0001ae400?, {0x2451af0?, 0x4?, 0x2451904?})
	github.com/envoyproxy/gateway/internal/cmd/egctl/translate.go:97 +0x14e
github.com/spf13/cobra.(*Command).execute(0xc000836300, {0xc0002158c0, 0x9, 0x9})
	github.com/spf13/cobra@v1.7.0/command.go:940 +0x87c
github.com/spf13/cobra.(*Command).ExecuteC(0xc0007c3800)
	github.com/spf13/cobra@v1.7.0/command.go:1068 +0x3a5
github.com/spf13/cobra.(*Command).Execute(0x0?)
	github.com/spf13/cobra@v1.7.0/command.go:992 +0x13
main.main()
	github.com/envoyproxy/gateway/cmd/egctl/main.go:16 +0x18
httproute + gatewayclass
» cat gatewayclass.yaml 
apiVersion: gateway.networking.k8s.io/v1beta1
kind: GatewayClass
metadata:
  name: envoyproxy
spec:
  controllerName: gateway.envoyproxy.io/gatewayclass-controller
---
apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
  name: app
spec:
  parentRefs:
    - name: default
      namespace: envoy-gateway-system
  hostnames:
    - test-auth.ihwa.liao.dev
  rules:
    - matches:
        - path:
            type: PathPrefix
            value: /
          headers:
            - name: authorization
              type: RegularExpression
              value: "Bearer .*"
      backendRefs:
        - name: web-app
          port: 80
    - matches:
        - path:
            type: PathPrefix
            value: /
      backendRefs:
        - name: auth-app
          port: 80

» ~/third_party/envoyproxy-gateway/default/egctl x translate --from gateway-api --to xds --type route --add-missing-resources --file gatewayclass.yaml 
{}
httproute + gateway + gatewayclass
» cat all.yaml         
apiVersion: gateway.networking.k8s.io/v1beta1
kind: GatewayClass
metadata:
  name: envoyproxy
spec:
  controllerName: gateway.envoyproxy.io/gatewayclass-controller
---
apiVersion: gateway.networking.k8s.io/v1beta1
kind: Gateway
metadata:
  name: default
  namespace: envoy-gateway-system
spec:
  gatewayClassName: envoyproxy
  listeners:
    - name: http
      protocol: HTTP
      port: 80
      allowedRoutes:
        namespaces:
          from: All
    - name: https
      protocol: HTTPS
      port: 443
      allowedRoutes:
        namespaces:
          from: All
      tls:
        mode: Terminate
        certificateRefs:
          - name: wildcard-letsencrypt
---
apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
  name: app
spec:
  parentRefs:
    - name: default
      namespace: envoy-gateway-system
  hostnames:
    - test-auth.ihwa.liao.dev
  rules:
    - matches:
        - path:
            type: PathPrefix
            value: /
          headers:
            - name: authorization
              type: RegularExpression
              value: "Bearer .*"
      backendRefs:
        - name: web-app
          port: 80
    - matches:
        - path:
            type: PathPrefix
            value: /
      backendRefs:
        - name: auth-app
          port: 80

» ~/third_party/envoyproxy-gateway/default/egctl x translate --from gateway-api --to xds --type route --add-missing-resources --file all.yaml
xds:
  envoy-gateway-system-default:
    '@type': type.googleapis.com/envoy.admin.v3.RoutesConfigDump
    dynamicRouteConfigs:
    - routeConfig:
        '@type': type.googleapis.com/envoy.config.route.v3.RouteConfiguration
        ignorePortInHostMatching: true
        name: envoy-gateway-system-default-http
        virtualHosts:
        - domains:
          - '*'
          name: envoy-gateway-system-default-http
          routes:
          - directResponse:
              status: 500
            match:
              headers:
              - name: :authority
                stringMatch:
                  exact: test-auth.ihwa.liao.dev
              - name: authorization
                stringMatch:
                  safeRegex:
                    regex: Bearer .*
              prefix: /
            name: envoy-gateway-system-app-rule-0-match-0-test-auth.ihwa.liao.dev
          - directResponse:
              status: 500
            match:
              headers:
              - name: :authority
                stringMatch:
                  exact: test-auth.ihwa.liao.dev
              prefix: /
            name: envoy-gateway-system-app-rule-1-match-0-test-auth.ihwa.liao.dev

Environment:
egctl built from current HEAD: e171678

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions