fix: resolve the issue with Kubernetes upgrade
Add missing cases, refactoring. Signed-off-by: Alexey Palazhchenko <alexey.palazhchenko@gmail.com>
This commit is contained in:
parent
74b2b5578c
commit
1f5a0c4065
1
go.mod
1
go.mod
@ -25,6 +25,7 @@ require (
|
|||||||
github.com/containernetworking/cni v0.8.1
|
github.com/containernetworking/cni v0.8.1
|
||||||
github.com/containernetworking/plugins v0.9.1
|
github.com/containernetworking/plugins v0.9.1
|
||||||
github.com/coreos/go-iptables v0.5.0
|
github.com/coreos/go-iptables v0.5.0
|
||||||
|
github.com/coreos/go-semver v0.3.0
|
||||||
github.com/docker/distribution v2.7.1+incompatible
|
github.com/docker/distribution v2.7.1+incompatible
|
||||||
github.com/docker/docker v20.10.4+incompatible
|
github.com/docker/docker v20.10.4+incompatible
|
||||||
github.com/docker/go-connections v0.4.0
|
github.com/docker/go-connections v0.4.0
|
||||||
|
@ -24,15 +24,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// UpgradeSelfHosted the Kubernetes control plane.
|
// UpgradeSelfHosted the Kubernetes control plane.
|
||||||
//
|
|
||||||
//nolint:gocyclo
|
|
||||||
func UpgradeSelfHosted(ctx context.Context, cluster cluster.K8sProvider, options UpgradeOptions) error {
|
func UpgradeSelfHosted(ctx context.Context, cluster cluster.K8sProvider, options UpgradeOptions) error {
|
||||||
switch {
|
switch path := options.Path(); path {
|
||||||
case strings.HasPrefix(options.FromVersion, "1.18.") && strings.HasPrefix(options.ToVersion, "1.19."):
|
case "1.18->1.19":
|
||||||
|
fallthrough
|
||||||
|
case "1.19->1.19":
|
||||||
return hyperkubeUpgrade(ctx, cluster, options)
|
return hyperkubeUpgrade(ctx, cluster, options)
|
||||||
case strings.HasPrefix(options.FromVersion, "1.19.") && strings.HasPrefix(options.ToVersion, "1.19."):
|
|
||||||
return hyperkubeUpgrade(ctx, cluster, options)
|
case "1.19->1.20":
|
||||||
case strings.HasPrefix(options.FromVersion, "1.19.") && strings.HasPrefix(options.ToVersion, "1.20."):
|
|
||||||
options.extraUpdaters = append(options.extraUpdaters, addControlPlaneToleration())
|
options.extraUpdaters = append(options.extraUpdaters, addControlPlaneToleration())
|
||||||
options.podCheckpointerExtraUpdaters = append(options.podCheckpointerExtraUpdaters, addControlPlaneToleration())
|
options.podCheckpointerExtraUpdaters = append(options.podCheckpointerExtraUpdaters, addControlPlaneToleration())
|
||||||
|
|
||||||
@ -48,10 +47,16 @@ func UpgradeSelfHosted(ctx context.Context, cluster cluster.K8sProvider, options
|
|||||||
}
|
}
|
||||||
|
|
||||||
return hyperkubeUpgrade(ctx, cluster, options)
|
return hyperkubeUpgrade(ctx, cluster, options)
|
||||||
case strings.HasPrefix(options.FromVersion, "1.20.") && strings.HasPrefix(options.ToVersion, "1.20."):
|
|
||||||
|
case "1.20->1.20":
|
||||||
|
fallthrough
|
||||||
|
case "1.20->1.21":
|
||||||
|
fallthrough
|
||||||
|
case "1.21->1.21":
|
||||||
return hyperkubeUpgrade(ctx, cluster, options)
|
return hyperkubeUpgrade(ctx, cluster, options)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("unsupported upgrade from %q to %q", options.FromVersion, options.ToVersion)
|
return fmt.Errorf("unsupported upgrade path %q (from %q to %q)", path, options.FromVersion, options.ToVersion)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/talos-systems/go-retry/retry"
|
"github.com/talos-systems/go-retry/retry"
|
||||||
@ -34,13 +33,20 @@ type UpgradeProvider interface {
|
|||||||
//
|
//
|
||||||
//nolint:gocyclo
|
//nolint:gocyclo
|
||||||
func UpgradeTalosManaged(ctx context.Context, cluster UpgradeProvider, options UpgradeOptions) error {
|
func UpgradeTalosManaged(ctx context.Context, cluster UpgradeProvider, options UpgradeOptions) error {
|
||||||
switch {
|
switch path := options.Path(); path {
|
||||||
case strings.HasPrefix(options.FromVersion, "1.19.") && strings.HasPrefix(options.ToVersion, "1.19."):
|
case "1.19->1.19":
|
||||||
case strings.HasPrefix(options.FromVersion, "1.19.") && strings.HasPrefix(options.ToVersion, "1.20."):
|
// nothing
|
||||||
|
|
||||||
|
case "1.19->1.20":
|
||||||
options.extraUpdaters = append(options.extraUpdaters, addControlPlaneToleration())
|
options.extraUpdaters = append(options.extraUpdaters, addControlPlaneToleration())
|
||||||
case strings.HasPrefix(options.FromVersion, "1.20.") && strings.HasPrefix(options.ToVersion, "1.20."):
|
|
||||||
|
// nothing for all those
|
||||||
|
case "1.20->1.20":
|
||||||
|
case "1.20->1.21":
|
||||||
|
case "1.21->1.21":
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("unsupported upgrade from %q to %q", options.FromVersion, options.ToVersion)
|
return fmt.Errorf("unsupported upgrade path %q (from %q to %q)", path, options.FromVersion, options.ToVersion)
|
||||||
}
|
}
|
||||||
|
|
||||||
k8sClient, err := cluster.K8sHelper(ctx)
|
k8sClient, err := cluster.K8sHelper(ctx)
|
||||||
|
@ -5,6 +5,9 @@
|
|||||||
package kubernetes
|
package kubernetes
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/coreos/go-semver/semver"
|
||||||
appsv1 "k8s.io/api/apps/v1"
|
appsv1 "k8s.io/api/apps/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -31,4 +34,17 @@ type UpgradeOptions struct {
|
|||||||
masterNodes []string
|
masterNodes []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Path returns upgrade path in a form "FromMajor.FromMinor->ToMajor.ToMinor" (e.g. "1.20->1.21"),
|
||||||
|
// or empty string, if one or both versions can't be parsed.
|
||||||
|
func (options *UpgradeOptions) Path() string {
|
||||||
|
from, fromErr := semver.NewVersion(options.FromVersion)
|
||||||
|
to, toErr := semver.NewVersion(options.ToVersion)
|
||||||
|
|
||||||
|
if fromErr != nil || toErr != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Sprintf("%d.%d->%d.%d", from.Major, from.Minor, to.Major, to.Minor)
|
||||||
|
}
|
||||||
|
|
||||||
type daemonsetUpdater func(ds string, daemonset *appsv1.DaemonSet) error
|
type daemonsetUpdater func(ds string, daemonset *appsv1.DaemonSet) error
|
||||||
|
39
pkg/cluster/kubernetes/upgrade_test.go
Normal file
39
pkg/cluster/kubernetes/upgrade_test.go
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
|
package kubernetes_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
|
"github.com/talos-systems/talos/pkg/cluster/kubernetes"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestPath(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
t.Run("Valid", func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
options := &kubernetes.UpgradeOptions{
|
||||||
|
FromVersion: "1.20.5",
|
||||||
|
ToVersion: "1.21.0-beta.0",
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.Equal(t, "1.20->1.21", options.Path())
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("Invalid", func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
options := &kubernetes.UpgradeOptions{
|
||||||
|
FromVersion: "foo",
|
||||||
|
ToVersion: "bar",
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.Equal(t, "", options.Path())
|
||||||
|
})
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user