forked from envoyproxy/gateway
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add EnvoyPatchPolicy support to Gateway API lib
Relates to envoyproxy#24 Signed-off-by: Arko Dasgupta <arko@tetrate.io>
- Loading branch information
Showing
12 changed files
with
206 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright Envoy Gateway Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// The full text of the Apache license is available in the LICENSE file at | ||
// the root of the repo. | ||
|
||
package gatewayapi | ||
|
||
import ( | ||
"sort" | ||
|
||
gwv1b1 "sigs.k8s.io/gateway-api/apis/v1beta1" | ||
|
||
egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1" | ||
"github.com/envoyproxy/gateway/internal/ir" | ||
) | ||
|
||
func (t *Translator) ProcessEnvoyPatchPolicies(envoyPatchPolicies []*egv1a1.EnvoyPatchPolicy, xdsIR XdsIRMap) { | ||
// Sort based on priority | ||
sort.Slice(envoyPatchPolicies, func(i, j int) bool { | ||
return envoyPatchPolicies[i].Spec.Priority < envoyPatchPolicies[j].Spec.Priority | ||
}) | ||
|
||
for _, policy := range envoyPatchPolicies { | ||
// Ensure policy can only target a Gateway | ||
if policy.Spec.TargetRef.Group != gwv1b1.GroupName || policy.Spec.TargetRef.Kind != KindGateway { | ||
// TODO: Update Status | ||
continue | ||
} | ||
|
||
// Ensure Policy and target Gateway are in the same namespace | ||
targetNs := policy.Spec.TargetRef.Namespace | ||
if targetNs == nil || policy.Namespace != string(*targetNs) { | ||
// TODO: Update Status | ||
continue | ||
} | ||
|
||
// Get the IR | ||
// It must exist since the gateways have already been processed | ||
irKey := irStringKey(string(*targetNs), string(policy.Spec.TargetRef.Name)) | ||
gwXdsIR, ok := xdsIR[irKey] | ||
if !ok { | ||
// TODO: Update Status | ||
continue | ||
} | ||
|
||
// Save the patch | ||
for _, patch := range policy.Spec.JSONPatches { | ||
irPatch := ir.JSONPatchConfig{} | ||
irPatch.Type = string(patch.Type) | ||
irPatch.Name = patch.Name | ||
irPatch.Operation.Op = string(patch.Operation.Op) | ||
irPatch.Operation.Path = patch.Operation.Path | ||
irPatch.Operation.Value = patch.Operation.Value | ||
|
||
gwXdsIR.JSONPatches = append(gwXdsIR.JSONPatches, &irPatch) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
internal/gatewayapi/testdata/envoypatchpolicy-valid.in.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
envoyPatchPolicies: | ||
- apiVersion: gateway.envoyproxy.io/v1alpha1 | ||
kind: EnvoyPatchPolicy | ||
metadata: | ||
namespace: envoy-gateway | ||
name: edit-conn-buffer-bytes | ||
spec: | ||
type: "JSONPatch" | ||
targetRef: | ||
group: gateway.networking.k8s.io | ||
kind: Gateway | ||
name: gateway-1 | ||
namespace: envoy-gateway | ||
jsonPatches: | ||
- type: "type.googleapis.com/envoy.config.listener.v3.Listener" | ||
name: "envoy-gateway-gateway-1-http" | ||
operation: | ||
op: replace | ||
path: "/per_connection_buffer_limit_bytes" | ||
value: "1024" | ||
- apiVersion: gateway.envoyproxy.io/v1alpha1 | ||
kind: EnvoyPatchPolicy | ||
metadata: | ||
namespace: envoy-gateway | ||
name: edit-ignore-global-limit | ||
spec: | ||
type: "JSONPatch" | ||
targetRef: | ||
group: gateway.networking.k8s.io | ||
kind: Gateway | ||
name: gateway-1 | ||
namespace: envoy-gateway | ||
# Higher priority | ||
priority: -1 | ||
jsonPatches: | ||
- type: "type.googleapis.com/envoy.config.listener.v3.Listener" | ||
name: "envoy-gateway-gateway-1-http" | ||
operation: | ||
op: replace | ||
path: "/ignore_global_conn_limit" | ||
value: "true" | ||
gateways: | ||
- apiVersion: gateway.networking.k8s.io/v1beta1 | ||
kind: Gateway | ||
metadata: | ||
namespace: envoy-gateway | ||
name: gateway-1 | ||
spec: | ||
gatewayClassName: envoy-gateway-class | ||
listeners: | ||
- name: http | ||
protocol: HTTP | ||
port: 80 | ||
allowedRoutes: | ||
namespaces: | ||
from: Same |
72 changes: 72 additions & 0 deletions
72
internal/gatewayapi/testdata/envoypatchpolicy-valid.out.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
gateways: | ||
- apiVersion: gateway.networking.k8s.io/v1beta1 | ||
kind: Gateway | ||
metadata: | ||
namespace: envoy-gateway | ||
name: gateway-1 | ||
spec: | ||
gatewayClassName: envoy-gateway-class | ||
listeners: | ||
- name: http | ||
protocol: HTTP | ||
port: 80 | ||
allowedRoutes: | ||
namespaces: | ||
from: Same | ||
status: | ||
listeners: | ||
- name: http | ||
supportedKinds: | ||
- group: gateway.networking.k8s.io | ||
kind: HTTPRoute | ||
- group: gateway.networking.k8s.io | ||
kind: GRPCRoute | ||
attachedRoutes: 0 | ||
conditions: | ||
- type: Programmed | ||
status: "True" | ||
reason: Programmed | ||
message: Sending translated listener configuration to the data plane | ||
- type: Accepted | ||
status: "True" | ||
reason: Accepted | ||
message: Listener has been successfully translated | ||
xdsIR: | ||
envoy-gateway-gateway-1: | ||
accessLog: | ||
text: | ||
- path: /dev/stdout | ||
http: | ||
- name: envoy-gateway-gateway-1-http | ||
address: 0.0.0.0 | ||
port: 10080 | ||
hostnames: | ||
- "*" | ||
jsonPatches: | ||
- type: "type.googleapis.com/envoy.config.listener.v3.Listener" | ||
name: "envoy-gateway-gateway-1-http" | ||
operation: | ||
op: replace | ||
path: "/ignore_global_conn_limit" | ||
value: "true" | ||
- type: "type.googleapis.com/envoy.config.listener.v3.Listener" | ||
name: "envoy-gateway-gateway-1-http" | ||
operation: | ||
op: replace | ||
path: "/per_connection_buffer_limit_bytes" | ||
value: "1024" | ||
infraIR: | ||
envoy-gateway-gateway-1: | ||
proxy: | ||
metadata: | ||
labels: | ||
gateway.envoyproxy.io/owning-gateway-namespace: envoy-gateway | ||
gateway.envoyproxy.io/owning-gateway-name: gateway-1 | ||
name: envoy-gateway-gateway-1 | ||
listeners: | ||
- address: "" | ||
ports: | ||
- name: http | ||
protocol: "HTTP" | ||
servicePort: 80 | ||
containerPort: 10080 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters