Repository: kubernetes/kubernetes
File: pkg/scheduler/backend/queue/unschedulable_pods.go (Go)

Code before:

// newUnschedulablePods initializes a new object of unschedulablePods.
func newUnschedulablePods(unschedulableRecorder, gatedRecorder metrics.MetricRecorder) *unschedulablePods {
	return &unschedulablePods{
		podInfoMap:            make(map[string]*framework.QueuedPodInfo),
		keyFunc:               util.GetPodFullName,
		unschedulableRecorder: unschedulableRecorder,
		gatedRecorder:         gatedRecorder,
	}
}

// updateMetricsOnStateChange handles the metric accounting when a pod changes
// between Gated and Unschedulable states.
func (u *unschedulablePods) updateMetricsOnStateChange(gatedBefore, isGated bool) {
	if gatedBefore == isGated {
		return
	}

	if gatedBefore {
		// Transition: Gated -> Ungated
		u.gatedRecorder.Dec()
		u.unschedulableRecorder.Inc()
	} else {
		// Transition: Ungated -> Gated
		u.unschedulableRecorder.Dec()
		u.gatedRecorder.Inc()
	}
}

// addOrUpdate adds a pod to the unschedulable podInfoMap.
// The event should show which event triggered the addition and is used for the metric recording.
func (u *unschedulablePods) addOrUpdate(pInfo *framework.QueuedPodInfo, gatedBefore bool, event string) {
	podID := u.keyFunc(pInfo.Pod)
	if _, exists := u.podInfoMap[podID]; exists {
		u.updateMetricsOnStateChange(gatedBefore, pInfo.Gated())
	} else {
		if pInfo.Gated() {
			u.gatedRecorder.Inc()
		} else {
			u.unschedulableRecorder.Inc()
		}
		metrics.SchedulerQueueIncomingPods.WithLabelValues("unschedulable", event).Inc()
	}
	u.podInfoMap[podID] = pInfo
}

// delete deletes a pod from the unschedulable podInfoMap.
// The `gated` parameter is used to figure out which metric should be decreased.
func (u *unschedulablePods) delete(pod *v1.Pod, gated bool) {
	podID := u.keyFunc(pod)
	if _, exists := u.podInfoMap[podID]; exists {

Review comment (suggestion):
Super-nit: change the sequence to be consistent with the `if` block branch.
```suggestion
		u.gatedRecorder.Inc()
		u.unschedulableRecorder.Dec()
```

Code after:
	unschedulableRecorder, gatedRecorder metrics.MetricRecorder
}

// newUnschedulablePods initializes a new object of unschedulablePods.
func newUnschedulablePods(unschedulableRecorder, gatedRecorder metrics.MetricRecorder) *unschedulablePods {
	return &unschedulablePods{
		podInfoMap:            make(map[string]*framework.QueuedPodInfo),
		keyFunc:               util.GetPodFullName,
		unschedulableRecorder: unschedulableRecorder,
		gatedRecorder:         gatedRecorder,
	}
}

// updateMetricsOnStateChange handles the metric accounting when a pod changes
// between Gated and Unschedulable states.
func (u *unschedulablePods) updateMetricsOnStateChange(gatedBefore, isGated bool) {
	if gatedBefore == isGated {
		return
	}

	if gatedBefore {
		// Transition: Gated -> Ungated
		u.gatedRecorder.Dec()
		u.unschedulableRecorder.Inc()
	} else {
		// Transition: Ungated -> Gated
		u.gatedRecorder.Inc()
		u.unschedulableRecorder.Dec()
	}
}

// addOrUpdate adds a pod to the unschedulable podInfoMap.
// The event should show which event triggered the addition and is used for the metric recording.
func (u *unschedulablePods) addOrUpdate(pInfo *framework.QueuedPodInfo, gatedBefore bool, event string) {
	podID := u.keyFunc(pInfo.Pod)
	if _, exists := u.podInfoMap[podID]; exists {
		u.updateMetricsOnStateChange(gatedBefore, pInfo.Gated())
	} else {
		if pInfo.Gated() {
			u.gatedRecorder.Inc()
		} else {
			u.unschedulableRecorder.Inc()
		}
		metrics.SchedulerQueueIncomingPods.WithLabelValues("unschedulable", event).Inc()
	}
	u.podInfoMap[podID] = pInfo
}

// delete deletes a pod from the unschedulable podInfoMap.
// The `gated` parameter is used to figure out which metric should be decreased.
func (u *unschedulablePods) delete(pod *v1.Pod, gated bool) {