From be8563765e1065232a0e12f667e387676eb86a76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BE=84=E6=BD=AD?= Date: Wed, 27 Sep 2023 09:37:38 +0800 Subject: [PATCH] support custom group in httproute (#561) --- .../istio/20230925-gateway-httproute.patch | 71 +++++++++++++++++++ samples/gateway-api/demo.yaml | 55 ++++++++++++++ 2 files changed, 126 insertions(+) create mode 100644 istio/1.12/patches/istio/20230925-gateway-httproute.patch create mode 100644 samples/gateway-api/demo.yaml diff --git a/istio/1.12/patches/istio/20230925-gateway-httproute.patch b/istio/1.12/patches/istio/20230925-gateway-httproute.patch new file mode 100644 index 000000000..dc3bfb95b --- /dev/null +++ b/istio/1.12/patches/istio/20230925-gateway-httproute.patch @@ -0,0 +1,71 @@ +diff -Naur istio/pilot/pkg/config/kube/gateway/conversion.go istio-new/pilot/pkg/config/kube/gateway/conversion.go +--- istio/pilot/pkg/config/kube/gateway/conversion.go 2023-09-25 17:26:32.000000000 +0800 ++++ istio-new/pilot/pkg/config/kube/gateway/conversion.go 2023-09-25 17:25:27.000000000 +0800 +@@ -656,6 +656,16 @@ + Port: &istio.PortSelector{Number: uint32(*to.Port)}, + }, nil + } ++ if equal((*string)(to.Group), "networking.higress.io") && nilOrEqual((*string)(to.Kind), "Service") { ++ var port *istio.PortSelector ++ if to.Port != nil { ++ port = &istio.PortSelector{Number: uint32(*to.Port)} ++ } ++ return &istio.Destination{ ++ Host: string(to.Name), ++ Port: port, ++ }, nil ++ } + return nil, &ConfigError{ + Reason: InvalidDestination, + Message: fmt.Sprintf("referencing unsupported backendRef: group %q kind %q", emptyIfNil((*string)(to.Group)), emptyIfNil((*string)(to.Kind))), +@@ -912,7 +922,7 @@ + ObservedGeneration: obj.Generation, + LastTransitionTime: metav1.Now(), + Reason: string(k8s.GatewayClassConditionStatusAccepted), +- Message: "Handled by Istio controller", ++ Message: "Handled by Higress controller", + }) + return gcs + }) +@@ -1371,6 +1381,10 @@ + return d + } + ++func equal(have *string, expected string) bool { ++ return have != nil && *have == expected ++} ++ + func nilOrEqual(have *string, expected string) bool { + return have == nil || *have == expected + } +diff -Naur istio/pilot/pkg/leaderelection/leaderelection.go istio-new/pilot/pkg/leaderelection/leaderelection.go +--- istio/pilot/pkg/leaderelection/leaderelection.go 2023-09-25 17:26:31.000000000 +0800 ++++ istio-new/pilot/pkg/leaderelection/leaderelection.go 2023-09-25 14:59:39.000000000 +0800 +@@ -35,20 +35,20 @@ + + // Various locks used throughout the code + const ( +- NamespaceController = "istio-namespace-controller-election" +- ServiceExportController = "istio-serviceexport-controller-election" ++ NamespaceController = "higress-namespace-controller-election" ++ ServiceExportController = "higress-serviceexport-controller-election" + // This holds the legacy name to not conflict with older control plane deployments which are just + // doing the ingress syncing. +- IngressController = "istio-leader" ++ IngressController = "higress-leader" + // GatewayStatusController controls the status of gateway.networking.k8s.io objects. For the v1alpha1 + // this was formally "istio-gateway-leader"; because they are a different API group we need a different + // election to ensure we do not only handle one or the other. +- GatewayStatusController = "istio-gateway-status-leader" ++ GatewayStatusController = "higress-gateway-status-leader" + // GatewayDeploymentController controls the Deployment/Service generation from Gateways. This is + // separate from GatewayStatusController to allow running in a separate process (for low priv). +- GatewayDeploymentController = "istio-gateway-deployment-leader" +- StatusController = "istio-status-leader" +- AnalyzeController = "istio-analyze-leader" ++ GatewayDeploymentController = "higress-gateway-deployment-leader" ++ StatusController = "higress-status-leader" ++ AnalyzeController = "higress-analyze-leader" + ) + + var ClusterScopedNamespaceController = NamespaceController diff --git a/samples/gateway-api/demo.yaml b/samples/gateway-api/demo.yaml new file mode 100644 index 000000000..c109f89e9 --- /dev/null +++ b/samples/gateway-api/demo.yaml @@ -0,0 +1,55 @@ +apiVersion: gateway.networking.k8s.io/v1alpha2 +kind: GatewayClass +metadata: + name: higress-gateway +spec: + controllerName: "higress.io/gateway-controller" +--- +apiVersion: gateway.networking.k8s.io/v1alpha2 +kind: Gateway +metadata: + name: higress-gateway + namespace: higress-system +spec: + gatewayClassName: higress-gateway + listeners: + - name: default + hostname: "*.gateway-api.com" + port: 80 + protocol: HTTP + allowedRoutes: + namespaces: + from: All +--- +apiVersion: gateway.networking.k8s.io/v1alpha2 +kind: HTTPRoute +metadata: + name: http + namespace: default +spec: + parentRefs: + - name: higress-gateway + namespace: higress-system + hostnames: ["www.gateway-api.com"] + rules: + - matches: + - path: + type: PathPrefix + value: / + filters: + - type: RequestHeaderModifier + requestHeaderModifier: + add: + - name: my-added-header + value: added-value-higress + backendRefs: + - name: foo-service + port: 5678 + - matches: + - path: + type: PathPrefix + value: /by-nacos + backendRefs: + - name: service-provider.DEFAULT-GROUP.public.nacos + group: networking.higress.io +