Skip to content

Commit 788ae63

Browse files
committed
Skip validation based on the presence of other annotations
Signed-off-by: Haywood Shannon <[email protected]>
1 parent 4a73e2c commit 788ae63

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

internal/configs/annotations.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -289,17 +289,10 @@ func parseAnnotations(ingEx *IngressEx, baseCfgParams *ConfigParams, isPlus bool
289289
}
290290

291291
if httpRedirectCode, exists := ingEx.Ingress.Annotations[HTTPRedirectCodeAnnotation]; exists {
292-
// Check if SSL redirect or redirect-to-https is enabled
293-
sslRedirectEnabled := cfgParams.SSLRedirect
294-
redirectToHTTPSEnabled := cfgParams.RedirectToHTTPS
295-
296-
// HTTP redirect code annotation only applies when SSL redirect or redirect-to-https is enabled
297-
if sslRedirectEnabled || redirectToHTTPSEnabled {
298-
if code, err := ParseHTTPRedirectCode(httpRedirectCode); err != nil {
299-
nl.Errorf(l, "Ingress %s/%s: Invalid value for nginx.org/http-redirect-code: %q: %v", ingEx.Ingress.GetNamespace(), ingEx.Ingress.GetName(), httpRedirectCode, err)
300-
} else {
301-
cfgParams.HTTPRedirectCode = code
302-
}
292+
if code, err := ParseHTTPRedirectCode(httpRedirectCode); err != nil {
293+
nl.Errorf(l, "Ingress %s/%s: Invalid value for nginx.org/http-redirect-code: %q: %v", ingEx.Ingress.GetNamespace(), ingEx.Ingress.GetName(), httpRedirectCode, err)
294+
} else {
295+
cfgParams.HTTPRedirectCode = code
303296
}
304297
}
305298

internal/configs/annotations_test.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,12 +1029,12 @@ func TestHTTPRedirectCodeAnnotationBehavior(t *testing.T) {
10291029
expectedCode: 307,
10301030
},
10311031
{
1032-
name: "redirect code ignored when SSL redirect disabled",
1032+
name: "redirect code applied when SSL redirect disabled",
10331033
annotations: map[string]string{
10341034
"nginx.org/ssl-redirect": "false",
10351035
"nginx.org/http-redirect-code": "307",
10361036
},
1037-
expectedCode: 301, // default
1037+
expectedCode: 307,
10381038
},
10391039
{
10401040
name: "redirect code applied with redirect-to-https",
@@ -1044,6 +1044,13 @@ func TestHTTPRedirectCodeAnnotationBehavior(t *testing.T) {
10441044
},
10451045
expectedCode: 302,
10461046
},
1047+
{
1048+
name: "redirect code applied without any redirect settings",
1049+
annotations: map[string]string{
1050+
"nginx.org/http-redirect-code": "308",
1051+
},
1052+
expectedCode: 308,
1053+
},
10471054
}
10481055

10491056
for _, tt := range tests {

0 commit comments

Comments
 (0)