Skip to content

Commit f1b3c2e

Browse files
committed
fix: support virt-externals with hw switches
the previous check was skipping external connections that were hardware annotated, but that is incorrect. what we really want is to perfrom the extra config steps (adding a link towards the externals and the VRF information) only if the connection is used to connect to virtual externals. the check is slightly complicated by the fact that we need to iterate over the attachments, but now things should work properly. Signed-off-by: Emanuele Di Pascale <[email protected]>
1 parent 6c332c7 commit f1b3c2e

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

pkg/hhfab/vlabconfig.go

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -662,21 +662,39 @@ func createVLABConfig(ctx context.Context, controls []fabapi.ControlNode, nodes
662662
}
663663
}
664664
} else if conn.Spec.External != nil {
665-
// in hybrid environments we can have physical switches connected to
666-
// both virtual and hardware externals. Since a connection is not associated
667-
// with a specific external, we need to annotate the connection itself
668-
if IsHardware(&conn) {
669-
slog.Debug("Skipping hardware external connection", "connection", conn.Name)
665+
// check if the connection is for hardware or virtual externals
666+
// (it cannot be both, complain if that is the case)
667+
var hwExt, virtExt bool
668+
for _, extAttach := range externalAttachs.Items {
669+
if extAttach.Spec.Connection != conn.Name {
670+
continue
671+
}
672+
extName := extAttach.Spec.External
673+
if hwExternals[extName] {
674+
hwExt = true
675+
} else {
676+
virtExt = true
677+
}
678+
}
679+
// here we want to do a bunch of stuff only if there are virtual externals attached on this connection
680+
switch {
681+
case hwExt && virtExt:
682+
return nil, fmt.Errorf("external connection %q has both hardware and virtual external attachments", conn.Name) //nolint:goerr113
683+
case !hwExt && !virtExt:
684+
slog.Debug("Skipping external connection as it has no attachments", "connection", conn.Name)
685+
686+
continue
687+
case hwExt:
688+
slog.Debug("Skipping external connection as it is for hardware externals", "connection", conn.Name)
670689

671690
continue
672691
}
692+
// now that we know that the connection is for virtual externals, we can add a link towards them,
693+
// which could be using a passthrough if the source is a hardware switch
673694
if externalID > MaxExternalConns {
674695
return nil, fmt.Errorf("too many external connections") //nolint:goerr113
675696
}
676-
677697
switchName := conn.Spec.External.Link.Switch.DeviceName()
678-
// add the link representing the virtual external connection
679-
// note that if the switch is hardware, we will require passthrough annotations
680698
nicName := fmt.Sprintf("enp2s%d", externalID)
681699
externalID++
682700
toStr := fmt.Sprintf("%s/%s", ExternalVMName, nicName)
@@ -688,7 +706,7 @@ func createVLABConfig(ctx context.Context, controls []fabapi.ControlNode, nodes
688706
Untagged: false,
689707
}
690708

691-
// check if there is any external attachment using this connection
709+
// iterate over the external attachments using this connection
692710
// note that we have a limitation where we cannot support both untagged and tagged
693711
// on the same connection, so complain if we notice that's the case
694712
var tagged, untagged bool
@@ -697,9 +715,9 @@ func createVLABConfig(ctx context.Context, controls []fabapi.ControlNode, nodes
697715
continue
698716
}
699717
extName := extAttach.Spec.External
700-
// nothing to do if the external is hardware
718+
// just a paranoid extra safety (unreachable, we already checked)
701719
if hwExternals[extName] {
702-
continue
720+
return nil, fmt.Errorf("external attachment %q is for hardware external %q", extAttach.Name, extName) //nolint:goerr113
703721
}
704722
extVrf, ok := cfg.Externals.VRFs[extName]
705723
if !ok {

0 commit comments

Comments
 (0)