@@ -14,12 +14,10 @@ import (
1414 "k8s.io/apimachinery/pkg/runtime"
1515 "k8s.io/apimachinery/pkg/types"
1616 ctrl "sigs.k8s.io/controller-runtime"
17- "sigs.k8s.io/controller-runtime/pkg/client"
1817 "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
1918
2019 "github.com/ydb-platform/ydb-kubernetes-operator/api/v1alpha1"
2120 . "github.com/ydb-platform/ydb-kubernetes-operator/internal/controllers/constants" //nolint:revive,stylecheck
22- "github.com/ydb-platform/ydb-kubernetes-operator/internal/labels"
2321 "github.com/ydb-platform/ydb-kubernetes-operator/internal/resources"
2422)
2523
@@ -204,11 +202,11 @@ func (r *Reconciler) waitForStatefulSetToScale(
204202 return r .updateStatus (ctx , databaseNodeSet , StatusUpdateRequeueDelay )
205203 }
206204
207- found := & appsv1.StatefulSet {}
205+ foundStatefulSet := & appsv1.StatefulSet {}
208206 err := r .Get (ctx , types.NamespacedName {
209207 Name : databaseNodeSet .Name ,
210208 Namespace : databaseNodeSet .Namespace ,
211- }, found )
209+ }, foundStatefulSet )
212210 if err != nil {
213211 if apierrors .IsNotFound (err ) {
214212 r .Recorder .Event (
@@ -223,51 +221,23 @@ func (r *Reconciler) waitForStatefulSetToScale(
223221 databaseNodeSet ,
224222 corev1 .EventTypeWarning ,
225223 "ControllerError" ,
226- fmt .Sprintf ("Failed to get StatefulSets : %s" , err ),
224+ fmt .Sprintf ("Failed to get StatefulSet : %s" , err ),
227225 )
228226 return Stop , ctrl.Result {RequeueAfter : DefaultRequeueDelay }, err
229227 }
230228
231- matchingLabels := client.MatchingLabels {}
232- for k , v := range databaseNodeSet .Labels {
233- matchingLabels [k ] = v
234- }
235-
236- podList := & corev1.PodList {}
237- opts := []client.ListOption {
238- client .InNamespace (databaseNodeSet .Namespace ),
239- client.MatchingLabels {labels .StatefulsetComponent : databaseNodeSet .Name },
240- }
241- err = r .List (ctx , podList , opts ... )
242- if err != nil {
243- r .Recorder .Event (
244- databaseNodeSet ,
245- corev1 .EventTypeWarning ,
246- "ControllerError" ,
247- fmt .Sprintf ("Failed to list StatefulSet pods: %s" , err ),
248- )
249- return Stop , ctrl.Result {RequeueAfter : DefaultRequeueDelay }, err
250- }
251-
252- runningPods := 0
253- for _ , e := range podList .Items {
254- if resources .PodIsReady (e ) {
255- runningPods ++
256- }
257- }
258-
259- if runningPods != int (databaseNodeSet .Spec .Nodes ) {
229+ if foundStatefulSet .Status .ReadyReplicas != databaseNodeSet .Spec .Nodes {
260230 r .Recorder .Event (
261231 databaseNodeSet ,
262232 corev1 .EventTypeNormal ,
263233 string (DatabaseNodeSetProvisioning ),
264- fmt .Sprintf ("Waiting for number of running nodes to match expected: %d != %d" , runningPods , databaseNodeSet .Spec .Nodes ),
234+ fmt .Sprintf ("Waiting for number of running nodes to match expected: %d != %d" , foundStatefulSet . Status . ReadyReplicas , databaseNodeSet .Spec .Nodes ),
265235 )
266236 meta .SetStatusCondition (& databaseNodeSet .Status .Conditions , metav1.Condition {
267237 Type : NodeSetProvisionedCondition ,
268238 Status : metav1 .ConditionFalse ,
269239 Reason : ReasonInProgress ,
270- Message : fmt .Sprintf ("Number of running nodes does not match expected: %d != %d" , runningPods , databaseNodeSet .Spec .Nodes ),
240+ Message : fmt .Sprintf ("Number of running nodes does not match expected: %d != %d" , foundStatefulSet . Status . ReadyReplicas , databaseNodeSet .Spec .Nodes ),
271241 })
272242 return r .updateStatus (ctx , databaseNodeSet , DefaultRequeueDelay )
273243 }
0 commit comments