Skip to content

Commit

Permalink
fix(bug): allow filtering overlay subnets (#199)
Browse files Browse the repository at this point in the history
In an older change where we allowed filtering multiple subnets with
same name based on cluster we introduced a regression where we
assumed all subnets have clusters. However, overlay subnets don't
have a associated cluster and also need to be accounted for.
  • Loading branch information
thunderboltsid authored Sep 26, 2024
1 parent e63a72f commit a7c7091
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions builder/nutanix/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ func (d *NutanixDriver) CreateRequest(ctx context.Context, vm VmConfig, state mu

state.Put("image_to_delete", imageToDelete)

cluster := &v3.ClusterIntentResponse{}
var cluster *v3.ClusterIntentResponse
if vm.ClusterUUID != "" {
cluster, err = conn.V3.GetCluster(ctx, vm.ClusterUUID)
if err != nil {
Expand All @@ -463,28 +463,43 @@ func (d *NutanixDriver) CreateRequest(ctx context.Context, vm VmConfig, state mu

NICList := []*v3.VMNic{}
for _, nic := range vm.VmNICs {
subnet := &v3.SubnetIntentResponse{}
var subnet *v3.SubnetIntentResponse
if nic.SubnetUUID != "" {
subnet, err = findSubnetByUUID(ctx, conn, nic.SubnetUUID)
if err != nil {
return nil, fmt.Errorf("error while findSubnetByUUID, %s", err.Error())
}

if subnet == nil {
return nil, fmt.Errorf("subnet with UUID %s not found", nic.SubnetUUID)
}
} else if nic.SubnetName != "" {
subnets, err := findSubnetByName(ctx, conn, nic.SubnetName)
if err != nil {
return nil, fmt.Errorf("error while findSubnetByName, %s", err.Error())
}

for _, s := range subnets {
if s.Spec.ClusterReference != nil && *s.Spec.ClusterReference.UUID == *cluster.Metadata.UUID {
// overlay subnets don't have a cluster reference
if s.Spec.ClusterReference == nil {
subnet = s
break
}

if s.Spec.ClusterReference != nil &&
s.Spec.ClusterReference.UUID != nil &&
cluster != nil &&
cluster.Metadata != nil &&
cluster.Metadata.UUID != nil &&
*s.Spec.ClusterReference.UUID == *cluster.Metadata.UUID {
subnet = s
break
}
}
}

if subnet == nil {
return nil, fmt.Errorf("subnet not found")
if subnet == nil {
return nil, fmt.Errorf("subnet named %s not found", nic.SubnetName)
}
}

isConnected := true
Expand Down

0 comments on commit a7c7091

Please sign in to comment.