Merge pull request #63662 from xchapter7x/pkg-scheduler-algorithmprovider

Automatic merge from submit-queue (batch tested with PRs 64285, 63660, 63661, 63662, 64883). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

use subtest for table units (pkg/scheduler/algorithmprovider)

**What this PR does / why we need it**: Update scheduler's unit table tests to use subtest

**Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*:

**Special notes for your reviewer**:
breaks up PR: https://github.com/kubernetes/kubernetes/pull/63281
/ref #63267

**Release note**:

```release-note
This PR will leverage subtests on the existing table tests for the scheduler units.
Some refactoring of error/status messages and functions to align with new approach.

```
pull/8/head
Kubernetes Submit Queue 2018-06-21 01:19:26 -07:00 committed by GitHub
commit 15902d9113
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 46 additions and 42 deletions

View File

@ -17,6 +17,7 @@ limitations under the License.
package algorithmprovider package algorithmprovider
import ( import (
"fmt"
"testing" "testing"
utilfeature "k8s.io/apiserver/pkg/util/feature" utilfeature "k8s.io/apiserver/pkg/util/feature"
@ -44,44 +45,48 @@ func TestDefaultConfigExists(t *testing.T) {
func TestAlgorithmProviders(t *testing.T) { func TestAlgorithmProviders(t *testing.T) {
for _, pn := range algorithmProviderNames { for _, pn := range algorithmProviderNames {
p, err := factory.GetAlgorithmProvider(pn) t.Run(pn, func(t *testing.T) {
if err != nil { p, err := factory.GetAlgorithmProvider(pn)
t.Errorf("error retrieving '%s' provider: %v", pn, err) if err != nil {
break t.Fatalf("error retrieving provider: %v", err)
}
if len(p.PriorityFunctionKeys) == 0 {
t.Errorf("%s algorithm provider shouldn't have 0 priority functions", pn)
}
for _, pf := range p.PriorityFunctionKeys.List() {
if !factory.IsPriorityFunctionRegistered(pf) {
t.Errorf("priority function %s is not registered but is used in the %s algorithm provider", pf, pn)
} }
} if len(p.PriorityFunctionKeys) == 0 {
for _, fp := range p.FitPredicateKeys.List() { t.Errorf("algorithm provider shouldn't have 0 priority functions")
if !factory.IsFitPredicateRegistered(fp) {
t.Errorf("fit predicate %s is not registered but is used in the %s algorithm provider", fp, pn)
} }
} for _, pf := range p.PriorityFunctionKeys.List() {
t.Run(fmt.Sprintf("priorityfunction/%s", pf), func(t *testing.T) {
if !factory.IsPriorityFunctionRegistered(pf) {
t.Errorf("priority function is not registered but is used in the algorithm provider")
}
})
}
for _, fp := range p.FitPredicateKeys.List() {
t.Run(fmt.Sprintf("fitpredicate/%s", fp), func(t *testing.T) {
if !factory.IsFitPredicateRegistered(fp) {
t.Errorf("fit predicate is not registered but is used in the algorithm provider")
}
})
}
})
} }
} }
func TestApplyFeatureGates(t *testing.T) { func TestApplyFeatureGates(t *testing.T) {
for _, pn := range algorithmProviderNames { for _, pn := range algorithmProviderNames {
p, err := factory.GetAlgorithmProvider(pn) t.Run(pn, func(t *testing.T) {
if err != nil { p, err := factory.GetAlgorithmProvider(pn)
t.Errorf("Error retrieving '%s' provider: %v", pn, err) if err != nil {
break t.Fatalf("Error retrieving provider: %v", err)
} }
if !p.FitPredicateKeys.Has("CheckNodeCondition") { if !p.FitPredicateKeys.Has("CheckNodeCondition") {
t.Errorf("Failed to find predicate: 'CheckNodeCondition'") t.Fatalf("Failed to find predicate: 'CheckNodeCondition'")
break }
}
if !p.FitPredicateKeys.Has("PodToleratesNodeTaints") { if !p.FitPredicateKeys.Has("PodToleratesNodeTaints") {
t.Errorf("Failed to find predicate: 'PodToleratesNodeTaints'") t.Fatalf("Failed to find predicate: 'PodToleratesNodeTaints'")
break }
} })
} }
// Apply features for algorithm providers. // Apply features for algorithm providers.
@ -90,20 +95,19 @@ func TestApplyFeatureGates(t *testing.T) {
ApplyFeatureGates() ApplyFeatureGates()
for _, pn := range algorithmProviderNames { for _, pn := range algorithmProviderNames {
p, err := factory.GetAlgorithmProvider(pn) t.Run(pn, func(t *testing.T) {
if err != nil { p, err := factory.GetAlgorithmProvider(pn)
t.Errorf("Error retrieving '%s' provider: %v", pn, err) if err != nil {
break t.Fatalf("Error retrieving '%s' provider: %v", pn, err)
} }
if !p.FitPredicateKeys.Has("PodToleratesNodeTaints") { if !p.FitPredicateKeys.Has("PodToleratesNodeTaints") {
t.Errorf("Failed to find predicate: 'PodToleratesNodeTaints'") t.Fatalf("Failed to find predicate: 'PodToleratesNodeTaints'")
break }
}
if p.FitPredicateKeys.Has("CheckNodeCondition") { if p.FitPredicateKeys.Has("CheckNodeCondition") {
t.Errorf("Unexpected predicate: 'CheckNodeCondition'") t.Fatalf("Unexpected predicate: 'CheckNodeCondition'")
break }
} })
} }
} }