@@ -662,21 +662,39 @@ func createVLABConfig(ctx context.Context, controls []fabapi.ControlNode, nodes
662
662
}
663
663
}
664
664
} 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 )
670
689
671
690
continue
672
691
}
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
673
694
if externalID > MaxExternalConns {
674
695
return nil , fmt .Errorf ("too many external connections" ) //nolint:goerr113
675
696
}
676
-
677
697
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
680
698
nicName := fmt .Sprintf ("enp2s%d" , externalID )
681
699
externalID ++
682
700
toStr := fmt .Sprintf ("%s/%s" , ExternalVMName , nicName )
@@ -688,7 +706,7 @@ func createVLABConfig(ctx context.Context, controls []fabapi.ControlNode, nodes
688
706
Untagged : false ,
689
707
}
690
708
691
- // check if there is any external attachment using this connection
709
+ // iterate over the external attachments using this connection
692
710
// note that we have a limitation where we cannot support both untagged and tagged
693
711
// on the same connection, so complain if we notice that's the case
694
712
var tagged , untagged bool
@@ -697,9 +715,9 @@ func createVLABConfig(ctx context.Context, controls []fabapi.ControlNode, nodes
697
715
continue
698
716
}
699
717
extName := extAttach .Spec .External
700
- // nothing to do if the external is hardware
718
+ // just a paranoid extra safety (unreachable, we already checked)
701
719
if hwExternals [extName ] {
702
- continue
720
+ return nil , fmt . Errorf ( "external attachment %q is for hardware external %q" , extAttach . Name , extName ) //nolint:goerr113
703
721
}
704
722
extVrf , ok := cfg .Externals .VRFs [extName ]
705
723
if ! ok {
0 commit comments