Skip to content

Commit

Permalink
refactor: Update MicroCluster methods
Browse files Browse the repository at this point in the history
Signed-off-by: Gabriel Mougard <gabriel.mougard@canonical.com>
  • Loading branch information
gabrielmougard committed Apr 29, 2024
1 parent cad9f34 commit 0ad16b7
Show file tree
Hide file tree
Showing 14 changed files with 26 additions and 29 deletions.
4 changes: 2 additions & 2 deletions microovn/api/certificates/regenerate_ca.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func regenerateCaPut(s *state.State, r *http.Request) response.Response {
responseData := types.NewRegenerateCaResponse()

// Check that this is the initial node that received the request and recreate new CA certificate
if !client.IsForwardedRequest(r) {
if !client.IsNotification(r) {
// Only one recipient of this request needs to generate new CA
logger.Info("Re-issuing CA certificate and private key")
err = ovn.GenerateNewCACertificate(s)
Expand All @@ -42,7 +42,7 @@ func regenerateCaPut(s *state.State, r *http.Request) response.Response {
}

// Get clients for rest of the cluster members
cluster, err := s.Cluster(r)
cluster, err := s.Cluster(false)
if err != nil {
logger.Errorf("Failed to get a client for every cluster member: %w", err)
return response.SyncResponse(false, &responseData)
Expand Down
2 changes: 1 addition & 1 deletion microovn/cmd/microovn/certificates_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (c *cmdCertificatesList) Run(cmd *cobra.Command, _ []string) error {
return err
}

m, err := microcluster.App(context.Background(), microcluster.Args{StateDir: c.common.FlagStateDir, Verbose: c.common.FlagLogVerbose, Debug: c.common.FlagLogDebug})
m, err := microcluster.App(microcluster.Args{StateDir: c.common.FlagStateDir, Verbose: c.common.FlagLogVerbose, Debug: c.common.FlagLogDebug})
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion microovn/cmd/microovn/certificates_regenerate_ca.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (c *cmdCertificatesRegenerateCa) Command() *cobra.Command {
// to issue new CA certificate and re-issue all OVN service certificates across the whole cluster.
func (c *cmdCertificatesRegenerateCa) Run(_ *cobra.Command, _ []string) error {
var response types.RegenerateCaResponse
m, err := microcluster.App(context.Background(), microcluster.Args{StateDir: c.common.FlagStateDir, Verbose: c.common.FlagLogVerbose, Debug: c.common.FlagLogDebug})
m, err := microcluster.App(microcluster.Args{StateDir: c.common.FlagStateDir, Verbose: c.common.FlagLogVerbose, Debug: c.common.FlagLogDebug})
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion microovn/cmd/microovn/certificates_reissue.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (c *cmdCertificatesReissue) Command() *cobra.Command {
// service to issue new certificate for selected OVN service.
func (c *cmdCertificatesReissue) Run(_ *cobra.Command, args []string) error {
var response types.IssueCertificateResponse
m, err := microcluster.App(context.Background(), microcluster.Args{StateDir: c.common.FlagStateDir, Verbose: c.common.FlagLogVerbose, Debug: c.common.FlagLogDebug})
m, err := microcluster.App(microcluster.Args{StateDir: c.common.FlagStateDir, Verbose: c.common.FlagLogVerbose, Debug: c.common.FlagLogDebug})
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions microovn/cmd/microovn/cluster_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ func (c *cmdClusterAdd) Run(cmd *cobra.Command, args []string) error {
return cmd.Help()
}

m, err := microcluster.App(context.Background(), microcluster.Args{StateDir: c.common.FlagStateDir, Verbose: c.common.FlagLogVerbose, Debug: c.common.FlagLogDebug})
m, err := microcluster.App(microcluster.Args{StateDir: c.common.FlagStateDir, Verbose: c.common.FlagLogVerbose, Debug: c.common.FlagLogDebug})
if err != nil {
return err
}

token, err := m.NewJoinToken(args[0])
token, err := m.NewJoinToken(context.Background(), args[0])
if err != nil {
return err
}
Expand Down
5 changes: 2 additions & 3 deletions microovn/cmd/microovn/cluster_bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"os"
"time"

"github.com/canonical/lxd/lxd/util"
"github.com/canonical/microcluster/microcluster"
Expand All @@ -31,7 +30,7 @@ func (c *cmdClusterBootstrap) Run(cmd *cobra.Command, args []string) error {
return cmd.Help()
}

m, err := microcluster.App(context.Background(), microcluster.Args{StateDir: c.common.FlagStateDir, Verbose: c.common.FlagLogVerbose, Debug: c.common.FlagLogDebug})
m, err := microcluster.App(microcluster.Args{StateDir: c.common.FlagStateDir, Verbose: c.common.FlagLogVerbose, Debug: c.common.FlagLogDebug})
if err != nil {
return fmt.Errorf("Unable to configure MicroOVN: %w", err)
}
Expand All @@ -46,5 +45,5 @@ func (c *cmdClusterBootstrap) Run(cmd *cobra.Command, args []string) error {
address := util.NetworkInterfaceAddress()
address = util.CanonicalNetworkAddress(address, 6443)

return m.NewCluster(hostname, address, nil, time.Second*30)
return m.NewCluster(context.Background(), hostname, address, nil)
}
5 changes: 2 additions & 3 deletions microovn/cmd/microovn/cluster_join.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"os"
"time"

"github.com/canonical/lxd/lxd/util"
"github.com/canonical/microcluster/microcluster"
Expand All @@ -31,7 +30,7 @@ func (c *cmdClusterJoin) Run(cmd *cobra.Command, args []string) error {
return cmd.Help()
}

m, err := microcluster.App(context.Background(), microcluster.Args{StateDir: c.common.FlagStateDir, Verbose: c.common.FlagLogVerbose, Debug: c.common.FlagLogDebug})
m, err := microcluster.App(microcluster.Args{StateDir: c.common.FlagStateDir, Verbose: c.common.FlagLogVerbose, Debug: c.common.FlagLogDebug})
if err != nil {
return fmt.Errorf("Unable to configure MicroCluster: %w", err)
}
Expand All @@ -46,5 +45,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], nil, time.Second*30)
return m.JoinCluster(context.Background(), hostname, address, args[0], nil)
}
2 changes: 1 addition & 1 deletion microovn/cmd/microovn/cluster_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (c *cmdClusterList) Command() *cobra.Command {
}

func (c *cmdClusterList) Run(cmd *cobra.Command, args []string) error {
m, err := microcluster.App(context.Background(), microcluster.Args{StateDir: c.common.FlagStateDir, Verbose: c.common.FlagLogVerbose, Debug: c.common.FlagLogDebug})
m, err := microcluster.App(microcluster.Args{StateDir: c.common.FlagStateDir, Verbose: c.common.FlagLogVerbose, Debug: c.common.FlagLogDebug})
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion microovn/cmd/microovn/cluster_remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (c *cmdClusterRemove) Run(cmd *cobra.Command, args []string) error {
return cmd.Help()
}

m, err := microcluster.App(context.Background(), microcluster.Args{StateDir: c.common.FlagStateDir, Verbose: c.common.FlagLogVerbose, Debug: c.common.FlagLogDebug})
m, err := microcluster.App(microcluster.Args{StateDir: c.common.FlagStateDir, Verbose: c.common.FlagLogVerbose, Debug: c.common.FlagLogDebug})
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions microovn/cmd/microovn/cluster_sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ func (c *cmdClusterSQL) Run(cmd *cobra.Command, args []string) error {
}
}

m, err := microcluster.App(context.Background(), microcluster.Args{StateDir: c.common.FlagStateDir, Verbose: c.common.FlagLogVerbose, Debug: c.common.FlagLogDebug})
m, err := microcluster.App(microcluster.Args{StateDir: c.common.FlagStateDir, Verbose: c.common.FlagLogVerbose, Debug: c.common.FlagLogDebug})
if err != nil {
return err
}

query := args[0]
dump, batch, err := m.SQL(query)
dump, batch, err := m.SQL(context.Background(), query)
if err != nil {
return err
}
Expand Down
9 changes: 4 additions & 5 deletions microovn/cmd/microovn/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"os"
"time"

"github.com/canonical/lxd/lxd/util"
"github.com/canonical/microcluster/microcluster"
Expand All @@ -31,7 +30,7 @@ func (c *cmdInit) Command() *cobra.Command {

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})
m, err := microcluster.App(microcluster.Args{StateDir: c.common.FlagStateDir, Verbose: c.common.FlagLogVerbose, Debug: c.common.FlagLogDebug})
if err != nil {
return err
}
Expand Down Expand Up @@ -81,7 +80,7 @@ func (c *cmdInit) Run(cmd *cobra.Command, args []string) error {
}

// Bootstrap the cluster.
err = m.NewCluster(hostName, address, nil, time.Second*30)
err = m.NewCluster(context.Background(), hostName, address, nil)
if err != nil {
return err
}
Expand All @@ -93,7 +92,7 @@ func (c *cmdInit) Run(cmd *cobra.Command, args []string) error {
return err
}

err = m.JoinCluster(hostName, address, token, nil, time.Second*30)
err = m.JoinCluster(context.Background(), hostName, address, token, nil)
if err != nil {
return err
}
Expand Down Expand Up @@ -121,7 +120,7 @@ func (c *cmdInit) Run(cmd *cobra.Command, args []string) error {
}

// Issue the token.
token, err := m.NewJoinToken(tokenName)
token, err := m.NewJoinToken(context.Background(), tokenName)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion microovn/cmd/microovn/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (c *cmdStatus) Command() *cobra.Command {
}

func (c *cmdStatus) Run(cmd *cobra.Command, args []string) error {
m, err := microcluster.App(context.Background(), microcluster.Args{StateDir: c.common.FlagStateDir, Verbose: c.common.FlagLogVerbose, Debug: c.common.FlagLogDebug})
m, err := microcluster.App(microcluster.Args{StateDir: c.common.FlagStateDir, Verbose: c.common.FlagLogVerbose, Debug: c.common.FlagLogDebug})
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions microovn/cmd/microovnd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,20 @@ func (c *cmdDaemon) Command() *cobra.Command {
}

func (c *cmdDaemon) Run(cmd *cobra.Command, args []string) error {
m, err := microcluster.App(context.Background(), microcluster.Args{StateDir: c.flagStateDir, Verbose: c.global.flagLogVerbose, Debug: c.global.flagLogDebug})
m, err := microcluster.App(microcluster.Args{StateDir: c.flagStateDir, Verbose: c.global.flagLogVerbose, Debug: c.global.flagLogDebug})
if err != nil {
return err
}

h := &config.Hooks{}
h.OnBootstrap = ovn.Bootstrap
h.PostBootstrap = ovn.Bootstrap
h.PreJoin = ovn.Join
h.OnNewMember = ovn.Refresh
h.PreRemove = ovn.Leave
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)
return m.Start(context.Background(), api.Endpoints, database.SchemaExtensions, []string{}, h)
}

func init() {
Expand Down
6 changes: 3 additions & 3 deletions microovn/database/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (

// SchemaExtensions is a list of schema extensions that can be passed to the MicroCluster daemon.
// Each entry will increase the database schema version by one, and will be applied after internal schema updates.
var SchemaExtensions = map[int]schema.Update{
1: schemaUpdate1,
2: schemaUpdateCascadeDeleteServices,
var SchemaExtensions = []schema.Update{
schemaUpdate1,
schemaUpdateCascadeDeleteServices,
}

func schemaUpdate1(ctx context.Context, tx *sql.Tx) error {
Expand Down

0 comments on commit 0ad16b7

Please sign in to comment.