From 4cbaa414688cbc9e67abe43a835b4eabeb33be02 Mon Sep 17 00:00:00 2001 From: jgoelen Date: Wed, 31 Jul 2024 08:50:41 +0200 Subject: [PATCH 1/2] Add Equal func for customheaders.Config --- internal/ingress/annotations/customheaders/main.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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|~^%]+$`) From 1280f560eed960edc1c1f5d501e58f79151d15f6 Mon Sep 17 00:00:00 2001 From: jgoelen Date: Wed, 31 Jul 2024 11:07:28 +0200 Subject: [PATCH 2/2] Add equality check of CustomHeaders to a Location --- pkg/apis/ingress/types_equals.go | 4 ++++ test/manifests/configuration-a.json | 7 ++++++- test/manifests/configuration-b.json | 7 ++++++- 3 files changed, 16 insertions(+), 2 deletions(-) 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",