Skip to content

Commit

Permalink
Merge branch 'main' into compression
Browse files Browse the repository at this point in the history
Signed-off-by: Huabing (Robin) Zhao <[email protected]>
  • Loading branch information
zhaohuabing authored Jan 7, 2025
2 parents 6035cd5 + 2a5ecaf commit 870e368
Show file tree
Hide file tree
Showing 37 changed files with 923 additions and 288 deletions.
2 changes: 1 addition & 1 deletion api/v1alpha1/backend_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ type FQDNEndpoint struct {
//
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:MaxLength=253
// +kubebuilder:validation:Pattern=`^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9]))*$`
// +kubebuilder:validation:Pattern=`^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$`
Hostname string `json:"hostname"`

// Port defines the port of the backend endpoint.
Expand Down
4 changes: 4 additions & 0 deletions api/v1alpha1/envoygateway_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ func (r *EnvoyGatewayProvider) GetEnvoyGatewayKubeProvider() *EnvoyGatewayKubern

r.Kubernetes.RateLimitDeployment.defaultKubernetesDeploymentSpec(DefaultRateLimitImage)

if r.Kubernetes.RateLimitHpa != nil {
r.Kubernetes.RateLimitHpa.setDefault()
}

if r.Kubernetes.ShutdownManager == nil {
r.Kubernetes.ShutdownManager = &ShutdownManager{Image: ptr.To(DefaultShutdownManagerImage)}
}
Expand Down
25 changes: 24 additions & 1 deletion api/v1alpha1/envoygateway_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,12 @@ type EnvoyGatewayKubernetesProvider struct {
// +optional
RateLimitDeployment *KubernetesDeploymentSpec `json:"rateLimitDeployment,omitempty"`

// RateLimitHpa defines the Horizontal Pod Autoscaler settings for Envoy ratelimit Deployment.
// If the HPA is set, Replicas field from RateLimitDeployment will be ignored.
//
// +optional
RateLimitHpa *KubernetesHorizontalPodAutoscalerSpec `json:"rateLimitHpa,omitempty"`

// Watch holds configuration of which input resources should be watched and reconciled.
// +optional
Watch *KubernetesWatchMode `json:"watch,omitempty"`
Expand Down Expand Up @@ -254,10 +260,27 @@ type KubernetesWatchMode struct {
NamespaceSelector *metav1.LabelSelector `json:"namespaceSelector,omitempty"`
}

const (
// KubernetesDeployModeTypeControllerNamespace indicates that the controller namespace is used for the infra proxy deployments.
KubernetesDeployModeTypeControllerNamespace = "ControllerNamespace"

// KubernetesDeployModeTypeGatewayNamespace indicates that the gateway namespace is used for the infra proxy deployments.
KubernetesDeployModeTypeGatewayNamespace = "GatewayNamespace"
)

// KubernetesDeployModeType defines the type of KubernetesDeployMode
type KubernetesDeployModeType string

// KubernetesDeployMode holds configuration for how to deploy managed resources such as the Envoy Proxy
// data plane fleet.
type KubernetesDeployMode struct {
// TODO
// Type indicates what deployment mode to use. "ControllerNamespace" and
// "GatewayNamespace" are currently supported.
// By default, when this field is unset or empty, Envoy Gateway will deploy Envoy Proxy fleet in the Controller namespace.
// +optional
// +kubebuilder:default=ControllerNamespace
// +kubebuilder:validation:Enum=ControllerNamespace;GatewayNamespace
Type *KubernetesDeployModeType `json:"type,omitempty"`
}

// EnvoyGatewayCustomProvider defines configuration for the Custom provider.
Expand Down
12 changes: 11 additions & 1 deletion api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ spec:
endpoint.
maxLength: 253
minLength: 1
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9]))*$
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$
type: string
port:
description: Port defines the port of the backend endpoint.
Expand Down
4 changes: 2 additions & 2 deletions examples/extension-server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.23.3

require (
github.com/envoyproxy/gateway v1.0.2
github.com/envoyproxy/go-control-plane v0.13.2
github.com/envoyproxy/go-control-plane v0.13.3
github.com/envoyproxy/go-control-plane/envoy v1.32.2
github.com/urfave/cli/v2 v2.27.5
google.golang.org/grpc v1.69.2
Expand Down Expand Up @@ -33,7 +33,7 @@ require (
github.com/x448/float16 v0.8.4 // indirect
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
golang.org/x/net v0.33.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/sys v0.29.0 // indirect
golang.org/x/text v0.21.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20241209162323-e6fa225c2576 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241209162323-e6fa225c2576 // indirect
Expand Down
8 changes: 4 additions & 4 deletions examples/extension-server/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/envoyproxy/go-control-plane v0.13.2 h1:HoRou/hxH5VAnylep8UAh0jFAllMY0UlP0TwPmIEgYI=
github.com/envoyproxy/go-control-plane v0.13.2/go.mod h1:mcYj6+AKxG86c/jKeZsCIWv8oLzhR+SJynG0TB94Xw8=
github.com/envoyproxy/go-control-plane v0.13.3 h1:F2vYcSF8iRNhfvhZQRZ5Dvuyu0TpXazE9+h53TzkvA4=
github.com/envoyproxy/go-control-plane v0.13.3/go.mod h1:uhvHSBAMSvy2Y+CuAYfByIRH19zcdir1rgmMzKUo3eA=
github.com/envoyproxy/go-control-plane/envoy v1.32.2 h1:zidqwmijfcbyKqVxjQDFx042PgX+p9U+/fu/f9VtSk8=
github.com/envoyproxy/go-control-plane/envoy v1.32.2/go.mod h1:eR2SOX2IedqlPvmiKjUH7Wu//S602JKI7HPC/L3SRq8=
github.com/envoyproxy/protoc-gen-validate v1.1.0 h1:tntQDh69XqOCOZsDz0lVJQez/2L6Uu2PdjCQwWCJ3bM=
Expand Down Expand Up @@ -106,8 +106,8 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ require (
github.com/google/go-containerregistry v0.20.2
github.com/hashicorp/go-multierror v1.1.1
github.com/miekg/dns v1.1.62
github.com/ohler55/ojg v1.25.1
github.com/ohler55/ojg v1.26.0
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.20.5
github.com/prometheus/client_model v0.6.1
Expand All @@ -53,7 +53,7 @@ require (
go.uber.org/zap v1.27.0
golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e
golang.org/x/net v0.33.0
golang.org/x/sys v0.28.0
golang.org/x/sys v0.29.0
google.golang.org/genproto/googleapis/api v0.0.0-20241209162323-e6fa225c2576
google.golang.org/grpc v1.69.2
google.golang.org/protobuf v1.36.1
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -625,8 +625,8 @@ github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f h1:y5//uYreIhSUg3J
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw=
github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/ohler55/ojg v1.25.1 h1:PKZlzUtatXJKtLIehVejKJKgtr9NoOSkWm4SBr/Fgns=
github.com/ohler55/ojg v1.25.1/go.mod h1:gQhDVpQLqrmnd2eqGAvJtn+NfKoYJbe/A4Sj3/Vro4o=
github.com/ohler55/ojg v1.26.0 h1:oDZZGGkBUa/g/pu58RijTUP2QXiXsNsEnlopvoupJS8=
github.com/ohler55/ojg v1.26.0/go.mod h1:gQhDVpQLqrmnd2eqGAvJtn+NfKoYJbe/A4Sj3/Vro4o=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo=
github.com/onsi/ginkgo v0.0.0-20170829012221-11459a886d9c/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
Expand Down Expand Up @@ -1030,8 +1030,8 @@ golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.27.0 h1:WP60Sv1nlK1T6SupCHbXzSaN0b9wUmsPoRS9b61A23Q=
golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM=
golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
8 changes: 6 additions & 2 deletions internal/infrastructure/kubernetes/proxy/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func expectedProxyContainers(infra *ir.ProxyInfra,
},
},
},
SecurityContext: expectedShutdownManagerSecurityContext(),
SecurityContext: expectedShutdownManagerSecurityContext(containerSpec),
},
}

Expand Down Expand Up @@ -384,7 +384,11 @@ func expectedEnvoySecurityContext(containerSpec *egv1a1.KubernetesContainerSpec)
return sc
}

func expectedShutdownManagerSecurityContext() *corev1.SecurityContext {
func expectedShutdownManagerSecurityContext(containerSpec *egv1a1.KubernetesContainerSpec) *corev1.SecurityContext {
if containerSpec != nil && containerSpec.SecurityContext != nil {
return containerSpec.SecurityContext
}

sc := resource.DefaultSecurityContext()

// run as non-root user
Expand Down
51 changes: 51 additions & 0 deletions internal/infrastructure/kubernetes/proxy/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import (
"testing"

"github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1"
"k8s.io/utils/ptr"

egv1a1 "github.com/envoyproxy/gateway/api/v1alpha1"
"github.com/envoyproxy/gateway/internal/infrastructure/kubernetes/resource"
)

func TestEnvoyPodSelector(t *testing.T) {
Expand Down Expand Up @@ -36,3 +41,49 @@ func TestEnvoyPodSelector(t *testing.T) {
})
}
}

func TestExpectedShutdownManagerSecurityContext(t *testing.T) {
defaultSecurityContext := func() *corev1.SecurityContext {
sc := resource.DefaultSecurityContext()

// run as non-root user
sc.RunAsGroup = ptr.To(int64(65532))
sc.RunAsUser = ptr.To(int64(65532))

// ShutdownManger creates a file to indicate the connection drain process is completed,
// so it needs file write permission.
sc.ReadOnlyRootFilesystem = nil
return sc
}

customSc := &corev1.SecurityContext{
Privileged: ptr.To(true),
RunAsUser: ptr.To(int64(21)),
RunAsGroup: ptr.To(int64(2100)),
}

tests := []struct {
name string
in *egv1a1.KubernetesContainerSpec
expected *corev1.SecurityContext
}{
{
name: "default",
in: nil,
expected: defaultSecurityContext(),
},
{
name: "default",
in: &egv1a1.KubernetesContainerSpec{
SecurityContext: customSc,
},
expected: customSc,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
got := expectedShutdownManagerSecurityContext(tc.in)
require.Equal(t, tc.expected, got)
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -336,16 +336,7 @@ spec:
cpu: 10m
memory: 32Mi
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
privileged: false
runAsGroup: 65532
runAsNonRoot: true
runAsUser: 65532
seccompProfile:
type: RuntimeDefault
privileged: true
startupProbe:
failureThreshold: 30
httpGet:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,16 +335,7 @@ spec:
cpu: 10m
memory: 32Mi
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
privileged: false
runAsGroup: 65532
runAsNonRoot: true
runAsUser: 65532
seccompProfile:
type: RuntimeDefault
privileged: true
startupProbe:
failureThreshold: 30
httpGet:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,16 +339,7 @@ spec:
cpu: 10m
memory: 32Mi
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
privileged: false
runAsGroup: 65532
runAsNonRoot: true
runAsUser: 65532
seccompProfile:
type: RuntimeDefault
privileged: true
startupProbe:
failureThreshold: 30
httpGet:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,16 +339,7 @@ spec:
cpu: 10m
memory: 32Mi
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
privileged: false
runAsGroup: 65532
runAsNonRoot: true
runAsUser: 65532
seccompProfile:
type: RuntimeDefault
privileged: true
startupProbe:
failureThreshold: 30
httpGet:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,16 +341,7 @@ spec:
cpu: 10m
memory: 32Mi
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
privileged: false
runAsGroup: 65532
runAsNonRoot: true
runAsUser: 65532
seccompProfile:
type: RuntimeDefault
privileged: true
startupProbe:
failureThreshold: 30
httpGet:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,16 +343,7 @@ spec:
cpu: 10m
memory: 32Mi
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
privileged: false
runAsGroup: 65532
runAsNonRoot: true
runAsUser: 65532
seccompProfile:
type: RuntimeDefault
privileged: true
startupProbe:
failureThreshold: 30
httpGet:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,16 +340,7 @@ spec:
cpu: 10m
memory: 32Mi
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
privileged: false
runAsGroup: 65532
runAsNonRoot: true
runAsUser: 65532
seccompProfile:
type: RuntimeDefault
privileged: true
startupProbe:
failureThreshold: 30
httpGet:
Expand Down
Loading

0 comments on commit 870e368

Please sign in to comment.