mirror of
https://github.com/fluxcd/flux2.git
synced 2025-10-30 07:47:09 +08:00
Better checks for reconciliation in reconcile run command
Signed-off-by: Somtochi Onyekwere <somtochionyekwere@gmail.com>
This commit is contained in:
@ -116,11 +116,13 @@ func (reconcile reconcileCommand) run(cmd *cobra.Command, args []string) error {
|
||||
reconciliationHandled(ctx, kubeClient, namespacedName, reconcile.object, lastHandledReconcileAt)); err != nil {
|
||||
return err
|
||||
}
|
||||
readyCond := apimeta.FindStatusCondition(*reconcile.object.GetStatusConditions(), meta.ReadyCondition)
|
||||
if readyCond == nil {
|
||||
return fmt.Errorf("status can't be determined")
|
||||
}
|
||||
|
||||
logger.Successf("%s reconciliation completed", reconcile.kind)
|
||||
|
||||
if apimeta.IsStatusConditionFalse(*reconcile.object.GetStatusConditions(), meta.ReadyCondition) {
|
||||
return fmt.Errorf("%s reconciliation failed", reconcile.kind)
|
||||
if readyCond.Status != metav1.ConditionTrue {
|
||||
return fmt.Errorf("%s reconciliation failed: ''%s", reconcile.kind, readyCond.Message)
|
||||
}
|
||||
logger.Successf(reconcile.object.successMessage())
|
||||
return nil
|
||||
@ -133,7 +135,9 @@ func reconciliationHandled(ctx context.Context, kubeClient client.Client,
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return obj.lastHandledReconcileRequest() != lastHandledReconcileAt, nil
|
||||
isProgressing := apimeta.IsStatusConditionPresentAndEqual(*obj.GetStatusConditions(),
|
||||
meta.ReadyCondition, metav1.ConditionUnknown)
|
||||
return obj.lastHandledReconcileRequest() != lastHandledReconcileAt && !isProgressing, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
apimeta "k8s.io/apimachinery/pkg/api/meta"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
|
||||
@ -68,22 +69,26 @@ func (reconcile reconcileWithSourceCommand) run(cmd *cobra.Command, args []strin
|
||||
rootArgs.namespace = nsCopy
|
||||
}
|
||||
|
||||
lastHandledReconcileAt := reconcile.object.lastHandledReconcileRequest()
|
||||
logger.Actionf("annotating %s %s in %s namespace", reconcile.kind, name, rootArgs.namespace)
|
||||
if err := requestReconciliation(ctx, kubeClient, namespacedName, reconcile.object); err != nil {
|
||||
return err
|
||||
}
|
||||
logger.Successf("%s annotated", reconcile.kind)
|
||||
|
||||
lastHandledReconcileAt := reconcile.object.lastHandledReconcileRequest()
|
||||
logger.Waitingf("waiting for %s reconciliation", reconcile.kind)
|
||||
if err := wait.PollImmediate(rootArgs.pollInterval, rootArgs.timeout,
|
||||
reconciliationHandled(ctx, kubeClient, namespacedName, reconcile.object, lastHandledReconcileAt)); err != nil {
|
||||
return err
|
||||
}
|
||||
logger.Successf("%s reconciliation completed", reconcile.kind)
|
||||
|
||||
if apimeta.IsStatusConditionFalse(*reconcile.object.GetStatusConditions(), meta.ReadyCondition) {
|
||||
return fmt.Errorf("%s reconciliation failed", reconcile.kind)
|
||||
readyCond := apimeta.FindStatusCondition(*reconcile.object.GetStatusConditions(), meta.ReadyCondition)
|
||||
if readyCond == nil {
|
||||
return fmt.Errorf("status can't be determined")
|
||||
}
|
||||
|
||||
if readyCond.Status != metav1.ConditionTrue {
|
||||
return fmt.Errorf("%s reconciliation failed: %s", reconcile.kind, readyCond.Message)
|
||||
}
|
||||
logger.Successf(reconcile.object.successMessage())
|
||||
return nil
|
||||
|
||||
@ -1,10 +1,8 @@
|
||||
► annotating GitRepository thrfg in {{ .ns }} namespace
|
||||
✔ GitRepository annotated
|
||||
◎ waiting for GitRepository reconciliation
|
||||
✔ GitRepository reconciliation completed
|
||||
✔ fetched revision 6.0.0/627d5c4bb67b77185f37e31d734b085019ff2951
|
||||
► annotating HelmRelease thrfg in {{ .ns }} namespace
|
||||
✔ HelmRelease annotated
|
||||
◎ waiting for HelmRelease reconciliation
|
||||
✔ HelmRelease reconciliation completed
|
||||
✔ applied revision 6.0.0
|
||||
|
||||
@ -1,10 +1,8 @@
|
||||
► annotating GitRepository tkfg in {{ .ns }} namespace
|
||||
✔ GitRepository annotated
|
||||
◎ waiting for GitRepository reconciliation
|
||||
✔ GitRepository reconciliation completed
|
||||
✔ fetched revision 6.0.0/627d5c4bb67b77185f37e31d734b085019ff2951
|
||||
► annotating Kustomization tkfg in {{ .ns }} namespace
|
||||
✔ Kustomization annotated
|
||||
◎ waiting for Kustomization reconciliation
|
||||
✔ Kustomization reconciliation completed
|
||||
✔ applied revision 6.0.0/627d5c4bb67b77185f37e31d734b085019ff2951
|
||||
|
||||
Reference in New Issue
Block a user