@@ -144,9 +144,29 @@ func Test_ResolveReferencesForField_SingleReference(t *testing.T) {
144144 if arr.Name == nil || *arr.Name == "" {
145145 return hasReferences, fmt.Errorf("provided resource reference is nil or empty: APIRef")
146146 }
147- namespace := ko.ObjectMeta.GetNamespace()
148- if arr.Namespace != nil && *arr.Namespace != "" {
149- namespace = *arr.Namespace
147+ namespace, isCrossNs, err := ackrt.ValidateCrossNamespaceReference(
148+ rm.cfg.EnableCrossNamespace,
149+ ko.ObjectMeta.GetNamespace(),
150+ arr.Namespace,
151+ *arr.Name,
152+ )
153+ if err != nil {
154+ return hasReferences, err
155+ }
156+ if isCrossNs {
157+ ackrtlog.FromContext(ctx).Info("cross-namespace resource reference detected; "+
158+ "this behavior will be disabled by default in a future release. "+
159+ "Set --enable-cross-namespace to preserve this behavior.",
160+ "ownerNamespace", ko.ObjectMeta.GetNamespace(),
161+ "targetNamespace", *arr.Namespace,
162+ "referenceName", *arr.Name,
163+ )
164+ crossNsMsg := fmt.Sprintf("Cross-namespace resource reference detected: "+
165+ "resource in namespace %q references %q in namespace %q. "+
166+ "Cross-namespace behavior will be disabled by default in a future release. "+
167+ "Set --enable-cross-namespace=true to preserve this behavior.",
168+ ko.ObjectMeta.GetNamespace(), *arr.Name, *arr.Namespace)
169+ setCrossNamespaceCondition(ko, crossNsMsg)
150170 }
151171 obj := &svcapitypes.API{}
152172 if err := getReferencedResourceState_API(ctx, apiReader, obj, *arr.Name, namespace); err != nil {
@@ -180,9 +200,29 @@ func Test_ResolveReferencesForField_ReferencingARN(t *testing.T) {
180200 if arr.Name == nil || *arr.Name == "" {
181201 return hasReferences, fmt.Errorf("provided resource reference is nil or empty: PermissionsBoundaryRef")
182202 }
183- namespace := ko.ObjectMeta.GetNamespace()
184- if arr.Namespace != nil && *arr.Namespace != "" {
185- namespace = *arr.Namespace
203+ namespace, isCrossNs, err := ackrt.ValidateCrossNamespaceReference(
204+ rm.cfg.EnableCrossNamespace,
205+ ko.ObjectMeta.GetNamespace(),
206+ arr.Namespace,
207+ *arr.Name,
208+ )
209+ if err != nil {
210+ return hasReferences, err
211+ }
212+ if isCrossNs {
213+ ackrtlog.FromContext(ctx).Info("cross-namespace resource reference detected; "+
214+ "this behavior will be disabled by default in a future release. "+
215+ "Set --enable-cross-namespace to preserve this behavior.",
216+ "ownerNamespace", ko.ObjectMeta.GetNamespace(),
217+ "targetNamespace", *arr.Namespace,
218+ "referenceName", *arr.Name,
219+ )
220+ crossNsMsg := fmt.Sprintf("Cross-namespace resource reference detected: "+
221+ "resource in namespace %q references %q in namespace %q. "+
222+ "Cross-namespace behavior will be disabled by default in a future release. "+
223+ "Set --enable-cross-namespace=true to preserve this behavior.",
224+ ko.ObjectMeta.GetNamespace(), *arr.Name, *arr.Namespace)
225+ setCrossNamespaceCondition(ko, crossNsMsg)
186226 }
187227 obj := &svcapitypes.Policy{}
188228 if err := getReferencedResourceState_Policy(ctx, apiReader, obj, *arr.Name, namespace); err != nil {
@@ -217,9 +257,29 @@ func Test_ResolveReferencesForField_SliceOfReferences(t *testing.T) {
217257 if arr.Name == nil || *arr.Name == "" {
218258 return hasReferences, fmt.Errorf("provided resource reference is nil or empty: SecurityGroupRefs")
219259 }
220- namespace := ko.ObjectMeta.GetNamespace()
221- if arr.Namespace != nil && *arr.Namespace != "" {
222- namespace = *arr.Namespace
260+ namespace, isCrossNs, err := ackrt.ValidateCrossNamespaceReference(
261+ rm.cfg.EnableCrossNamespace,
262+ ko.ObjectMeta.GetNamespace(),
263+ arr.Namespace,
264+ *arr.Name,
265+ )
266+ if err != nil {
267+ return hasReferences, err
268+ }
269+ if isCrossNs {
270+ ackrtlog.FromContext(ctx).Info("cross-namespace resource reference detected; "+
271+ "this behavior will be disabled by default in a future release. "+
272+ "Set --enable-cross-namespace to preserve this behavior.",
273+ "ownerNamespace", ko.ObjectMeta.GetNamespace(),
274+ "targetNamespace", *arr.Namespace,
275+ "referenceName", *arr.Name,
276+ )
277+ crossNsMsg := fmt.Sprintf("Cross-namespace resource reference detected: "+
278+ "resource in namespace %q references %q in namespace %q. "+
279+ "Cross-namespace behavior will be disabled by default in a future release. "+
280+ "Set --enable-cross-namespace=true to preserve this behavior.",
281+ ko.ObjectMeta.GetNamespace(), *arr.Name, *arr.Namespace)
282+ setCrossNamespaceCondition(ko, crossNsMsg)
223283 }
224284 obj := &ec2apitypes.SecurityGroup{}
225285 if err := getReferencedResourceState_SecurityGroup(ctx, apiReader, obj, *arr.Name, namespace); err != nil {
@@ -258,9 +318,29 @@ func Test_ResolveReferencesForField_NestedSingleReference(t *testing.T) {
258318 if arr.Name == nil || *arr.Name == "" {
259319 return hasReferences, fmt.Errorf("provided resource reference is nil or empty: JWTConfiguration.IssuerRef")
260320 }
261- namespace := ko.ObjectMeta.GetNamespace()
262- if arr.Namespace != nil && *arr.Namespace != "" {
263- namespace = *arr.Namespace
321+ namespace, isCrossNs, err := ackrt.ValidateCrossNamespaceReference(
322+ rm.cfg.EnableCrossNamespace,
323+ ko.ObjectMeta.GetNamespace(),
324+ arr.Namespace,
325+ *arr.Name,
326+ )
327+ if err != nil {
328+ return hasReferences, err
329+ }
330+ if isCrossNs {
331+ ackrtlog.FromContext(ctx).Info("cross-namespace resource reference detected; "+
332+ "this behavior will be disabled by default in a future release. "+
333+ "Set --enable-cross-namespace to preserve this behavior.",
334+ "ownerNamespace", ko.ObjectMeta.GetNamespace(),
335+ "targetNamespace", *arr.Namespace,
336+ "referenceName", *arr.Name,
337+ )
338+ crossNsMsg := fmt.Sprintf("Cross-namespace resource reference detected: "+
339+ "resource in namespace %q references %q in namespace %q. "+
340+ "Cross-namespace behavior will be disabled by default in a future release. "+
341+ "Set --enable-cross-namespace=true to preserve this behavior.",
342+ ko.ObjectMeta.GetNamespace(), *arr.Name, *arr.Namespace)
343+ setCrossNamespaceCondition(ko, crossNsMsg)
264344 }
265345 obj := &svcapitypes.API{}
266346 if err := getReferencedResourceState_API(ctx, apiReader, obj, *arr.Name, namespace); err != nil {
@@ -299,9 +379,29 @@ func Test_ResolveReferencesForField_SingleReference_DeeplyNested(t *testing.T) {
299379 if arr.Name == nil || *arr.Name == "" {
300380 return hasReferences, fmt.Errorf("provided resource reference is nil or empty: Logging.LoggingEnabled.TargetBucketRef")
301381 }
302- namespace := ko.ObjectMeta.GetNamespace()
303- if arr.Namespace != nil && *arr.Namespace != "" {
304- namespace = *arr.Namespace
382+ namespace, isCrossNs, err := ackrt.ValidateCrossNamespaceReference(
383+ rm.cfg.EnableCrossNamespace,
384+ ko.ObjectMeta.GetNamespace(),
385+ arr.Namespace,
386+ *arr.Name,
387+ )
388+ if err != nil {
389+ return hasReferences, err
390+ }
391+ if isCrossNs {
392+ ackrtlog.FromContext(ctx).Info("cross-namespace resource reference detected; "+
393+ "this behavior will be disabled by default in a future release. "+
394+ "Set --enable-cross-namespace to preserve this behavior.",
395+ "ownerNamespace", ko.ObjectMeta.GetNamespace(),
396+ "targetNamespace", *arr.Namespace,
397+ "referenceName", *arr.Name,
398+ )
399+ crossNsMsg := fmt.Sprintf("Cross-namespace resource reference detected: "+
400+ "resource in namespace %q references %q in namespace %q. "+
401+ "Cross-namespace behavior will be disabled by default in a future release. "+
402+ "Set --enable-cross-namespace=true to preserve this behavior.",
403+ ko.ObjectMeta.GetNamespace(), *arr.Name, *arr.Namespace)
404+ setCrossNamespaceCondition(ko, crossNsMsg)
305405 }
306406 obj := &svcapitypes.Bucket{}
307407 if err := getReferencedResourceState_Bucket(ctx, apiReader, obj, *arr.Name, namespace); err != nil {
@@ -340,9 +440,29 @@ func Test_ResolveReferencesForField_SingleReference_WithinSlice(t *testing.T) {
340440 if arr.Name == nil || *arr.Name == "" {
341441 return hasReferences, fmt.Errorf("provided resource reference is nil or empty: Routes.GatewayRef")
342442 }
343- namespace := ko.ObjectMeta.GetNamespace()
344- if arr.Namespace != nil && *arr.Namespace != "" {
345- namespace = *arr.Namespace
443+ namespace, isCrossNs, err := ackrt.ValidateCrossNamespaceReference(
444+ rm.cfg.EnableCrossNamespace,
445+ ko.ObjectMeta.GetNamespace(),
446+ arr.Namespace,
447+ *arr.Name,
448+ )
449+ if err != nil {
450+ return hasReferences, err
451+ }
452+ if isCrossNs {
453+ ackrtlog.FromContext(ctx).Info("cross-namespace resource reference detected; "+
454+ "this behavior will be disabled by default in a future release. "+
455+ "Set --enable-cross-namespace to preserve this behavior.",
456+ "ownerNamespace", ko.ObjectMeta.GetNamespace(),
457+ "targetNamespace", *arr.Namespace,
458+ "referenceName", *arr.Name,
459+ )
460+ crossNsMsg := fmt.Sprintf("Cross-namespace resource reference detected: "+
461+ "resource in namespace %q references %q in namespace %q. "+
462+ "Cross-namespace behavior will be disabled by default in a future release. "+
463+ "Set --enable-cross-namespace=true to preserve this behavior.",
464+ ko.ObjectMeta.GetNamespace(), *arr.Name, *arr.Namespace)
465+ setCrossNamespaceCondition(ko, crossNsMsg)
346466 }
347467 obj := &svcapitypes.InternetGateway{}
348468 if err := getReferencedResourceState_InternetGateway(ctx, apiReader, obj, *arr.Name, namespace); err != nil {
@@ -384,9 +504,29 @@ func Test_ResolveReferencesForField_SingleReference_WithinMultipleSlices(t *test
384504 if arr.Name == nil || *arr.Name == "" {
385505 return hasReferences, fmt.Errorf("provided resource reference is nil or empty: Notification.LambdaFunctionConfigurations.Filter.Key.FilterRules.ValueRef")
386506 }
387- namespace := ko.ObjectMeta.GetNamespace()
388- if arr.Namespace != nil && *arr.Namespace != "" {
389- namespace = *arr.Namespace
507+ namespace, isCrossNs, err := ackrt.ValidateCrossNamespaceReference(
508+ rm.cfg.EnableCrossNamespace,
509+ ko.ObjectMeta.GetNamespace(),
510+ arr.Namespace,
511+ *arr.Name,
512+ )
513+ if err != nil {
514+ return hasReferences, err
515+ }
516+ if isCrossNs {
517+ ackrtlog.FromContext(ctx).Info("cross-namespace resource reference detected; "+
518+ "this behavior will be disabled by default in a future release. "+
519+ "Set --enable-cross-namespace to preserve this behavior.",
520+ "ownerNamespace", ko.ObjectMeta.GetNamespace(),
521+ "targetNamespace", *arr.Namespace,
522+ "referenceName", *arr.Name,
523+ )
524+ crossNsMsg := fmt.Sprintf("Cross-namespace resource reference detected: "+
525+ "resource in namespace %q references %q in namespace %q. "+
526+ "Cross-namespace behavior will be disabled by default in a future release. "+
527+ "Set --enable-cross-namespace=true to preserve this behavior.",
528+ ko.ObjectMeta.GetNamespace(), *arr.Name, *arr.Namespace)
529+ setCrossNamespaceCondition(ko, crossNsMsg)
390530 }
391531 obj := &svcapitypes.Bucket{}
392532 if err := getReferencedResourceState_Bucket(ctx, apiReader, obj, *arr.Name, namespace); err != nil {
0 commit comments