Skip to content

Commit

Permalink
some fabric-wide validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Frostman committed Mar 4, 2024
1 parent 88f52d4 commit 3a1a896
Showing 1 changed file with 27 additions and 17 deletions.
44 changes: 27 additions & 17 deletions pkg/wiring/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -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
}

0 comments on commit 3a1a896

Please sign in to comment.