Skip to content

Commit

Permalink
microovn/cmd/microovn: Add an option in the CLI init to specify custo…
Browse files Browse the repository at this point in the history
…m Geneve encapsulation IP

Signed-off-by: Gabriel Mougard <[email protected]>
  • Loading branch information
gabrielmougard committed Jan 16, 2024
1 parent bc95825 commit 0066c79
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion microovn/cmd/microovn/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,24 @@ func (c *cmdInit) Command() *cobra.Command {
return cmd
}

func (c *cmdInit) wantsCustomEncapsulationIP(hostName string) (string, string, error) {
wantsCustomEncapsulationIP, err := c.common.asker.AskBool(fmt.Sprintf("Would you like to define a custom encapsulation IP address for %q ? (yes/no) [default=no]: ", hostName), "no")
if err != nil {
return "", "", err
}

if wantsCustomEncapsulationIP {
encapIP, err := c.common.asker.AskString(fmt.Sprintf("Please enter the custom encapsulation IP address for %q: ", hostName), "", nil)
if err != nil {
return "", "", err
}

return fmt.Sprintf("%s.ovn-encap-ip", hostName), encapIP, nil
}

return "", "", nil
}

func (c *cmdInit) Run(cmd *cobra.Command, args []string) error {
// Connect to the daemon.
m, err := microcluster.App(context.Background(), microcluster.Args{StateDir: c.common.FlagStateDir, Verbose: c.common.FlagLogVerbose, Debug: c.common.FlagLogDebug})
Expand Down Expand Up @@ -80,8 +98,19 @@ func (c *cmdInit) Run(cmd *cobra.Command, args []string) error {
return err
}

// Handle custom encapsulation IP for this system at bootstrap time.
key, encapIP, err := c.wantsCustomEncapsulationIP(hostName)
if err != nil {
return err
}

var optionalConfig map[string]string
if key != "" && encapIP != "" {
optionalConfig = map[string]string{key: encapIP}
}

// Bootstrap the cluster.
err = m.NewCluster(hostName, address, nil, time.Second*30)
err = m.NewCluster(hostName, address, optionalConfig, time.Second*30)
if err != nil {
return err
}
Expand Down Expand Up @@ -126,6 +155,21 @@ func (c *cmdInit) Run(cmd *cobra.Command, args []string) error {
return err
}

// Register a potential custom encapsulation IP for other systems,
// so that when they will join the cluster, their encapsulation IP
// for the Geneve tunnel will be automatically configured.
key, encapIP, err := c.wantsCustomEncapsulationIP(tokenName)
if err != nil {
return err
}

if key != "" && encapIP != "" {
_, _, err = m.SQL(fmt.Sprintf("INSERT INTO config (key, value) VALUES ('%s', '%s')", key, encapIP))
if err != nil {
return err
}
}

fmt.Println(token)
}
}
Expand Down

0 comments on commit 0066c79

Please sign in to comment.