Skip to content

Commit ddd6898

Browse files
committed
chore(VpcPeering): remove duplicated code that loads local and remote KCP Network
1 parent 3f730bd commit ddd6898

File tree

4 files changed

+6
-487
lines changed

4 files changed

+6
-487
lines changed

internal/controller/cloud-control/vpcpeering_aws_test.go

Lines changed: 0 additions & 292 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
. "github.com/onsi/ginkgo/v2"
1919
. "github.com/onsi/gomega"
2020
"k8s.io/apimachinery/pkg/api/meta"
21-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2221
"k8s.io/utils/ptr"
2322
)
2423

@@ -372,297 +371,6 @@ var _ = Describe("Feature: KCP VpcPeering", func() {
372371
})
373372
})
374373

375-
// When prevent deletion of KCP Network while used by VpcPeering is implemented, this test case
376-
// is obsolete, but keeping it just in case, but with Network reconciler ignoring the created
377-
// networks, so they can be deleted while used by VpcPeering
378-
It("Scenario: KCP AWS VpcPeering is deleted when local and remote networks are missing", func() {
379-
const (
380-
kymaName = "76f1dec7-c7d3-4129-9730-478f4cba241a"
381-
kcpPeeringName = "f658c189-0f09-4c4b-8da6-49b3db61546d"
382-
localVpcId = "vpc-7e9d1ce03b49ae18d"
383-
localVpcCidr = "10.180.0.0/16"
384-
remoteVpcId = "vpc-3a1cdc66b2778658e"
385-
remoteVpcCidr = "10.200.0.0/16"
386-
remoteAccountId = "777755556666"
387-
remoteRegion = "eu-west1"
388-
localMainRouteTable = "rtb-007a6396ac2021245"
389-
localRouteTable = "rtb-c44da7a78dbf49bde"
390-
remoteMainRouteTable = "rtb-c0b83bb46e6d208b9"
391-
remoteRouteTable = "rtb-30b3c0b6d895ed2d0"
392-
)
393-
394-
scope := &cloudcontrolv1beta1.Scope{}
395-
396-
By("Given Scope exists", func() {
397-
// Tell Scope reconciler to ignore this kymaName
398-
kcpscope.Ignore.AddName(kymaName)
399-
400-
Eventually(CreateScopeAws).
401-
WithArguments(infra.Ctx(), infra, scope, WithName(kymaName)).
402-
Should(Succeed())
403-
})
404-
405-
vpcName := scope.Spec.Scope.Aws.VpcNetwork
406-
remoteVpcName := "Remote Network Name"
407-
408-
awsMockLocal := infra.AwsMock().MockConfigs(scope.Spec.Scope.Aws.AccountId, scope.Spec.Region)
409-
awsMockRemote := infra.AwsMock().MockConfigs(remoteAccountId, remoteRegion)
410-
411-
By("And Given AWS VPC exists", func() {
412-
awsMockLocal.AddVpc(
413-
localVpcId,
414-
localVpcCidr,
415-
awsutil.Ec2Tags("Name", vpcName),
416-
awsmock.VpcSubnetsFromScope(scope),
417-
)
418-
})
419-
420-
By("And Given AWS route table exists", func() {
421-
awsMockLocal.AddRouteTable(
422-
ptr.To(localMainRouteTable),
423-
ptr.To(localVpcId),
424-
awsutil.Ec2Tags(fmt.Sprintf("kubernetes.io/cluster/%s", vpcName), "1"),
425-
[]ec2types.RouteTableAssociation{
426-
{
427-
Main: ptr.To(true),
428-
},
429-
})
430-
431-
awsMockLocal.AddRouteTable(
432-
ptr.To(localRouteTable),
433-
ptr.To(localVpcId),
434-
awsutil.Ec2Tags(fmt.Sprintf("kubernetes.io/cluster/%s", vpcName), "1"),
435-
[]ec2types.RouteTableAssociation{})
436-
})
437-
438-
By("And Given AWS remote VPC exists", func() {
439-
awsMockRemote.AddVpc(
440-
remoteVpcId,
441-
remoteVpcCidr,
442-
awsutil.Ec2Tags("Name", remoteVpcName, kymaName, kymaName),
443-
nil,
444-
)
445-
})
446-
447-
By("And Given AWS remote route table exists", func() {
448-
449-
awsMockRemote.AddRouteTable(
450-
ptr.To(remoteMainRouteTable),
451-
ptr.To(remoteVpcId),
452-
awsutil.Ec2Tags(),
453-
[]ec2types.RouteTableAssociation{
454-
{
455-
Main: ptr.To(true),
456-
},
457-
})
458-
459-
awsMockRemote.AddRouteTable(
460-
ptr.To(remoteRouteTable),
461-
ptr.To(remoteVpcId),
462-
awsutil.Ec2Tags(),
463-
[]ec2types.RouteTableAssociation{})
464-
})
465-
466-
localKcpNetworkName := common.KcpNetworkKymaCommonName(scope.Name)
467-
remoteKcpNetworkName := scope.Name + "--remote"
468-
469-
var localKcpNet *cloudcontrolv1beta1.Network
470-
471-
By("And Given local KCP Network exists", func() {
472-
// must tell reconciler to ignore it, since it would prevent deletion when used by peering
473-
kcpnetwork.Ignore.AddName(localKcpNetworkName)
474-
localKcpNet = cloudcontrolv1beta1.NewNetworkBuilder().
475-
WithScope(scope.Name).
476-
WithAwsRef(scope.Spec.Scope.Aws.AccountId, scope.Spec.Region, scope.Spec.Scope.Aws.Network.VPC.Id, localKcpNetworkName).
477-
Build()
478-
Expect(CreateObj(infra.Ctx(), infra.KCP().Client(), localKcpNet, WithName(localKcpNetworkName))).
479-
To(Succeed())
480-
481-
localKcpNet.Status.Network = localKcpNet.Spec.Network.Reference.DeepCopy()
482-
localKcpNet.Status.State = string(cloudcontrolv1beta1.StateReady)
483-
meta.SetStatusCondition(&localKcpNet.Status.Conditions, metav1.Condition{
484-
Type: cloudcontrolv1beta1.ConditionTypeReady,
485-
Status: metav1.ConditionTrue,
486-
Reason: cloudcontrolv1beta1.ReasonReady,
487-
Message: cloudcontrolv1beta1.ReasonReady,
488-
})
489-
Expect(composed.PatchObjStatus(infra.Ctx(), localKcpNet, infra.KCP().Client())).
490-
To(Succeed())
491-
})
492-
493-
var remoteKcpNet *cloudcontrolv1beta1.Network
494-
495-
By("And Given remote KCP Network exists", func() {
496-
// must tell reconciler to ignore it, since it would prevent deletion when used by peering
497-
kcpnetwork.Ignore.AddName(remoteKcpNetworkName)
498-
remoteKcpNet = cloudcontrolv1beta1.NewNetworkBuilder().
499-
WithScope(scope.Name).
500-
WithAwsRef(remoteAccountId, remoteRegion, remoteVpcId, remoteVpcName).
501-
Build()
502-
Expect(CreateObj(infra.Ctx(), infra.KCP().Client(), remoteKcpNet, WithName(remoteKcpNetworkName))).
503-
Should(Succeed())
504-
505-
remoteKcpNet.Status.Network = remoteKcpNet.Spec.Network.Reference.DeepCopy()
506-
remoteKcpNet.Status.State = string(cloudcontrolv1beta1.StateReady)
507-
meta.SetStatusCondition(&remoteKcpNet.Status.Conditions, metav1.Condition{
508-
Type: cloudcontrolv1beta1.ConditionTypeReady,
509-
Status: metav1.ConditionTrue,
510-
Reason: cloudcontrolv1beta1.ReasonReady,
511-
Message: cloudcontrolv1beta1.ReasonReady,
512-
})
513-
Expect(composed.PatchObjStatus(infra.Ctx(), remoteKcpNet, infra.KCP().Client())).
514-
To(Succeed())
515-
})
516-
517-
var kcpPeering *cloudcontrolv1beta1.VpcPeering
518-
519-
By("When KCP VpcPeering is created", func() {
520-
kcpPeering = (&cloudcontrolv1beta1.VpcPeeringBuilder{}).
521-
WithScope(kymaName).
522-
WithRemoteRef("skr-namespace", "skr-aws-ip-range").
523-
WithDetails(localKcpNetworkName, infra.KCP().Namespace(), remoteKcpNetworkName, infra.KCP().Namespace(), "", false, true).
524-
Build()
525-
526-
Eventually(CreateObj).
527-
WithArguments(infra.Ctx(), infra.KCP().Client(), kcpPeering,
528-
WithName(kcpPeeringName),
529-
).Should(Succeed())
530-
531-
})
532-
533-
By("Then KCP VpcPeering has status id", func() {
534-
Eventually(LoadAndCheck).
535-
WithArguments(infra.Ctx(), infra.KCP().Client(), kcpPeering,
536-
NewObjActions(),
537-
HaveFinalizer(api.CommonFinalizerDeletionHook),
538-
HavingKcpVpcPeeringStatusIdNotEmpty(),
539-
).Should(Succeed())
540-
})
541-
542-
By("When remote VpcPeeringConnection is initiated", func() {
543-
awsMockRemote.InitiateVpcPeeringConnection(kcpPeering.Status.Id, localVpcId, remoteVpcId)
544-
})
545-
546-
By("When AWS VPC Peering state is active", func() {
547-
Expect(
548-
awsMockLocal.SetVpcPeeringConnectionStatusCode(localVpcId, remoteVpcId, ec2types.VpcPeeringConnectionStateReasonCodeActive),
549-
).NotTo(HaveOccurred())
550-
551-
Expect(
552-
awsMockRemote.SetVpcPeeringConnectionStatusCode(localVpcId, remoteVpcId, ec2types.VpcPeeringConnectionStateReasonCodeActive),
553-
).NotTo(HaveOccurred())
554-
})
555-
556-
By("Then KCP VpcPeering is ready", func() {
557-
Eventually(LoadAndCheck).
558-
WithArguments(infra.Ctx(), infra.KCP().Client(), kcpPeering,
559-
NewObjActions(),
560-
HavingConditionTrue(cloudcontrolv1beta1.ConditionTypeReady),
561-
).
562-
Should(Succeed())
563-
})
564-
565-
By("And Then KCP VpcPeering status id equals to remoteId", func() {
566-
Expect(kcpPeering.Status.Id).To(Equal(kcpPeering.Status.RemoteId))
567-
})
568-
569-
By("And Then KCP VpcPeering status vpcId equals to existing AWS VPC id", func() {
570-
Expect(kcpPeering.Status.VpcId).To(Equal(localVpcId))
571-
})
572-
573-
By("And Then found local VpcPeeringConnection AccepterVpcInfo VpcId equals to remote vpc id", func() {
574-
localPeering, _ := awsMockLocal.DescribeVpcPeeringConnection(infra.Ctx(), kcpPeering.Status.Id)
575-
Expect(*localPeering.AccepterVpcInfo.VpcId).To(Equal(remoteVpcId))
576-
})
577-
578-
By("And Then local route tables have peering route to remote VPC CIDR", func() {
579-
Expect(awsMockLocal.GetRoute(localVpcId, localMainRouteTable, kcpPeering.Status.Id, remoteVpcCidr)).
580-
NotTo(BeNil(), fmt.Sprintf("Local main route table should have peering route to %s", remoteVpcCidr))
581-
582-
Expect(awsMockLocal.GetRoute(localVpcId, localRouteTable, kcpPeering.Status.Id, remoteVpcCidr)).
583-
ToNot(BeNil(), fmt.Sprintf("Local route table should have peering route to %s", remoteVpcCidr))
584-
})
585-
586-
By("And Then remote route tables have peering route to VPC CIDR", func() {
587-
Expect(awsMockRemote.GetRoute(remoteVpcId, remoteMainRouteTable, kcpPeering.Status.RemoteId, localVpcCidr)).
588-
NotTo(BeNil(), fmt.Sprintf("Remote route table should have peering route to %s", remoteVpcCidr))
589-
590-
Expect(awsMockRemote.GetRoute(remoteVpcId, remoteRouteTable, kcpPeering.Status.RemoteId, localVpcCidr)).
591-
ToNot(BeNil(), fmt.Sprintf("Remote route table should have peering route to %s", remoteVpcCidr))
592-
})
593-
594-
// Deleting KCP remote Network before VpcPeering deletion
595-
By("When KCP local Network is deleted", func() {
596-
Eventually(Delete).
597-
WithArguments(infra.Ctx(), infra.KCP().Client(), localKcpNet).
598-
Should(Succeed(), "failed deleting local KCP Network")
599-
})
600-
601-
By("Then KCP local Network does not exist", func() {
602-
Eventually(IsDeleted).
603-
WithArguments(infra.Ctx(), infra.KCP().Client(), localKcpNet).
604-
Should(Succeed(), "expected KCP local Network not to exist (be deleted), but it still exists")
605-
})
606-
607-
// Deleting KCP remote Network before VpcPeering deletion
608-
By("When KCP remote Network is deleted", func() {
609-
Eventually(Delete).
610-
WithArguments(infra.Ctx(), infra.KCP().Client(), remoteKcpNet).
611-
Should(Succeed(), "failed deleting remote KCP Network")
612-
})
613-
614-
By("Then KCP remote Network does not exist", func() {
615-
Eventually(IsDeleted).
616-
WithArguments(infra.Ctx(), infra.KCP().Client(), remoteKcpNet).
617-
Should(Succeed(), "expected KCP remote Network not to exist (be deleted), but it still exists")
618-
})
619-
620-
// DELETE
621-
622-
By("When KCP VpcPeering is deleted", func() {
623-
Eventually(Delete).
624-
WithArguments(infra.Ctx(), infra.KCP().Client(), kcpPeering).
625-
Should(Succeed(), "failed deleting VpcPeering")
626-
})
627-
628-
By("Then VpcPeering does not exist", func() {
629-
Eventually(IsDeleted).
630-
WithArguments(infra.Ctx(), infra.KCP().Client(), kcpPeering).
631-
Should(Succeed(), "expected VpcPeering not to exist (be deleted), but it still exists")
632-
})
633-
634-
By("And Then local VpcPeeringConnection is deleted", func() {
635-
localPeering, err := awsMockLocal.DescribeVpcPeeringConnection(infra.Ctx(), kcpPeering.Status.Id)
636-
Expect(err).To(HaveOccurred())
637-
Expect(localPeering).To(BeNil())
638-
})
639-
640-
By("And Then local route tables have no peering routes to remote VPC CIDRs", func() {
641-
Expect(awsMockLocal.GetRoute(localVpcId, localMainRouteTable, kcpPeering.Status.Id, remoteVpcCidr)).
642-
To(BeNil(), fmt.Sprintf("Local main route table should not have peering route to %s", remoteVpcCidr))
643-
644-
Expect(awsMockLocal.GetRoute(localVpcId, localRouteTable, kcpPeering.Status.Id, remoteVpcCidr)).
645-
To(BeNil(), fmt.Sprintf("Local route table should not have peering route to %s", remoteVpcCidr))
646-
647-
})
648-
649-
// VpcPeeringConnection and Routes are not deleted since KCP remote Network is deleted previously
650-
By("And Then remote VpcPeeringConnection is not deleted", func() {
651-
remotePeering, err := awsMockRemote.DescribeVpcPeeringConnection(infra.Ctx(), kcpPeering.Status.Id)
652-
Expect(err).NotTo(HaveOccurred())
653-
Expect(remotePeering).NotTo(BeNil())
654-
})
655-
656-
By("And Then remote route tables have peering routes to local VPC CIDR", func() {
657-
Expect(awsMockRemote.GetRoute(remoteVpcId, remoteMainRouteTable, kcpPeering.Status.RemoteId, localVpcCidr)).
658-
NotTo(BeNil(), fmt.Sprintf("Remote main route table should have peering route to %s", localVpcCidr))
659-
660-
Expect(awsMockRemote.GetRoute(remoteVpcId, remoteRouteTable, kcpPeering.Status.RemoteId, localVpcCidr)).
661-
NotTo(BeNil(), fmt.Sprintf("Remote route table should have peering route to %s", localVpcCidr))
662-
663-
})
664-
})
665-
666374
It("Scenario: KCP AWS VpcPeering can be deleted when remote VPC Network authorization is revoked", func() {
667375
const (
668376
kymaName = "50de99f8-0b35-4ac2-900e-793091f1a853"

0 commit comments

Comments
 (0)