Skip to content

Commit

Permalink
Publish a list of pending charts as part of the installation status (#…
Browse files Browse the repository at this point in the history
…164)

* update embedded-cluster-kinds to add new status field

* set pending charts when relevant
  • Loading branch information
laverya authored May 6, 2024
1 parent 977eddc commit b592fc7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 28 deletions.
43 changes: 22 additions & 21 deletions controllers/installation_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ func (r *InstallationReconciler) ReconcileK0sVersion(ctx context.Context, in *v1
// cluster then there is no upgrade to be executed, just set it to Installed and
// move on.
if in.Spec.Config == nil || in.Spec.Config.Version == "" || uniqinst {
in.Status.SetState(v1beta1.InstallationStateKubernetesInstalled, "")
in.Status.SetState(v1beta1.InstallationStateKubernetesInstalled, "", nil)
return nil
}

Expand All @@ -501,7 +501,7 @@ func (r *InstallationReconciler) ReconcileK0sVersion(ctx context.Context, in *v1
// fetch the metadata for the desired embedded cluster version.
meta, err := release.MetadataFor(ctx, in, r.Client)
if err != nil {
in.Status.SetState(v1beta1.InstallationStateFailed, err.Error())
in.Status.SetState(v1beta1.InstallationStateFailed, err.Error(), nil)
return nil
}

Expand All @@ -515,7 +515,7 @@ func (r *InstallationReconciler) ReconcileK0sVersion(ctx context.Context, in *v1
running, err := version.NewVersion(runningVersion)
if err != nil {
reason := fmt.Sprintf("Invalid running version %s", runningVersion)
in.Status.SetState(v1beta1.InstallationStateFailed, reason)
in.Status.SetState(v1beta1.InstallationStateFailed, reason, nil)
return nil
}

Expand All @@ -527,21 +527,21 @@ func (r *InstallationReconciler) ReconcileK0sVersion(ctx context.Context, in *v1
index := strings.Index(desiredVersion, "k0s")
if index == -1 {
reason := fmt.Sprintf("Invalid desired version %s", desiredVersion)
in.Status.SetState(v1beta1.InstallationStateFailed, reason)
in.Status.SetState(v1beta1.InstallationStateFailed, reason, nil)
return nil
}
desiredVersion = desiredVersion[:index+len("k0s")]
desired, err := version.NewVersion(desiredVersion)
if err != nil {
reason := fmt.Sprintf("Invalid desired version %s", in.Spec.Config.Version)
in.Status.SetState(v1beta1.InstallationStateFailed, reason)
in.Status.SetState(v1beta1.InstallationStateFailed, reason, nil)
return nil
}

// stop here if someone is trying a downgrade. we do not support this, flag the
// installation accordingly and returns.
if running.GreaterThan(desired) {
in.Status.SetState(v1beta1.InstallationStateFailed, "Downgrades not supported")
in.Status.SetState(v1beta1.InstallationStateFailed, "Downgrades not supported", nil)
return nil
}

Expand Down Expand Up @@ -584,7 +584,7 @@ func (r *InstallationReconciler) ReconcileK0sVersion(ctx context.Context, in *v1
// issues multiple upgrade requests at the same time.
if !autopilot.HasThePlanEnded(plan) {
reason := fmt.Sprintf("Another upgrade is in progress (%s)", plan.Spec.ID)
in.Status.SetState(v1beta1.InstallationStateWaiting, reason)
in.Status.SetState(v1beta1.InstallationStateWaiting, reason, nil)
return nil
}

Expand All @@ -601,7 +601,7 @@ func (r *InstallationReconciler) ReconcileK0sVersion(ctx context.Context, in *v1
func (r *InstallationReconciler) ReconcileHelmCharts(ctx context.Context, in *v1beta1.Installation) error {
if in.Spec.Config == nil || in.Spec.Config.Version == "" {
if in.Status.State == v1beta1.InstallationStateKubernetesInstalled {
in.Status.SetState(v1beta1.InstallationStateInstalled, "Installed")
in.Status.SetState(v1beta1.InstallationStateInstalled, "Installed", nil)
}
return nil
}
Expand All @@ -617,15 +617,15 @@ func (r *InstallationReconciler) ReconcileHelmCharts(ctx context.Context, in *v1

meta, err := release.MetadataFor(ctx, in, r.Client)
if err != nil {
in.Status.SetState(v1beta1.InstallationStateHelmChartUpdateFailure, err.Error())
in.Status.SetState(v1beta1.InstallationStateHelmChartUpdateFailure, err.Error(), nil)
return nil
}

// skip if the new release has no addon configs - this should not happen in production
if len(meta.Configs.Charts) == 0 {
log.Info("Addons", "configcheck", "no addons")
if in.Status.State == v1beta1.InstallationStateKubernetesInstalled {
in.Status.SetState(v1beta1.InstallationStateInstalled, "Installed")
in.Status.SetState(v1beta1.InstallationStateInstalled, "Installed", nil)
}
return nil
}
Expand Down Expand Up @@ -680,19 +680,19 @@ func (r *InstallationReconciler) ReconcileHelmCharts(ctx context.Context, in *v1
if len(chartErrorString) > 1024 {
chartErrorString = chartErrorString[:1024]
}
in.Status.SetState(v1beta1.InstallationStateHelmChartUpdateFailure, chartErrorString)
in.Status.SetState(v1beta1.InstallationStateHelmChartUpdateFailure, chartErrorString, nil)
return nil
}

// If all addons match their target version + values, mark installation as complete
if len(pendingCharts) == 0 && !chartDrift {
in.Status.SetState(v1beta1.InstallationStateInstalled, "Addons upgraded")
in.Status.SetState(v1beta1.InstallationStateInstalled, "Addons upgraded", nil)
return nil
}

if len(pendingCharts) > 0 {
// If there are pending charts, mark the installation as pending with a message about the pending charts
in.Status.SetState(v1beta1.InstallationStatePendingChartCreation, fmt.Sprintf("Pending charts: %v", pendingCharts))
in.Status.SetState(v1beta1.InstallationStatePendingChartCreation, fmt.Sprintf("Pending charts: %v", pendingCharts), pendingCharts)
return nil
}

Expand All @@ -710,7 +710,7 @@ func (r *InstallationReconciler) ReconcileHelmCharts(ctx context.Context, in *v1

// Replace the current chart configs with the new chart configs
clusterConfig.Spec.Extensions.Helm = combinedConfigs
in.Status.SetState(v1beta1.InstallationStateAddonsInstalling, "Installing addons")
in.Status.SetState(v1beta1.InstallationStateAddonsInstalling, "Installing addons", nil)
log.Info("Updating cluster config with new helm charts", "updated charts", changedCharts)
//Update the clusterConfig
if err := r.Update(ctx, &clusterConfig); err != nil {
Expand All @@ -726,7 +726,7 @@ func (r *InstallationReconciler) SetStateBasedOnPlan(in *v1beta1.Installation, p
reason := autopilot.ReasonForState(plan)
switch plan.Status.State {
case "":
in.Status.SetState(v1beta1.InstallationStateEnqueued, reason)
in.Status.SetState(v1beta1.InstallationStateEnqueued, reason, nil)
case apcore.PlanIncompleteTargets:
fallthrough
case apcore.PlanInconsistentTargets:
Expand All @@ -738,15 +738,15 @@ func (r *InstallationReconciler) SetStateBasedOnPlan(in *v1beta1.Installation, p
case apcore.PlanMissingSignalNode:
fallthrough
case apcore.PlanApplyFailed:
in.Status.SetState(v1beta1.InstallationStateFailed, reason)
in.Status.SetState(v1beta1.InstallationStateFailed, reason, nil)
case apcore.PlanSchedulable:
fallthrough
case apcore.PlanSchedulableWait:
in.Status.SetState(v1beta1.InstallationStateInstalling, reason)
in.Status.SetState(v1beta1.InstallationStateInstalling, reason, nil)
case apcore.PlanCompleted:
in.Status.SetState(v1beta1.InstallationStateKubernetesInstalled, reason)
in.Status.SetState(v1beta1.InstallationStateKubernetesInstalled, reason, nil)
default:
in.Status.SetState(v1beta1.InstallationStateFailed, reason)
in.Status.SetState(v1beta1.InstallationStateFailed, reason, nil)
}
}

Expand Down Expand Up @@ -872,7 +872,7 @@ func (r *InstallationReconciler) StartUpgrade(ctx context.Context, in *v1beta1.I
// the installation state to 'Installed' and return. no extra autopilot plan creation
// is necessary at this stage.
if len(commands) == 0 {
in.Status.SetState(v1beta1.InstallationStateKubernetesInstalled, "")
in.Status.SetState(v1beta1.InstallationStateKubernetesInstalled, "", nil)
return nil
}

Expand All @@ -892,7 +892,7 @@ func (r *InstallationReconciler) StartUpgrade(ctx context.Context, in *v1beta1.I
if err := r.Create(ctx, &plan); err != nil {
return fmt.Errorf("failed to create upgrade plan: %w", err)
}
in.Status.SetState(v1beta1.InstallationStateEnqueued, "")
in.Status.SetState(v1beta1.InstallationStateEnqueued, "", nil)
return nil
}

Expand Down Expand Up @@ -931,6 +931,7 @@ func (r *InstallationReconciler) DisableOldInstallations(ctx context.Context, it
in.Status.SetState(
v1beta1.InstallationStateObsolete,
"This is not the most recent installation object",
nil,
)
r.Status().Update(ctx, &in)
}
Expand Down
10 changes: 6 additions & 4 deletions controllers/installation_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,8 +634,9 @@ password: original`,
},
},
out: v1beta1.InstallationStatus{
State: v1beta1.InstallationStatePendingChartCreation,
Reason: "Pending charts: [metachart]",
State: v1beta1.InstallationStatePendingChartCreation,
Reason: "Pending charts: [metachart]",
PendingCharts: []string{"metachart"},
},
releaseMeta: ectypes.ReleaseMetadata{
Configs: k0sv1beta1.HelmExtensions{
Expand Down Expand Up @@ -693,8 +694,9 @@ password: original`,
},
},
out: v1beta1.InstallationStatus{
State: v1beta1.InstallationStatePendingChartCreation,
Reason: "Pending charts: [metachart]",
State: v1beta1.InstallationStatePendingChartCreation,
Reason: "Pending charts: [metachart]",
PendingCharts: []string{"metachart"},
},
releaseMeta: ectypes.ReleaseMetadata{
Configs: k0sv1beta1.HelmExtensions{
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/ohler55/ojg v1.21.5
github.com/onsi/ginkgo/v2 v2.17.2
github.com/onsi/gomega v1.33.0
github.com/replicatedhq/embedded-cluster-kinds v1.1.6
github.com/replicatedhq/embedded-cluster-kinds v1.1.8
github.com/stretchr/testify v1.9.0
k8s.io/api v0.30.0
k8s.io/apimachinery v0.30.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ github.com/prometheus/common v0.45.0 h1:2BGz0eBc2hdMDLnO/8n0jeB3oPrt2D08CekT0lne
github.com/prometheus/common v0.45.0/go.mod h1:YJmSTw9BoKxJplESWWxlbyttQR4uaEcGyv9MZjVOJsY=
github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo=
github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo=
github.com/replicatedhq/embedded-cluster-kinds v1.1.6 h1:eJgXyo981RiNM2thKhXKxs/pq9rD0yqQY6zEZ12WPWM=
github.com/replicatedhq/embedded-cluster-kinds v1.1.6/go.mod h1:tj418fVUIy1xzxKacfoMx0SG4Oy5HF7RYC6Sy1mXgcU=
github.com/replicatedhq/embedded-cluster-kinds v1.1.8 h1:rqNV97STbWUBv0H0QsyPP+kHDGGZ7Wif/0lk2eDIxNU=
github.com/replicatedhq/embedded-cluster-kinds v1.1.8/go.mod h1:tj418fVUIy1xzxKacfoMx0SG4Oy5HF7RYC6Sy1mXgcU=
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
Expand Down

0 comments on commit b592fc7

Please sign in to comment.