Skip to content

Commit

Permalink
feat: add powercycle mode in reboot
Browse files Browse the repository at this point in the history
- Fixes #4569
- Updated reboot process sequence
- Updted api.descriptors to avoid proto type change linting error #4612 (comment)
Signed-off-by: Rohit Dandamudi <rohit.dandamudi@siderolabs.com>

Signed-off-by: Rohit Dandamudi <rohit.dandamudi@siderolabs.com>
  • Loading branch information
Rohit Dandamudi committed Dec 2, 2021
1 parent bc69f6e commit 7f99222
Show file tree
Hide file tree
Showing 12 changed files with 2,329 additions and 2,020 deletions.
Binary file modified api/api.descriptors
Binary file not shown.
10 changes: 9 additions & 1 deletion api/machine/machine.proto
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ service MachineService {
rpc NetworkDeviceStats(google.protobuf.Empty) returns (NetworkDeviceStatsResponse);
rpc Processes(google.protobuf.Empty) returns (ProcessesResponse);
rpc Read(ReadRequest) returns (stream common.Data);
rpc Reboot(google.protobuf.Empty) returns (RebootResponse);
rpc Reboot(RebootRequest) returns (RebootResponse);
rpc Restart(RestartRequest) returns (RestartResponse);
rpc Rollback(RollbackRequest) returns (RollbackResponse);
rpc Reset(ResetRequest) returns (ResetResponse);
Expand Down Expand Up @@ -90,6 +90,14 @@ message ApplyConfigurationResponse {
}

// rpc reboot
message RebootRequest {
enum Mode {
DEFAULT = 0;
POWERCYCLE = 1;
}
Mode mode = 1;
}

// The reboot message containing the reboot status.
message Reboot {
common.Metadata metadata = 1;
Expand Down
15 changes: 14 additions & 1 deletion cmd/talosctl/cmd/talos/reboot.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,19 @@ var rebootCmd = &cobra.Command{
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return WithClient(func(ctx context.Context, c *client.Client) error {
if err := c.Reboot(ctx); err != nil {
mode, err := cmd.Flags().GetString("mode")
if err != nil {
return fmt.Errorf("error getting input value for --mode flag: %s", err)
}

opts := []client.RebootMode{}

// skips kexec and reboots with power cycle
if mode == "powercycle" {
opts = append(opts, client.WithPowerCycle)
}

if err := c.Reboot(ctx, opts...); err != nil {
return fmt.Errorf("error executing reboot: %s", err)
}

Expand All @@ -31,5 +43,6 @@ var rebootCmd = &cobra.Command{
}

func init() {
rebootCmd.Flags().StringP("mode", "m", "default", "select the reboot mode: \"default\", \"powercyle\" (skips kexec)")
addCommand(rebootCmd)
}
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func (s *Server) GenerateConfiguration(ctx context.Context, in *machine.Generate
// Reboot implements the machine.MachineServer interface.
//
//nolint:dupl
func (s *Server) Reboot(ctx context.Context, in *emptypb.Empty) (reply *machine.RebootResponse, err error) {
func (s *Server) Reboot(ctx context.Context, in *machine.RebootRequest) (reply *machine.RebootResponse, err error) {
log.Printf("reboot via API received")

if err := s.checkSupported(runtime.Reboot); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1754,6 +1754,14 @@ func ActivateLogicalVolumes(seq runtime.Sequence, data interface{}) (runtime.Tas
//nolint:gocyclo
func KexecPrepare(seq runtime.Sequence, data interface{}) (runtime.TaskExecutionFunc, string) {
return func(ctx context.Context, logger *log.Logger, r runtime.Runtime) error {
if req, ok := data.(*machineapi.RebootRequest); ok {
if req.Mode == machineapi.RebootRequest_POWERCYCLE {
log.Print("kexec skipped as reboot with power cycle was requested")

return nil
}
}

if r.Config() == nil {
return nil
}
Expand Down
3 changes: 1 addition & 2 deletions internal/integration/api/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"time"

"google.golang.org/grpc/codes"
"google.golang.org/protobuf/types/known/emptypb"

"github.com/talos-systems/talos/internal/integration/base"
machineapi "github.com/talos-systems/talos/pkg/machinery/api/machine"
Expand Down Expand Up @@ -137,7 +136,7 @@ func (suite *EtcdSuite) TestEtcdLeaveCluster() {
// NB: Reboot the node so that it can rejoin the etcd cluster. This allows us
// to check the cluster health and catch any issues in rejoining.
suite.AssertRebooted(suite.ctx, node, func(nodeCtx context.Context) error {
_, err = suite.Client.MachineClient.Reboot(nodeCtx, &emptypb.Empty{})
_, err = suite.Client.MachineClient.Reboot(nodeCtx, &machineapi.RebootRequest{})

return err
}, 10*time.Minute)
Expand Down

0 comments on commit 7f99222

Please sign in to comment.