Skip to content

Commit

Permalink
fix(k0s): images do not get updated on upgrades (#1320)
Browse files Browse the repository at this point in the history
* fix(k0s): images do not get updated on upgrades

* f

* f

* f

* f

* f

* f

* Trigger Build
  • Loading branch information
emosbaugh authored Oct 15, 2024
1 parent 393accf commit 0851b39
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
File renamed without changes.
36 changes: 35 additions & 1 deletion operator/pkg/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@ package upgrade
import (
"context"
"fmt"
"reflect"
"time"

apv1b2 "github.com/k0sproject/k0s/pkg/apis/autopilot/v1beta2"
k0sv1beta1 "github.com/k0sproject/k0s/pkg/apis/k0s/v1beta1"
"github.com/replicatedhq/embedded-cluster/kinds/apis/v1beta1"
clusterv1beta1 "github.com/replicatedhq/embedded-cluster/kinds/apis/v1beta1"
"github.com/replicatedhq/embedded-cluster/operator/pkg/autopilot"
"github.com/replicatedhq/embedded-cluster/operator/pkg/charts"
"github.com/replicatedhq/embedded-cluster/operator/pkg/k8sutil"
"github.com/replicatedhq/embedded-cluster/operator/pkg/registry"
"github.com/replicatedhq/embedded-cluster/operator/pkg/release"
"github.com/replicatedhq/embedded-cluster/pkg/config"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/util/wait"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -27,7 +30,12 @@ const (
// Upgrade upgrades the embedded cluster to the version specified in the installation.
// First the k0s cluster is upgraded, then addon charts are upgraded, and finally the installation is unlocked.
func Upgrade(ctx context.Context, cli client.Client, in *clusterv1beta1.Installation) error {
err := k0sUpgrade(ctx, cli, in)
err := clusterConfigUpdate(ctx, cli, in)
if err != nil {
return fmt.Errorf("cluster config update: %w", err)
}

err = k0sUpgrade(ctx, cli, in)
if err != nil {
return fmt.Errorf("k0s upgrade: %w", err)
}
Expand Down Expand Up @@ -142,6 +150,32 @@ func k0sUpgrade(ctx context.Context, cli client.Client, in *clusterv1beta1.Insta
return nil
}

// clusterConfigUpdate updates the cluster config with the latest images.
func clusterConfigUpdate(ctx context.Context, cli client.Client, in *clusterv1beta1.Installation) error {
var currentCfg k0sv1beta1.ClusterConfig
err := cli.Get(ctx, client.ObjectKey{Name: "k0s", Namespace: "kube-system"}, &currentCfg)
if err != nil {
return fmt.Errorf("get cluster config: %w", err)
}

cfg := config.RenderK0sConfig()
if currentCfg.Spec.Images != nil {
if reflect.DeepEqual(*currentCfg.Spec.Images, *cfg.Spec.Images) {
return nil
}
}

currentCfg.Spec.Images = cfg.Spec.Images

err = cli.Update(ctx, &currentCfg)
if err != nil {
return fmt.Errorf("update cluster config: %w", err)
}
fmt.Println("Updated cluster config with new images")

return nil
}

// registryMigrationStatus ensures that the registry migration complete condition is set orior to
// reconciling the helm charts. Otherwise, the registry chart will revert back to non-ha mode.
func registryMigrationStatus(ctx context.Context, cli client.Client, in *clusterv1beta1.Installation) error {
Expand Down

0 comments on commit 0851b39

Please sign in to comment.