diff --git a/internal/ingress/annotations/parser/validators.go b/internal/ingress/annotations/parser/validators.go index 3c724a3110..c6dccaa6e3 100644 --- a/internal/ingress/annotations/parser/validators.go +++ b/internal/ingress/annotations/parser/validators.go @@ -20,6 +20,7 @@ import ( "errors" "fmt" "regexp" + "slices" "strconv" "strings" "time" @@ -147,10 +148,8 @@ func ValidateOptions(options []string, caseSensitive, trimSpace bool) Annotation if !caseSensitive { s = strings.ToLower(s) } - for _, option := range options { - if s == option { - return nil - } + if slices.Contains(options, s) { + return nil } return fmt.Errorf("value does not match any valid option") } diff --git a/internal/ingress/controller/certificate.go b/internal/ingress/controller/certificate.go index 76aafec3cb..1b2383f306 100644 --- a/internal/ingress/controller/certificate.go +++ b/internal/ingress/controller/certificate.go @@ -19,6 +19,7 @@ package controller import ( "crypto/x509" "net" + "slices" "strings" "unicode/utf8" ) @@ -40,10 +41,8 @@ func verifyHostname(h string, c *x509.Certificate) error { if ip := net.ParseIP(candidateIP); ip != nil { // We only match IP addresses against IP SANs. // https://tools.ietf.org/html/rfc6125#appendix-B.2 - for _, candidate := range c.IPAddresses { - if ip.Equal(candidate) { - return nil - } + if slices.ContainsFunc(c.IPAddresses, ip.Equal) { + return nil } return x509.HostnameError{Certificate: c, Host: candidateIP} } diff --git a/internal/ingress/controller/controller.go b/internal/ingress/controller/controller.go index 0894c0dfc1..6cd6398164 100644 --- a/internal/ingress/controller/controller.go +++ b/internal/ingress/controller/controller.go @@ -18,6 +18,7 @@ package controller import ( "fmt" + "slices" "sort" "strconv" "strings" @@ -1568,11 +1569,9 @@ func mergeAlternativeBackend(ing *ingress.Ingress, priUps, altUps *ingress.Backe return false } - for _, ab := range priUps.AlternativeBackends { - if ab == altUps.Name { - klog.V(2).Infof("skip merge alternative backend %v into %v, it's already present", altUps.Name, priUps.Name) - return true - } + if slices.Contains(priUps.AlternativeBackends, altUps.Name) { + klog.V(2).Infof("skip merge alternative backend %v into %v, it's already present", altUps.Name, priUps.Name) + return true } if ing.ParsedAnnotations != nil && ing.ParsedAnnotations.SessionAffinity.CanaryBehavior != "legacy" { diff --git a/pkg/apis/ingress/types_equals.go b/pkg/apis/ingress/types_equals.go index 6fba3bd453..19d71f0bb1 100644 --- a/pkg/apis/ingress/types_equals.go +++ b/pkg/apis/ingress/types_equals.go @@ -18,6 +18,7 @@ package ingress import ( "k8s.io/ingress-nginx/pkg/util/sets" + "slices" ) // Equal tests for equality between two Configuration types @@ -64,13 +65,7 @@ func (c1 *Configuration) Equal(c2 *Configuration) bool { } for _, ptb1 := range c1.PassthroughBackends { - found := false - for _, ptb2 := range c2.PassthroughBackends { - if ptb1.Equal(ptb2) { - found = true - break - } - } + found := slices.ContainsFunc(c2.PassthroughBackends, ptb1.Equal) if !found { return false }