Skip to content

Commit

Permalink
refactor: set defaults in Deployment, else k8s sets them for you, cre…
Browse files Browse the repository at this point in the history
…ating infinite reconciliation loop (envoyproxy#1594)

* fix: envoy proxy resource apply bug.

Signed-off-by: qicz <qiczzhu@gmail.com>

* update pointer.

Signed-off-by: qicz <qiczzhu@gmail.com>

* add comment

Signed-off-by: qicz <qiczzhu@gmail.com>

* update cm cmp logic.

Signed-off-by: qicz <qiczzhu@gmail.com>

* fix lint

Signed-off-by: qicz <qiczzhu@gmail.com>

* add probe field default value.

Signed-off-by: qicz <qiczzhu@gmail.com>

* fix uts

Signed-off-by: qicz <qiczzhu@gmail.com>

* align probe

Signed-off-by: qicz <qiczzhu@gmail.com>

* optimize deploy compare logic

Signed-off-by: qicz <qiczzhu@gmail.com>

* add compare deploy uts

Signed-off-by: qicz <qiczzhu@gmail.com>

* rm cm binarydata cmp

Signed-off-by: qicz <qiczzhu@gmail.com>

* rm deploy cmp logic

Signed-off-by: qicz <qiczzhu@gmail.com>

* fix ut

Signed-off-by: qicz <qiczzhu@gmail.com>

* fix lint

Signed-off-by: qicz <qiczzhu@gmail.com>

---------

Signed-off-by: qicz <qiczzhu@gmail.com>
Signed-off-by: qi <qiczzhu@gmail.com>
  • Loading branch information
qicz authored Jul 27, 2023
1 parent b37e2e9 commit 9ba9103
Show file tree
Hide file tree
Showing 25 changed files with 132 additions and 11 deletions.
14 changes: 10 additions & 4 deletions internal/infrastructure/kubernetes/proxy/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,15 @@ func expectedProxyContainers(infra *ir.ProxyInfra, deploymentConfig *egcfgv1a1.K
ReadinessProbe: &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Path: bootstrap.EnvoyReadinessPath,
Port: intstr.IntOrString{Type: intstr.Int, IntVal: bootstrap.EnvoyReadinessPort},
Path: bootstrap.EnvoyReadinessPath,
Port: intstr.IntOrString{Type: intstr.Int, IntVal: bootstrap.EnvoyReadinessPort},
Scheme: corev1.URISchemeHTTP,
},
},
TimeoutSeconds: 1,
PeriodSeconds: 10,
SuccessThreshold: 1,
FailureThreshold: 3,
},
},
}
Expand Down Expand Up @@ -222,7 +227,8 @@ func expectedDeploymentVolumes(name string, deploymentSpec *egcfgv1a1.Kubernetes
Name: "certs",
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: "envoy",
SecretName: "envoy",
DefaultMode: pointer.Int32(420),
},
},
},
Expand All @@ -243,7 +249,7 @@ func expectedDeploymentVolumes(name string, deploymentSpec *egcfgv1a1.Kubernetes
Path: SdsCertFilename,
},
},
DefaultMode: pointer.Int32(int32(420)),
DefaultMode: pointer.Int32(420),
Optional: pointer.Bool(false),
},
},
Expand Down
2 changes: 2 additions & 0 deletions internal/infrastructure/kubernetes/proxy/resource_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ func (r *ResourceRender) Deployment() (*appsv1.Deployment, error) {
Volumes: expectedDeploymentVolumes(r.infra.Name, deploymentConfig),
},
},
RevisionHistoryLimit: pointer.Int32(10),
ProgressDeadlineSeconds: pointer.Int32(600),
},
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ func TestDeployment(t *testing.T) {
Name: "certs",
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: "custom-envoy-cert",
SecretName: "custom-envoy-cert",
DefaultMode: pointer.Int32(420),
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ spec:
httpGet:
path: /ready
port: 19001
scheme: HTTP
timeoutSeconds: 1
periodSeconds: 10
successThreshold: 1
failureThreshold: 3
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
Expand All @@ -84,6 +89,7 @@ spec:
- name: certs
secret:
secretName: envoy
defaultMode: 420
- configMap:
defaultMode: 420
items:
Expand All @@ -94,3 +100,5 @@ spec:
name: envoy-default-64656661
optional: false
name: sds
revisionHistoryLimit: 10
progressDeadlineSeconds: 600
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ spec:
httpGet:
path: /ready
port: 19001
scheme: HTTP
timeoutSeconds: 1
periodSeconds: 10
successThreshold: 1
failureThreshold: 3
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
Expand All @@ -85,6 +90,7 @@ spec:
- name: certs
secret:
secretName: envoy
defaultMode: 420
- configMap:
defaultMode: 420
items:
Expand All @@ -95,3 +101,5 @@ spec:
name: envoy-default-64656661
optional: false
name: sds
revisionHistoryLimit: 10
progressDeadlineSeconds: 600
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ spec:
httpGet:
path: /ready
port: 19001
scheme: HTTP
timeoutSeconds: 1
periodSeconds: 10
successThreshold: 1
failureThreshold: 3
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
securityContext:
Expand All @@ -192,6 +197,7 @@ spec:
- name: certs
secret:
secretName: envoy
defaultMode: 420
- configMap:
defaultMode: 420
items:
Expand All @@ -202,3 +208,5 @@ spec:
name: envoy-default-64656661
optional: false
name: sds
revisionHistoryLimit: 10
progressDeadlineSeconds: 600
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ spec:
httpGet:
path: /ready
port: 19001
scheme: HTTP
timeoutSeconds: 1
periodSeconds: 10
successThreshold: 1
failureThreshold: 3
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
securityContext:
Expand All @@ -190,6 +195,7 @@ spec:
- name: certs
secret:
secretName: envoy
defaultMode: 420
- configMap:
defaultMode: 420
items:
Expand All @@ -200,3 +206,5 @@ spec:
name: envoy-default-64656661
optional: false
name: sds
revisionHistoryLimit: 10
progressDeadlineSeconds: 600
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ spec:
httpGet:
path: /ready
port: 19001
scheme: HTTP
timeoutSeconds: 1
periodSeconds: 10
successThreshold: 1
failureThreshold: 3
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
Expand All @@ -181,6 +186,7 @@ spec:
- name: certs
secret:
secretName: envoy
defaultMode: 420
- configMap:
defaultMode: 420
items:
Expand All @@ -191,3 +197,5 @@ spec:
name: envoy-default-64656661
optional: false
name: sds
revisionHistoryLimit: 10
progressDeadlineSeconds: 600
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ spec:
httpGet:
path: /ready
port: 19001
scheme: HTTP
timeoutSeconds: 1
periodSeconds: 10
successThreshold: 1
failureThreshold: 3
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
Expand All @@ -207,6 +212,7 @@ spec:
- name: certs
secret:
secretName: envoy
defaultMode: 420
- configMap:
defaultMode: 420
items:
Expand All @@ -217,3 +223,5 @@ spec:
name: envoy-default-64656661
optional: false
name: sds
revisionHistoryLimit: 10
progressDeadlineSeconds: 600
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ spec:
httpGet:
path: /ready
port: 19001
scheme: HTTP
timeoutSeconds: 1
periodSeconds: 10
successThreshold: 1
failureThreshold: 3
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
securityContext:
Expand All @@ -194,6 +199,7 @@ spec:
- name: certs
secret:
secretName: envoy
defaultMode: 420
- configMap:
defaultMode: 420
items:
Expand All @@ -204,3 +210,5 @@ spec:
name: envoy-default-64656661
optional: false
name: sds
revisionHistoryLimit: 10
progressDeadlineSeconds: 600
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ spec:
httpGet:
path: /ready
port: 19001
scheme: HTTP
timeoutSeconds: 1
periodSeconds: 10
successThreshold: 1
failureThreshold: 3
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
securityContext:
Expand All @@ -194,6 +199,7 @@ spec:
- name: certs
secret:
secretName: custom-envoy-cert
defaultMode: 420
- configMap:
defaultMode: 420
items:
Expand All @@ -204,3 +210,5 @@ spec:
name: envoy-default-64656661
optional: false
name: sds
revisionHistoryLimit: 10
progressDeadlineSeconds: 600
13 changes: 13 additions & 0 deletions internal/infrastructure/kubernetes/proxy_infra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ package kubernetes

import (
"context"
"reflect"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand All @@ -30,6 +32,17 @@ func newTestInfra(t *testing.T) *Infra {
return newTestInfraWithClient(t, cli)
}

func TestCmpBytes(t *testing.T) {
m1 := map[string][]byte{}
m1["a"] = []byte("aaa")
m2 := map[string][]byte{}
m2["a"] = []byte("aaa")

assert.True(t, reflect.DeepEqual(m1, m2))
assert.False(t, reflect.DeepEqual(nil, m2))
assert.False(t, reflect.DeepEqual(m1, nil))
}

func newTestInfraWithClient(t *testing.T, cli client.Client) *Infra {
cfg, err := config.New()
require.NoError(t, err)
Expand Down
7 changes: 5 additions & 2 deletions internal/infrastructure/kubernetes/ratelimit/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"strconv"

corev1 "k8s.io/api/core/v1"
"k8s.io/utils/pointer"
"sigs.k8s.io/controller-runtime/pkg/client"

egcfgv1a1 "github.com/envoyproxy/gateway/api/config/v1alpha1"
Expand Down Expand Up @@ -161,7 +162,8 @@ func expectedDeploymentVolumes(rateLimit *egcfgv1a1.RateLimit, rateLimitDeployme
Name: "redis-certs",
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: string(rateLimit.Backend.Redis.TLS.CertificateRef.Name),
SecretName: string(rateLimit.Backend.Redis.TLS.CertificateRef.Name),
DefaultMode: pointer.Int32(420),
},
},
})
Expand All @@ -171,7 +173,8 @@ func expectedDeploymentVolumes(rateLimit *egcfgv1a1.RateLimit, rateLimitDeployme
Name: "certs",
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: "envoy-rate-limit",
SecretName: "envoy-rate-limit",
DefaultMode: pointer.Int32(420),
},
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ func (r *ResourceRender) Deployment() (*appsv1.Deployment, error) {
Tolerations: r.rateLimitDeployment.Pod.Tolerations,
},
},
RevisionHistoryLimit: pointer.Int32(10),
ProgressDeadlineSeconds: pointer.Int32(600),
},
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,8 @@ func TestDeployment(t *testing.T) {
Name: "certs",
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: "custom-cert",
SecretName: "custom-cert",
DefaultMode: pointer.Int32(420),
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,6 @@ spec:
- name: certs
secret:
secretName: envoy-rate-limit
defaultMode: 420
revisionHistoryLimit: 10
progressDeadlineSeconds: 600
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,6 @@ spec:
- name: certs
secret:
secretName: envoy-rate-limit
defaultMode: 420
revisionHistoryLimit: 10
progressDeadlineSeconds: 600
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,6 @@ spec:
- name: certs
secret:
secretName: envoy-rate-limit
defaultMode: 420
revisionHistoryLimit: 10
progressDeadlineSeconds: 600
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,6 @@ spec:
- name: certs
secret:
secretName: envoy-rate-limit
defaultMode: 420
revisionHistoryLimit: 10
progressDeadlineSeconds: 600
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,6 @@ spec:
- name: certs
secret:
secretName: envoy-rate-limit
defaultMode: 420
revisionHistoryLimit: 10
progressDeadlineSeconds: 600
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,6 @@ spec:
- name: certs
secret:
secretName: envoy-rate-limit
defaultMode: 420
revisionHistoryLimit: 10
progressDeadlineSeconds: 600
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ spec:
- name: redis-certs
secret:
secretName: ratelimit-cert
defaultMode: 420
- name: certs
secret:
secretName: envoy-rate-limit
defaultMode: 420
revisionHistoryLimit: 10
progressDeadlineSeconds: 600
Loading

0 comments on commit 9ba9103

Please sign in to comment.