mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 14:37:00 +00:00
pod-overhead: add Overhead to RuntimeClass
Co-authored-by: Tim Allclair <tallclair@google.com> Signed-off-by: Eric Ernst <eric.ernst@intel.com>
This commit is contained in:
parent
33713087f4
commit
bcb046a443
@ -33,11 +33,23 @@ func addConversionFuncs(s *runtime.Scheme) error {
|
|||||||
func Convert_v1alpha1_RuntimeClass_To_node_RuntimeClass(in *v1alpha1.RuntimeClass, out *node.RuntimeClass, s conversion.Scope) error {
|
func Convert_v1alpha1_RuntimeClass_To_node_RuntimeClass(in *v1alpha1.RuntimeClass, out *node.RuntimeClass, s conversion.Scope) error {
|
||||||
out.ObjectMeta = in.ObjectMeta
|
out.ObjectMeta = in.ObjectMeta
|
||||||
out.Handler = in.Spec.RuntimeHandler
|
out.Handler = in.Spec.RuntimeHandler
|
||||||
|
if in.Spec.Overhead != nil {
|
||||||
|
out.Overhead = &node.Overhead{}
|
||||||
|
if err := Convert_v1alpha1_Overhead_To_node_Overhead(in.Spec.Overhead, out.Overhead, s); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func Convert_node_RuntimeClass_To_v1alpha1_RuntimeClass(in *node.RuntimeClass, out *v1alpha1.RuntimeClass, s conversion.Scope) error {
|
func Convert_node_RuntimeClass_To_v1alpha1_RuntimeClass(in *node.RuntimeClass, out *v1alpha1.RuntimeClass, s conversion.Scope) error {
|
||||||
out.ObjectMeta = in.ObjectMeta
|
out.ObjectMeta = in.ObjectMeta
|
||||||
out.Spec.RuntimeHandler = in.Handler
|
out.Spec.RuntimeHandler = in.Handler
|
||||||
|
if in.Overhead != nil {
|
||||||
|
out.Spec.Overhead = &v1alpha1.Overhead{}
|
||||||
|
if err := Convert_node_Overhead_To_v1alpha1_Overhead(in.Overhead, out.Spec.Overhead, s); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -21,34 +21,85 @@ import (
|
|||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
corev1 "k8s.io/api/core/v1"
|
||||||
v1alpha1 "k8s.io/api/node/v1alpha1"
|
v1alpha1 "k8s.io/api/node/v1alpha1"
|
||||||
|
"k8s.io/apimachinery/pkg/api/resource"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
core "k8s.io/kubernetes/pkg/apis/core"
|
||||||
node "k8s.io/kubernetes/pkg/apis/node"
|
node "k8s.io/kubernetes/pkg/apis/node"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRuntimeClassConversion(t *testing.T) {
|
func TestRuntimeClassConversion(t *testing.T) {
|
||||||
const (
|
const (
|
||||||
name = "puppy"
|
name = "puppy"
|
||||||
handler = "heidi"
|
handler = "heidi"
|
||||||
|
cpuOverhead = "100"
|
||||||
)
|
)
|
||||||
internalRC := node.RuntimeClass{
|
tests := map[string]struct {
|
||||||
ObjectMeta: metav1.ObjectMeta{Name: name},
|
internal *node.RuntimeClass
|
||||||
Handler: handler,
|
external *v1alpha1.RuntimeClass
|
||||||
}
|
}{
|
||||||
v1alpha1RC := v1alpha1.RuntimeClass{
|
"fully-specified": {
|
||||||
ObjectMeta: metav1.ObjectMeta{Name: name},
|
internal: &node.RuntimeClass{
|
||||||
Spec: v1alpha1.RuntimeClassSpec{
|
ObjectMeta: metav1.ObjectMeta{Name: name},
|
||||||
RuntimeHandler: handler,
|
Handler: handler,
|
||||||
|
Overhead: &node.Overhead{
|
||||||
|
PodFixed: core.ResourceList{
|
||||||
|
core.ResourceCPU: resource.MustParse(cpuOverhead),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
external: &v1alpha1.RuntimeClass{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{Name: name},
|
||||||
|
Spec: v1alpha1.RuntimeClassSpec{
|
||||||
|
RuntimeHandler: handler,
|
||||||
|
Overhead: &v1alpha1.Overhead{
|
||||||
|
PodFixed: corev1.ResourceList{
|
||||||
|
corev1.ResourceCPU: resource.MustParse(cpuOverhead),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"empty-overhead": {
|
||||||
|
internal: &node.RuntimeClass{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{Name: name},
|
||||||
|
Handler: handler,
|
||||||
|
Overhead: &node.Overhead{},
|
||||||
|
},
|
||||||
|
external: &v1alpha1.RuntimeClass{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{Name: name},
|
||||||
|
Spec: v1alpha1.RuntimeClassSpec{
|
||||||
|
RuntimeHandler: handler,
|
||||||
|
Overhead: &v1alpha1.Overhead{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"empty": {
|
||||||
|
internal: &node.RuntimeClass{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{Name: name},
|
||||||
|
Handler: handler,
|
||||||
|
},
|
||||||
|
external: &v1alpha1.RuntimeClass{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{Name: name},
|
||||||
|
Spec: v1alpha1.RuntimeClassSpec{
|
||||||
|
RuntimeHandler: handler,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
convertedInternal := node.RuntimeClass{}
|
for name, test := range tests {
|
||||||
require.NoError(t,
|
t.Run(name, func(t *testing.T) {
|
||||||
Convert_v1alpha1_RuntimeClass_To_node_RuntimeClass(&v1alpha1RC, &convertedInternal, nil))
|
convertedInternal := &node.RuntimeClass{}
|
||||||
assert.Equal(t, internalRC, convertedInternal)
|
require.NoError(t,
|
||||||
|
Convert_v1alpha1_RuntimeClass_To_node_RuntimeClass(test.external, convertedInternal, nil))
|
||||||
|
assert.Equal(t, test.internal, convertedInternal, "external -> internal")
|
||||||
|
|
||||||
convertedV1alpha1 := v1alpha1.RuntimeClass{}
|
convertedV1alpha1 := &v1alpha1.RuntimeClass{}
|
||||||
require.NoError(t,
|
require.NoError(t,
|
||||||
Convert_node_RuntimeClass_To_v1alpha1_RuntimeClass(&internalRC, &convertedV1alpha1, nil))
|
Convert_node_RuntimeClass_To_v1alpha1_RuntimeClass(test.internal, convertedV1alpha1, nil))
|
||||||
assert.Equal(t, v1alpha1RC, convertedV1alpha1)
|
assert.Equal(t, test.external, convertedV1alpha1, "internal -> external")
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||||||
package v1alpha1
|
package v1alpha1
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
corev1 "k8s.io/api/core/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -58,6 +59,20 @@ type RuntimeClassSpec struct {
|
|||||||
// The RuntimeHandler must conform to the DNS Label (RFC 1123) requirements
|
// The RuntimeHandler must conform to the DNS Label (RFC 1123) requirements
|
||||||
// and is immutable.
|
// and is immutable.
|
||||||
RuntimeHandler string `json:"runtimeHandler" protobuf:"bytes,1,opt,name=runtimeHandler"`
|
RuntimeHandler string `json:"runtimeHandler" protobuf:"bytes,1,opt,name=runtimeHandler"`
|
||||||
|
|
||||||
|
// Overhead represents the resource overhead associated with running a pod for a
|
||||||
|
// given RuntimeClass. For more details, see
|
||||||
|
// https://git.k8s.io/enhancements/keps/sig-node/20190226-pod-overhead.md
|
||||||
|
// This field is alpha-level as of Kubernetes v1.15, and is only honored by servers that enable the PodOverhead feature.
|
||||||
|
// +optional
|
||||||
|
Overhead *Overhead `json:"overhead,omitempty" protobuf:"bytes,2,opt,name=overhead"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Overhead structure represents the resource overhead associated with running a pod.
|
||||||
|
type Overhead struct {
|
||||||
|
// PodFixed represents the fixed resource overhead associated with running a pod.
|
||||||
|
// +optional
|
||||||
|
PodFixed corev1.ResourceList `json:"podFixed,omitempty" protobuf:"bytes,1,opt,name=podFixed,casttype=k8s.io/api/core/v1.ResourceList,castkey=k8s.io/api/core/v1.ResourceName,castvalue=k8s.io/apimachinery/pkg/api/resource.Quantity"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
|
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
|
||||||
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||||||
package v1beta1
|
package v1beta1
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
corev1 "k8s.io/api/core/v1"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -48,6 +49,20 @@ type RuntimeClass struct {
|
|||||||
// The Handler must conform to the DNS Label (RFC 1123) requirements, and is
|
// The Handler must conform to the DNS Label (RFC 1123) requirements, and is
|
||||||
// immutable.
|
// immutable.
|
||||||
Handler string `json:"handler" protobuf:"bytes,2,opt,name=handler"`
|
Handler string `json:"handler" protobuf:"bytes,2,opt,name=handler"`
|
||||||
|
|
||||||
|
// Overhead represents the resource overhead associated with running a pod for a
|
||||||
|
// given RuntimeClass. For more details, see
|
||||||
|
// https://git.k8s.io/enhancements/keps/sig-node/20190226-pod-overhead.md
|
||||||
|
// This field is alpha-level as of Kubernetes v1.15, and is only honored by servers that enable the PodOverhead feature.
|
||||||
|
// +optional
|
||||||
|
Overhead *Overhead `json:"overhead,omitempty" protobuf:"bytes,3,opt,name=overhead"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Overhead structure represents the resource overhead associated with running a pod.
|
||||||
|
type Overhead struct {
|
||||||
|
// PodFixed represents the fixed resource overhead associated with running a pod.
|
||||||
|
// +optional
|
||||||
|
PodFixed corev1.ResourceList `json:"podFixed,omitempty" protobuf:"bytes,1,opt,name=podFixed,casttype=k8s.io/api/core/v1.ResourceList,castkey=k8s.io/api/core/v1.ResourceName,castvalue=k8s.io/apimachinery/pkg/api/resource.Quantity"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
|
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
|
||||||
|
Loading…
Reference in New Issue
Block a user