apiserver: fix defaulting for apf bootstrap configuration

This commit is contained in:
Abu Kashem
2022-10-20 18:50:14 -04:00
committed by Mike Spreitzer
parent 284020cfdf
commit 424b23bb15
4 changed files with 47 additions and 19 deletions

View File

@@ -17,31 +17,45 @@ limitations under the License.
package internalbootstrap
import (
"fmt"
"testing"
"github.com/google/go-cmp/cmp"
flowcontrol "k8s.io/api/flowcontrol/v1beta3"
apiequality "k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apiserver/pkg/apis/flowcontrol/bootstrap"
)
func TestMandatoryAlreadyDefaulted(t *testing.T) {
func TestBootstrapConfigurationWithDefaulted(t *testing.T) {
scheme := NewAPFScheme()
for _, obj := range bootstrap.MandatoryFlowSchemas {
obj2 := obj.DeepCopyObject().(*flowcontrol.FlowSchema)
scheme.Default(obj2)
if apiequality.Semantic.DeepEqual(obj, obj2) {
t.Logf("Defaulting makes no change to %#+v", *obj)
} else {
t.Errorf("Defaulting changed %#+v to %#+v", *obj, *obj2)
}
bootstrapFlowSchemas := make([]*flowcontrol.FlowSchema, 0)
bootstrapFlowSchemas = append(bootstrapFlowSchemas, bootstrap.MandatoryFlowSchemas...)
bootstrapFlowSchemas = append(bootstrapFlowSchemas, bootstrap.SuggestedFlowSchemas...)
for _, original := range bootstrapFlowSchemas {
t.Run(fmt.Sprintf("FlowSchema/%s", original.Name), func(t *testing.T) {
defaulted := original.DeepCopyObject().(*flowcontrol.FlowSchema)
scheme.Default(defaulted)
if apiequality.Semantic.DeepEqual(original, defaulted) {
t.Logf("Defaulting makes no change to FlowSchema: %q", original.Name)
return
}
t.Errorf("Expected defaulting to not change FlowSchema: %q, diff: %s", original.Name, cmp.Diff(original, defaulted))
})
}
for _, obj := range bootstrap.MandatoryPriorityLevelConfigurations {
obj2 := obj.DeepCopyObject().(*flowcontrol.PriorityLevelConfiguration)
scheme.Default(obj2)
if apiequality.Semantic.DeepEqual(obj, obj2) {
t.Logf("Defaulting makes no change to %#+v", *obj)
} else {
t.Errorf("Defaulting changed %#+v to %#+v", *obj, *obj2)
}
bootstrapPriorityLevels := make([]*flowcontrol.PriorityLevelConfiguration, 0)
bootstrapPriorityLevels = append(bootstrapPriorityLevels, bootstrap.MandatoryPriorityLevelConfigurations...)
bootstrapPriorityLevels = append(bootstrapPriorityLevels, bootstrap.SuggestedPriorityLevelConfigurations...)
for _, original := range bootstrapPriorityLevels {
t.Run(fmt.Sprintf("PriorityLevelConfiguration/%s", original.Name), func(t *testing.T) {
defaulted := original.DeepCopyObject().(*flowcontrol.PriorityLevelConfiguration)
scheme.Default(defaulted)
if apiequality.Semantic.DeepEqual(original, defaulted) {
t.Logf("Defaulting makes no change to PriorityLevelConfiguration: %q", original.Name)
return
}
t.Errorf("Expected defaulting to not change PriorityLevelConfiguration: %q, diff: %s", original.Name, cmp.Diff(original, defaulted))
})
}
}