Skip to content

Commit

Permalink
bug: do not fail to install if no embedded cluster installation (#4362)
Browse files Browse the repository at this point in the history
* bug: do not fail to install if no embedded cluster installation

if no embedded cluster installation object has been found in the cluster
we can't start an upgrade. on this case (where the installation does not
exists) we shouldn't be failing but moving on instead.

during the initial cluster bootstrap the installation object may take a
while to be created therefore a scenario where the kots app is installed
but no installation object exists is valid.

* chore: fixed comment

* Update pkg/embeddedcluster/monitor.go

Co-authored-by: Andrew Lavery <[email protected]>

---------

Co-authored-by: Andrew Lavery <[email protected]>
  • Loading branch information
ricardomaraschini and laverya authored Jan 16, 2024
1 parent ec82ef4 commit f8f4479
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
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.
// (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

0 comments on commit f8f4479

Please sign in to comment.