Skip to content

Commit

Permalink
Skip the error if forced to enter maintenance mode
Browse files Browse the repository at this point in the history
Signed-off-by: Chi Wai Chan <[email protected]>
  • Loading branch information
chanchiwai-ray committed Jan 3, 2025
1 parent 5d850e1 commit 81663ad
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
7 changes: 6 additions & 1 deletion microceph/ceph/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@ import (
)

// RunOperations runs the provided operations or prints out the action plan.
func RunOperations(name string, operations []Operation, dryRun bool) error {
func RunOperations(name string, operations []Operation, dryRun, force bool) error {
for _, ops := range operations {
if dryRun {
fmt.Println(ops.DryRun(name))
} else {
err := ops.Run(name)
if err != nil {
logger.Errorf("%v", err)
// Skip the error if forced
if force {
return nil
}
return err
}
}
Expand Down
14 changes: 4 additions & 10 deletions microceph/cmd/microceph/cluster_maintenance_enter.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,8 @@ func (c *cmdClusterMaintenanceEnter) Run(cmd *cobra.Command, args []string) erro
clusterOps := ceph.ClusterOps{CephClient: client.MClient, ClusterClient: cli}
operations := []ceph.Operation{
&ceph.CheckNodeInClusterOps{ClusterOps: clusterOps},
}

// pre-flight checks
if !c.flagForce {
operations = append(operations, []ceph.Operation{
&ceph.CheckOsdOkToStopOps{ClusterOps: clusterOps},
&ceph.CheckNonOsdSvcEnoughOps{ClusterOps: clusterOps, MinMon: 3, MinMds: 1, MinMgr: 1},
}...)
&ceph.CheckOsdOkToStopOps{ClusterOps: clusterOps},
&ceph.CheckNonOsdSvcEnoughOps{ClusterOps: clusterOps, MinMon: 3, MinMds: 1, MinMgr: 1},
}

// optionally set noout
Expand All @@ -76,9 +70,9 @@ func (c *cmdClusterMaintenanceEnter) Run(cmd *cobra.Command, args []string) erro
}...)
}

err = ceph.RunOperations(name, operations, c.flagDryRun)
err = ceph.RunOperations(name, operations, c.flagDryRun, c.flagForce)
if err != nil {
return fmt.Errorf("Failed to enter maintenance mode: %v", err)
return fmt.Errorf("failed to enter maintenance mode: %v", err)
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions microceph/cmd/microceph/cluster_maintenance_exit.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ func (c *cmdClusterMaintenanceExit) Run(cmd *cobra.Command, args []string) error
&ceph.StartOsdOps{ClusterOps: clusterOps},
}...)

err = ceph.RunOperations(name, operations, c.flagDryRun)
err = ceph.RunOperations(name, operations, c.flagDryRun, false)
if err != nil {
return fmt.Errorf("Failed to exit maintenance mode: %v", err)
return fmt.Errorf("failed to exit maintenance mode: %v", err)
}

return nil
Expand Down

0 comments on commit 81663ad

Please sign in to comment.