Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: do not fail to install if no embedded cluster installation #4362

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions pkg/embeddedcluster/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package embeddedcluster

import (
"context"
"errors"
"fmt"
"sync"
"time"
Expand All @@ -18,6 +19,7 @@ var stateMut = sync.Mutex{}
// it starts the upgrade process. We only start an upgrade if the following conditions are met:
// - The app has an embedded cluster configuration.
// - The app embedded cluster configuration differs from the current embedded cluster config.
// - The current cluster config (as part of the Installation object) already exists in the cluster.
func MaybeStartClusterUpgrade(ctx context.Context, client kubernetes.Interface, store store.Store, conf *v1beta1.Config) error {
if conf == nil {
return nil
Expand All @@ -33,6 +35,13 @@ func MaybeStartClusterUpgrade(ctx context.Context, client kubernetes.Interface,

spec := conf.Spec
if upgrade, err := RequiresUpgrade(ctx, spec); err != nil {
// if there is no installation object we can't start an upgrade. this is a valid
// scenario specially during cluster bootstrap. as we do not need to upgrade the
// cluster just after its installation we can return nil here.
ricardomaraschini marked this conversation as resolved.
Show resolved Hide resolved
// (the cluster in the first kots version will match the cluster installed during bootstrap)
if errors.Is(err, ErrNoInstallations) {
return nil
}
return fmt.Errorf("failed to check if upgrade is required: %w", err)
} else if !upgrade {
return nil
Expand Down
5 changes: 4 additions & 1 deletion pkg/embeddedcluster/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import (
const configMapName = "embedded-cluster-config"
const configMapNamespace = "embedded-cluster"

// ErrNoInstallations is returned when no installation object is found in the cluster.
var ErrNoInstallations = fmt.Errorf("no installations found")

// ReadConfigMap will read the Kurl config from a configmap
func ReadConfigMap(client kubernetes.Interface) (*corev1.ConfigMap, error) {
return client.CoreV1().ConfigMaps(configMapNamespace).Get(context.TODO(), configMapName, metav1.GetOptions{})
Expand Down Expand Up @@ -96,7 +99,7 @@ func GetCurrentInstallation(ctx context.Context) (*embeddedclusterv1beta1.Instal
return nil, fmt.Errorf("failed to list installations: %w", err)
}
if len(installationList.Items) == 0 {
return nil, fmt.Errorf("no installations found")
return nil, ErrNoInstallations
}
items := installationList.Items
sort.SliceStable(items, func(i, j int) bool {
Expand Down
Loading