From b3fa76fcdd803bd33e44d38fd866c46e9910e2c3 Mon Sep 17 00:00:00 2001 From: fabriziopandini Date: Wed, 28 Oct 2020 10:46:21 +0100 Subject: [PATCH] KCP should update conditions when reconcileHealth is failing --- controlplane/kubeadm/controllers/controller.go | 8 +------- controlplane/kubeadm/controllers/scale.go | 12 ++++++++++++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/controlplane/kubeadm/controllers/controller.go b/controlplane/kubeadm/controllers/controller.go index 1d3309c1ed6e..909fd2720c06 100644 --- a/controlplane/kubeadm/controllers/controller.go +++ b/controlplane/kubeadm/controllers/controller.go @@ -304,12 +304,6 @@ func (r *KubeadmControlPlaneReconciler) reconcile(ctx context.Context, cluster * // source ref (reason@machine/name) so the problem can be easily tracked down to its source machine. conditions.SetAggregate(controlPlane.KCP, controlplanev1.MachinesReadyCondition, controlPlane.Machines.ConditionGetters(), conditions.AddSourceRef()) - // reconcileControlPlaneHealth returns err if there is a machine being deleted or if the control plane is unhealthy. - // If the control plane is not yet initialized, this call shouldn't fail. - if result, err := r.reconcileControlPlaneHealth(ctx, cluster, kcp, controlPlane); err != nil || !result.IsZero() { - return result, err - } - // Control plane machines rollout due to configuration changes (e.g. upgrades) takes precedence over other operations. needRollout := controlPlane.MachinesNeedingRollout() switch { @@ -317,7 +311,7 @@ func (r *KubeadmControlPlaneReconciler) reconcile(ctx context.Context, cluster * logger.Info("Rolling out Control Plane machines", "needRollout", needRollout.Names()) // NOTE: we are using Status.UpdatedReplicas from the previous reconciliation only to provide a meaningful message // and this does not influence any reconciliation logic. - conditions.MarkFalse(controlPlane.KCP, controlplanev1.MachinesSpecUpToDateCondition, controlplanev1.RollingUpdateInProgressReason, clusterv1.ConditionSeverityWarning, "Rolling %d replicas with outdated spec (%d replicas up to date)", len(needRollout), kcp.Status.UpdatedReplicas) + conditions.MarkFalse(controlPlane.KCP, controlplanev1.MachinesSpecUpToDateCondition, controlplanev1.RollingUpdateInProgressReason, clusterv1.ConditionSeverityWarning, "Rolling %d replicas with outdated spec (%d replicas up to date)", len(needRollout), len(controlPlane.Machines)-len(needRollout)) return r.upgradeControlPlane(ctx, cluster, kcp, controlPlane, needRollout) default: // make sure last upgrade operation is marked as completed. diff --git a/controlplane/kubeadm/controllers/scale.go b/controlplane/kubeadm/controllers/scale.go index 27faa9e77dce..50a43ca6bf30 100644 --- a/controlplane/kubeadm/controllers/scale.go +++ b/controlplane/kubeadm/controllers/scale.go @@ -62,6 +62,12 @@ func (r *KubeadmControlPlaneReconciler) initializeControlPlane(ctx context.Conte func (r *KubeadmControlPlaneReconciler) scaleUpControlPlane(ctx context.Context, cluster *clusterv1.Cluster, kcp *controlplanev1.KubeadmControlPlane, controlPlane *internal.ControlPlane) (ctrl.Result, error) { logger := controlPlane.Logger() + // reconcileControlPlaneHealth returns err if there is a machine being deleted or if the control plane is unhealthy. + // If the control plane is not yet initialized, this call shouldn't fail. + if result, err := r.reconcileControlPlaneHealth(ctx, cluster, kcp, controlPlane); err != nil || !result.IsZero() { + return result, err + } + // Create the bootstrap configuration bootstrapSpec := controlPlane.JoinControlPlaneConfig() fd := controlPlane.NextFailureDomainForScaleUp() @@ -84,6 +90,12 @@ func (r *KubeadmControlPlaneReconciler) scaleDownControlPlane( ) (ctrl.Result, error) { logger := controlPlane.Logger() + // reconcileControlPlaneHealth returns err if there is a machine being deleted or if the control plane is unhealthy. + // If the control plane is not yet initialized, this call shouldn't fail. + if result, err := r.reconcileControlPlaneHealth(ctx, cluster, kcp, controlPlane); err != nil || !result.IsZero() { + return result, err + } + workloadCluster, err := r.managementCluster.GetWorkloadCluster(ctx, util.ObjectKey(cluster)) if err != nil { logger.Error(err, "Failed to create client to workload cluster")