Skip to content

Commit

Permalink
fix: upgrade-k8s bug with empty config values and provision script
Browse files Browse the repository at this point in the history
First, if the config for some component image (e.g. `apiServer`) is empty,
Talos pushes default image which is unknown to the script, so verify
that change is not no-op, as otherwise script will hang forvever waiting
for k8s control plane config update.

Second, with bootkube bootstrap it was fine to omit explicit kubernetes
version in upgrade test, but with Talos-managed that means that after
Talos upgrade Kubernetes gets upgraded as well (as Talos config doesn't
contain K8s version, and defaults are used). This is not what we want to
test actually.

Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
(cherry picked from commit 125b86f)
  • Loading branch information
smira committed Mar 19, 2021
1 parent 6ffe084 commit 26c9246
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion internal/integration/provision/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ func (suite *UpgradeSuite) setupCluster() {
&bundle.InputOptions{
ClusterName: clusterName,
Endpoint: suite.controlPlaneEndpoint,
KubeVersion: "", // keep empty so that default version is used per Talos version
KubeVersion: suite.spec.SourceK8sVersion,
GenOptions: append(
genOptions,
generate.WithEndpointList(masterEndpoints),
Expand Down
14 changes: 9 additions & 5 deletions pkg/cluster/kubernetes/talos_managed.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"time"

"github.com/talos-systems/go-retry/retry"
"github.com/talos-systems/os-runtime/pkg/resource"
"github.com/talos-systems/os-runtime/pkg/state"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"

Expand Down Expand Up @@ -120,7 +121,7 @@ func upgradeNodeConfigPatch(ctx context.Context, cluster UpgradeProvider, option

skipConfigWait := false

err = patchNodeConfig(ctx, cluster, node, upgradeConfigPatcher(options, service))
err = patchNodeConfig(ctx, cluster, node, upgradeConfigPatcher(options, service, watchInitial.Resource))
if err != nil {
if errors.Is(err, errUpdateSkipped) {
skipConfigWait = true
Expand Down Expand Up @@ -154,12 +155,15 @@ func upgradeNodeConfigPatch(ctx context.Context, cluster UpgradeProvider, option
var errUpdateSkipped = fmt.Errorf("update skipped")

//nolint:gocyclo
func upgradeConfigPatcher(options UpgradeOptions, service string) func(config *v1alpha1config.Config) error {
func upgradeConfigPatcher(options UpgradeOptions, service string, configResource resource.Resource) func(config *v1alpha1config.Config) error {
return func(config *v1alpha1config.Config) error {
if config.ClusterConfig == nil {
config.ClusterConfig = &v1alpha1config.ClusterConfig{}
}

configData := configResource.(*resource.Any).Value().(map[string]interface{}) //nolint: errcheck,forcetypeassert
configImage := configData["image"].(string) //nolint: errcheck,forcetypeassert

switch service {
case kubeAPIServer:
if config.ClusterConfig.APIServerConfig == nil {
Expand All @@ -168,7 +172,7 @@ func upgradeConfigPatcher(options UpgradeOptions, service string) func(config *v

image := fmt.Sprintf("%s:v%s", constants.KubernetesAPIServerImage, options.ToVersion)

if config.ClusterConfig.APIServerConfig.ContainerImage == image {
if config.ClusterConfig.APIServerConfig.ContainerImage == image || configImage == image {
return errUpdateSkipped
}

Expand All @@ -180,7 +184,7 @@ func upgradeConfigPatcher(options UpgradeOptions, service string) func(config *v

image := fmt.Sprintf("%s:v%s", constants.KubernetesControllerManagerImage, options.ToVersion)

if config.ClusterConfig.ControllerManagerConfig.ContainerImage == image {
if config.ClusterConfig.ControllerManagerConfig.ContainerImage == image || configImage == image {
return errUpdateSkipped
}

Expand All @@ -192,7 +196,7 @@ func upgradeConfigPatcher(options UpgradeOptions, service string) func(config *v

image := fmt.Sprintf("%s:v%s", constants.KubernetesSchedulerImage, options.ToVersion)

if config.ClusterConfig.SchedulerConfig.ContainerImage == image {
if config.ClusterConfig.SchedulerConfig.ContainerImage == image || configImage == image {
return errUpdateSkipped
}

Expand Down

0 comments on commit 26c9246

Please sign in to comment.