Skip to content

Commit

Permalink
cmd/microcloud: refactor validateSystems to adapt checks whether we…
Browse files Browse the repository at this point in the history
… are in preseed or interactive mode

* If we are not in preseed, the call the `detectCollisions` that output advanced network info (net interface collisions, subnet collisions)
* Else, we use the former approach: check if the OVN underlay and Ceph cluster network is a valid CIDR subnet notation and output a warning if the subnets are shared.

Signed-off-by: Gabriel Mougard <[email protected]>
  • Loading branch information
gabrielmougard committed Feb 10, 2025
1 parent 8cf88a2 commit 935c04a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 22 deletions.
43 changes: 26 additions & 17 deletions cmd/microcloud/main_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ func (c *initConfig) RunInteractive(cmd *cobra.Command, args []string) error {
return err
}

err = c.validateSystems(s)
err = c.validateSystems(s, false)
if err != nil {
return err
}
Expand Down Expand Up @@ -677,26 +677,35 @@ func detectCollisions(systems map[string]InitSystem) []string {
return warnings
}

func (c *initConfig) validateSystems(s *service.Handler) (err error) {
for _, sys := range c.systems {
if sys.MicroCephInternalNetworkSubnet == "" || sys.OVNGeneveAddr == "" {
continue
}

_, subnet, err := net.ParseCIDR(sys.MicroCephInternalNetworkSubnet)
if err != nil {
return fmt.Errorf("Failed to parse available network interface CIDR address: %q: %w", subnet, err)
func (c *initConfig) validateSystems(s *service.Handler, preseed bool) (err error) {
if !preseed {
fmt.Println("Checking network configuration ...")
warnings := detectCollisions(c.systems)
if len(warnings) > 0 {
for _, warning := range warnings {
fmt.Println(tui.SummarizeResult(warning))
}
}
} else {
for _, sys := range c.systems {
if sys.MicroCephInternalNetwork == nil || sys.OVNGeneveNetwork == nil {
continue
}

underlayIP := net.ParseIP(sys.OVNGeneveAddr)
if underlayIP == nil {
return fmt.Errorf("OVN underlay IP %q is invalid", sys.OVNGeneveAddr)
}
_, subnet, err := net.ParseCIDR(sys.MicroCephInternalNetwork.Subnet.String())
if err != nil {
return fmt.Errorf("Failed to parse available network interface CIDR address: %q: %w", subnet, err)
}

if subnet.Contains(underlayIP) {
tui.PrintWarning(fmt.Sprintf("OVN underlay IP (%s) is shared with the Ceph cluster network (%s)\n", underlayIP.String(), subnet.String()))
underlayIP := net.ParseIP(sys.OVNGeneveNetwork.IP.String())
if underlayIP == nil {
return fmt.Errorf("OVN underlay IP %q is invalid", sys.OVNGeneveNetwork.IP.String())
}

break
if sys.MicroCephInternalNetwork.Subnet.Contains(sys.OVNGeneveNetwork.IP) {
tui.PrintWarning(fmt.Sprintf("OVN underlay IP (%s) is shared with the Ceph cluster network (%s)\n", sys.OVNGeneveNetwork.IP.String(), sys.MicroCephInternalNetwork.Subnet.String()))
break
}
}
}

Expand Down
8 changes: 4 additions & 4 deletions cmd/microcloud/main_init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func ensureValidateSystemsPasses(handler *service.Handler, testSystems map[strin
systems := newTestSystemsMap(system)
cfg := initConfig{systems: systems, bootstrap: true}

err := cfg.validateSystems(handler)
err := cfg.validateSystems(handler, false)
if err != nil {
t.Fatalf("Valid system %q failed validate: %s", testName, err)
}
Expand All @@ -67,7 +67,7 @@ func ensureValidateSystemsFails(handler *service.Handler, testSystems map[string
systems := newTestSystemsMap(system)
cfg := initConfig{systems: systems, bootstrap: true}

err := cfg.validateSystems(handler)
err := cfg.validateSystems(handler, false)
if err == nil {
t.Fatalf("Invalid system %q passed validation", testName)
}
Expand Down Expand Up @@ -202,7 +202,7 @@ func TestValidateSystemsMultiSystem(t *testing.T) {
systems := newTestSystemsMap(sys1, sys2)
cfg := initConfig{systems: systems, bootstrap: true}

err := cfg.validateSystems(handler)
err := cfg.validateSystems(handler, false)
if err == nil {
t.Fatalf("sys2 with conflicting management IP and ipv4.ovn.ranges passed validation")
}
Expand All @@ -223,7 +223,7 @@ func TestValidateSystemsMultiSystem(t *testing.T) {
systems = newTestSystemsMap(sys3, sys4)
cfg = initConfig{systems: systems, bootstrap: true}

err = cfg.validateSystems(handler)
err = cfg.validateSystems(handler, false)
if err == nil {
t.Fatalf("sys4 with conflicting management IP and ipv6.ovn.ranges passed validation")
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/microcloud/preseed.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func (c *initConfig) RunPreseed(cmd *cobra.Command) error {
}
}

err = c.validateSystems(s)
err = c.validateSystems(s, true)
if err != nil {
return err
}
Expand Down

0 comments on commit 935c04a

Please sign in to comment.