Skip to content

Commit

Permalink
lxd/main_cluster: Fix linter errors
Browse files Browse the repository at this point in the history
Signed-off-by: Wesley Hershberger <[email protected]>
  • Loading branch information
MggMuggins committed Jul 15, 2024
1 parent 197e0bd commit f34fd5c
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions lxd/main_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type cmdCluster struct {
global *cmdGlobal
}

// Command returns a subcommand for administrating a cluster.
func (c *cmdCluster) Command() *cobra.Command {
cmd := &cobra.Command{}
cmd.Use = "cluster"
Expand All @@ -55,8 +56,8 @@ func (c *cmdCluster) Command() *cobra.Command {
cmd.AddCommand(listDatabase.Command())

// Recover
recover := cmdClusterRecoverFromQuorumLoss{global: c.global}
cmd.AddCommand(recover.Command())
clusterRecover := cmdClusterRecoverFromQuorumLoss{global: c.global}
cmd.AddCommand(clusterRecover.Command())

// Remove a raft node.
removeRaftNode := cmdClusterRemoveRaftNode{global: c.global}
Expand All @@ -76,7 +77,7 @@ func (c *cmdCluster) Command() *cobra.Command {
return cmd
}

const SegmentComment = "# Latest dqlite segment ID: %s"
const segmentComment = "# Latest dqlite segment ID: %s"

// ClusterMember is a more human-readable representation of the db.RaftNode struct.
type ClusterMember struct {
Expand Down Expand Up @@ -142,6 +143,7 @@ type cmdClusterEdit struct {
global *cmdGlobal
}

// Command returns a command for reconfiguring a cluster.
func (c *cmdClusterEdit) Command() *cobra.Command {
cmd := &cobra.Command{}
cmd.Use = "edit"
Expand All @@ -153,6 +155,7 @@ func (c *cmdClusterEdit) Command() *cobra.Command {
return cmd
}

// Run executes the command for reconfiguring a cluster.
func (c *cmdClusterEdit) Run(cmd *cobra.Command, args []string) error {
// Make sure that the daemon is not running.
_, err := lxd.ConnectLXDUnix("", nil)
Expand Down Expand Up @@ -216,7 +219,7 @@ func (c *cmdClusterEdit) Run(cmd *cobra.Command, args []string) error {
if len(config.Members) > 0 {
data = []byte(
clusterEditComment + "\n\n" +
fmt.Sprintf(SegmentComment, segmentID) + "\n\n" +
fmt.Sprintf(segmentComment, segmentID) + "\n\n" +
string(data))
}

Expand Down Expand Up @@ -323,6 +326,7 @@ type cmdClusterShow struct {
global *cmdGlobal
}

// Command returns a command for showing the current cluster configuration.
func (c *cmdClusterShow) Command() *cobra.Command {
cmd := &cobra.Command{}
cmd.Use = "show"
Expand All @@ -334,6 +338,7 @@ func (c *cmdClusterShow) Command() *cobra.Command {
return cmd
}

// Run executes the command for showing the current cluster configuration.
func (c *cmdClusterShow) Run(cmd *cobra.Command, args []string) error {
database, err := db.OpenNode(filepath.Join(sys.DefaultOS().VarDir, "database"), nil)
if err != nil {
Expand Down Expand Up @@ -368,7 +373,7 @@ func (c *cmdClusterShow) Run(cmd *cobra.Command, args []string) error {
}

if len(config.Members) > 0 {
fmt.Printf(SegmentComment+"\n\n%s", segmentID, data)
fmt.Printf(segmentComment+"\n\n%s", segmentID, data)
} else {
fmt.Print(data)
}
Expand All @@ -380,6 +385,7 @@ type cmdClusterListDatabase struct {
global *cmdGlobal
}

// Command returns a command for showing the database roles of cluster members.
func (c *cmdClusterListDatabase) Command() *cobra.Command {
cmd := &cobra.Command{}
cmd.Use = "list-database"
Expand All @@ -391,6 +397,7 @@ func (c *cmdClusterListDatabase) Command() *cobra.Command {
return cmd
}

// Run executes the command for showing the database roles of cluster members.
func (c *cmdClusterListDatabase) Run(cmd *cobra.Command, args []string) error {
os := sys.DefaultOS()

Expand Down Expand Up @@ -436,6 +443,7 @@ type cmdClusterRecoverFromQuorumLoss struct {
flagNonInteractive bool
}

// Command returns a command for rebuilding a cluster based on the current member.
func (c *cmdClusterRecoverFromQuorumLoss) Command() *cobra.Command {
cmd := &cobra.Command{}
cmd.Use = "recover-from-quorum-loss"
Expand All @@ -448,6 +456,7 @@ func (c *cmdClusterRecoverFromQuorumLoss) Command() *cobra.Command {
return cmd
}

// Run executes the command for rebuilding a cluster based on the current member.
func (c *cmdClusterRecoverFromQuorumLoss) Run(cmd *cobra.Command, args []string) error {
// Make sure that the daemon is not running.
_, err := lxd.ConnectLXDUnix("", nil)
Expand Down Expand Up @@ -482,6 +491,7 @@ type cmdClusterRemoveRaftNode struct {
flagNonInteractive bool
}

// Command returns a command for removing a raft node from the currently running database.
func (c *cmdClusterRemoveRaftNode) Command() *cobra.Command {
cmd := &cobra.Command{}
cmd.Use = "remove-raft-node <address>"
Expand All @@ -494,6 +504,7 @@ func (c *cmdClusterRemoveRaftNode) Command() *cobra.Command {
return cmd
}

// Run executes the command for removing a raft node from the currently running database.
func (c *cmdClusterRemoveRaftNode) Run(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
_ = cmd.Help()
Expand Down

0 comments on commit f34fd5c

Please sign in to comment.