Skip to content

Commit 41c914f

Browse files
committed
chore: make multiple ext. attach an error
the warning is easy to miss and then we end up spending a lot of time troubleshooting this. I'm keeping the option to force this with a --yes flag because we might still want to test this in the future, or use the generated yaml as a base that will be edited afterwards. Signed-off-by: Emanuele Di Pascale <[email protected]>
1 parent d479a96 commit 41c914f

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

cmd/hhfab/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ func Run(ctx context.Context) error {
721721
Name: "generate",
722722
Aliases: []string{"gen"},
723723
Usage: "generate VLAB wiring diagram",
724-
Flags: flatten(defaultFlags, vlabWiringGenFlags),
724+
Flags: flatten(defaultFlags, vlabWiringGenFlags, []cli.Flag{yesFlag}),
725725
Before: before(false),
726726
Action: func(_ *cli.Context) error {
727727
builder := hhfab.VLABBuilder{
@@ -743,6 +743,7 @@ func Run(ctx context.Context) error {
743743
ExtMCLAGConnCount: uint8(wgExtMCLAGConns), //nolint:gosec
744744
ExtESLAGConnCount: uint8(wgExtESLAGConns), //nolint:gosec
745745
ExtOrphanConnCount: uint8(wgExtOrphanConns), //nolint:gosec
746+
YesFlag: yes,
746747
}
747748

748749
if err := hhfab.VLABGenerate(ctx, workDir, cacheDir, builder, hhfab.DefaultVLABGeneratedFile); err != nil {

pkg/hhfab/vlabbuilder.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package hhfab
55

66
import (
77
"context"
8+
"errors"
89
"fmt"
910
"log/slog"
1011
"slices"
@@ -40,6 +41,7 @@ type VLABBuilder struct {
4041
ExtMCLAGConnCount uint8 // number of external connections to generate from MCLAG leaves
4142
ExtESLAGConnCount uint8 // number of external connections to generate from ESLAG leaves
4243
ExtOrphanConnCount uint8 // number of external connections to generate from orphan leaves
44+
YesFlag bool
4345

4446
data *apiutil.Loader
4547
ifaceTracker map[string]uint8 // next available interface ID for each switch
@@ -209,11 +211,21 @@ func (b *VLABBuilder) Build(ctx context.Context, l *apiutil.Loader, fabricMode m
209211

210212
// warn about https://github.com/githedgehog/internal/issues/145 if there are multiple external connections
211213
if b.ExtMCLAGConnCount+b.ExtESLAGConnCount+b.ExtOrphanConnCount > 1 {
212-
slog.Warn("Multiple external connections are not supported if using virtual switches",
214+
logMsg := "Multiple external connections are not supported if using virtual switches"
215+
logArgs := []any{
213216
"extMCLAGConnCount", b.ExtMCLAGConnCount,
214217
"extESLAGConnCount", b.ExtESLAGConnCount,
215218
"extOrphanConnCount", b.ExtOrphanConnCount,
216-
)
219+
}
220+
if b.YesFlag {
221+
slog.Warn(logMsg, logArgs...)
222+
slog.Warn("Proceeding anyway due to --yes flag")
223+
} else {
224+
slog.Error(logMsg, logArgs...)
225+
slog.Error("Use --yes to proceed anyway")
226+
227+
return errors.New(logMsg) //nolint:goerr113
228+
}
217229
}
218230

219231
slog.Info("Building VLAB wiring diagram", "fabricMode", fabricMode)

0 commit comments

Comments
 (0)