Skip to content

Commit

Permalink
Merge pull request #106 from masnax/backport-microcluster
Browse files Browse the repository at this point in the history
[branch-22.03] Backport microcluster dependency update
  • Loading branch information
fnordahl authored Nov 30, 2023
2 parents d29c175 + 813bcc9 commit 1d18f95
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 58 deletions.
2 changes: 1 addition & 1 deletion microovn/cmd/microovn/cluster_bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ func (c *cmdClusterBootstrap) Run(cmd *cobra.Command, args []string) error {
address := util.NetworkInterfaceAddress()
address = util.CanonicalNetworkAddress(address, 6443)

return m.NewCluster(hostname, address, time.Second*30)
return m.NewCluster(hostname, address, nil, time.Second*30)
}
2 changes: 1 addition & 1 deletion microovn/cmd/microovn/cluster_join.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ func (c *cmdClusterJoin) Run(cmd *cobra.Command, args []string) error {
address := util.NetworkInterfaceAddress()
address = util.CanonicalNetworkAddress(address, 6443)

return m.JoinCluster(hostname, address, args[0], time.Second*30)
return m.JoinCluster(hostname, address, args[0], nil, time.Second*30)
}
18 changes: 9 additions & 9 deletions microovn/cmd/microovn/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"time"

"github.com/canonical/lxd/lxd/util"
cli "github.com/canonical/lxd/shared/cmd"
"github.com/canonical/microcluster/microcluster"
"github.com/spf13/cobra"
)
Expand All @@ -20,6 +19,7 @@ type cmdInit struct {
}

func (c *cmdInit) Command() *cobra.Command {

cmd := &cobra.Command{
Use: "init",
Short: "Interactive configuration of MicroOVN",
Expand Down Expand Up @@ -60,13 +60,13 @@ func (c *cmdInit) Run(cmd *cobra.Command, args []string) error {

// Get system address.
address := util.NetworkInterfaceAddress()
address, err = cli.AskString(fmt.Sprintf("Please choose the address MicroOVN will be listening on [default=%s]: ", address), address, nil)
address, err = c.common.asker.AskString(fmt.Sprintf("Please choose the address MicroOVN will be listening on [default=%s]: ", address), address, nil)
if err != nil {
return err
}
address = util.CanonicalNetworkAddress(address, 6443)

wantsBootstrap, err := cli.AskBool("Would you like to create a new MicroOVN cluster? (yes/no) [default=no]: ", "no")
wantsBootstrap, err := c.common.asker.AskBool("Would you like to create a new MicroOVN cluster? (yes/no) [default=no]: ", "no")
if err != nil {
return err
}
Expand All @@ -75,25 +75,25 @@ func (c *cmdInit) Run(cmd *cobra.Command, args []string) error {
mode = "bootstrap"

// Offer overriding the name.
hostName, err = cli.AskString(fmt.Sprintf("Please choose a name for this system [default=%s]: ", hostName), hostName, nil)
hostName, err = c.common.asker.AskString(fmt.Sprintf("Please choose a name for this system [default=%s]: ", hostName), hostName, nil)
if err != nil {
return err
}

// Bootstrap the cluster.
err = m.NewCluster(hostName, address, time.Second*30)
err = m.NewCluster(hostName, address, nil, time.Second*30)
if err != nil {
return err
}
} else {
mode = "join"

token, err := cli.AskString("Please enter your join token: ", "", nil)
token, err := c.common.asker.AskString("Please enter your join token: ", "", nil)
if err != nil {
return err
}

err = m.JoinCluster(hostName, address, token, time.Second*30)
err = m.JoinCluster(hostName, address, token, nil, time.Second*30)
if err != nil {
return err
}
Expand All @@ -104,14 +104,14 @@ func (c *cmdInit) Run(cmd *cobra.Command, args []string) error {

// Add additional servers.
if mode != "join" {
wantsMachines, err := cli.AskBool("Would you like to add additional servers to the cluster? (yes/no) [default=no]: ", "no")
wantsMachines, err := c.common.asker.AskBool("Would you like to add additional servers to the cluster? (yes/no) [default=no]: ", "no")
if err != nil {
return err
}

if wantsMachines {
for {
tokenName, err := cli.AskString("What's the name of the new MicroOVN server? (empty to exit): ", "", func(input string) error { return nil })
tokenName, err := c.common.asker.AskString("What's the name of the new MicroOVN server? (empty to exit): ", "", func(input string) error { return nil })
if err != nil {
return err
}
Expand Down
6 changes: 5 additions & 1 deletion microovn/cmd/microovn/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
package main

import (
"bufio"
"os"

"github.com/spf13/cobra"

cli "github.com/canonical/lxd/shared/cmd"
"github.com/canonical/microovn/microovn/version"
)

Expand All @@ -19,11 +21,13 @@ type CmdControl struct {
FlagLogDebug bool
FlagLogVerbose bool
FlagStateDir string

asker cli.Asker
}

func main() {
// common flags.
commonCmd := CmdControl{}
commonCmd := CmdControl{asker: cli.NewAsker(bufio.NewReader(os.Stdin))}

app := &cobra.Command{
Use: "microovn",
Expand Down
3 changes: 2 additions & 1 deletion microovn/cmd/microovnd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/canonical/lxd/shared/logger"
"github.com/canonical/microcluster/config"
"github.com/canonical/microcluster/microcluster"
"github.com/canonical/microcluster/state"
"github.com/spf13/cobra"

"github.com/canonical/microovn/microovn/api"
Expand Down Expand Up @@ -70,7 +71,7 @@ func (c *cmdDaemon) Run(cmd *cobra.Command, args []string) error {
h.PreJoin = ovn.Join
h.OnNewMember = ovn.Refresh
h.PreRemove = ovn.Leave
h.PostRemove = ovn.Refresh
h.PostRemove = func(s *state.State, force bool) error { return ovn.Refresh(s) }
h.OnStart = ovn.Start

return m.Start(api.Endpoints, database.SchemaExtensions, h)
Expand Down
24 changes: 12 additions & 12 deletions microovn/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/canonical/microovn/microovn
go 1.18

require (
github.com/canonical/lxd v0.0.0-20230806201234-7f46f7113341
github.com/canonical/microcluster v0.0.0-20230705140256-7726061a60bb
github.com/canonical/lxd v0.0.0-20231002162033-38796399c135
github.com/canonical/microcluster v0.0.0-20231129010136-61fc11fddb9b
github.com/gorilla/mux v1.8.0
github.com/olekukonko/tablewriter v0.0.5
github.com/pkg/errors v0.9.1
Expand All @@ -23,7 +23,7 @@ require (
github.com/go-macaroon-bakery/macaroonpb v1.0.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/renameio v1.0.1 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/gorilla/schema v1.2.0 // indirect
github.com/gorilla/securecookie v1.1.1 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
Expand All @@ -37,7 +37,7 @@ require (
github.com/mattn/go-sqlite3 v1.14.17 // indirect
github.com/muhlemmer/gu v0.3.1 // indirect
github.com/pborman/uuid v1.2.1 // indirect
github.com/pkg/sftp v1.13.5 // indirect
github.com/pkg/sftp v1.13.6 // indirect
github.com/pkg/xattr v0.4.9 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
Expand All @@ -46,15 +46,15 @@ require (
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.8.4 // indirect
github.com/zitadel/oidc/v2 v2.7.0 // indirect
golang.org/x/crypto v0.12.0 // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/oauth2 v0.11.0 // indirect
github.com/zitadel/oidc/v2 v2.11.0 // indirect
golang.org/x/crypto v0.13.0 // indirect
golang.org/x/net v0.15.0 // indirect
golang.org/x/oauth2 v0.12.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/term v0.11.0 // indirect
golang.org/x/text v0.12.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/term v0.12.0 // indirect
golang.org/x/text v0.13.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/errgo.v1 v1.0.1 // indirect
gopkg.in/httprequest.v1 v1.2.1 // indirect
Expand Down
Loading

0 comments on commit 1d18f95

Please sign in to comment.