From 3a1a8967e5fea71b938614f96551c2557cd86890 Mon Sep 17 00:00:00 2001 From: Sergei Lukianov Date: Mon, 4 Mar 2024 13:35:16 -0800 Subject: [PATCH] some fabric-wide validation --- pkg/wiring/validation.go | 44 ++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/pkg/wiring/validation.go b/pkg/wiring/validation.go index 3ce458b8..992725ce 100644 --- a/pkg/wiring/validation.go +++ b/pkg/wiring/validation.go @@ -11,6 +11,11 @@ import ( ) func ValidateFabric(ctx context.Context, kube client.Client, fabricCfg *meta.FabricConfig) error { + if fabricCfg == nil { + return errors.Errorf("fabric config is required") + } + + // TODO auto iterate through all types to validate // for k, v := range kube.Scheme().AllKnownTypes() { // if !strings.Contains(k.Group, "githedgehog.com") { // continue @@ -20,23 +25,6 @@ func ValidateFabric(ctx context.Context, kube client.Client, fabricCfg *meta.Fab // } // } - if fabricCfg == nil { - // TODO remove hardcode - fabricCfg = &meta.FabricConfig{ - ControlVIP: "172.30.1.1/24", - VPCIRBVLANRanges: []meta.VLANRange{{From: 3000, To: 3999}}, - VPCPeeringVLANRanges: []meta.VLANRange{{From: 100, To: 999}}, - VPCPeeringDisabled: false, - ReservedSubnets: []string{"172.28.0.0/24", "172.29.0.0/24", "172.30.0.0/24", "172.31.0.0/24"}, - DHCPMode: meta.DHCPModeHedgehog, - FabricMode: meta.FabricModeSpineLeaf, - FabricMTU: 9100, - ServerFacingMTUOffset: 64, - } - } - - // TODO auto iterate through all types to validate - rackList := &wiringapi.RackList{} if err := kube.List(ctx, rackList); err != nil { return errors.Wrapf(err, "error listing racks") @@ -217,5 +205,27 @@ func ValidateFabric(ctx context.Context, kube client.Client, fabricCfg *meta.Fab } } + // Some Fabric-wide validation + + if len(swList.Items) == 0 { + return errors.Errorf("no switches found") + } + + if len(serverList.Items) == 0 { + return errors.Errorf("no servers found") + } + controls := 0 + for _, server := range serverList.Items { + if server.IsControl() { + controls++ + } + } + if controls == 0 { + return errors.Errorf("no controllers found") + } + if controls > 1 { + return errors.Errorf("multiple controllers not supported") + } + return nil }