You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
m.CreateVpcWithContext(context.TODO(), gomock.AssignableToTypeOf(&ec2.CreateVpcInput{})).Return(nil, errors.New("The maximum number of VPCs has been reached"))
m.CreateVpcWithContext(context.TODO(), gomock.AssignableToTypeOf(&ec2.CreateVpcInput{})).After(describeVPCByNameCall).Return(nil, errors.New("The maximum number of VPCs has been reached"))
returnerrors.Wrap(err, "failed to patch conditions")
106
+
// .spec.vpc.id is nil. This means no managed VPC exists or we failed to save its ID before. Check if a managed VPC
107
+
// with the desired name exists, or if not, create a new managed VPC.
108
+
109
+
vpc, err:=s.describeVPCByName()
110
+
iferr==nil {
111
+
// An VPC already exists with the desired name
112
+
113
+
if!vpc.Tags.HasOwned(s.scope.Name()) {
114
+
returnerrors.Errorf(
115
+
"found VPC %q which cannot be managed by CAPA due to lack of tags (either tag the VPC manually with `%s=%s`, or provide the `vpc.id` field instead if you wish to bring your own VPC as shown in https://cluster-api-aws.sigs.k8s.io/topics/bring-your-own-aws-infrastructure)",
116
+
vpc.ID,
117
+
infrav1.ClusterTagKey(s.scope.Name()),
118
+
infrav1.ResourceLifecycleOwned)
111
119
}
120
+
} else {
121
+
if!awserrors.IsNotFound(err) {
122
+
returnerrors.Wrap(err, "failed to describe VPC resources by name")
123
+
}
124
+
125
+
// VPC with that name does not exist yet. Create it.
126
+
vpc, err=s.createVPC()
127
+
iferr!=nil {
128
+
returnerrors.Wrap(err, "failed to create new managed VPC")
129
+
}
130
+
s.scope.Info("Created VPC", "vpc-id", vpc.ID)
112
131
}
113
-
vpc, err:=s.createVPC()
114
-
iferr!=nil {
115
-
returnerrors.Wrap(err, "failed to create new vpc")
if (err!=nil&&awserrors.IsNotFound(err)) || (out!=nil&&len(out.Vpcs) ==0) {
613
+
returnnil, awserrors.NewNotFound(fmt.Sprintf("could not find VPC by name %q", vpcName))
614
+
}
615
+
iferr!=nil {
616
+
returnnil, errors.Wrapf(err, "failed to query ec2 for VPCs by name %q", vpcName)
617
+
}
618
+
iflen(out.Vpcs) >1 {
619
+
returnnil, awserrors.NewConflict(fmt.Sprintf("found %v VPCs with name %q. Only one VPC per cluster name is supported. Ensure duplicate VPCs are deleted for this AWS account and there are no conflicting instances of Cluster API Provider AWS. Filtered VPCs: %v", len(out.Vpcs), vpcName, out.GoString()))
620
+
}
621
+
622
+
switch*out.Vpcs[0].State {
623
+
caseec2.VpcStateAvailable, ec2.VpcStatePending:
624
+
default:
625
+
returnnil, awserrors.NewNotFound(fmt.Sprintf("could not find available or pending VPC by name %q", vpcName))
0 commit comments