From e39d18f0c06e1d483b0a075146c561bee1f7c16c Mon Sep 17 00:00:00 2001 From: Yassine TIJANI Date: Tue, 26 Mar 2019 21:41:12 +0100 Subject: [PATCH] introduce topology into the runtimeClass API --- api/openapi-spec/swagger.json | 42 +++++++++++++++++++ pkg/apis/node/BUILD | 1 + pkg/apis/node/types.go | 20 +++++++++ pkg/apis/node/v1alpha1/BUILD | 2 + pkg/apis/node/v1alpha1/conversion.go | 3 ++ .../node/v1alpha1/zz_generated.conversion.go | 37 ++++++++++++++++ pkg/apis/node/v1beta1/BUILD | 3 ++ pkg/apis/node/v1beta1/conversion.go | 25 +++++++++++ pkg/apis/node/v1beta1/register.go | 7 ++++ .../node/v1beta1/zz_generated.conversion.go | 36 ++++++++++++++++ pkg/apis/node/zz_generated.deepcopy.go | 34 +++++++++++++++ staging/src/k8s.io/api/node/v1alpha1/BUILD | 1 + staging/src/k8s.io/api/node/v1alpha1/types.go | 20 +++++++++ .../v1alpha1/types_swagger_doc_generated.go | 11 +++++ .../node/v1alpha1/zz_generated.deepcopy.go | 36 +++++++++++++++- staging/src/k8s.io/api/node/v1beta1/BUILD | 1 + staging/src/k8s.io/api/node/v1beta1/types.go | 22 ++++++++++ .../v1beta1/types_swagger_doc_generated.go | 11 +++++ .../api/node/v1beta1/zz_generated.deepcopy.go | 34 +++++++++++++++ 19 files changed, 345 insertions(+), 1 deletion(-) create mode 100644 pkg/apis/node/v1beta1/conversion.go diff --git a/api/openapi-spec/swagger.json b/api/openapi-spec/swagger.json index ec0639d0f8..ccaae47b8d 100644 --- a/api/openapi-spec/swagger.json +++ b/api/openapi-spec/swagger.json @@ -13280,6 +13280,10 @@ "runtimeHandler": { "description": "RuntimeHandler specifies the underlying runtime and configuration that the CRI implementation will use to handle pods of this class. The possible values are specific to the node & CRI configuration. It is assumed that all handlers are available on every node, and handlers of the same name are equivalent on every node. For example, a handler called \"runc\" might specify that the runc OCI runtime (using native Linux containers) will be used to run the containers in a pod. The RuntimeHandler must conform to the DNS Label (RFC 1123) requirements and is immutable.", "type": "string" + }, + "topology": { + "$ref": "#/definitions/io.k8s.api.node.v1alpha1.Topology", + "description": "Topology specifies the scheduling constrains that are necessary to assign pods to the right node" } }, "required": [ @@ -13287,6 +13291,23 @@ ], "type": "object" }, + "io.k8s.api.node.v1alpha1.Topology": { + "description": "Topology specifies the structure of scheduling constrains for the runtime class", + "properties": { + "nodeSelector": { + "$ref": "#/definitions/io.k8s.api.core.v1.NodeSelector", + "description": "nodeSelector selects the set of nodes that support this RuntimeClass. Pods using this RuntimeClass can only be scheduled to a node matched by this selector. The nodeSelector is intersected (AND) with a pod's other node affinity or node selector requirements." + }, + "tolerations": { + "description": "tolerations adds tolerations to pods running with this RuntimeClass.", + "items": { + "$ref": "#/definitions/io.k8s.api.core.v1.Toleration" + }, + "type": "array" + } + }, + "type": "object" + }, "io.k8s.api.node.v1beta1.RuntimeClass": { "description": "RuntimeClass defines a class of container runtime supported in the cluster. The RuntimeClass is used to determine which container runtime is used to run all containers in a pod. RuntimeClasses are (currently) manually defined by a user or cluster provisioner, and referenced in the PodSpec. The Kubelet is responsible for resolving the RuntimeClassName reference before running the pod. For more details, see https://git.k8s.io/enhancements/keps/sig-node/runtime-class.md", "properties": { @@ -13305,6 +13326,10 @@ "metadata": { "$ref": "#/definitions/io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta", "description": "More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata" + }, + "topology": { + "$ref": "#/definitions/io.k8s.api.node.v1beta1.Topology", + "description": "Topology describes the set of nodes in the cluster that support this RuntimeClass. The rules are applied to the pod during scheduling time. If topology is nil, this RuntimeClass is assumed to be supported by all nodes. pods to the right node" } }, "required": [ @@ -13354,6 +13379,23 @@ } ] }, + "io.k8s.api.node.v1beta1.Topology": { + "description": "Topology specifies the scheduling constraints for nodes supporting a RuntimeClass.", + "properties": { + "nodeSelector": { + "$ref": "#/definitions/io.k8s.api.core.v1.NodeSelector", + "description": "nodeSelector selects the set of nodes that support this RuntimeClass. Pods using this RuntimeClass can only be scheduled to a node matched by this selector. The nodeSelector is intersected (AND) with a pod's other node affinity or node selector requirements. A nil nodeSelector selects all nodes." + }, + "tolerations": { + "description": "tolerations adds tolerations to pods running with this RuntimeClass. the tolerations are appended (excluding duplicates) to the pod's tolerations during admission.", + "items": { + "$ref": "#/definitions/io.k8s.api.core.v1.Toleration" + }, + "type": "array" + } + }, + "type": "object" + }, "io.k8s.api.policy.v1beta1.AllowedCSIDriver": { "description": "AllowedCSIDriver represents a single inline CSI Driver that is allowed to be used.", "properties": { diff --git a/pkg/apis/node/BUILD b/pkg/apis/node/BUILD index c5f4063c12..ea6be581f4 100644 --- a/pkg/apis/node/BUILD +++ b/pkg/apis/node/BUILD @@ -11,6 +11,7 @@ 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", diff --git a/pkg/apis/node/types.go b/pkg/apis/node/types.go index a10648f384..5db5600f9b 100644 --- a/pkg/apis/node/types.go +++ b/pkg/apis/node/types.go @@ -17,6 +17,7 @@ limitations under the License. package node import ( + v1 "k8s.io/kubernetes/pkg/apis/core" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -45,6 +46,25 @@ type RuntimeClass struct { // The Handler must conform to the DNS Label (RFC 1123) requirements, and is // immutable. Handler string + + // Topology specifies the scheduling constrains that are necessary to assign + // pods to the right node + // +optional + Topology *Topology +} + +// Topology specifies the structure of scheduling constrains for the runtime class +type Topology struct { + // nodeSelector selects the set of nodes that support this RuntimeClass. + // Pods using this RuntimeClass can only be scheduled to a node matched by + // this selector. The nodeSelector is intersected (AND) with a pod's other + // node affinity or node selector requirements. + // +optional + NodeSelector *v1.NodeSelector + + // tolerations adds tolerations to pods running with this RuntimeClass. + // +optional + Tolerations []v1.Toleration } // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object diff --git a/pkg/apis/node/v1alpha1/BUILD b/pkg/apis/node/v1alpha1/BUILD index 3e817dcbc8..061c744953 100644 --- a/pkg/apis/node/v1alpha1/BUILD +++ b/pkg/apis/node/v1alpha1/BUILD @@ -11,7 +11,9 @@ 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", diff --git a/pkg/apis/node/v1alpha1/conversion.go b/pkg/apis/node/v1alpha1/conversion.go index f1e96ea31a..d9da7f6cde 100644 --- a/pkg/apis/node/v1alpha1/conversion.go +++ b/pkg/apis/node/v1alpha1/conversion.go @@ -21,6 +21,7 @@ import ( conversion "k8s.io/apimachinery/pkg/conversion" runtime "k8s.io/apimachinery/pkg/runtime" node "k8s.io/kubernetes/pkg/apis/node" + "unsafe" ) func addConversionFuncs(s *runtime.Scheme) error { @@ -33,11 +34,13 @@ 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 + out.Topology = (*node.Topology)(unsafe.Pointer(in.Spec.Topology)) 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 + out.Spec.Topology = (*v1alpha1.Topology)(unsafe.Pointer(in.Topology)) return nil } diff --git a/pkg/apis/node/v1alpha1/zz_generated.conversion.go b/pkg/apis/node/v1alpha1/zz_generated.conversion.go index dcb097f842..c7c602f990 100644 --- a/pkg/apis/node/v1alpha1/zz_generated.conversion.go +++ b/pkg/apis/node/v1alpha1/zz_generated.conversion.go @@ -21,9 +21,13 @@ 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" ) @@ -54,6 +58,16 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddGeneratedConversionFunc((*v1alpha1.Topology)(nil), (*node.Topology)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha1_Topology_To_node_Topology(a.(*v1alpha1.Topology), b.(*node.Topology), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*node.Topology)(nil), (*v1alpha1.Topology)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_node_Topology_To_v1alpha1_Topology(a.(*node.Topology), b.(*v1alpha1.Topology), 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 { @@ -76,6 +90,7 @@ 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.Topology requires manual conversion: does not exist in peer-type return nil } @@ -120,3 +135,25 @@ 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_Topology_To_node_Topology(in *v1alpha1.Topology, out *node.Topology, s conversion.Scope) error { + out.NodeSelector = (*core.NodeSelector)(unsafe.Pointer(in.NodeSelector)) + out.Tolerations = *(*[]core.Toleration)(unsafe.Pointer(&in.Tolerations)) + return nil +} + +// Convert_v1alpha1_Topology_To_node_Topology is an autogenerated conversion function. +func Convert_v1alpha1_Topology_To_node_Topology(in *v1alpha1.Topology, out *node.Topology, s conversion.Scope) error { + return autoConvert_v1alpha1_Topology_To_node_Topology(in, out, s) +} + +func autoConvert_node_Topology_To_v1alpha1_Topology(in *node.Topology, out *v1alpha1.Topology, s conversion.Scope) error { + out.NodeSelector = (*v1.NodeSelector)(unsafe.Pointer(in.NodeSelector)) + out.Tolerations = *(*[]v1.Toleration)(unsafe.Pointer(&in.Tolerations)) + return nil +} + +// Convert_node_Topology_To_v1alpha1_Topology is an autogenerated conversion function. +func Convert_node_Topology_To_v1alpha1_Topology(in *node.Topology, out *v1alpha1.Topology, s conversion.Scope) error { + return autoConvert_node_Topology_To_v1alpha1_Topology(in, out, s) +} diff --git a/pkg/apis/node/v1beta1/BUILD b/pkg/apis/node/v1beta1/BUILD index 692be926ae..53b756e3a7 100644 --- a/pkg/apis/node/v1beta1/BUILD +++ b/pkg/apis/node/v1beta1/BUILD @@ -3,6 +3,7 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library") go_library( name = "go_default_library", srcs = [ + "conversion.go", "doc.go", "register.go", "zz_generated.conversion.go", @@ -10,7 +11,9 @@ 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", diff --git a/pkg/apis/node/v1beta1/conversion.go b/pkg/apis/node/v1beta1/conversion.go new file mode 100644 index 0000000000..b7d88363d2 --- /dev/null +++ b/pkg/apis/node/v1beta1/conversion.go @@ -0,0 +1,25 @@ +/* +Copyright 2019 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 v1beta1 + +import ( + "k8s.io/apimachinery/pkg/runtime" +) + +func addConversionFuncs(s *runtime.Scheme) error { + return s.AddConversionFuncs() +} diff --git a/pkg/apis/node/v1beta1/register.go b/pkg/apis/node/v1beta1/register.go index e018e3b70e..19250848d0 100644 --- a/pkg/apis/node/v1beta1/register.go +++ b/pkg/apis/node/v1beta1/register.go @@ -37,3 +37,10 @@ var ( // AddToScheme node API registration AddToScheme = localSchemeBuilder.AddToScheme ) + +func init() { + // We only register manually written functions here. The registration of the + // generated functions takes place in the generated files. The separation + // makes the code compile even when the generated files are missing. + localSchemeBuilder.Register(addConversionFuncs) +} diff --git a/pkg/apis/node/v1beta1/zz_generated.conversion.go b/pkg/apis/node/v1beta1/zz_generated.conversion.go index ebe97f937c..8ab2ab3be6 100644 --- a/pkg/apis/node/v1beta1/zz_generated.conversion.go +++ b/pkg/apis/node/v1beta1/zz_generated.conversion.go @@ -23,9 +23,11 @@ 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" ) @@ -56,12 +58,23 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddGeneratedConversionFunc((*v1beta1.Topology)(nil), (*node.Topology)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta1_Topology_To_node_Topology(a.(*v1beta1.Topology), b.(*node.Topology), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*node.Topology)(nil), (*v1beta1.Topology)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_node_Topology_To_v1beta1_Topology(a.(*node.Topology), b.(*v1beta1.Topology), 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.Topology = (*node.Topology)(unsafe.Pointer(in.Topology)) return nil } @@ -73,6 +86,7 @@ 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.Topology = (*v1beta1.Topology)(unsafe.Pointer(in.Topology)) return nil } @@ -102,3 +116,25 @@ 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_Topology_To_node_Topology(in *v1beta1.Topology, out *node.Topology, s conversion.Scope) error { + out.NodeSelector = (*core.NodeSelector)(unsafe.Pointer(in.NodeSelector)) + out.Tolerations = *(*[]core.Toleration)(unsafe.Pointer(&in.Tolerations)) + return nil +} + +// Convert_v1beta1_Topology_To_node_Topology is an autogenerated conversion function. +func Convert_v1beta1_Topology_To_node_Topology(in *v1beta1.Topology, out *node.Topology, s conversion.Scope) error { + return autoConvert_v1beta1_Topology_To_node_Topology(in, out, s) +} + +func autoConvert_node_Topology_To_v1beta1_Topology(in *node.Topology, out *v1beta1.Topology, s conversion.Scope) error { + out.NodeSelector = (*v1.NodeSelector)(unsafe.Pointer(in.NodeSelector)) + out.Tolerations = *(*[]v1.Toleration)(unsafe.Pointer(&in.Tolerations)) + return nil +} + +// Convert_node_Topology_To_v1beta1_Topology is an autogenerated conversion function. +func Convert_node_Topology_To_v1beta1_Topology(in *node.Topology, out *v1beta1.Topology, s conversion.Scope) error { + return autoConvert_node_Topology_To_v1beta1_Topology(in, out, s) +} diff --git a/pkg/apis/node/zz_generated.deepcopy.go b/pkg/apis/node/zz_generated.deepcopy.go index eb27effc89..11349c9d1d 100644 --- a/pkg/apis/node/zz_generated.deepcopy.go +++ b/pkg/apis/node/zz_generated.deepcopy.go @@ -22,6 +22,7 @@ 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. @@ -29,6 +30,11 @@ func (in *RuntimeClass) DeepCopyInto(out *RuntimeClass) { *out = *in out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + if in.Topology != nil { + in, out := &in.Topology, &out.Topology + *out = new(Topology) + (*in).DeepCopyInto(*out) + } return } @@ -82,3 +88,31 @@ 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 *Topology) DeepCopyInto(out *Topology) { + *out = *in + if in.NodeSelector != nil { + in, out := &in.NodeSelector, &out.NodeSelector + *out = new(core.NodeSelector) + (*in).DeepCopyInto(*out) + } + 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 Topology. +func (in *Topology) DeepCopy() *Topology { + if in == nil { + return nil + } + out := new(Topology) + in.DeepCopyInto(out) + return out +} diff --git a/staging/src/k8s.io/api/node/v1alpha1/BUILD b/staging/src/k8s.io/api/node/v1alpha1/BUILD index 4f8f496f61..dc2094afa4 100644 --- a/staging/src/k8s.io/api/node/v1alpha1/BUILD +++ b/staging/src/k8s.io/api/node/v1alpha1/BUILD @@ -14,6 +14,7 @@ go_library( importpath = "k8s.io/api/node/v1alpha1", visibility = ["//visibility:public"], deps = [ + "//staging/src/k8s.io/api/core/v1: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", diff --git a/staging/src/k8s.io/api/node/v1alpha1/types.go b/staging/src/k8s.io/api/node/v1alpha1/types.go index 2ce67c116f..3518c7796b 100644 --- a/staging/src/k8s.io/api/node/v1alpha1/types.go +++ b/staging/src/k8s.io/api/node/v1alpha1/types.go @@ -17,6 +17,7 @@ limitations under the License. package v1alpha1 import ( + "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -58,6 +59,25 @@ type RuntimeClassSpec struct { // The RuntimeHandler must conform to the DNS Label (RFC 1123) requirements // and is immutable. RuntimeHandler string `json:"runtimeHandler" protobuf:"bytes,1,opt,name=runtimeHandler"` + + // Topology specifies the scheduling constrains that are necessary to assign + // pods to the right node + // +optional + Topology *Topology `json:"topology,omitempty" protobuf:"bytes,3,opt,name=topology"` +} + +// Topology specifies the structure of scheduling constrains for the runtime class +type Topology struct { + // nodeSelector selects the set of nodes that support this RuntimeClass. + // Pods using this RuntimeClass can only be scheduled to a node matched by + // this selector. The nodeSelector is intersected (AND) with a pod's other + // node affinity or node selector requirements. + // +optional + NodeSelector *v1.NodeSelector `json:"nodeSelector,omitempty" protobuf:"bytes,1,rep,name=nodeSelector"` + + // tolerations adds tolerations to pods running with this RuntimeClass. + // +optional + Tolerations []v1.Toleration `json:"tolerations,omitempty" protobuf:"bytes,2,opt,name=tolerations"` } // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object diff --git a/staging/src/k8s.io/api/node/v1alpha1/types_swagger_doc_generated.go b/staging/src/k8s.io/api/node/v1alpha1/types_swagger_doc_generated.go index a51fa525df..9b7183332b 100644 --- a/staging/src/k8s.io/api/node/v1alpha1/types_swagger_doc_generated.go +++ b/staging/src/k8s.io/api/node/v1alpha1/types_swagger_doc_generated.go @@ -50,10 +50,21 @@ func (RuntimeClassList) SwaggerDoc() map[string]string { var map_RuntimeClassSpec = map[string]string{ "": "RuntimeClassSpec is a specification of a RuntimeClass. It contains parameters that are required to describe the RuntimeClass to the Container Runtime Interface (CRI) implementation, as well as any other components that need to understand how the pod will be run. The RuntimeClassSpec is immutable.", "runtimeHandler": "RuntimeHandler specifies the underlying runtime and configuration that the CRI implementation will use to handle pods of this class. The possible values are specific to the node & CRI configuration. It is assumed that all handlers are available on every node, and handlers of the same name are equivalent on every node. For example, a handler called \"runc\" might specify that the runc OCI runtime (using native Linux containers) will be used to run the containers in a pod. The RuntimeHandler must conform to the DNS Label (RFC 1123) requirements and is immutable.", + "topology": "Topology specifies the scheduling constrains that are necessary to assign pods to the right node", } func (RuntimeClassSpec) SwaggerDoc() map[string]string { return map_RuntimeClassSpec } +var map_Topology = map[string]string{ + "": "Topology specifies the structure of scheduling constrains for the runtime class", + "nodeSelector": "nodeSelector selects the set of nodes that support this RuntimeClass. Pods using this RuntimeClass can only be scheduled to a node matched by this selector. The nodeSelector is intersected (AND) with a pod's other node affinity or node selector requirements.", + "tolerations": "tolerations adds tolerations to pods running with this RuntimeClass.", +} + +func (Topology) SwaggerDoc() map[string]string { + return map_Topology +} + // AUTO-GENERATED FUNCTIONS END HERE diff --git a/staging/src/k8s.io/api/node/v1alpha1/zz_generated.deepcopy.go b/staging/src/k8s.io/api/node/v1alpha1/zz_generated.deepcopy.go index 0d63110b3b..30c50160d3 100644 --- a/staging/src/k8s.io/api/node/v1alpha1/zz_generated.deepcopy.go +++ b/staging/src/k8s.io/api/node/v1alpha1/zz_generated.deepcopy.go @@ -21,6 +21,7 @@ limitations under the License. package v1alpha1 import ( + v1 "k8s.io/api/core/v1" runtime "k8s.io/apimachinery/pkg/runtime" ) @@ -29,7 +30,7 @@ func (in *RuntimeClass) DeepCopyInto(out *RuntimeClass) { *out = *in out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - out.Spec = in.Spec + in.Spec.DeepCopyInto(&out.Spec) return } @@ -87,6 +88,11 @@ func (in *RuntimeClassList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *RuntimeClassSpec) DeepCopyInto(out *RuntimeClassSpec) { *out = *in + if in.Topology != nil { + in, out := &in.Topology, &out.Topology + *out = new(Topology) + (*in).DeepCopyInto(*out) + } return } @@ -99,3 +105,31 @@ func (in *RuntimeClassSpec) DeepCopy() *RuntimeClassSpec { in.DeepCopyInto(out) return out } + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Topology) DeepCopyInto(out *Topology) { + *out = *in + if in.NodeSelector != nil { + in, out := &in.NodeSelector, &out.NodeSelector + *out = new(v1.NodeSelector) + (*in).DeepCopyInto(*out) + } + if in.Tolerations != nil { + in, out := &in.Tolerations, &out.Tolerations + *out = make([]v1.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 Topology. +func (in *Topology) DeepCopy() *Topology { + if in == nil { + return nil + } + out := new(Topology) + in.DeepCopyInto(out) + return out +} diff --git a/staging/src/k8s.io/api/node/v1beta1/BUILD b/staging/src/k8s.io/api/node/v1beta1/BUILD index 5ae9e598da..214090d851 100644 --- a/staging/src/k8s.io/api/node/v1beta1/BUILD +++ b/staging/src/k8s.io/api/node/v1beta1/BUILD @@ -14,6 +14,7 @@ go_library( importpath = "k8s.io/api/node/v1beta1", visibility = ["//visibility:public"], deps = [ + "//staging/src/k8s.io/api/core/v1: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", diff --git a/staging/src/k8s.io/api/node/v1beta1/types.go b/staging/src/k8s.io/api/node/v1beta1/types.go index 993c6e5066..4234df5eb0 100644 --- a/staging/src/k8s.io/api/node/v1beta1/types.go +++ b/staging/src/k8s.io/api/node/v1beta1/types.go @@ -17,6 +17,7 @@ limitations under the License. package v1beta1 import ( + "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -48,6 +49,27 @@ type RuntimeClass struct { // The Handler must conform to the DNS Label (RFC 1123) requirements, and is // immutable. Handler string `json:"handler" protobuf:"bytes,2,opt,name=handler"` + + // Topology describes the set of nodes in the cluster that support this RuntimeClass. The rules are applied to the pod during scheduling time. + // If topology is nil, this RuntimeClass is assumed to be supported by all nodes. + // pods to the right node + // +optional + Topology *Topology `json:"topology,omitempty" protobuf:"bytes,3,opt,name=topology"` +} + +// Topology specifies the scheduling constraints for nodes supporting a RuntimeClass. +type Topology struct { + // nodeSelector selects the set of nodes that support this RuntimeClass. + // Pods using this RuntimeClass can only be scheduled to a node matched by + // this selector. The nodeSelector is intersected (AND) with a pod's other + // node affinity or node selector requirements. A nil nodeSelector selects all nodes. + // +optional + NodeSelector *v1.NodeSelector `json:"nodeSelector,omitempty" protobuf:"bytes,1,rep,name=nodeSelector"` + + // tolerations adds tolerations to pods running with this RuntimeClass. + // the tolerations are appended (excluding duplicates) to the pod's tolerations during admission. + // +optional + Tolerations []v1.Toleration `json:"tolerations,omitempty" protobuf:"bytes,2,opt,name=tolerations"` } // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object diff --git a/staging/src/k8s.io/api/node/v1beta1/types_swagger_doc_generated.go b/staging/src/k8s.io/api/node/v1beta1/types_swagger_doc_generated.go index 8bfa304e78..c98957fcc6 100644 --- a/staging/src/k8s.io/api/node/v1beta1/types_swagger_doc_generated.go +++ b/staging/src/k8s.io/api/node/v1beta1/types_swagger_doc_generated.go @@ -31,6 +31,7 @@ var map_RuntimeClass = map[string]string{ "": "RuntimeClass defines a class of container runtime supported in the cluster. The RuntimeClass is used to determine which container runtime is used to run all containers in a pod. RuntimeClasses are (currently) manually defined by a user or cluster provisioner, and referenced in the PodSpec. The Kubelet is responsible for resolving the RuntimeClassName reference before running the pod. For more details, see https://git.k8s.io/enhancements/keps/sig-node/runtime-class.md", "metadata": "More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata", "handler": "Handler specifies the underlying runtime and configuration that the CRI implementation will use to handle pods of this class. The possible values are specific to the node & CRI configuration. It is assumed that all handlers are available on every node, and handlers of the same name are equivalent on every node. For example, a handler called \"runc\" might specify that the runc OCI runtime (using native Linux containers) will be used to run the containers in a pod. The Handler must conform to the DNS Label (RFC 1123) requirements, and is immutable.", + "topology": "Topology describes the set of nodes in the cluster that support this RuntimeClass. The rules are applied to the pod during scheduling time. If topology is nil, this RuntimeClass is assumed to be supported by all nodes. pods to the right node", } func (RuntimeClass) SwaggerDoc() map[string]string { @@ -47,4 +48,14 @@ func (RuntimeClassList) SwaggerDoc() map[string]string { return map_RuntimeClassList } +var map_Topology = map[string]string{ + "": "Topology specifies the scheduling constraints for nodes supporting a RuntimeClass.", + "nodeSelector": "nodeSelector selects the set of nodes that support this RuntimeClass. Pods using this RuntimeClass can only be scheduled to a node matched by this selector. The nodeSelector is intersected (AND) with a pod's other node affinity or node selector requirements. A nil nodeSelector selects all nodes.", + "tolerations": "tolerations adds tolerations to pods running with this RuntimeClass. the tolerations are appended (excluding duplicates) to the pod's tolerations during admission.", +} + +func (Topology) SwaggerDoc() map[string]string { + return map_Topology +} + // AUTO-GENERATED FUNCTIONS END HERE diff --git a/staging/src/k8s.io/api/node/v1beta1/zz_generated.deepcopy.go b/staging/src/k8s.io/api/node/v1beta1/zz_generated.deepcopy.go index 98b5d480af..cccc806e89 100644 --- a/staging/src/k8s.io/api/node/v1beta1/zz_generated.deepcopy.go +++ b/staging/src/k8s.io/api/node/v1beta1/zz_generated.deepcopy.go @@ -21,6 +21,7 @@ limitations under the License. package v1beta1 import ( + v1 "k8s.io/api/core/v1" runtime "k8s.io/apimachinery/pkg/runtime" ) @@ -29,6 +30,11 @@ func (in *RuntimeClass) DeepCopyInto(out *RuntimeClass) { *out = *in out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + if in.Topology != nil { + in, out := &in.Topology, &out.Topology + *out = new(Topology) + (*in).DeepCopyInto(*out) + } return } @@ -82,3 +88,31 @@ 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 *Topology) DeepCopyInto(out *Topology) { + *out = *in + if in.NodeSelector != nil { + in, out := &in.NodeSelector, &out.NodeSelector + *out = new(v1.NodeSelector) + (*in).DeepCopyInto(*out) + } + if in.Tolerations != nil { + in, out := &in.Tolerations, &out.Tolerations + *out = make([]v1.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 Topology. +func (in *Topology) DeepCopy() *Topology { + if in == nil { + return nil + } + out := new(Topology) + in.DeepCopyInto(out) + return out +}