From 97033111fef52614e6450b17309e22e734ba19d8 Mon Sep 17 00:00:00 2001 From: Ruslan Aliev Date: Thu, 8 Feb 2024 20:40:44 -0600 Subject: [PATCH] Small adjustments to CRD additional print columns Change-Id: I3e5ed921118d7db8c1bf38d7f4931c704d9c3712 Signed-off-by: Ruslan Aliev --- api/v1/armadachart_types.go | 29 ++++------------ cmd/main.go | 2 +- .../armada.airshipit.org_armadacharts.yaml | 33 +++++-------------- pkg/controller/armadachart_controller.go | 10 +++--- pkg/runner/runner.go | 5 +++ pkg/waitutil/wait.go | 7 +++- 6 files changed, 32 insertions(+), 54 deletions(-) diff --git a/api/v1/armadachart_types.go b/api/v1/armadachart_types.go index 23c06b5..cbef4ca 100644 --- a/api/v1/armadachart_types.go +++ b/api/v1/armadachart_types.go @@ -135,27 +135,14 @@ type ArmadaChartStatus struct { // +optional Conditions []metav1.Condition `json:"conditions,omitempty"` - // LastAppliedRevision is the revision of the last successfully applied source. - // +optional - LastAppliedRevision string `json:"lastAppliedRevision,omitempty"` - - // LastAttemptedRevision is the revision of the last reconciliation attempt. - // +optional - LastAttemptedRevision string `json:"lastAttemptedRevision,omitempty"` - - // LastAttemptedValuesChecksum is the SHA1 checksum of the values of the last + // LastAppliedValuesChecksum is the SHA1 checksum of the values of the last // reconciliation attempt. // +optional - LastAttemptedValuesChecksum string `json:"lastAttemptedValuesChecksum,omitempty"` + LastAppliedValuesChecksum string `json:"lastAttemptedValuesChecksum,omitempty"` - // LastReleaseRevision is the revision of the last successful Helm release. + // LastAppliedChartSource is the URL of chart of the last reconciliation attempt // +optional - LastReleaseRevision int `json:"lastReleaseRevision,omitempty"` - - // HelmChart is the namespaced name of the HelmChart resource created by - // the controller for the ArmadaChart. - // +optional - HelmChart string `json:"helmChart,omitempty"` + LastAppliedChartSource string `json:"lastAttemptedChartSource,omitempty"` // Failures is the reconciliation failure count against the latest desired // state. It is reset after a successful reconciliation. @@ -229,7 +216,6 @@ func ArmadaChartReady(ac ArmadaChart) ArmadaChart { Message: "Release reconciliation succeeded", } apimeta.SetStatusCondition(ac.GetStatusConditions(), newCondition) - ac.Status.LastAppliedRevision = ac.Status.LastAttemptedRevision resetFailureCounts(&ac) setTested(&ac) return ac @@ -299,13 +285,12 @@ func setConfigDefaults(config *rest.Config) error { //+kubebuilder:object:root=true //+kubebuilder:subresource:status -// +kubebuilder:printcolumn:name="Namespace",type=string,JSONPath=`.metadata.namespace` // +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp" -// +kubebuilder:printcolumn:name="Ready",type=boolean,JSONPath=`.status.conditions[?(@.type=="Ready")].status` -// +kubebuilder:printcolumn:name="Message",type=string,JSONPath=`.status.conditions[?(@.type=="Ready")].message`,priority=10 +// +kubebuilder:printcolumn:name="Ready",type=string,JSONPath=`.status.conditions[?(@.type=="Ready")].status` // +kubebuilder:printcolumn:name="Helm Status",type=string,JSONPath=`.status.helmStatus` -// +kubebuilder:printcolumn:name="Wait Completed",type=boolean,JSONPath=`.status.waitCompleted` +// +kubebuilder:printcolumn:name="Wait Done",type=boolean,JSONPath=`.status.waitCompleted` // +kubebuilder:printcolumn:name="Tested",type=boolean,JSONPath=`.status.tested` +// +kubebuilder:printcolumn:name="Message",type=string,JSONPath=`.status.conditions[?(@.type=="Ready")].message`,priority=10 // ArmadaChart is the Schema for the armadacharts API type ArmadaChart struct { diff --git a/cmd/main.go b/cmd/main.go index 903964e..e2fca20 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -69,7 +69,7 @@ func main() { opts.BindFlags(flag.CommandLine) flag.Parse() - managerLogger := zap.New() + managerLogger := zap.New(zap.ConsoleEncoder()) ctrl.SetLogger(managerLogger) klog.SetLoggerWithOptions(managerLogger.WithName("runtime"), klog.ContextualLogger(true)) diff --git a/config/crd/bases/armada.airshipit.org_armadacharts.yaml b/config/crd/bases/armada.airshipit.org_armadacharts.yaml index cf4550e..f2f9181 100644 --- a/config/crd/bases/armada.airshipit.org_armadacharts.yaml +++ b/config/crd/bases/armada.airshipit.org_armadacharts.yaml @@ -15,28 +15,25 @@ spec: scope: Namespaced versions: - additionalPrinterColumns: - - jsonPath: .metadata.namespace - name: Namespace - type: string - jsonPath: .metadata.creationTimestamp name: Age type: date - jsonPath: .status.conditions[?(@.type=="Ready")].status name: Ready - type: boolean - - jsonPath: .status.conditions[?(@.type=="Ready")].message - name: Message - priority: 10 type: string - jsonPath: .status.helmStatus name: Helm Status type: string - jsonPath: .status.waitCompleted - name: Wait Completed + name: Wait Done type: boolean - jsonPath: .status.tested name: Tested type: boolean + - jsonPath: .status.conditions[?(@.type=="Ready")].message + name: Message + priority: 10 + type: string name: v1 schema: openAPIV3Schema: @@ -219,10 +216,6 @@ spec: the latest desired state. It is reset after a successful reconciliation. format: int64 type: integer - helmChart: - description: HelmChart is the namespaced name of the HelmChart resource - created by the controller for the ArmadaChart. - type: string helmStatus: description: HelmStatus describes the status of helm release type: string @@ -231,22 +224,14 @@ spec: the latest desired state. It is reset after a successful reconciliation. format: int64 type: integer - lastAppliedRevision: - description: LastAppliedRevision is the revision of the last successfully - applied source. - type: string - lastAttemptedRevision: - description: LastAttemptedRevision is the revision of the last reconciliation - attempt. + lastAttemptedChartSource: + description: LastAppliedChartSource is the URL of chart of the last + reconciliation attempt type: string lastAttemptedValuesChecksum: - description: LastAttemptedValuesChecksum is the SHA1 checksum of the + description: LastAppliedValuesChecksum is the SHA1 checksum of the values of the last reconciliation attempt. type: string - lastReleaseRevision: - description: LastReleaseRevision is the revision of the last successful - Helm release. - type: integer observedGeneration: description: ObservedGeneration is the last observed generation. format: int64 diff --git a/pkg/controller/armadachart_controller.go b/pkg/controller/armadachart_controller.go index 43275ef..3bcf552 100644 --- a/pkg/controller/armadachart_controller.go +++ b/pkg/controller/armadachart_controller.go @@ -189,6 +189,9 @@ func (r *ArmadaChartReconciler) reconcileChart(ctx context.Context, if rel.Info.Status.IsPending() { log.Info("warning: release in pending state, unlocking") rel.SetStatus(release.StatusFailed, fmt.Sprintf("release unlocked from stale state")) + if err = run.UpdateReleaseStatus(rel); err != nil { + return armadav1.ArmadaChartNotReady(ac, "UpdateHelmStatusFailed", err.Error()), err + } } else { for _, delRes := range ac.Spec.Upgrade.PreUpgrade.Delete { log.Info(fmt.Sprintf("deleting all %ss in %s ns with labels %v", delRes.Type, ac.Spec.Namespace, delRes.Labels)) @@ -221,6 +224,7 @@ func (r *ArmadaChartReconciler) reconcileChart(ctx context.Context, return armadav1.ArmadaChartNotReady(ac, "InstallUpgradeFailed", err.Error()), err } ac.Status.HelmStatus = string(rel.Info.Status) + ac.Status.LastAppliedChartSource = ac.Spec.Source.Location if err := r.patchStatus(ctx, &ac); err != nil { log.Error(err, "unable to update armadachart status") } @@ -241,7 +245,6 @@ func (r *ArmadaChartReconciler) waitRelease(ctx context.Context, restCfg *rest.C log := ctrl.LoggerFrom(ctx) if hr.Status.WaitCompleted { - log.Info("wait has been already completed") return hr, nil } @@ -430,11 +433,6 @@ func isUpdateRequired(ctx context.Context, release *release.Release, chrt *chart log.Info(cmp.Diff(release.Chart.Templates, chrt.Templates)) return true - //case !cmp.Equal(release.Chart.Values, chrt.Values, cmpopts.EquateEmpty()): - // log.Info("There are CHART DEF VALUES diffs") - // log.Info(cmp.Diff(release.Chart.Values, chrt.Values, cmpopts.EquateEmpty())) - // return true - case !cmp.Equal(release.Config, vals.AsMap(), cmpopts.EquateEmpty()): log.Info("There are chart values diffs found") log.Info(cmp.Diff(release.Config, vals.AsMap(), cmpopts.EquateEmpty())) diff --git a/pkg/runner/runner.go b/pkg/runner/runner.go index 1dadaf5..fe943d6 100644 --- a/pkg/runner/runner.go +++ b/pkg/runner/runner.go @@ -157,6 +157,11 @@ func (r *Runner) ObserveLastRelease(ac armadav1.ArmadaChart) (*release.Release, return rel, err } +// UpdateReleaseStatus sets the new status for release +func (r *Runner) UpdateReleaseStatus(rel *release.Release) error { + return r.config.Releases.Update(rel) +} + func wrapActionErr(log *LogBuffer, err error) error { if err == nil { return err diff --git a/pkg/waitutil/wait.go b/pkg/waitutil/wait.go index 2801f59..fe512d4 100644 --- a/pkg/waitutil/wait.go +++ b/pkg/waitutil/wait.go @@ -120,6 +120,11 @@ func processEvent(logger logr.Logger, event watch.Event, minReady *MinReady) (St return Error, errors.New(fmt.Sprintf("resource %s: got error event %s", metaObj.GetName(), event.Object)) } + if event.Type == "DELETED" { + logger.Info("Resource %s: removed from tracking", metaObj.GetName()) + return Skipped, nil + } + status := getObjectStatus(event.Object, minReady) logger.Info(fmt.Sprintf("object type: %T, status: %s", event.Object, status.Msg)) return status.StatusType, nil @@ -384,7 +389,7 @@ func (c *WaitOptions) Wait(parent context.Context) error { } cfu := func(event watch.Event) (bool, error) { - if ready, err := processEvent(c.Logger, event, minReady); ready != Ready || err != nil { + if ready, err := processEvent(c.Logger, event, minReady); (ready != Ready && ready != Skipped) || err != nil { return false, err }