Small adjustments to CRD additional print columns

Change-Id: I3e5ed921118d7db8c1bf38d7f4931c704d9c3712
Signed-off-by: Ruslan Aliev <raliev@mirantis.com>
This commit is contained in:
Ruslan Aliev 2024-02-08 20:40:44 -06:00
parent 0f3ef2a6c9
commit 97033111fe
6 changed files with 32 additions and 54 deletions

View File

@ -135,27 +135,14 @@ type ArmadaChartStatus struct {
// +optional // +optional
Conditions []metav1.Condition `json:"conditions,omitempty"` Conditions []metav1.Condition `json:"conditions,omitempty"`
// LastAppliedRevision is the revision of the last successfully applied source. // LastAppliedValuesChecksum is the SHA1 checksum of the values of the last
// +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
// reconciliation attempt. // reconciliation attempt.
// +optional // +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 // +optional
LastReleaseRevision int `json:"lastReleaseRevision,omitempty"` LastAppliedChartSource string `json:"lastAttemptedChartSource,omitempty"`
// HelmChart is the namespaced name of the HelmChart resource created by
// the controller for the ArmadaChart.
// +optional
HelmChart string `json:"helmChart,omitempty"`
// Failures is the reconciliation failure count against the latest desired // Failures is the reconciliation failure count against the latest desired
// state. It is reset after a successful reconciliation. // state. It is reset after a successful reconciliation.
@ -229,7 +216,6 @@ func ArmadaChartReady(ac ArmadaChart) ArmadaChart {
Message: "Release reconciliation succeeded", Message: "Release reconciliation succeeded",
} }
apimeta.SetStatusCondition(ac.GetStatusConditions(), newCondition) apimeta.SetStatusCondition(ac.GetStatusConditions(), newCondition)
ac.Status.LastAppliedRevision = ac.Status.LastAttemptedRevision
resetFailureCounts(&ac) resetFailureCounts(&ac)
setTested(&ac) setTested(&ac)
return ac return ac
@ -299,13 +285,12 @@ func setConfigDefaults(config *rest.Config) error {
//+kubebuilder:object:root=true //+kubebuilder:object:root=true
//+kubebuilder:subresource:status //+kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Namespace",type=string,JSONPath=`.metadata.namespace`
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp" // +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
// +kubebuilder:printcolumn:name="Ready",type=boolean,JSONPath=`.status.conditions[?(@.type=="Ready")].status` // +kubebuilder:printcolumn:name="Ready",type=string,JSONPath=`.status.conditions[?(@.type=="Ready")].status`
// +kubebuilder:printcolumn:name="Message",type=string,JSONPath=`.status.conditions[?(@.type=="Ready")].message`,priority=10
// +kubebuilder:printcolumn:name="Helm Status",type=string,JSONPath=`.status.helmStatus` // +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="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 // ArmadaChart is the Schema for the armadacharts API
type ArmadaChart struct { type ArmadaChart struct {

View File

@ -69,7 +69,7 @@ func main() {
opts.BindFlags(flag.CommandLine) opts.BindFlags(flag.CommandLine)
flag.Parse() flag.Parse()
managerLogger := zap.New() managerLogger := zap.New(zap.ConsoleEncoder())
ctrl.SetLogger(managerLogger) ctrl.SetLogger(managerLogger)
klog.SetLoggerWithOptions(managerLogger.WithName("runtime"), klog.ContextualLogger(true)) klog.SetLoggerWithOptions(managerLogger.WithName("runtime"), klog.ContextualLogger(true))

View File

@ -15,28 +15,25 @@ spec:
scope: Namespaced scope: Namespaced
versions: versions:
- additionalPrinterColumns: - additionalPrinterColumns:
- jsonPath: .metadata.namespace
name: Namespace
type: string
- jsonPath: .metadata.creationTimestamp - jsonPath: .metadata.creationTimestamp
name: Age name: Age
type: date type: date
- jsonPath: .status.conditions[?(@.type=="Ready")].status - jsonPath: .status.conditions[?(@.type=="Ready")].status
name: Ready name: Ready
type: boolean
- jsonPath: .status.conditions[?(@.type=="Ready")].message
name: Message
priority: 10
type: string type: string
- jsonPath: .status.helmStatus - jsonPath: .status.helmStatus
name: Helm Status name: Helm Status
type: string type: string
- jsonPath: .status.waitCompleted - jsonPath: .status.waitCompleted
name: Wait Completed name: Wait Done
type: boolean type: boolean
- jsonPath: .status.tested - jsonPath: .status.tested
name: Tested name: Tested
type: boolean type: boolean
- jsonPath: .status.conditions[?(@.type=="Ready")].message
name: Message
priority: 10
type: string
name: v1 name: v1
schema: schema:
openAPIV3Schema: openAPIV3Schema:
@ -219,10 +216,6 @@ spec:
the latest desired state. It is reset after a successful reconciliation. the latest desired state. It is reset after a successful reconciliation.
format: int64 format: int64
type: integer type: integer
helmChart:
description: HelmChart is the namespaced name of the HelmChart resource
created by the controller for the ArmadaChart.
type: string
helmStatus: helmStatus:
description: HelmStatus describes the status of helm release description: HelmStatus describes the status of helm release
type: string type: string
@ -231,22 +224,14 @@ spec:
the latest desired state. It is reset after a successful reconciliation. the latest desired state. It is reset after a successful reconciliation.
format: int64 format: int64
type: integer type: integer
lastAppliedRevision: lastAttemptedChartSource:
description: LastAppliedRevision is the revision of the last successfully description: LastAppliedChartSource is the URL of chart of the last
applied source. reconciliation attempt
type: string
lastAttemptedRevision:
description: LastAttemptedRevision is the revision of the last reconciliation
attempt.
type: string type: string
lastAttemptedValuesChecksum: lastAttemptedValuesChecksum:
description: LastAttemptedValuesChecksum is the SHA1 checksum of the description: LastAppliedValuesChecksum is the SHA1 checksum of the
values of the last reconciliation attempt. values of the last reconciliation attempt.
type: string type: string
lastReleaseRevision:
description: LastReleaseRevision is the revision of the last successful
Helm release.
type: integer
observedGeneration: observedGeneration:
description: ObservedGeneration is the last observed generation. description: ObservedGeneration is the last observed generation.
format: int64 format: int64

View File

@ -189,6 +189,9 @@ func (r *ArmadaChartReconciler) reconcileChart(ctx context.Context,
if rel.Info.Status.IsPending() { if rel.Info.Status.IsPending() {
log.Info("warning: release in pending state, unlocking") log.Info("warning: release in pending state, unlocking")
rel.SetStatus(release.StatusFailed, fmt.Sprintf("release unlocked from stale state")) 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 { } else {
for _, delRes := range ac.Spec.Upgrade.PreUpgrade.Delete { 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)) 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 return armadav1.ArmadaChartNotReady(ac, "InstallUpgradeFailed", err.Error()), err
} }
ac.Status.HelmStatus = string(rel.Info.Status) ac.Status.HelmStatus = string(rel.Info.Status)
ac.Status.LastAppliedChartSource = ac.Spec.Source.Location
if err := r.patchStatus(ctx, &ac); err != nil { if err := r.patchStatus(ctx, &ac); err != nil {
log.Error(err, "unable to update armadachart status") 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) log := ctrl.LoggerFrom(ctx)
if hr.Status.WaitCompleted { if hr.Status.WaitCompleted {
log.Info("wait has been already completed")
return hr, nil 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)) log.Info(cmp.Diff(release.Chart.Templates, chrt.Templates))
return true 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()): case !cmp.Equal(release.Config, vals.AsMap(), cmpopts.EquateEmpty()):
log.Info("There are chart values diffs found") log.Info("There are chart values diffs found")
log.Info(cmp.Diff(release.Config, vals.AsMap(), cmpopts.EquateEmpty())) log.Info(cmp.Diff(release.Config, vals.AsMap(), cmpopts.EquateEmpty()))

View File

@ -157,6 +157,11 @@ func (r *Runner) ObserveLastRelease(ac armadav1.ArmadaChart) (*release.Release,
return rel, err 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 { func wrapActionErr(log *LogBuffer, err error) error {
if err == nil { if err == nil {
return err return err

View File

@ -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)) 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) status := getObjectStatus(event.Object, minReady)
logger.Info(fmt.Sprintf("object type: %T, status: %s", event.Object, status.Msg)) logger.Info(fmt.Sprintf("object type: %T, status: %s", event.Object, status.Msg))
return status.StatusType, nil return status.StatusType, nil
@ -384,7 +389,7 @@ func (c *WaitOptions) Wait(parent context.Context) error {
} }
cfu := func(event watch.Event) (bool, 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 return false, err
} }