Skip to content

Commit 85dedff

Browse files
authored
VPC: Move vpc status update before tagging (#1984)
Move the status update after creating a vpc to occur prior to attempting to tag the vpc. This will align with other resource reconciliation paths.
1 parent fd6f36c commit 85dedff

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

cloud/scope/vpc_cluster.go

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -452,31 +452,22 @@ func (s *VPCClusterScope) ReconcileVPC() (bool, error) {
452452

453453
// If no VPC id was found, we need to create a new VPC.
454454
s.V(3).Info("Creating a VPC")
455-
vpcDetails, err := s.createVPC()
455+
err = s.createVPC()
456456
if err != nil {
457457
return false, fmt.Errorf("failed to create vpc: %w", err)
458458
}
459459

460460
s.V(3).Info("Successfully created VPC")
461-
var vpcName *string
462-
if vpcDetails != nil {
463-
vpcName = vpcDetails.Name
464-
}
465-
s.SetResourceStatus(infrav1beta2.ResourceTypeVPC, &infrav1beta2.ResourceStatus{
466-
ID: *vpcDetails.ID,
467-
Name: vpcName,
468-
Ready: false,
469-
})
470461
return true, nil
471462
}
472463

473-
func (s *VPCClusterScope) createVPC() (*vpcv1.VPC, error) {
464+
func (s *VPCClusterScope) createVPC() error {
474465
// We use the cluster's Resource Group ID, as we expect to create all resources in that Resource Group.
475466
resourceGroupID, err := s.GetResourceGroupID()
476467
if err != nil {
477-
return nil, fmt.Errorf("failed retreiving resource group id during vpc creation: %w", err)
468+
return fmt.Errorf("failed retreiving resource group id during vpc creation: %w", err)
478469
} else if resourceGroupID == "" {
479-
return nil, fmt.Errorf("resource group id is empty cannot create vpc")
470+
return fmt.Errorf("resource group id is empty cannot create vpc")
480471
}
481472
vpcName := s.GetServiceName(infrav1beta2.ResourceTypeVPC)
482473
if s.NetworkSpec() != nil && s.NetworkSpec().VPC != nil && s.NetworkSpec().VPC.Name != nil {
@@ -492,17 +483,25 @@ func (s *VPCClusterScope) createVPC() (*vpcv1.VPC, error) {
492483
}
493484
vpcDetails, _, err := s.VPCClient.CreateVPC(vpcOptions)
494485
if err != nil {
495-
return nil, fmt.Errorf("error creating vpc: %w", err)
486+
return fmt.Errorf("error creating vpc: %w", err)
496487
} else if vpcDetails == nil {
497-
return nil, fmt.Errorf("no vpc details after creation")
488+
return fmt.Errorf("no vpc details after creation")
498489
}
499490

491+
// Set the VPC status.
492+
s.SetResourceStatus(infrav1beta2.ResourceTypeVPC, &infrav1beta2.ResourceStatus{
493+
ID: *vpcDetails.ID,
494+
Name: vpcDetails.Name,
495+
// We wait for a followup reconcile loop to set as Ready, to confirm the VPC can be found.
496+
Ready: false,
497+
})
498+
500499
// NOTE: This tagging is only attempted once. We may wish to refactor in case this single attempt fails.
501500
if err = s.TagResource(s.Name(), *vpcDetails.CRN); err != nil {
502-
return nil, fmt.Errorf("error tagging vpc: %w", err)
501+
return fmt.Errorf("error tagging vpc: %w", err)
503502
}
504503

505-
return vpcDetails, nil
504+
return nil
506505
}
507506

508507
// ReconcileVPCCustomImage reconciles the VPC Custom Image.

0 commit comments

Comments
 (0)