Revert "Introduce topology into the runtimeClass API"

This commit is contained in:
Yassine TIJANI
2019-05-31 20:49:40 +00:00
committed by GitHub
parent b7fa33ec15
commit 480d5e47b6
27 changed files with 76 additions and 1341 deletions

View File

@@ -11,7 +11,6 @@ go_library(
importpath = "k8s.io/kubernetes/pkg/apis/node",
visibility = ["//visibility:public"],
deps = [
"//pkg/apis/core:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",

View File

@@ -18,7 +18,6 @@ package node
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/kubernetes/pkg/apis/core"
)
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
@@ -46,31 +45,6 @@ type RuntimeClass struct {
// The Handler must conform to the DNS Label (RFC 1123) requirements, and is
// immutable.
Handler string
// Scheduling holds the scheduling constraints to ensure that pods running
// with this RuntimeClass are scheduled to nodes that support it.
// If scheduling is nil, this RuntimeClass is assumed to be supported by all
// nodes.
// +optional
Scheduling *Scheduling
}
// Scheduling specifies the scheduling constraints for nodes supporting a
// RuntimeClass.
type Scheduling struct {
// nodeSelector lists labels that must be present on nodes that support this
// RuntimeClass. Pods using this RuntimeClass can only be scheduled to a
// node matched by this selector. The RuntimeClass nodeSelector is merged
// with a pod's existing nodeSelector. Any conflicts will cause the pod to
// be rejected in admission.
// +optional
NodeSelector map[string]string
// tolerations are appended (excluding duplicates) to pods running with this
// RuntimeClass during admission, effectively unioning the set of nodes
// tolerated by the pod and the RuntimeClass.
// +optional
Tolerations []core.Toleration
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

View File

@@ -11,9 +11,7 @@ go_library(
importpath = "k8s.io/kubernetes/pkg/apis/node/v1alpha1",
visibility = ["//visibility:public"],
deps = [
"//pkg/apis/core:go_default_library",
"//pkg/apis/node:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/api/node/v1alpha1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/conversion:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
@@ -40,9 +38,7 @@ go_test(
srcs = ["conversion_test.go"],
embed = [":go_default_library"],
deps = [
"//pkg/apis/core:go_default_library",
"//pkg/apis/node:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/api/node/v1alpha1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/github.com/stretchr/testify/assert:go_default_library",

View File

@@ -33,19 +33,11 @@ func addConversionFuncs(s *runtime.Scheme) error {
func Convert_v1alpha1_RuntimeClass_To_node_RuntimeClass(in *v1alpha1.RuntimeClass, out *node.RuntimeClass, s conversion.Scope) error {
out.ObjectMeta = in.ObjectMeta
out.Handler = in.Spec.RuntimeHandler
if in.Spec.Scheduling != nil {
out.Scheduling = new(node.Scheduling)
autoConvert_v1alpha1_Scheduling_To_node_Scheduling(in.Spec.Scheduling, out.Scheduling, s)
}
return nil
}
func Convert_node_RuntimeClass_To_v1alpha1_RuntimeClass(in *node.RuntimeClass, out *v1alpha1.RuntimeClass, s conversion.Scope) error {
out.ObjectMeta = in.ObjectMeta
out.Spec.RuntimeHandler = in.Handler
if in.Scheduling != nil {
out.Spec.Scheduling = new(v1alpha1.Scheduling)
autoConvert_node_Scheduling_To_v1alpha1_Scheduling(in.Scheduling, out.Spec.Scheduling, s)
}
return nil
}

View File

@@ -21,10 +21,8 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1"
v1alpha1 "k8s.io/api/node/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
core "k8s.io/kubernetes/pkg/apis/core"
node "k8s.io/kubernetes/pkg/apis/node"
)
@@ -33,77 +31,24 @@ func TestRuntimeClassConversion(t *testing.T) {
name = "puppy"
handler = "heidi"
)
tests := map[string]struct {
internal *node.RuntimeClass
external *v1alpha1.RuntimeClass
}{
"fully-specified": {
internal: &node.RuntimeClass{
ObjectMeta: metav1.ObjectMeta{Name: name},
Handler: handler,
Scheduling: &node.Scheduling{
NodeSelector: map[string]string{"extra-soft": "true"},
Tolerations: []core.Toleration{{
Key: "stinky",
Operator: core.TolerationOpExists,
Effect: core.TaintEffectNoSchedule,
}},
},
},
external: &v1alpha1.RuntimeClass{
ObjectMeta: metav1.ObjectMeta{Name: name},
Spec: v1alpha1.RuntimeClassSpec{
RuntimeHandler: handler,
Scheduling: &v1alpha1.Scheduling{
NodeSelector: map[string]string{"extra-soft": "true"},
Tolerations: []corev1.Toleration{{
Key: "stinky",
Operator: corev1.TolerationOpExists,
Effect: corev1.TaintEffectNoSchedule,
}},
},
},
},
},
"empty-scheduling": {
internal: &node.RuntimeClass{
ObjectMeta: metav1.ObjectMeta{Name: name},
Handler: handler,
Scheduling: &node.Scheduling{},
},
external: &v1alpha1.RuntimeClass{
ObjectMeta: metav1.ObjectMeta{Name: name},
Spec: v1alpha1.RuntimeClassSpec{
RuntimeHandler: handler,
Scheduling: &v1alpha1.Scheduling{},
},
},
},
"empty": {
internal: &node.RuntimeClass{
ObjectMeta: metav1.ObjectMeta{Name: name},
Handler: handler,
},
external: &v1alpha1.RuntimeClass{
ObjectMeta: metav1.ObjectMeta{Name: name},
Spec: v1alpha1.RuntimeClassSpec{
RuntimeHandler: handler,
},
},
internalRC := node.RuntimeClass{
ObjectMeta: metav1.ObjectMeta{Name: name},
Handler: handler,
}
v1alpha1RC := v1alpha1.RuntimeClass{
ObjectMeta: metav1.ObjectMeta{Name: name},
Spec: v1alpha1.RuntimeClassSpec{
RuntimeHandler: handler,
},
}
for name, test := range tests {
t.Run(name, func(t *testing.T) {
convertedInternal := &node.RuntimeClass{}
require.NoError(t,
Convert_v1alpha1_RuntimeClass_To_node_RuntimeClass(test.external, convertedInternal, nil))
assert.Equal(t, test.internal, convertedInternal, "external -> internal")
convertedInternal := node.RuntimeClass{}
require.NoError(t,
Convert_v1alpha1_RuntimeClass_To_node_RuntimeClass(&v1alpha1RC, &convertedInternal, nil))
assert.Equal(t, internalRC, convertedInternal)
convertedV1alpha1 := &v1alpha1.RuntimeClass{}
require.NoError(t,
Convert_node_RuntimeClass_To_v1alpha1_RuntimeClass(test.internal, convertedV1alpha1, nil))
assert.Equal(t, test.external, convertedV1alpha1, "internal -> external")
})
}
convertedV1alpha1 := v1alpha1.RuntimeClass{}
require.NoError(t,
Convert_node_RuntimeClass_To_v1alpha1_RuntimeClass(&internalRC, &convertedV1alpha1, nil))
assert.Equal(t, v1alpha1RC, convertedV1alpha1)
}

View File

@@ -21,13 +21,9 @@ limitations under the License.
package v1alpha1
import (
unsafe "unsafe"
v1 "k8s.io/api/core/v1"
v1alpha1 "k8s.io/api/node/v1alpha1"
conversion "k8s.io/apimachinery/pkg/conversion"
runtime "k8s.io/apimachinery/pkg/runtime"
core "k8s.io/kubernetes/pkg/apis/core"
node "k8s.io/kubernetes/pkg/apis/node"
)
@@ -58,16 +54,6 @@ func RegisterConversions(s *runtime.Scheme) error {
}); err != nil {
return err
}
if err := s.AddGeneratedConversionFunc((*v1alpha1.Scheduling)(nil), (*node.Scheduling)(nil), func(a, b interface{}, scope conversion.Scope) error {
return Convert_v1alpha1_Scheduling_To_node_Scheduling(a.(*v1alpha1.Scheduling), b.(*node.Scheduling), scope)
}); err != nil {
return err
}
if err := s.AddGeneratedConversionFunc((*node.Scheduling)(nil), (*v1alpha1.Scheduling)(nil), func(a, b interface{}, scope conversion.Scope) error {
return Convert_node_Scheduling_To_v1alpha1_Scheduling(a.(*node.Scheduling), b.(*v1alpha1.Scheduling), scope)
}); err != nil {
return err
}
if err := s.AddConversionFunc((*node.RuntimeClass)(nil), (*v1alpha1.RuntimeClass)(nil), func(a, b interface{}, scope conversion.Scope) error {
return Convert_node_RuntimeClass_To_v1alpha1_RuntimeClass(a.(*node.RuntimeClass), b.(*v1alpha1.RuntimeClass), scope)
}); err != nil {
@@ -90,7 +76,6 @@ func autoConvert_v1alpha1_RuntimeClass_To_node_RuntimeClass(in *v1alpha1.Runtime
func autoConvert_node_RuntimeClass_To_v1alpha1_RuntimeClass(in *node.RuntimeClass, out *v1alpha1.RuntimeClass, s conversion.Scope) error {
out.ObjectMeta = in.ObjectMeta
// WARNING: in.Handler requires manual conversion: does not exist in peer-type
// WARNING: in.Scheduling requires manual conversion: does not exist in peer-type
return nil
}
@@ -135,25 +120,3 @@ func autoConvert_node_RuntimeClassList_To_v1alpha1_RuntimeClassList(in *node.Run
func Convert_node_RuntimeClassList_To_v1alpha1_RuntimeClassList(in *node.RuntimeClassList, out *v1alpha1.RuntimeClassList, s conversion.Scope) error {
return autoConvert_node_RuntimeClassList_To_v1alpha1_RuntimeClassList(in, out, s)
}
func autoConvert_v1alpha1_Scheduling_To_node_Scheduling(in *v1alpha1.Scheduling, out *node.Scheduling, s conversion.Scope) error {
out.NodeSelector = *(*map[string]string)(unsafe.Pointer(&in.NodeSelector))
out.Tolerations = *(*[]core.Toleration)(unsafe.Pointer(&in.Tolerations))
return nil
}
// Convert_v1alpha1_Scheduling_To_node_Scheduling is an autogenerated conversion function.
func Convert_v1alpha1_Scheduling_To_node_Scheduling(in *v1alpha1.Scheduling, out *node.Scheduling, s conversion.Scope) error {
return autoConvert_v1alpha1_Scheduling_To_node_Scheduling(in, out, s)
}
func autoConvert_node_Scheduling_To_v1alpha1_Scheduling(in *node.Scheduling, out *v1alpha1.Scheduling, s conversion.Scope) error {
out.NodeSelector = *(*map[string]string)(unsafe.Pointer(&in.NodeSelector))
out.Tolerations = *(*[]v1.Toleration)(unsafe.Pointer(&in.Tolerations))
return nil
}
// Convert_node_Scheduling_To_v1alpha1_Scheduling is an autogenerated conversion function.
func Convert_node_Scheduling_To_v1alpha1_Scheduling(in *node.Scheduling, out *v1alpha1.Scheduling, s conversion.Scope) error {
return autoConvert_node_Scheduling_To_v1alpha1_Scheduling(in, out, s)
}

View File

@@ -10,9 +10,7 @@ go_library(
importpath = "k8s.io/kubernetes/pkg/apis/node/v1beta1",
visibility = ["//visibility:public"],
deps = [
"//pkg/apis/core:go_default_library",
"//pkg/apis/node:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/api/node/v1beta1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/conversion:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",

View File

@@ -23,11 +23,9 @@ package v1beta1
import (
unsafe "unsafe"
v1 "k8s.io/api/core/v1"
v1beta1 "k8s.io/api/node/v1beta1"
conversion "k8s.io/apimachinery/pkg/conversion"
runtime "k8s.io/apimachinery/pkg/runtime"
core "k8s.io/kubernetes/pkg/apis/core"
node "k8s.io/kubernetes/pkg/apis/node"
)
@@ -58,23 +56,12 @@ func RegisterConversions(s *runtime.Scheme) error {
}); err != nil {
return err
}
if err := s.AddGeneratedConversionFunc((*v1beta1.Scheduling)(nil), (*node.Scheduling)(nil), func(a, b interface{}, scope conversion.Scope) error {
return Convert_v1beta1_Scheduling_To_node_Scheduling(a.(*v1beta1.Scheduling), b.(*node.Scheduling), scope)
}); err != nil {
return err
}
if err := s.AddGeneratedConversionFunc((*node.Scheduling)(nil), (*v1beta1.Scheduling)(nil), func(a, b interface{}, scope conversion.Scope) error {
return Convert_node_Scheduling_To_v1beta1_Scheduling(a.(*node.Scheduling), b.(*v1beta1.Scheduling), scope)
}); err != nil {
return err
}
return nil
}
func autoConvert_v1beta1_RuntimeClass_To_node_RuntimeClass(in *v1beta1.RuntimeClass, out *node.RuntimeClass, s conversion.Scope) error {
out.ObjectMeta = in.ObjectMeta
out.Handler = in.Handler
out.Scheduling = (*node.Scheduling)(unsafe.Pointer(in.Scheduling))
return nil
}
@@ -86,7 +73,6 @@ func Convert_v1beta1_RuntimeClass_To_node_RuntimeClass(in *v1beta1.RuntimeClass,
func autoConvert_node_RuntimeClass_To_v1beta1_RuntimeClass(in *node.RuntimeClass, out *v1beta1.RuntimeClass, s conversion.Scope) error {
out.ObjectMeta = in.ObjectMeta
out.Handler = in.Handler
out.Scheduling = (*v1beta1.Scheduling)(unsafe.Pointer(in.Scheduling))
return nil
}
@@ -116,25 +102,3 @@ func autoConvert_node_RuntimeClassList_To_v1beta1_RuntimeClassList(in *node.Runt
func Convert_node_RuntimeClassList_To_v1beta1_RuntimeClassList(in *node.RuntimeClassList, out *v1beta1.RuntimeClassList, s conversion.Scope) error {
return autoConvert_node_RuntimeClassList_To_v1beta1_RuntimeClassList(in, out, s)
}
func autoConvert_v1beta1_Scheduling_To_node_Scheduling(in *v1beta1.Scheduling, out *node.Scheduling, s conversion.Scope) error {
out.NodeSelector = *(*map[string]string)(unsafe.Pointer(&in.NodeSelector))
out.Tolerations = *(*[]core.Toleration)(unsafe.Pointer(&in.Tolerations))
return nil
}
// Convert_v1beta1_Scheduling_To_node_Scheduling is an autogenerated conversion function.
func Convert_v1beta1_Scheduling_To_node_Scheduling(in *v1beta1.Scheduling, out *node.Scheduling, s conversion.Scope) error {
return autoConvert_v1beta1_Scheduling_To_node_Scheduling(in, out, s)
}
func autoConvert_node_Scheduling_To_v1beta1_Scheduling(in *node.Scheduling, out *v1beta1.Scheduling, s conversion.Scope) error {
out.NodeSelector = *(*map[string]string)(unsafe.Pointer(&in.NodeSelector))
out.Tolerations = *(*[]v1.Toleration)(unsafe.Pointer(&in.Tolerations))
return nil
}
// Convert_node_Scheduling_To_v1beta1_Scheduling is an autogenerated conversion function.
func Convert_node_Scheduling_To_v1beta1_Scheduling(in *node.Scheduling, out *v1beta1.Scheduling, s conversion.Scope) error {
return autoConvert_node_Scheduling_To_v1beta1_Scheduling(in, out, s)
}

View File

@@ -6,10 +6,8 @@ go_library(
importpath = "k8s.io/kubernetes/pkg/apis/node/validation",
visibility = ["//visibility:public"],
deps = [
"//pkg/apis/core/validation:go_default_library",
"//pkg/apis/node:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/api/validation:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/validation:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
],
)
@@ -19,7 +17,6 @@ go_test(
srcs = ["validation_test.go"],
embed = [":go_default_library"],
deps = [
"//pkg/apis/core:go_default_library",
"//pkg/apis/node:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/github.com/stretchr/testify/assert:go_default_library",

View File

@@ -18,9 +18,7 @@ package validation
import (
apivalidation "k8s.io/apimachinery/pkg/api/validation"
unversionedvalidation "k8s.io/apimachinery/pkg/apis/meta/v1/validation"
"k8s.io/apimachinery/pkg/util/validation/field"
corevalidation "k8s.io/kubernetes/pkg/apis/core/validation"
"k8s.io/kubernetes/pkg/apis/node"
)
@@ -32,10 +30,6 @@ func ValidateRuntimeClass(rc *node.RuntimeClass) field.ErrorList {
allErrs = append(allErrs, field.Invalid(field.NewPath("handler"), rc.Handler, msg))
}
if rc.Scheduling != nil {
allErrs = append(allErrs, validateScheduling(rc.Scheduling, field.NewPath("scheduling"))...)
}
return allErrs
}
@@ -47,12 +41,3 @@ func ValidateRuntimeClassUpdate(new, old *node.RuntimeClass) field.ErrorList {
return allErrs
}
func validateScheduling(s *node.Scheduling, fldPath *field.Path) field.ErrorList {
var allErrs field.ErrorList
if s.NodeSelector != nil {
allErrs = append(allErrs, unversionedvalidation.ValidateLabels(s.NodeSelector, fldPath.Child("nodeSelector"))...)
}
allErrs = append(allErrs, corevalidation.ValidateTolerations(s.Tolerations, fldPath.Child("tolerations"))...)
return allErrs
}

View File

@@ -20,7 +20,6 @@ import (
"testing"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/kubernetes/pkg/apis/core"
"k8s.io/kubernetes/pkg/apis/node"
"github.com/stretchr/testify/assert"
@@ -127,70 +126,3 @@ func TestValidateRuntimeUpdate(t *testing.T) {
})
}
}
func TestValidateScheduling(t *testing.T) {
tests := []struct {
name string
scheduling *node.Scheduling
expectErrs int
}{{
name: "valid scheduling",
scheduling: &node.Scheduling{
NodeSelector: map[string]string{"valid": "yes"},
Tolerations: []core.Toleration{{
Key: "valid",
Operator: core.TolerationOpExists,
Effect: core.TaintEffectNoSchedule,
}},
},
}, {
name: "empty scheduling",
scheduling: &node.Scheduling{},
}, {
name: "invalid nodeSelector",
scheduling: &node.Scheduling{
NodeSelector: map[string]string{"not a valid key!!!": "nope"},
},
expectErrs: 1,
}, {
name: "invalid toleration",
scheduling: &node.Scheduling{
Tolerations: []core.Toleration{{
Key: "valid",
Operator: core.TolerationOpExists,
Effect: core.TaintEffectNoSchedule,
}, {
Key: "not a valid key!!!",
Operator: core.TolerationOpExists,
Effect: core.TaintEffectNoSchedule,
}},
},
expectErrs: 1,
}, {
name: "invalid scheduling",
scheduling: &node.Scheduling{
NodeSelector: map[string]string{"not a valid key!!!": "nope"},
Tolerations: []core.Toleration{{
Key: "valid",
Operator: core.TolerationOpExists,
Effect: core.TaintEffectNoSchedule,
}, {
Key: "not a valid toleration key!!!",
Operator: core.TolerationOpExists,
Effect: core.TaintEffectNoSchedule,
}},
},
expectErrs: 2,
}}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
rc := &node.RuntimeClass{
ObjectMeta: metav1.ObjectMeta{Name: "foo"},
Handler: "bar",
Scheduling: test.scheduling,
}
assert.Len(t, ValidateRuntimeClass(rc), test.expectErrs)
})
}
}

View File

@@ -22,7 +22,6 @@ package node
import (
runtime "k8s.io/apimachinery/pkg/runtime"
core "k8s.io/kubernetes/pkg/apis/core"
)
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
@@ -30,11 +29,6 @@ func (in *RuntimeClass) DeepCopyInto(out *RuntimeClass) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
if in.Scheduling != nil {
in, out := &in.Scheduling, &out.Scheduling
*out = new(Scheduling)
(*in).DeepCopyInto(*out)
}
return
}
@@ -88,33 +82,3 @@ func (in *RuntimeClassList) DeepCopyObject() runtime.Object {
}
return nil
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Scheduling) DeepCopyInto(out *Scheduling) {
*out = *in
if in.NodeSelector != nil {
in, out := &in.NodeSelector, &out.NodeSelector
*out = make(map[string]string, len(*in))
for key, val := range *in {
(*out)[key] = val
}
}
if in.Tolerations != nil {
in, out := &in.Tolerations, &out.Tolerations
*out = make([]core.Toleration, len(*in))
for i := range *in {
(*in)[i].DeepCopyInto(&(*out)[i])
}
}
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Scheduling.
func (in *Scheduling) DeepCopy() *Scheduling {
if in == nil {
return nil
}
out := new(Scheduling)
in.DeepCopyInto(out)
return out
}