mirror of
				https://github.com/fluxcd/flux2.git
				synced 2025-10-31 08:17:19 +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 { | 		reconciliationHandled(ctx, kubeClient, namespacedName, reconcile.object, lastHandledReconcileAt)); err != nil { | ||||||
| 		return err | 		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 readyCond.Status != metav1.ConditionTrue { | ||||||
|  | 		return fmt.Errorf("%s reconciliation failed: ''%s", reconcile.kind, readyCond.Message) | ||||||
| 	if apimeta.IsStatusConditionFalse(*reconcile.object.GetStatusConditions(), meta.ReadyCondition) { |  | ||||||
| 		return fmt.Errorf("%s reconciliation failed", reconcile.kind) |  | ||||||
| 	} | 	} | ||||||
| 	logger.Successf(reconcile.object.successMessage()) | 	logger.Successf(reconcile.object.successMessage()) | ||||||
| 	return nil | 	return nil | ||||||
| @ -133,7 +135,9 @@ func reconciliationHandled(ctx context.Context, kubeClient client.Client, | |||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return false, err | 			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" | 	"github.com/spf13/cobra" | ||||||
| 	apimeta "k8s.io/apimachinery/pkg/api/meta" | 	apimeta "k8s.io/apimachinery/pkg/api/meta" | ||||||
|  | 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||||||
| 	"k8s.io/apimachinery/pkg/types" | 	"k8s.io/apimachinery/pkg/types" | ||||||
| 	"k8s.io/apimachinery/pkg/util/wait" | 	"k8s.io/apimachinery/pkg/util/wait" | ||||||
|  |  | ||||||
| @ -68,22 +69,26 @@ func (reconcile reconcileWithSourceCommand) run(cmd *cobra.Command, args []strin | |||||||
| 		rootArgs.namespace = nsCopy | 		rootArgs.namespace = nsCopy | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	lastHandledReconcileAt := reconcile.object.lastHandledReconcileRequest() | ||||||
| 	logger.Actionf("annotating %s %s in %s namespace", reconcile.kind, name, rootArgs.namespace) | 	logger.Actionf("annotating %s %s in %s namespace", reconcile.kind, name, rootArgs.namespace) | ||||||
| 	if err := requestReconciliation(ctx, kubeClient, namespacedName, reconcile.object); err != nil { | 	if err := requestReconciliation(ctx, kubeClient, namespacedName, reconcile.object); err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| 	logger.Successf("%s annotated", reconcile.kind) | 	logger.Successf("%s annotated", reconcile.kind) | ||||||
|  |  | ||||||
| 	lastHandledReconcileAt := reconcile.object.lastHandledReconcileRequest() |  | ||||||
| 	logger.Waitingf("waiting for %s reconciliation", reconcile.kind) | 	logger.Waitingf("waiting for %s reconciliation", reconcile.kind) | ||||||
| 	if err := wait.PollImmediate(rootArgs.pollInterval, rootArgs.timeout, | 	if err := wait.PollImmediate(rootArgs.pollInterval, rootArgs.timeout, | ||||||
| 		reconciliationHandled(ctx, kubeClient, namespacedName, reconcile.object, lastHandledReconcileAt)); err != nil { | 		reconciliationHandled(ctx, kubeClient, namespacedName, reconcile.object, lastHandledReconcileAt)); err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| 	logger.Successf("%s reconciliation completed", reconcile.kind) |  | ||||||
|  |  | ||||||
| 	if apimeta.IsStatusConditionFalse(*reconcile.object.GetStatusConditions(), meta.ReadyCondition) { | 	readyCond := apimeta.FindStatusCondition(*reconcile.object.GetStatusConditions(), meta.ReadyCondition) | ||||||
| 		return fmt.Errorf("%s reconciliation failed", reconcile.kind) | 	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()) | 	logger.Successf(reconcile.object.successMessage()) | ||||||
| 	return nil | 	return nil | ||||||
|  | |||||||
| @ -1,10 +1,8 @@ | |||||||
| ► annotating GitRepository thrfg in {{ .ns }} namespace | ► annotating GitRepository thrfg in {{ .ns }} namespace | ||||||
| ✔ GitRepository annotated | ✔ GitRepository annotated | ||||||
| ◎ waiting for GitRepository reconciliation | ◎ waiting for GitRepository reconciliation | ||||||
| ✔ GitRepository reconciliation completed |  | ||||||
| ✔ fetched revision 6.0.0/627d5c4bb67b77185f37e31d734b085019ff2951 | ✔ fetched revision 6.0.0/627d5c4bb67b77185f37e31d734b085019ff2951 | ||||||
| ► annotating HelmRelease thrfg in {{ .ns }} namespace | ► annotating HelmRelease thrfg in {{ .ns }} namespace | ||||||
| ✔ HelmRelease annotated | ✔ HelmRelease annotated | ||||||
| ◎ waiting for HelmRelease reconciliation | ◎ waiting for HelmRelease reconciliation | ||||||
| ✔ HelmRelease reconciliation completed |  | ||||||
| ✔ applied revision 6.0.0 | ✔ applied revision 6.0.0 | ||||||
|  | |||||||
| @ -1,10 +1,8 @@ | |||||||
| ► annotating GitRepository tkfg in {{ .ns }} namespace | ► annotating GitRepository tkfg in {{ .ns }} namespace | ||||||
| ✔ GitRepository annotated | ✔ GitRepository annotated | ||||||
| ◎ waiting for GitRepository reconciliation | ◎ waiting for GitRepository reconciliation | ||||||
| ✔ GitRepository reconciliation completed |  | ||||||
| ✔ fetched revision 6.0.0/627d5c4bb67b77185f37e31d734b085019ff2951 | ✔ fetched revision 6.0.0/627d5c4bb67b77185f37e31d734b085019ff2951 | ||||||
| ► annotating Kustomization tkfg in {{ .ns }} namespace | ► annotating Kustomization tkfg in {{ .ns }} namespace | ||||||
| ✔ Kustomization annotated | ✔ Kustomization annotated | ||||||
| ◎ waiting for Kustomization reconciliation | ◎ waiting for Kustomization reconciliation | ||||||
| ✔ Kustomization reconciliation completed |  | ||||||
| ✔ applied revision 6.0.0/627d5c4bb67b77185f37e31d734b085019ff2951 | ✔ applied revision 6.0.0/627d5c4bb67b77185f37e31d734b085019ff2951 | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 Somtochi Onyekwere
					Somtochi Onyekwere