Skip to content

Commit

Permalink
Merge pull request #6922 from yaroslava-serdiuk/provreq-injector
Browse files Browse the repository at this point in the history
Add ProvisioningClass validation to Provisioning pods injector
  • Loading branch information
k8s-ci-robot authored Jun 20, 2024
2 parents 49c4e05 + b7e5d90 commit 6d0e137
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
5 changes: 5 additions & 0 deletions cluster-autoscaler/processors/provreq/injector.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"k8s.io/autoscaler/cluster-autoscaler/apis/provisioningrequest/autoscaling.x-k8s.io/v1beta1"
"k8s.io/autoscaler/cluster-autoscaler/context"
"k8s.io/autoscaler/cluster-autoscaler/processors/pods"
"k8s.io/autoscaler/cluster-autoscaler/provisioningrequest"
provreqconditions "k8s.io/autoscaler/cluster-autoscaler/provisioningrequest/conditions"
provreqpods "k8s.io/autoscaler/cluster-autoscaler/provisioningrequest/pods"
"k8s.io/autoscaler/cluster-autoscaler/provisioningrequest/provreqclient"
Expand Down Expand Up @@ -53,6 +54,10 @@ func (p *ProvisioningRequestPodsInjector) Process(
return nil, err
}
for _, pr := range provReqs {
if ok, found := provisioningrequest.SupportedProvisioningClasses[pr.Spec.ProvisioningClassName]; !ok || !found {
klog.Warningf("Provisioning Class %s is not supported", pr.Spec.ProvisioningClassName)
continue
}
conditions := pr.Status.Conditions
if apimeta.IsStatusConditionTrue(conditions, v1beta1.Failed) || apimeta.IsStatusConditionTrue(conditions, v1beta1.Provisioned) {
continue
Expand Down
23 changes: 14 additions & 9 deletions cluster-autoscaler/processors/provreq/injector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,16 @@ func TestProvisioningRequestPodsInjector(t *testing.T) {
}

podsA := 10
newProvReqA := testProvisioningRequestWithCondition("new", podsA)
newAcceptedProvReqA := testProvisioningRequestWithCondition("new-accepted", podsA, accepted)
newProvReqA := testProvisioningRequestWithCondition("new", podsA, v1beta1.ProvisioningClassCheckCapacity)
newAcceptedProvReqA := testProvisioningRequestWithCondition("new-accepted", podsA, v1beta1.ProvisioningClassCheckCapacity, accepted)

podsB := 20
notProvisionedAcceptedProvReqB := testProvisioningRequestWithCondition("provisioned-false-B", podsB, notProvisioned, accepted)
provisionedAcceptedProvReqB := testProvisioningRequestWithCondition("provisioned-and-accepted", podsB, provisioned, accepted)
failedProvReq := testProvisioningRequestWithCondition("failed", podsA, failed)
notProvisionedRecentlyProvReqB := testProvisioningRequestWithCondition("provisioned-false-recently-B", podsB, notProvisionedRecently)
unknownProvisionedProvReqB := testProvisioningRequestWithCondition("provisioned-unknown-B", podsB, unknownProvisioned)
notProvisionedAcceptedProvReqB := testProvisioningRequestWithCondition("provisioned-false-B", podsB, v1beta1.ProvisioningClassBestEffortAtomicScaleUp, notProvisioned, accepted)
provisionedAcceptedProvReqB := testProvisioningRequestWithCondition("provisioned-and-accepted", podsB, v1beta1.ProvisioningClassBestEffortAtomicScaleUp, provisioned, accepted)
failedProvReq := testProvisioningRequestWithCondition("failed", podsA, v1beta1.ProvisioningClassBestEffortAtomicScaleUp, failed)
notProvisionedRecentlyProvReqB := testProvisioningRequestWithCondition("provisioned-false-recently-B", podsB, v1beta1.ProvisioningClassBestEffortAtomicScaleUp, notProvisionedRecently)
unknownProvisionedProvReqB := testProvisioningRequestWithCondition("provisioned-unknown-B", podsB, v1beta1.ProvisioningClassBestEffortAtomicScaleUp, unknownProvisioned)
unknownClass := testProvisioningRequestWithCondition("new-accepted", podsA, "unknown-class", accepted)

testCases := []struct {
name string
Expand Down Expand Up @@ -109,6 +110,10 @@ func TestProvisioningRequestPodsInjector(t *testing.T) {
name: "Provisioned=Unknown, no pods are injected",
provReqs: []*provreqwrapper.ProvisioningRequest{unknownProvisionedProvReqB, failedProvReq, notProvisionedRecentlyProvReqB},
},
{
name: "ProvisionedClass is unknown, no pods are injected",
provReqs: []*provreqwrapper.ProvisioningRequest{unknownClass, failedProvReq},
},
}
for _, tc := range testCases {
client := provreqclient.NewFakeProvisioningRequestClient(context.Background(), t, tc.provReqs...)
Expand All @@ -132,8 +137,8 @@ func TestProvisioningRequestPodsInjector(t *testing.T) {

}

func testProvisioningRequestWithCondition(name string, podCount int, conditions ...metav1.Condition) *provreqwrapper.ProvisioningRequest {
pr := provreqwrapper.BuildTestProvisioningRequest("ns", name, "10", "100", "", int32(podCount), false, time.Now(), "ProvisioningClass")
func testProvisioningRequestWithCondition(name string, podCount int, class string, conditions ...metav1.Condition) *provreqwrapper.ProvisioningRequest {
pr := provreqwrapper.BuildTestProvisioningRequest("ns", name, "10", "100", "", int32(podCount), false, time.Now(), class)
pr.Status.Conditions = conditions
return pr
}

0 comments on commit 6d0e137

Please sign in to comment.