57
57
assignedPodOtherUpdate = ClusterEvent {Resource : Pod , ActionType : updatePodOther , Label : "AssignedPodUpdate" }
58
58
// AssignedPodDelete is the event when an assigned pod is deleted.
59
59
AssignedPodDelete = ClusterEvent {Resource : Pod , ActionType : Delete , Label : "AssignedPodDelete" }
60
- // PodRequestChange is the event when a pod's resource request is changed .
61
- PodRequestChange = ClusterEvent {Resource : Pod , ActionType : UpdatePodRequest , Label : "PodRequestChange " }
60
+ // PodRequestScaledDown is the event when a pod's resource request is scaled down .
61
+ PodRequestScaledDown = ClusterEvent {Resource : Pod , ActionType : UpdatePodScaleDown , Label : "PodRequestScaledDown " }
62
62
// PodLabelChange is the event when a pod's label is changed.
63
63
PodLabelChange = ClusterEvent {Resource : Pod , ActionType : UpdatePodLabel , Label : "PodLabelChange" }
64
64
// NodeSpecUnschedulableChange is the event when unschedulable node spec is changed.
@@ -108,7 +108,7 @@ var (
108
108
func PodSchedulingPropertiesChange (newPod * v1.Pod , oldPod * v1.Pod ) (events []ClusterEvent ) {
109
109
podChangeExtracters := []podChangeExtractor {
110
110
extractPodLabelsChange ,
111
- extractPodResourceRequestChange ,
111
+ extractPodScaleDown ,
112
112
}
113
113
114
114
for _ , fn := range podChangeExtracters {
@@ -128,13 +128,27 @@ func PodSchedulingPropertiesChange(newPod *v1.Pod, oldPod *v1.Pod) (events []Clu
128
128
129
129
type podChangeExtractor func (newNode * v1.Pod , oldNode * v1.Pod ) * ClusterEvent
130
130
131
- func extractPodResourceRequestChange (newPod , oldPod * v1.Pod ) * ClusterEvent {
131
+ // extractPodScaleDown interprets the update of a pod and returns PodRequestScaledDown event if any pod's resource request(s) is scaled down.
132
+ func extractPodScaleDown (newPod , oldPod * v1.Pod ) * ClusterEvent {
132
133
opt := resource.PodResourcesOptions {
133
134
InPlacePodVerticalScalingEnabled : utilfeature .DefaultFeatureGate .Enabled (features .InPlacePodVerticalScaling ),
134
135
}
135
- if ! equality .Semantic .DeepEqual (resource .PodRequests (newPod , opt ), resource .PodRequests (oldPod , opt )) {
136
- return & PodRequestChange
136
+ newPodRequests := resource .PodRequests (newPod , opt )
137
+ oldPodRequests := resource .PodRequests (oldPod , opt )
138
+
139
+ for rName , oldReq := range oldPodRequests {
140
+ newReq , ok := newPodRequests [rName ]
141
+ if ! ok {
142
+ // The resource request of rName is removed.
143
+ return & PodRequestScaledDown
144
+ }
145
+
146
+ if oldReq .MilliValue () > newReq .MilliValue () {
147
+ // The resource request of rName is scaled down.
148
+ return & PodRequestScaledDown
149
+ }
137
150
}
151
+
138
152
return nil
139
153
}
140
154
0 commit comments