From 5802ecc4b5708e73f4a36ad2e6eb45bcca3aebc1 Mon Sep 17 00:00:00 2001 From: k8s-infra-cherrypick-robot <90416843+k8s-infra-cherrypick-robot@users.noreply.github.com> Date: Thu, 9 Jan 2025 14:28:32 -0800 Subject: [PATCH] Annotations: Reload on custom header changes. (#12653) Co-authored-by: jgoelen --- internal/ingress/annotations/customheaders/main.go | 13 +++++++++++++ pkg/apis/ingress/types_equals.go | 4 ++++ test/manifests/configuration-a.json | 7 ++++++- test/manifests/configuration-b.json | 7 ++++++- 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/internal/ingress/annotations/customheaders/main.go b/internal/ingress/annotations/customheaders/main.go index 774e9c3d3a..bc0ef2eb52 100644 --- a/internal/ingress/annotations/customheaders/main.go +++ b/internal/ingress/annotations/customheaders/main.go @@ -18,6 +18,7 @@ package customheaders import ( "fmt" + "reflect" "regexp" "k8s.io/klog/v2" @@ -35,6 +36,18 @@ type Config struct { Headers map[string]string `json:"headers,omitempty"` } +// Equal tests for equality between two Config types +func (c1 *Config) Equal(c2 *Config) bool { + if c1 == c2 { + return true + } + if c1 == nil || c2 == nil { + return false + } + + return reflect.DeepEqual(c1.Headers, c2.Headers) +} + var ( headerRegexp = regexp.MustCompile(`^[a-zA-Z\d\-_]+$`) valueRegexp = regexp.MustCompile(`^[a-zA-Z\d_ :;.,\\/"'?!(){}\[\]@<>=\-+*#$&\x60|~^%]+$`) diff --git a/pkg/apis/ingress/types_equals.go b/pkg/apis/ingress/types_equals.go index eeed9a06e4..e8ef2af4dc 100644 --- a/pkg/apis/ingress/types_equals.go +++ b/pkg/apis/ingress/types_equals.go @@ -470,6 +470,10 @@ func (l1 *Location) Equal(l2 *Location) bool { return false } + if !l1.CustomHeaders.Equal(&l2.CustomHeaders) { + return false + } + return true } diff --git a/test/manifests/configuration-a.json b/test/manifests/configuration-a.json index ba513c616a..f9599d77cd 100644 --- a/test/manifests/configuration-a.json +++ b/test/manifests/configuration-a.json @@ -302,7 +302,12 @@ "validationDepth": 0 }, "use-port-in-redirects": false, - "configuration-snippet": "" + "configuration-snippet": "", + "customHeaders": { + "headers": { + "Server": "HAL9000" + } + } }] }, { "hostname": "dev.mycompany.com", diff --git a/test/manifests/configuration-b.json b/test/manifests/configuration-b.json index 9e40785b4d..d2e71bb29c 100644 --- a/test/manifests/configuration-b.json +++ b/test/manifests/configuration-b.json @@ -302,7 +302,12 @@ "validationDepth": 0 }, "use-port-in-redirects": false, - "configuration-snippet": "" + "configuration-snippet": "", + "customHeaders": { + "headers": { + "Server": "HAL9000" + } + } }] }, { "hostname": "dev.mycompany.com",