-
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.
- Loading branch information
1 parent
b0c2524
commit b493ccc
Showing
8 changed files
with
287 additions
and
31 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
18 changes: 18 additions & 0 deletions
18
cluster-autoscaler/core/scaleup/orchestrator/wrapper_orchestrator_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,18 @@ | ||
/* | ||
Copyright 2024 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 orchestrator | ||
|
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
215 changes: 215 additions & 0 deletions
215
cluster-autoscaler/provisioningrequest/checkcapacity/condition_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,215 @@ | ||
/* | ||
Copyright 2024 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 checkcapacity | ||
|
||
import ( | ||
"testing" | ||
|
||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/autoscaler/cluster-autoscaler/provisioningrequest/apis/autoscaling.x-k8s.io/v1beta1" | ||
"k8s.io/autoscaler/cluster-autoscaler/provisioningrequest/provreqwrapper" | ||
) | ||
|
||
func TestBookCapacity(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
prConditions []v1.Condition | ||
want bool | ||
}{ | ||
{ | ||
name: "Expired", | ||
prConditions: []v1.Condition{ | ||
{ | ||
Type: v1beta1.CapacityFound, | ||
Status: v1.ConditionTrue, | ||
}, | ||
{ | ||
Type: v1beta1.Expired, | ||
Status: v1.ConditionTrue, | ||
}, | ||
}, | ||
want: false, | ||
}, | ||
{ | ||
name: "Failed", | ||
prConditions: []v1.Condition{ | ||
{ | ||
Type: v1beta1.CapacityFound, | ||
Status: v1.ConditionTrue, | ||
}, | ||
{ | ||
Type: v1beta1.Failed, | ||
Status: v1.ConditionTrue, | ||
}, | ||
}, | ||
want: false, | ||
}, | ||
{ | ||
name: "empty conditions", | ||
want: false, | ||
}, | ||
{ | ||
name: "Capacity found and provisioned", | ||
prConditions: []v1.Condition{ | ||
{ | ||
Type: v1beta1.CapacityFound, | ||
Status: v1.ConditionTrue, | ||
}, | ||
{ | ||
Type: v1beta1.Provisioned, | ||
Status: v1.ConditionTrue, | ||
}, | ||
}, | ||
want: true, | ||
}, | ||
{ | ||
name: "Capacity is not found", | ||
prConditions: []v1.Condition{ | ||
{ | ||
Type: v1beta1.CapacityFound, | ||
Status: v1.ConditionFalse, | ||
}, | ||
}, | ||
want: false, | ||
}, | ||
} | ||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
pr := provreqwrapper.NewV1Beta1ProvisioningRequest( | ||
&v1beta1.ProvisioningRequest{ | ||
Spec: v1beta1.ProvisioningRequestSpec{ | ||
ProvisioningClassName: v1beta1.ProvisioningClassCheckCapacity, | ||
}, | ||
Status: v1beta1.ProvisioningRequestStatus{ | ||
Conditions: test.prConditions, | ||
}, | ||
}, nil) | ||
got := bookCapacity(pr) | ||
if got != test.want { | ||
t.Errorf("Want: %v, got: %v", test.want, got) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestSetCondition(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
oldConditions []v1.Condition | ||
newType string | ||
newStatus v1.ConditionStatus | ||
want []v1.Condition | ||
}{ | ||
{ | ||
name: "CapacityFound added, empty conditions before", | ||
newType: v1beta1.CapacityFound, | ||
newStatus: v1.ConditionTrue, | ||
want: []v1.Condition{ | ||
{ | ||
Type: v1beta1.CapacityFound, | ||
Status: v1.ConditionTrue, | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "CapacityFound updated", | ||
oldConditions: []v1.Condition{ | ||
{ | ||
Type: v1beta1.CapacityFound, | ||
Status: v1.ConditionFalse, | ||
}, | ||
}, | ||
newType: v1beta1.CapacityFound, | ||
newStatus: v1.ConditionTrue, | ||
want: []v1.Condition{ | ||
{ | ||
Type: v1beta1.CapacityFound, | ||
Status: v1.ConditionTrue, | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "Failed added, non-empty conditions before", | ||
oldConditions: []v1.Condition{ | ||
{ | ||
Type: v1beta1.CapacityFound, | ||
Status: v1.ConditionTrue, | ||
}, | ||
}, | ||
newType: v1beta1.Failed, | ||
newStatus: v1.ConditionTrue, | ||
want: []v1.Condition{ | ||
{ | ||
Type: v1beta1.CapacityFound, | ||
Status: v1.ConditionTrue, | ||
}, | ||
{ | ||
Type: v1beta1.Failed, | ||
Status: v1.ConditionTrue, | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "Expired, empty conditions before", | ||
oldConditions: []v1.Condition{ | ||
{ | ||
Type: v1beta1.CapacityFound, | ||
Status: v1.ConditionTrue, | ||
}, | ||
}, | ||
newType: v1beta1.Provisioned, | ||
newStatus: v1.ConditionFalse, | ||
want: []v1.Condition{ | ||
{ | ||
Type: v1beta1.CapacityFound, | ||
Status: v1.ConditionTrue, | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "Unknown type, conditions are not updated", | ||
newType: v1beta1.Expired, | ||
newStatus: v1.ConditionFalse, | ||
want: []v1.Condition{ | ||
{ | ||
Type: v1beta1.Expired, | ||
Status: v1.ConditionFalse, | ||
}, | ||
}, | ||
}, | ||
} | ||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
pr := provreqwrapper.NewV1Beta1ProvisioningRequest( | ||
&v1beta1.ProvisioningRequest{ | ||
Status: v1beta1.ProvisioningRequestStatus{ | ||
Conditions: test.oldConditions, | ||
}, | ||
}, nil) | ||
setCondition(pr, test.newType, test.newStatus, "", "") | ||
got := pr.Conditions() | ||
if len(got) > 2 || len(got) != len(test.want) || got[0].Type != test.want[0].Type || got[0].Status != test.want[0].Status { | ||
t.Errorf("want %v, got: %v", test.want, got) | ||
} | ||
if len(got) == 2 { | ||
if got[1].Type != test.want[1].Type || got[1].Status != test.want[1].Status { | ||
t.Errorf("want %v, got: %v", test.want, got) | ||
} | ||
} | ||
}) | ||
} | ||
} |
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
Oops, something went wrong.