Skip to content

Commit 0a6f2a3

Browse files
committed
polish log & merge lppItem and lcItem processing logic
1 parent c6a515f commit 0a6f2a3

1 file changed

Lines changed: 14 additions & 33 deletions

File tree

pkg/controller/launcher-populator/populator.go

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func (ctl *controller) OnAdd(obj any, isInInitialList bool) {
136136
item := lcItem{cache.MetaObjectToName(typed)}
137137
ctl.Queue.Add(item)
138138
default:
139-
ctl.enqueueLogger.V(5).Info("Notified of add of ignored object", "type", fmt.Sprintf("%T", obj))
139+
ctl.enqueueLogger.V(5).Info("Notified of add of object of ignored type", "type", fmt.Sprintf("%T", obj))
140140
return
141141
}
142142
}
@@ -190,36 +190,22 @@ func (ctl *controller) process(ctx context.Context, item queueItem) (error, bool
190190
}
191191

192192
func (item lppItem) process(ctx context.Context, ctl *controller) (error, bool) {
193-
logger := klog.FromContext(ctx)
194-
195-
// Build desired state from all policies
196-
populationPolicy, err := ctl.buildDesiredStateFromPolicies(ctx)
197-
if err != nil {
198-
logger.Error(err, "Failed to build desired state from policies")
199-
return err, true
200-
}
201-
202-
logger.Info("Final population policy", "policy", MapToLoggable(populationPolicy))
203-
204-
// Adjust launcher pods according to final requirements
205-
needsRequeue, err := ctl.reconcileAllLaunchers(ctx, populationPolicy)
206-
if err != nil {
207-
logger.Error(err, "Failed to reconcile launchers")
208-
return err, true
209-
}
210-
211-
if needsRequeue {
212-
return nil, true
213-
}
214-
return nil, false
193+
return ctl.reconcileFromPolicies(ctx)
215194
}
216195

217196
func (item lcItem) process(ctx context.Context, ctl *controller) (error, bool) {
218-
logger := klog.FromContext(ctx)
219-
220-
// Build desired state from all policies.
221197
// No special treatment for any particular LauncherConfig;
222198
// missing LauncherConfigs are handled inside buildDesiredStateFromPolicies.
199+
return ctl.reconcileFromPolicies(ctx)
200+
}
201+
202+
// reconcileFromPolicies builds the desired state from all policies and reconciles
203+
// all launcher pods accordingly. It is the common implementation shared by
204+
// lppItem.process and lcItem.process.
205+
func (ctl *controller) reconcileFromPolicies(ctx context.Context) (error, bool) {
206+
logger := klog.FromContext(ctx)
207+
208+
// Build desired state from all policies
223209
populationPolicy, err := ctl.buildDesiredStateFromPolicies(ctx)
224210
if err != nil {
225211
logger.Error(err, "Failed to build desired state from policies")
@@ -235,10 +221,7 @@ func (item lcItem) process(ctx context.Context, ctl *controller) (error, bool) {
235221
return err, true
236222
}
237223

238-
if needsRequeue {
239-
return nil, true
240-
}
241-
return nil, false
224+
return nil, needsRequeue
242225
}
243226

244227
// buildDesiredStateFromPolicies builds the desired state map from all policies.
@@ -331,9 +314,7 @@ func (ctl *controller) reconcileAllLaunchers(ctx context.Context, desired map[No
331314
logger.Error(err, "Failed to reconcile launchers on node", "node", nodeName)
332315
continue
333316
}
334-
if needsRequeue {
335-
anyRequeueNeeded = true
336-
}
317+
anyRequeueNeeded = anyRequeueNeeded || needsRequeue
337318
}
338319

339320
return anyRequeueNeeded, nil

0 commit comments

Comments
 (0)