-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7688 from macsko/enforce_provisioning_request_pro…
…cessing_even_if_all_pods_are_young Enforce provisioning requests processing even if all pods are new
- Loading branch information
Showing
9 changed files
with
191 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
Copyright 2025 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package pods | ||
|
||
import apiv1 "k8s.io/api/core/v1" | ||
|
||
// ScaleUpEnforcer can force scale up even if all pods are new or MaxNodesTotal was achieved. | ||
type ScaleUpEnforcer interface { | ||
ShouldForceScaleUp(unschedulablePods []*apiv1.Pod) bool | ||
} | ||
|
||
// NoOpScaleUpEnforcer returns false by default in case of ProvisioningRequests disabled. | ||
type NoOpScaleUpEnforcer struct { | ||
} | ||
|
||
// NewDefaultScaleUpEnforcer creates an instance of ScaleUpEnforcer. | ||
func NewDefaultScaleUpEnforcer() ScaleUpEnforcer { | ||
return &NoOpScaleUpEnforcer{} | ||
} | ||
|
||
// ShouldForceScaleUp returns false by default. | ||
func (p *NoOpScaleUpEnforcer) ShouldForceScaleUp(unschedulablePods []*apiv1.Pod) bool { | ||
return false | ||
} |
34 changes: 34 additions & 0 deletions
34
cluster-autoscaler/processors/pods/scaleup_enforcer_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
Copyright 2025 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package pods | ||
|
||
import ( | ||
"testing" | ||
|
||
apiv1 "k8s.io/api/core/v1" | ||
testutils "k8s.io/autoscaler/cluster-autoscaler/utils/test" | ||
) | ||
|
||
func TestDefaultScaleUpEnforcer(t *testing.T) { | ||
p1 := testutils.BuildTestPod("p1", 40, 0) | ||
unschedulablePods := []*apiv1.Pod{p1} | ||
scaleUpEnforcer := NewDefaultScaleUpEnforcer() | ||
forceScaleUp := scaleUpEnforcer.ShouldForceScaleUp(unschedulablePods) | ||
if forceScaleUp { | ||
t.Errorf("Error: scaleUpEnforcer should not force scale up by default") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
Copyright 2025 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package provreq | ||
|
||
import ( | ||
apiv1 "k8s.io/api/core/v1" | ||
"k8s.io/autoscaler/cluster-autoscaler/processors/pods" | ||
) | ||
|
||
// ProvisioningRequestScaleUpEnforcer forces scale up if there is any unschedulable pod that belongs to ProvisioningRequest. | ||
type ProvisioningRequestScaleUpEnforcer struct { | ||
} | ||
|
||
// NewProvisioningRequestScaleUpEnforcer creates a ProvisioningRequest scale up enforcer. | ||
func NewProvisioningRequestScaleUpEnforcer() pods.ScaleUpEnforcer { | ||
return &ProvisioningRequestScaleUpEnforcer{} | ||
} | ||
|
||
// ShouldForceScaleUp forces scale up if there is any unschedulable pod that belongs to ProvisioningRequest. | ||
func (p *ProvisioningRequestScaleUpEnforcer) ShouldForceScaleUp(unschedulablePods []*apiv1.Pod) bool { | ||
for _, pod := range unschedulablePods { | ||
if _, ok := provisioningRequestName(pod); ok { | ||
return true | ||
} | ||
} | ||
return false | ||
} |
66 changes: 66 additions & 0 deletions
66
cluster-autoscaler/processors/provreq/scaleup_enforcer_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
Copyright 2025 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package provreq | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
apiv1 "k8s.io/api/core/v1" | ||
corev1 "k8s.io/api/core/v1" | ||
v1 "k8s.io/autoscaler/cluster-autoscaler/apis/provisioningrequest/autoscaling.x-k8s.io/v1" | ||
"k8s.io/autoscaler/cluster-autoscaler/provisioningrequest/pods" | ||
testutils "k8s.io/autoscaler/cluster-autoscaler/utils/test" | ||
) | ||
|
||
func TestProvisioningRequestScaleUpEnforcer(t *testing.T) { | ||
prPod1 := testutils.BuildTestPod("pr-pod-1", 500, 10) | ||
prPod1.Annotations[v1.ProvisioningRequestPodAnnotationKey] = "pr-class" | ||
|
||
prPod2 := testutils.BuildTestPod("pr-pod-2", 500, 10) | ||
prPod2.Annotations[pods.DeprecatedProvisioningRequestPodAnnotationKey] = "pr-class-2" | ||
|
||
pod1 := testutils.BuildTestPod("pod-1", 500, 10) | ||
pod2 := testutils.BuildTestPod("pod-2", 500, 10) | ||
|
||
testCases := map[string]struct { | ||
unschedulablePods []*apiv1.Pod | ||
want bool | ||
}{ | ||
"Any pod with ProvisioningRequest annotation key forces scale up": { | ||
unschedulablePods: []*corev1.Pod{prPod1, pod1}, | ||
want: true, | ||
}, | ||
"Any pod with ProvisioningRequest deprecated annotation key forces scale up": { | ||
unschedulablePods: []*corev1.Pod{prPod2, pod1}, | ||
want: true, | ||
}, | ||
"Pod without ProvisioningRequest annotation key don't force scale up": { | ||
unschedulablePods: []*corev1.Pod{pod1, pod2}, | ||
want: false, | ||
}, | ||
"No pods don't force scale up": { | ||
unschedulablePods: []*corev1.Pod{}, | ||
want: false, | ||
}, | ||
} | ||
for _, test := range testCases { | ||
scaleUpEnforcer := NewProvisioningRequestScaleUpEnforcer() | ||
got := scaleUpEnforcer.ShouldForceScaleUp(test.unschedulablePods) | ||
assert.Equal(t, got, test.want) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters