Skip to content

Commit

Permalink
Merge pull request canonical#365 from masnax/update-microcluster
Browse files Browse the repository at this point in the history
Update microcluster dependency
  • Loading branch information
sabaini authored Jun 12, 2024
2 parents bc3fe1e + 9784bbf commit 556b907
Show file tree
Hide file tree
Showing 33 changed files with 150 additions and 141 deletions.
7 changes: 4 additions & 3 deletions microceph/client/client_configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package client
import (
"context"
"fmt"
"github.com/canonical/microceph/microceph/interfaces"
"time"

"github.com/canonical/lxd/shared/api"
"github.com/canonical/lxd/shared/logger"
"github.com/canonical/microceph/microceph/api/types"
"github.com/canonical/microcluster/client"

"github.com/canonical/microceph/microceph/api/types"
"github.com/canonical/microceph/microceph/interfaces"
)

func SetClientConfig(ctx context.Context, c *client.Client, data *types.ClientConfig) error {
Expand Down Expand Up @@ -80,7 +81,7 @@ func UpdateClientConf(ctx context.Context, c *client.Client) error {
// Sends the update conf request to every other member of the cluster.
func SendUpdateClientConfRequestToClusterMembers(s interfaces.StateInterface) error {
// Get a collection of clients to every other cluster member, with the notification user-agent set.
cluster, err := s.ClusterState().Cluster(nil)
cluster, err := s.ClusterState().Cluster(false)
if err != nil {
logger.Errorf("failed to get a client for every cluster member: %v", err)
return err
Expand Down
5 changes: 3 additions & 2 deletions microceph/client/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import (

"github.com/canonical/lxd/shared/api"
"github.com/canonical/lxd/shared/logger"
"github.com/canonical/microceph/microceph/api/types"
"github.com/canonical/microcluster/client"
"github.com/canonical/microcluster/state"

"github.com/canonical/microceph/microceph/api/types"
)

// GetServices returns the list of configured ceph services.
Expand Down Expand Up @@ -84,7 +85,7 @@ func SendRestartRequestToClusterMembers(s *state.State, services []string) error
}

// Get a collection of clients to every other cluster member, with the notification user-agent set.
cluster, err := s.Cluster(nil)
cluster, err := s.Cluster(false)
if err != nil {
logger.Errorf("failed to get a client for every cluster member: %v", err)
return err
Expand Down
7 changes: 4 additions & 3 deletions microceph/cmd/microceph/client_config_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import (
"fmt"

lxdCmd "github.com/canonical/lxd/shared/cmd"
"github.com/canonical/microcluster/microcluster"
"github.com/spf13/cobra"

"github.com/canonical/microceph/microceph/api/types"
"github.com/canonical/microceph/microceph/ceph"
"github.com/canonical/microceph/microceph/client"
"github.com/canonical/microcluster/microcluster"
"github.com/spf13/cobra"
)

type cmdClientConfigGet struct {
Expand Down Expand Up @@ -45,7 +46,7 @@ func (c *cmdClientConfigGet) Run(cmd *cobra.Command, args []string) error {
return fmt.Errorf("key %s is invalid. \nSupported Keys: %v", args[0], allowList.Keys())
}

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 MicroCeph: %w", err)
}
Expand Down
7 changes: 4 additions & 3 deletions microceph/cmd/microceph/client_config_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (
"fmt"

lxdCmd "github.com/canonical/lxd/shared/cmd"
"github.com/canonical/microceph/microceph/api/types"
"github.com/canonical/microceph/microceph/client"
"github.com/canonical/microcluster/microcluster"
"github.com/spf13/cobra"

"github.com/canonical/microceph/microceph/api/types"
"github.com/canonical/microceph/microceph/client"
)

type cmdClientConfigList struct {
Expand Down Expand Up @@ -36,7 +37,7 @@ func (c *cmdClientConfigList) 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 MicroCeph: %w", err)
}
Expand Down
9 changes: 5 additions & 4 deletions microceph/cmd/microceph/client_config_reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package main
import (
"context"
"fmt"
"github.com/canonical/microceph/microceph/constants"

"github.com/canonical/microcluster/microcluster"
"github.com/spf13/cobra"

"github.com/canonical/microceph/microceph/api/types"
"github.com/canonical/microceph/microceph/ceph"
"github.com/canonical/microceph/microceph/client"
"github.com/canonical/microcluster/microcluster"
"github.com/spf13/cobra"
"github.com/canonical/microceph/microceph/constants"
)

type cmdClientConfigReset struct {
Expand Down Expand Up @@ -52,7 +53,7 @@ func (c *cmdClientConfigReset) Run(cmd *cobra.Command, args []string) error {
args[0], constants.CliForcePrompt)
}

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 MicroCeph: %w", err)
}
Expand Down
7 changes: 4 additions & 3 deletions microceph/cmd/microceph/client_config_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"context"
"fmt"

"github.com/canonical/microcluster/microcluster"
"github.com/spf13/cobra"

"github.com/canonical/microceph/microceph/api/types"
"github.com/canonical/microceph/microceph/ceph"
"github.com/canonical/microceph/microceph/client"
"github.com/canonical/microcluster/microcluster"
"github.com/spf13/cobra"
)

type cmdClientConfigSet struct {
Expand Down Expand Up @@ -44,7 +45,7 @@ func (c *cmdClientConfigSet) Run(cmd *cobra.Command, args []string) error {
return fmt.Errorf("configuring key %s is not supported.\nSupported Keys: %v", args[0], allowList.Keys())
}

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 MicroCeph: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions microceph/cmd/microceph/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
13 changes: 8 additions & 5 deletions microceph/cmd/microceph/cluster_bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (
"os"
"time"

"github.com/canonical/microceph/microceph/constants"

"github.com/canonical/lxd/lxd/util"
"github.com/canonical/microceph/microceph/common"
"github.com/canonical/microcluster/microcluster"
"github.com/spf13/cobra"

"github.com/canonical/microceph/microceph/common"
"github.com/canonical/microceph/microceph/constants"
)

type cmdClusterBootstrap struct {
Expand Down Expand Up @@ -43,7 +43,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 MicroCeph: %w", err)
}
Expand Down Expand Up @@ -74,7 +74,10 @@ func (c *cmdClusterBootstrap) Run(cmd *cobra.Command, args []string) error {
}

// Bootstrap microcluster.
err = m.NewCluster(hostname, address, common.EncodeBootstrapConfig(data), time.Second*60)
ctx, cancel := context.WithTimeout(context.Background(), time.Second*60)
defer cancel()

err = m.NewCluster(ctx, hostname, address, common.EncodeBootstrapConfig(data))
if err != nil {
return err
}
Expand Down
7 changes: 4 additions & 3 deletions microceph/cmd/microceph/cluster_config_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import (
"fmt"

lxdCmd "github.com/canonical/lxd/shared/cmd"
"github.com/canonical/microcluster/microcluster"
"github.com/spf13/cobra"

"github.com/canonical/microceph/microceph/api/types"
"github.com/canonical/microceph/microceph/ceph"
"github.com/canonical/microceph/microceph/client"
"github.com/canonical/microcluster/microcluster"
"github.com/spf13/cobra"
)

type cmdClusterConfigGet struct {
Expand Down Expand Up @@ -40,7 +41,7 @@ func (c *cmdClusterConfigGet) Run(cmd *cobra.Command, args []string) error {
return fmt.Errorf("Key %s is invalid. \nPermitted Keys: %v", args[0], allowList.Keys())
}

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 MicroCeph: %w", err)
}
Expand Down
7 changes: 4 additions & 3 deletions microceph/cmd/microceph/cluster_config_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (
"fmt"

lxdCmd "github.com/canonical/lxd/shared/cmd"
"github.com/canonical/microceph/microceph/api/types"
"github.com/canonical/microceph/microceph/client"
"github.com/canonical/microcluster/microcluster"
"github.com/spf13/cobra"

"github.com/canonical/microceph/microceph/api/types"
"github.com/canonical/microceph/microceph/client"
)

type cmdClusterConfigList struct {
Expand All @@ -32,7 +33,7 @@ func (c *cmdClusterConfigList) 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 MicroCeph: %w", err)
}
Expand Down
7 changes: 4 additions & 3 deletions microceph/cmd/microceph/cluster_config_reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"context"
"fmt"

"github.com/canonical/microcluster/microcluster"
"github.com/spf13/cobra"

"github.com/canonical/microceph/microceph/api/types"
"github.com/canonical/microceph/microceph/ceph"
"github.com/canonical/microceph/microceph/client"
"github.com/canonical/microcluster/microcluster"
"github.com/spf13/cobra"
)

type cmdClusterConfigReset struct {
Expand Down Expand Up @@ -40,7 +41,7 @@ func (c *cmdClusterConfigReset) Run(cmd *cobra.Command, args []string) error {
return fmt.Errorf("Resetting key %s is not allowed", args[0])
}

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 MicroCeph: %w", err)
}
Expand Down
7 changes: 4 additions & 3 deletions microceph/cmd/microceph/cluster_config_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"context"
"fmt"

"github.com/canonical/microcluster/microcluster"
"github.com/spf13/cobra"

"github.com/canonical/microceph/microceph/api/types"
"github.com/canonical/microceph/microceph/ceph"
"github.com/canonical/microceph/microceph/client"
"github.com/canonical/microcluster/microcluster"
"github.com/spf13/cobra"
)

type cmdClusterConfigSet struct {
Expand Down Expand Up @@ -40,7 +41,7 @@ func (c *cmdClusterConfigSet) Run(cmd *cobra.Command, args []string) error {
return fmt.Errorf("Configuring key %s is not allowed. \nPermitted Keys: %v", args[0], allowList.Keys())
}

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 MicroCeph: %w", err)
}
Expand Down
10 changes: 7 additions & 3 deletions microceph/cmd/microceph/cluster_join.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import (
"time"

"github.com/canonical/lxd/lxd/util"
"github.com/canonical/microceph/microceph/constants"
"github.com/canonical/microcluster/microcluster"
"github.com/spf13/cobra"

"github.com/canonical/microceph/microceph/constants"
)

type cmdClusterJoin struct {
Expand All @@ -35,7 +36,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 @@ -54,5 +55,8 @@ func (c *cmdClusterJoin) Run(cmd *cobra.Command, args []string) error {
address = util.CanonicalNetworkAddress(address, constants.BootstrapPortConst)

token := args[0]
return m.JoinCluster(hostname, address, token, nil, time.Minute*5)
ctx, cancel := context.WithTimeout(context.Background(), time.Minute*5)
defer cancel()

return m.JoinCluster(ctx, hostname, address, token, nil)
}
2 changes: 1 addition & 1 deletion microceph/cmd/microceph/cluster_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,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
7 changes: 4 additions & 3 deletions microceph/cmd/microceph/cluster_migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"context"

"github.com/canonical/lxd/shared/logger"
"github.com/canonical/microceph/microceph/api/types"
"github.com/canonical/microceph/microceph/client"
"github.com/canonical/microcluster/microcluster"
"github.com/spf13/cobra"

"github.com/canonical/microceph/microceph/api/types"
"github.com/canonical/microceph/microceph/client"
)

type cmdClusterMigrate struct {
Expand All @@ -29,7 +30,7 @@ func (c *cmdClusterMigrate) 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
5 changes: 2 additions & 3 deletions microceph/cmd/microceph/cluster_remove.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package main

import (
"context"
"fmt"

"github.com/canonical/lxd/shared/logger"
microCli "github.com/canonical/microcluster/client"

"github.com/canonical/microcluster/microcluster"
"github.com/spf13/cobra"

Expand Down Expand Up @@ -36,7 +35,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 microceph/cmd/microceph/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
Loading

0 comments on commit 556b907

Please sign in to comment.