From b592fc73ee1c63c5a19d35dd8fde29a38a74927f Mon Sep 17 00:00:00 2001 From: Andrew Lavery Date: Mon, 6 May 2024 20:39:56 +0800 Subject: [PATCH] Publish a list of pending charts as part of the installation status (#164) * update embedded-cluster-kinds to add new status field * set pending charts when relevant --- controllers/installation_controller.go | 43 +++++++++++---------- controllers/installation_controller_test.go | 10 +++-- go.mod | 2 +- go.sum | 4 +- 4 files changed, 31 insertions(+), 28 deletions(-) diff --git a/controllers/installation_controller.go b/controllers/installation_controller.go index 67cbb0db6..34369bc48 100644 --- a/controllers/installation_controller.go +++ b/controllers/installation_controller.go @@ -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 } @@ -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 } @@ -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 } @@ -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 } @@ -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 } @@ -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 } @@ -617,7 +617,7 @@ 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 } @@ -625,7 +625,7 @@ func (r *InstallationReconciler) ReconcileHelmCharts(ctx context.Context, in *v1 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 } @@ -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 } @@ -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 { @@ -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: @@ -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) } } @@ -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 } @@ -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 } @@ -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) } diff --git a/controllers/installation_controller_test.go b/controllers/installation_controller_test.go index 1cf6985de..3ab18d390 100644 --- a/controllers/installation_controller_test.go +++ b/controllers/installation_controller_test.go @@ -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{ @@ -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{ diff --git a/go.mod b/go.mod index 4ad276aac..2b9eb3d65 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 03fcc22a9..b0e16a151 100644 --- a/go.sum +++ b/go.sum @@ -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=