@@ -3,11 +3,11 @@ package appprotectdos
33import (
44 "errors"
55 "fmt"
6- "strings"
76
87 "github.com/nginx/kubernetes-ingress/internal/configs"
98 "github.com/nginx/kubernetes-ingress/internal/k8s/appprotectcommon"
109 nl "github.com/nginx/kubernetes-ingress/internal/logger"
10+ "github.com/nginx/kubernetes-ingress/internal/nsutils"
1111 "github.com/nginx/kubernetes-ingress/pkg/apis/dos/v1beta1"
1212 "github.com/nginx/kubernetes-ingress/pkg/apis/dos/validation"
1313 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
@@ -169,7 +169,7 @@ func (ci *Configuration) AddOrUpdateDosProtectedResource(protectedConf *v1beta1.
169169 if protectedEx .Obj .Spec .ApDosPolicy != "" {
170170 policyReference := protectedEx .Obj .Spec .ApDosPolicy
171171 // if the policy reference does not have a namespace, use the dos protected' namespace
172- if ! strings . Contains (policyReference , "/" ) {
172+ if ! nsutils . HasNamespace (policyReference ) {
173173 policyReference = protectedEx .Obj .Namespace + "/" + policyReference
174174 }
175175 _ , err := ci .getPolicy (policyReference )
@@ -181,7 +181,7 @@ func (ci *Configuration) AddOrUpdateDosProtectedResource(protectedConf *v1beta1.
181181 if protectedEx .Obj .Spec .DosSecurityLog != nil && protectedEx .Obj .Spec .DosSecurityLog .ApDosLogConf != "" {
182182 logConfReference := protectedEx .Obj .Spec .DosSecurityLog .ApDosLogConf
183183 // if the log conf reference does not have a namespace, use the dos protected' namespace
184- if ! strings . Contains (logConfReference , "/" ) {
184+ if ! nsutils . HasNamespace (logConfReference ) {
185185 logConfReference = protectedEx .Obj .Namespace + "/" + logConfReference
186186 }
187187 _ , err := ci .getLogConf (logConfReference )
@@ -243,7 +243,7 @@ func (ci *Configuration) GetValidDosEx(parentNamespace string, nsName string) (*
243243 if protectedEx .Obj .Spec .ApDosPolicy != "" {
244244 policyReference := protectedEx .Obj .Spec .ApDosPolicy
245245 // if the policy reference does not have a namespace, use the dos protected' namespace
246- if ! strings . Contains (policyReference , "/" ) {
246+ if ! nsutils . HasNamespace (policyReference ) {
247247 policyReference = protectedEx .Obj .Namespace + "/" + policyReference
248248 }
249249 pol , err := ci .getPolicy (policyReference )
@@ -255,7 +255,7 @@ func (ci *Configuration) GetValidDosEx(parentNamespace string, nsName string) (*
255255 if protectedEx .Obj .Spec .DosSecurityLog != nil && protectedEx .Obj .Spec .DosSecurityLog .ApDosLogConf != "" {
256256 logConfReference := protectedEx .Obj .Spec .DosSecurityLog .ApDosLogConf
257257 // if the log conf reference does not have a namespace, use the dos protected' namespace
258- if ! strings . Contains (logConfReference , "/" ) {
258+ if ! nsutils . HasNamespace (logConfReference ) {
259259 logConfReference = protectedEx .Obj .Namespace + "/" + logConfReference
260260 }
261261 log , err := ci .getLogConf (logConfReference )
@@ -268,7 +268,7 @@ func (ci *Configuration) GetValidDosEx(parentNamespace string, nsName string) (*
268268}
269269
270270func getNsName (defaultNamespace string , name string ) string {
271- if ! strings . Contains (name , "/" ) {
271+ if ! nsutils . HasNamespace (name ) {
272272 return defaultNamespace + "/" + name
273273 }
274274 return name
0 commit comments