Skip to content

Commit bfa6072

Browse files
committed
Simplify func careAbout
Signed-off-by: Jun Duan <jun.duan.phd@outlook.com>
1 parent 820ec51 commit bfa6072

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

pkg/controller/dual-pods/controller.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -323,27 +323,27 @@ const (
323323
infSvrItemDontCare infSvrItemType = "dont_care"
324324
)
325325

326-
// careAbout returns an infSvrItem item and a bool owned.
327-
// Returns owned=true for server-requesting Pods, bound direct server-providing Pods, and launcher-based server-providing Pods;
328-
// returns owned=false for unbound direct providers and other Pods.
329-
func careAbout(pod *corev1.Pod) (item infSvrItem, it infSvrItemType, owned bool) {
326+
// careAbout returns an infSvrItem and an infSvrItemType.
327+
// The controller cares about server-requesting Pods, bound direct server-providing Pods, and launcher-based server-providing Pods.
328+
// The controller doesn't care about unbound direct providers and other Pods.
329+
func careAbout(pod *corev1.Pod) (item infSvrItem, it infSvrItemType) {
330330
if len(pod.Annotations[api.ServerPatchAnnotationName]) > 0 {
331-
return infSvrItem{pod.UID, pod.Name}, infSvrItemRequester, true
331+
return infSvrItem{pod.UID, pod.Name}, infSvrItemRequester
332332
}
333333
requesterStr := pod.Annotations[requesterAnnotationKey]
334334
requesterParts := strings.Split(requesterStr, " ")
335335
if len(requesterParts) != 2 {
336-
return infSvrItem{}, infSvrItemDontCare, false
336+
return infSvrItem{}, infSvrItemDontCare
337337
}
338-
return infSvrItem{apitypes.UID(requesterParts[0]), requesterParts[1]}, infSvrItemBoundDirectProvider, true
338+
return infSvrItem{apitypes.UID(requesterParts[0]), requesterParts[1]}, infSvrItemBoundDirectProvider
339339
}
340340

341341
const requesterIndexName = "requester"
342342

343343
func requesterIndexFunc(obj any) ([]string, error) {
344344
pod := obj.(*corev1.Pod)
345-
item, it, owned := careAbout(pod)
346-
if owned && it == infSvrItemBoundDirectProvider {
345+
item, it := careAbout(pod)
346+
if it == infSvrItemBoundDirectProvider {
347347
return []string{string(item.UID)}, nil
348348
}
349349
return []string{}, nil
@@ -352,7 +352,7 @@ func requesterIndexFunc(obj any) ([]string, error) {
352352
func (ctl *controller) OnAdd(obj any, isInInitialList bool) {
353353
switch typed := obj.(type) {
354354
case *corev1.Pod:
355-
if item, it, owned := careAbout(typed); !owned {
355+
if item, it := careAbout(typed); it == infSvrItemDontCare {
356356
ctl.enqueueLogger.V(5).Info("Ignoring add of irrelevant Pod", "name", typed.Name)
357357
return
358358
} else {
@@ -391,7 +391,7 @@ func (ctl *controller) OnAdd(obj any, isInInitialList bool) {
391391
func (ctl *controller) OnUpdate(prev, obj any) {
392392
switch typed := obj.(type) {
393393
case *corev1.Pod:
394-
if item, it, owned := careAbout(typed); !owned {
394+
if item, it := careAbout(typed); it == infSvrItemDontCare {
395395
ctl.enqueueLogger.V(5).Info("Ignoring update of irrelevant Pod", "name", typed.Name)
396396
return
397397
} else {
@@ -433,7 +433,7 @@ func (ctl *controller) OnDelete(obj any) {
433433
}
434434
switch typed := obj.(type) {
435435
case *corev1.Pod:
436-
if item, it, owned := careAbout(typed); !owned {
436+
if item, it := careAbout(typed); it == infSvrItemDontCare {
437437
ctl.enqueueLogger.V(5).Info("Ignoring delete of irrelevant Pod", "name", typed.Name)
438438
return
439439
} else {

0 commit comments

Comments
 (0)