Skip to content

Commit

Permalink
Append elements on match, instead of removing for cors-annotations (k…
Browse files Browse the repository at this point in the history
…ubernetes#8185)

* fixes kubernetes#8168 by appending elements on match, instead of removing

* refactor the corsOriginRegex comparison, and initialize CorsAllowOrigin
  • Loading branch information
L1ghtman2k authored and rchshld committed May 17, 2023
1 parent 64bfcf4 commit 716ac08
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions internal/ingress/annotations/cors/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,22 @@ func (c cors) Parse(ing *networking.Ingress) (interface{}, error) {
config.CorsEnabled = false
}

config.CorsAllowOrigin = []string{}
unparsedOrigins, err := parser.GetStringAnnotation("cors-allow-origin", ing)
if err == nil {
config.CorsAllowOrigin = strings.Split(unparsedOrigins, ",")
for i, origin := range config.CorsAllowOrigin {
origins := strings.Split(unparsedOrigins, ",")
for _, origin := range origins {
origin = strings.TrimSpace(origin)
if origin == "*" {
config.CorsAllowOrigin = []string{"*"}
break
}

if !corsOriginRegex.MatchString(origin) {
klog.Errorf("Error parsing cors-allow-origin parameters. Supplied incorrect origin: %s. Skipping.", origin)
config.CorsAllowOrigin = append(config.CorsAllowOrigin[:i], config.CorsAllowOrigin[i+1:]...)
continue
}
config.CorsAllowOrigin = append(config.CorsAllowOrigin, origin)
klog.Infof("Current config.corsAllowOrigin %v", config.CorsAllowOrigin)
}
} else {
Expand Down

0 comments on commit 716ac08

Please sign in to comment.