Skip to content

Commit

Permalink
fix: leave etcd for staged upgrades
Browse files Browse the repository at this point in the history
Upgrade itself is going to happen after the reboot, but we need to leave
etcd if the disks are to be wiped (!preserve) upgrade.

We're not doing integration test right now, as we need source version
for the upgrade to contain a fix. We can add a test once we release new
version with this fix (dropped a note to look into that later).

Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
  • Loading branch information
smira authored and talos-bot committed Dec 22, 2020
1 parent f1964aa commit e75bb27
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ func (s *Server) Upgrade(ctx context.Context, in *machine.UpgradeRequest) (reply
defer mu.Unlock(ctx) // nolint: errcheck
}

if err := s.Controller.Run(runtime.SequenceReboot, in); err != nil {
if err := s.Controller.Run(runtime.SequenceStageUpgrade, in); err != nil {
log.Println("reboot for staged upgrade failed:", err)

if err != runtime.ErrLocked {
Expand Down
8 changes: 7 additions & 1 deletion internal/app/machined/pkg/runtime/sequencer.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const (
SequenceShutdown
// SequenceUpgrade is the upgrade sequence.
SequenceUpgrade
// SequenceStageUpgrade is the stage upgrade sequence.
SequenceStageUpgrade
// SequenceReset is the reset sequence.
SequenceReset
// SequenceReboot is the reboot sequence.
Expand All @@ -46,6 +48,7 @@ const (
install = "install"
shutdown = "shutdown"
upgrade = "upgrade"
stageUpgrade = "stageUpgrade"
reset = "reset"
reboot = "reboot"
recover = "recover"
Expand All @@ -54,7 +57,7 @@ const (

// String returns the string representation of a `Sequence`.
func (s Sequence) String() string {
return [...]string{applyConfiguration, boot, bootstrap, initialize, install, shutdown, upgrade, reset, reboot, recover, noop}[s]
return [...]string{applyConfiguration, boot, bootstrap, initialize, install, shutdown, upgrade, stageUpgrade, reset, reboot, recover, noop}[s]
}

// ParseSequence returns a `Sequence` that matches the specified string.
Expand All @@ -76,6 +79,8 @@ func ParseSequence(s string) (seq Sequence, err error) {
seq = SequenceShutdown
case upgrade:
seq = SequenceUpgrade
case stageUpgrade:
seq = SequenceStageUpgrade
case reset:
seq = SequenceReset
case reboot:
Expand Down Expand Up @@ -116,6 +121,7 @@ type Sequencer interface {
Recover(Runtime, *machine.RecoverRequest) []Phase
Reset(Runtime, ResetOptions) []Phase
Shutdown(Runtime) []Phase
StageUpgrade(Runtime, *machine.UpgradeRequest) []Phase
Upgrade(Runtime, *machine.UpgradeRequest) []Phase
}

Expand Down
11 changes: 11 additions & 0 deletions internal/app/machined/pkg/runtime/sequencer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ func TestSequence_String(t *testing.T) {
s: runtime.SequenceUpgrade,
want: "upgrade",
},
{
name: "stageUpgrade",
s: runtime.SequenceStageUpgrade,
want: "stageUpgrade",
},
{
name: "reboot",
s: runtime.SequenceReboot,
Expand Down Expand Up @@ -98,6 +103,12 @@ func TestParseSequence(t *testing.T) {
wantSeq: runtime.SequenceUpgrade,
wantErr: false,
},
{
name: "stageUpgrade",
args: args{"stageUpgrade"},
wantSeq: runtime.SequenceStageUpgrade,
wantErr: false,
},
{
name: "reboot",
args: args{"reboot"},
Expand Down
11 changes: 11 additions & 0 deletions internal/app/machined/pkg/runtime/v1alpha1/v1alpha1_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,17 @@ func (c *Controller) phases(seq runtime.Sequence, data interface{}) ([]runtime.P
}

phases = c.s.Upgrade(c.r, in)
case runtime.SequenceStageUpgrade:
var (
in *machine.UpgradeRequest
ok bool
)

if in, ok = data.(*machine.UpgradeRequest); !ok {
return nil, runtime.ErrInvalidSequenceData
}

phases = c.s.StageUpgrade(c.r, in)
case runtime.SequenceReset:
var (
in runtime.ResetOptions
Expand Down
23 changes: 23 additions & 0 deletions internal/app/machined/pkg/runtime/v1alpha1/v1alpha1_sequencer.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,29 @@ func (*Sequencer) Shutdown(r runtime.Runtime) []runtime.Phase {
return phases
}

// StageUpgrade is the stage upgrade sequence.
func (*Sequencer) StageUpgrade(r runtime.Runtime, in *machineapi.UpgradeRequest) []runtime.Phase {
phases := PhaseList{}

switch r.State().Platform().Mode() { //nolint: exhaustive
case runtime.ModeContainer:
return nil
default:
phases = phases.AppendWhen(
!in.GetPreserve() && (r.Config().Machine().Type() != machine.TypeJoin),
"leave",
LeaveEtcd,
).AppendList(
stopAllPhaselist(r),
).Append(
"reboot",
Reboot,
)
}

return phases
}

// Upgrade is the upgrade sequence.
func (*Sequencer) Upgrade(r runtime.Runtime, in *machineapi.UpgradeRequest) []runtime.Phase {
phases := PhaseList{}
Expand Down

0 comments on commit e75bb27

Please sign in to comment.