Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: set defaults in Deployment, else k8s sets them for you, creating infinite reconciliation loop #1594

Merged
merged 30 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
3c8691d
fix: envoy proxy resource apply bug.
qicz Jun 26, 2023
602823c
Merge branch 'main' of github.com:envoyproxy/gateway into fix-1590
qicz Jun 26, 2023
fdfa5ef
update pointer.
qicz Jun 26, 2023
2887058
add comment
qicz Jun 26, 2023
328a7dc
update cm cmp logic.
qicz Jun 26, 2023
ce239fc
Merge branch 'main' of github.com:envoyproxy/gateway into fix-1590
qicz Jun 26, 2023
9a3eb1e
fix lint
qicz Jun 27, 2023
d566e91
Merge branch 'main' into fix-1590
qicz Jun 27, 2023
7ed2fe7
add probe field default value.
qicz Jun 27, 2023
2c933e3
fix uts
qicz Jun 27, 2023
e66ce57
Merge branch 'main' into fix-1590
qicz Jun 28, 2023
abba9dd
align probe
qicz Jun 28, 2023
31728a4
Merge branch 'fix-1590' of github.com:qicz/gateway into fix-1590
qicz Jun 28, 2023
548b37e
Merge branch 'main' of github.com:envoyproxy/gateway into fix-1590
qicz Jun 28, 2023
fd7d1cd
Merge branch 'main' of github.com:envoyproxy/gateway into fix-1590
qicz Jun 29, 2023
8cbbbe1
Merge branch 'main' of github.com:envoyproxy/gateway into fix-1590
qicz Jun 30, 2023
7af9137
optimize deploy compare logic
qicz Jun 30, 2023
fa4c2cd
add compare deploy uts
qicz Jun 30, 2023
3103b41
Merge branch 'main' of github.com:envoyproxy/gateway into fix-1590
qicz Jul 3, 2023
3917ec2
Merge branch 'main' of github.com:envoyproxy/gateway into fix-1590
qicz Jul 4, 2023
c046f0f
Merge branch 'main' into fix-1590
qicz Jul 18, 2023
2e568d4
Merge branch 'main' into fix-1590
qicz Jul 22, 2023
754e3a3
Merge branch 'main' into fix-1590
qicz Jul 25, 2023
5bb8dee
Merge branch 'fix-1590' of github.com:qicz/gateway into fix-1590
qicz Jul 25, 2023
c53e9a9
rm cm binarydata cmp
qicz Jul 25, 2023
3a18130
rm deploy cmp logic
qicz Jul 26, 2023
7765c59
Merge branch 'main' of github.com:envoyproxy/gateway into fix-1590
qicz Jul 26, 2023
8a70ff0
fix ut
qicz Jul 26, 2023
6dc116b
Merge branch 'main' into fix-1590
qicz Jul 26, 2023
ff25ed3
fix lint
qicz Jul 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason why this is being set, can this be moved into a separate PR, tia

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this belongs to this fix.

the TimeoutSecounds will fill the default value, and compare the current from k8s and deployment from code, it never equal forever will fire current bug : more terminating pod and deployment generation will increment all the time

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

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
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),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are these field being set ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

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