Skip to content

Commit

Permalink
Update ProvReq annotations to new prefix
Browse files Browse the repository at this point in the history
Use autoscaling.x-k8s.io rather than cluster-autoscaler.kubernetes.io
  • Loading branch information
kisieland committed May 28, 2024
1 parent 6c1e3e7 commit e0f4b75
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,11 @@ import (
v1 "k8s.io/api/core/v1"
"k8s.io/autoscaler/cluster-autoscaler/context"
"k8s.io/autoscaler/cluster-autoscaler/processors/pods"
provreqpods "k8s.io/autoscaler/cluster-autoscaler/provisioningrequest/pods"
"k8s.io/autoscaler/cluster-autoscaler/utils/klogx"
)

const (
// ProvisioningRequestPodAnnotationKey is an annotation on pod that indicate that pod was created by ProvisioningRequest.
ProvisioningRequestPodAnnotationKey = "cluster-autoscaler.kubernetes.io/consume-provisioning-request"
maxProvReqEvent = 50
)
const maxProvReqEvent = 50

// EventManager is an interface for handling events for provisioning request.
type EventManager interface {
Expand Down Expand Up @@ -102,6 +99,9 @@ func provisioningRequestName(pod *v1.Pod) (string, bool) {
if pod == nil || pod.Annotations == nil {
return "", false
}
provReqName, found := pod.Annotations[ProvisioningRequestPodAnnotationKey]
provReqName, found := pod.Annotations[provreqpods.ProvisioningRequestPodAnnotationKey]
if !found {
provReqName, found = pod.Annotations[provreqpods.DeprecatedProvisioningRequestPodAnnotationKey]
}
return provReqName, found
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@ import (
apiv1 "k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/autoscaler/cluster-autoscaler/context"
provreqpods "k8s.io/autoscaler/cluster-autoscaler/provisioningrequest/pods"
. "k8s.io/autoscaler/cluster-autoscaler/utils/test"
"k8s.io/client-go/tools/record"
)

func TestProvisioningRequestPodsFilter(t *testing.T) {
prPod1 := BuildTestPod("pr-pod-1", 500, 10)
prPod1.Annotations[ProvisioningRequestPodAnnotationKey] = "pr-class"
prPod1.Annotations[provreqpods.ProvisioningRequestPodAnnotationKey] = "pr-class"

prPod2 := BuildTestPod("pr-pod-2", 500, 10)
prPod2.Annotations[ProvisioningRequestPodAnnotationKey] = "pr-class-2"
prPod2.Annotations[provreqpods.ProvisioningRequestPodAnnotationKey] = "pr-class-2"

pod1 := BuildTestPod("pod-1", 500, 10)
pod2 := BuildTestPod("pod-2", 500, 10)
Expand Down Expand Up @@ -91,7 +92,7 @@ func TestEventManager(t *testing.T) {

for i := 0; i < 10; i++ {
prPod := BuildTestPod(fmt.Sprintf("pr-pod-%d", i), 10, 10)
prPod.Annotations[ProvisioningRequestPodAnnotationKey] = "pr-class"
prPod.Annotations[provreqpods.ProvisioningRequestPodAnnotationKey] = "pr-class"
unscheduledPods = append(unscheduledPods, prPod)
}
got, err := prFilter.Process(ctx, unscheduledPods)
Expand Down
7 changes: 5 additions & 2 deletions cluster-autoscaler/proposals/provisioning-request.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,13 @@ not required in ProvReq’s template, though can be specified):

```yaml
annotations:
"cluster-autoscaler.kubernetes.io/provisioning-class-name": "provreq-class-name"
"cluster-autoscaler.kubernetes.io/consume-provisioning-request": "provreq-name"
"autoscaling.x-k8s.io/provisioning-class-name": "provreq-class-name"
"autoscaling.x-k8s.io/consume-provisioning-request": "provreq-name"
```
Previous prosoal included annotations with prefix `cluster-autoscaler.kubernetes.io`
but were deprecated as part of API reivew.

If those are provided for the pods that consume the ProvReq with `check-capacity.kubernetes.io` class,
the CA will not provision the capacity, even if it was needed (as some other pods might have been
scheduled on it) and will result in visibility events passed to the ProvReq and pods.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (
"k8s.io/autoscaler/cluster-autoscaler/core/scaleup/orchestrator"
"k8s.io/autoscaler/cluster-autoscaler/estimator"
ca_processors "k8s.io/autoscaler/cluster-autoscaler/processors"
"k8s.io/autoscaler/cluster-autoscaler/processors/provreq"
"k8s.io/autoscaler/cluster-autoscaler/processors/status"
provreqpods "k8s.io/autoscaler/cluster-autoscaler/provisioningrequest/pods"
"k8s.io/autoscaler/cluster-autoscaler/utils/errors"
"k8s.io/autoscaler/cluster-autoscaler/utils/taints"
schedulerframework "k8s.io/kubernetes/pkg/scheduler/framework"
Expand Down Expand Up @@ -87,7 +87,7 @@ func (o *WrapperOrchestrator) ScaleUp(

func splitOut(unschedulablePods []*apiv1.Pod) (provReqPods, regularPods []*apiv1.Pod) {
for _, pod := range unschedulablePods {
if _, ok := pod.Annotations[provreq.ProvisioningRequestPodAnnotationKey]; ok {
if _, ok := pod.Annotations[provreqpods.ProvisioningRequestPodAnnotationKey]; ok {
provReqPods = append(provReqPods, pod)
} else {
regularPods = append(regularPods, pod)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import (
"k8s.io/autoscaler/cluster-autoscaler/context"
"k8s.io/autoscaler/cluster-autoscaler/estimator"
ca_processors "k8s.io/autoscaler/cluster-autoscaler/processors"
"k8s.io/autoscaler/cluster-autoscaler/processors/provreq"
"k8s.io/autoscaler/cluster-autoscaler/processors/status"
provreqpods "k8s.io/autoscaler/cluster-autoscaler/provisioningrequest/pods"
"k8s.io/autoscaler/cluster-autoscaler/utils/errors"
"k8s.io/autoscaler/cluster-autoscaler/utils/taints"
. "k8s.io/autoscaler/cluster-autoscaler/utils/test"
Expand All @@ -53,7 +53,7 @@ func TestWrapperScaleUp(t *testing.T) {
BuildTestPod("pr-pod-2", 1, 100),
}
for _, pod := range provReqPods {
pod.Annotations[provreq.ProvisioningRequestPodAnnotationKey] = "true"
pod.Annotations[provreqpods.ProvisioningRequestPodAnnotationKey] = "true"
}
unschedulablePods := append(regularPods, provReqPods...)
_, err := o.ScaleUp(unschedulablePods, nil, nil, nil, false)
Expand Down
8 changes: 6 additions & 2 deletions cluster-autoscaler/provisioningrequest/pods/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ import (

const (
// ProvisioningRequestPodAnnotationKey is a key used to annotate pods consuming provisioning request.
ProvisioningRequestPodAnnotationKey = "cluster-autoscaler.kubernetes.io/consume-provisioning-request"
ProvisioningRequestPodAnnotationKey = "autoscaling.x-k8s.io/consume-provisioning-request"
// ProvisioningClassPodAnnotationKey is a key used to add annotation about Provisioning Class
ProvisioningClassPodAnnotationKey = "cluster-autoscaler.kubernetes.io/provisioning-class-name"
ProvisioningClassPodAnnotationKey = "autoscaling.x-k8s.io/provisioning-class-name"
// DeprecatedProvisioningRequestPodAnnotationKey is a key used to annotate pods consuming provisioning request.
DeprecatedProvisioningRequestPodAnnotationKey = "cluster-autoscaler.kubernetes.io/consume-provisioning-request"
// DeprecatedProvisioningClassPodAnnotationKey is a key used to add annotation about Provisioning Class
DeprecatedProvisioningClassPodAnnotationKey = "cluster-autoscaler.kubernetes.io/provisioning-class-name"
)

// PodsForProvisioningRequest returns a list of pods for which Provisioning
Expand Down

0 comments on commit e0f4b75

Please sign in to comment.