From 4e91166bc62f2b346eaf394345503caeb62a1fc0 Mon Sep 17 00:00:00 2001 From: jiangyaoguo Date: Thu, 25 Feb 2016 17:30:31 +0800 Subject: [PATCH] Use PreferAvoidPods annotation to avoid pods being scheduled to specific node. 1. define PreferAvoidPods annotation 2. add PreferAvoidPodsPriority 3. validate AvoidPods in node annotations --- pkg/api/helpers.go | 15 + pkg/api/helpers_test.go | 96 ++ pkg/api/types.generated.go | 819 +++++++++++++++++ pkg/api/types.go | 28 + pkg/api/v1/generated.pb.go | 866 ++++++++++++++---- pkg/api/v1/generated.proto | 31 + pkg/api/v1/types.generated.go | 819 +++++++++++++++++ pkg/api/v1/types.go | 28 + pkg/api/v1/types_swagger_doc_generated.go | 30 + pkg/api/validation/validation.go | 45 +- pkg/api/validation/validation_test.go | 197 +++- .../algorithm/priorities/priorities.go | 76 ++ .../algorithm/priorities/priorities_test.go | 135 +++ .../algorithmprovider/defaults/defaults.go | 11 + 14 files changed, 2995 insertions(+), 201 deletions(-) diff --git a/pkg/api/helpers.go b/pkg/api/helpers.go index ca873b3096f..b1881914231 100644 --- a/pkg/api/helpers.go +++ b/pkg/api/helpers.go @@ -428,6 +428,10 @@ const ( // CreatedByAnnotation represents the key used to store the spec(json) // used to create the resource. CreatedByAnnotation = "kubernetes.io/created-by" + + // PreferAvoidPodsAnnotationKey represents the key of preferAvoidPods data (json serialized) + // in the Annotations of a Node. + PreferAvoidPodsAnnotationKey string = "scheduler.alpha.kubernetes.io/preferAvoidPods" ) // GetAffinityFromPod gets the json serialized affinity data from Pod.Annotations @@ -500,3 +504,14 @@ func TaintToleratedByTolerations(taint *Taint, tolerations []Toleration) bool { } return tolerated } + +func GetAvoidPodsFromNodeAnnotations(annotations map[string]string) (AvoidPods, error) { + var avoidPods AvoidPods + if len(annotations) > 0 && annotations[PreferAvoidPodsAnnotationKey] != "" { + err := json.Unmarshal([]byte(annotations[PreferAvoidPodsAnnotationKey]), &avoidPods) + if err != nil { + return avoidPods, err + } + } + return avoidPods, nil +} diff --git a/pkg/api/helpers_test.go b/pkg/api/helpers_test.go index 70f9bf609b6..49b50b69e04 100644 --- a/pkg/api/helpers_test.go +++ b/pkg/api/helpers_test.go @@ -295,3 +295,99 @@ func TestGetAffinityFromPod(t *testing.T) { } } } + +func TestGetAvoidPodsFromNode(t *testing.T) { + controllerFlag := true + testCases := []struct { + node *Node + expectValue AvoidPods + expectErr bool + }{ + { + node: &Node{}, + expectValue: AvoidPods{}, + expectErr: false, + }, + { + node: &Node{ + ObjectMeta: ObjectMeta{ + Annotations: map[string]string{ + PreferAvoidPodsAnnotationKey: ` + { + "preferAvoidPods": [ + { + "podSignature": { + "podController": { + "apiVersion": "v1", + "kind": "ReplicationController", + "name": "foo", + "uid": "abcdef123456", + "controller": true + } + }, + "reason": "some reason", + "message": "some message" + } + ] + }`, + }, + }, + }, + expectValue: AvoidPods{ + PreferAvoidPods: []PreferAvoidPodsEntry{ + { + PodSignature: PodSignature{ + PodController: &OwnerReference{ + APIVersion: "v1", + Kind: "ReplicationController", + Name: "foo", + UID: "abcdef123456", + Controller: &controllerFlag, + }, + }, + Reason: "some reason", + Message: "some message", + }, + }, + }, + expectErr: false, + }, + { + node: &Node{ + // Missing end symbol of "podController" and "podSignature" + ObjectMeta: ObjectMeta{ + Annotations: map[string]string{ + PreferAvoidPodsAnnotationKey: ` + { + "preferAvoidPods": [ + { + "podSignature": { + "podController": { + "kind": "ReplicationController", + "apiVersion": "v1" + "reason": "some reason", + "message": "some message" + } + ] + }`, + }, + }, + }, + expectValue: AvoidPods{}, + expectErr: true, + }, + } + + for i, tc := range testCases { + v, err := GetAvoidPodsFromNodeAnnotations(tc.node.Annotations) + if err == nil && tc.expectErr { + t.Errorf("[%v]expected error but got none.", i) + } + if err != nil && !tc.expectErr { + t.Errorf("[%v]did not expect error but got: %v", i, err) + } + if !reflect.DeepEqual(tc.expectValue, v) { + t.Errorf("[%v]expect value %v but got %v with %v", i, tc.expectValue, v, v.PreferAvoidPods[0].PodSignature.PodController.Controller) + } + } +} diff --git a/pkg/api/types.generated.go b/pkg/api/types.generated.go index 67d3dbc27c3..5cc82f5793c 100644 --- a/pkg/api/types.generated.go +++ b/pkg/api/types.generated.go @@ -37409,6 +37409,706 @@ func (x *AttachedVolume) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) { z.DecSendContainerState(codecSelfer_containerArrayEnd1234) } +func (x *AvoidPods) CodecEncodeSelf(e *codec1978.Encoder) { + var h codecSelfer1234 + z, r := codec1978.GenHelperEncoder(e) + _, _, _ = h, z, r + if x == nil { + r.EncodeNil() + } else { + yym1 := z.EncBinary() + _ = yym1 + if false { + } else if z.HasExtensions() && z.EncExt(x) { + } else { + yysep2 := !z.EncBinary() + yy2arr2 := z.EncBasicHandle().StructToArray + var yyq2 [1]bool + _, _, _ = yysep2, yyq2, yy2arr2 + const yyr2 bool = false + yyq2[0] = len(x.PreferAvoidPods) != 0 + var yynn2 int + if yyr2 || yy2arr2 { + r.EncodeArrayStart(1) + } else { + yynn2 = 0 + for _, b := range yyq2 { + if b { + yynn2++ + } + } + r.EncodeMapStart(yynn2) + yynn2 = 0 + } + if yyr2 || yy2arr2 { + z.EncSendContainerState(codecSelfer_containerArrayElem1234) + if yyq2[0] { + if x.PreferAvoidPods == nil { + r.EncodeNil() + } else { + yym4 := z.EncBinary() + _ = yym4 + if false { + } else { + h.encSlicePreferAvoidPodsEntry(([]PreferAvoidPodsEntry)(x.PreferAvoidPods), e) + } + } + } else { + r.EncodeNil() + } + } else { + if yyq2[0] { + z.EncSendContainerState(codecSelfer_containerMapKey1234) + r.EncodeString(codecSelferC_UTF81234, string("preferAvoidPods")) + z.EncSendContainerState(codecSelfer_containerMapValue1234) + if x.PreferAvoidPods == nil { + r.EncodeNil() + } else { + yym5 := z.EncBinary() + _ = yym5 + if false { + } else { + h.encSlicePreferAvoidPodsEntry(([]PreferAvoidPodsEntry)(x.PreferAvoidPods), e) + } + } + } + } + if yyr2 || yy2arr2 { + z.EncSendContainerState(codecSelfer_containerArrayEnd1234) + } else { + z.EncSendContainerState(codecSelfer_containerMapEnd1234) + } + } + } +} + +func (x *AvoidPods) CodecDecodeSelf(d *codec1978.Decoder) { + var h codecSelfer1234 + z, r := codec1978.GenHelperDecoder(d) + _, _, _ = h, z, r + yym1 := z.DecBinary() + _ = yym1 + if false { + } else if z.HasExtensions() && z.DecExt(x) { + } else { + yyct2 := r.ContainerType() + if yyct2 == codecSelferValueTypeMap1234 { + yyl2 := r.ReadMapStart() + if yyl2 == 0 { + z.DecSendContainerState(codecSelfer_containerMapEnd1234) + } else { + x.codecDecodeSelfFromMap(yyl2, d) + } + } else if yyct2 == codecSelferValueTypeArray1234 { + yyl2 := r.ReadArrayStart() + if yyl2 == 0 { + z.DecSendContainerState(codecSelfer_containerArrayEnd1234) + } else { + x.codecDecodeSelfFromArray(yyl2, d) + } + } else { + panic(codecSelferOnlyMapOrArrayEncodeToStructErr1234) + } + } +} + +func (x *AvoidPods) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) { + var h codecSelfer1234 + z, r := codec1978.GenHelperDecoder(d) + _, _, _ = h, z, r + var yys3Slc = z.DecScratchBuffer() // default slice to decode into + _ = yys3Slc + var yyhl3 bool = l >= 0 + for yyj3 := 0; ; yyj3++ { + if yyhl3 { + if yyj3 >= l { + break + } + } else { + if r.CheckBreak() { + break + } + } + z.DecSendContainerState(codecSelfer_containerMapKey1234) + yys3Slc = r.DecodeBytes(yys3Slc, true, true) + yys3 := string(yys3Slc) + z.DecSendContainerState(codecSelfer_containerMapValue1234) + switch yys3 { + case "preferAvoidPods": + if r.TryDecodeAsNil() { + x.PreferAvoidPods = nil + } else { + yyv4 := &x.PreferAvoidPods + yym5 := z.DecBinary() + _ = yym5 + if false { + } else { + h.decSlicePreferAvoidPodsEntry((*[]PreferAvoidPodsEntry)(yyv4), d) + } + } + default: + z.DecStructFieldNotFound(-1, yys3) + } // end switch yys3 + } // end for yyj3 + z.DecSendContainerState(codecSelfer_containerMapEnd1234) +} + +func (x *AvoidPods) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) { + var h codecSelfer1234 + z, r := codec1978.GenHelperDecoder(d) + _, _, _ = h, z, r + var yyj6 int + var yyb6 bool + var yyhl6 bool = l >= 0 + yyj6++ + if yyhl6 { + yyb6 = yyj6 > l + } else { + yyb6 = r.CheckBreak() + } + if yyb6 { + z.DecSendContainerState(codecSelfer_containerArrayEnd1234) + return + } + z.DecSendContainerState(codecSelfer_containerArrayElem1234) + if r.TryDecodeAsNil() { + x.PreferAvoidPods = nil + } else { + yyv7 := &x.PreferAvoidPods + yym8 := z.DecBinary() + _ = yym8 + if false { + } else { + h.decSlicePreferAvoidPodsEntry((*[]PreferAvoidPodsEntry)(yyv7), d) + } + } + for { + yyj6++ + if yyhl6 { + yyb6 = yyj6 > l + } else { + yyb6 = r.CheckBreak() + } + if yyb6 { + break + } + z.DecSendContainerState(codecSelfer_containerArrayElem1234) + z.DecStructFieldNotFound(yyj6-1, "") + } + z.DecSendContainerState(codecSelfer_containerArrayEnd1234) +} + +func (x *PreferAvoidPodsEntry) CodecEncodeSelf(e *codec1978.Encoder) { + var h codecSelfer1234 + z, r := codec1978.GenHelperEncoder(e) + _, _, _ = h, z, r + if x == nil { + r.EncodeNil() + } else { + yym1 := z.EncBinary() + _ = yym1 + if false { + } else if z.HasExtensions() && z.EncExt(x) { + } else { + yysep2 := !z.EncBinary() + yy2arr2 := z.EncBasicHandle().StructToArray + var yyq2 [4]bool + _, _, _ = yysep2, yyq2, yy2arr2 + const yyr2 bool = false + yyq2[1] = true + yyq2[2] = x.Reason != "" + yyq2[3] = x.Message != "" + var yynn2 int + if yyr2 || yy2arr2 { + r.EncodeArrayStart(4) + } else { + yynn2 = 1 + for _, b := range yyq2 { + if b { + yynn2++ + } + } + r.EncodeMapStart(yynn2) + yynn2 = 0 + } + if yyr2 || yy2arr2 { + z.EncSendContainerState(codecSelfer_containerArrayElem1234) + yy4 := &x.PodSignature + yy4.CodecEncodeSelf(e) + } else { + z.EncSendContainerState(codecSelfer_containerMapKey1234) + r.EncodeString(codecSelferC_UTF81234, string("podSignature")) + z.EncSendContainerState(codecSelfer_containerMapValue1234) + yy6 := &x.PodSignature + yy6.CodecEncodeSelf(e) + } + if yyr2 || yy2arr2 { + z.EncSendContainerState(codecSelfer_containerArrayElem1234) + if yyq2[1] { + yy9 := &x.EvictionTime + yym10 := z.EncBinary() + _ = yym10 + if false { + } else if z.HasExtensions() && z.EncExt(yy9) { + } else if yym10 { + z.EncBinaryMarshal(yy9) + } else if !yym10 && z.IsJSONHandle() { + z.EncJSONMarshal(yy9) + } else { + z.EncFallback(yy9) + } + } else { + r.EncodeNil() + } + } else { + if yyq2[1] { + z.EncSendContainerState(codecSelfer_containerMapKey1234) + r.EncodeString(codecSelferC_UTF81234, string("evictionTime")) + z.EncSendContainerState(codecSelfer_containerMapValue1234) + yy11 := &x.EvictionTime + yym12 := z.EncBinary() + _ = yym12 + if false { + } else if z.HasExtensions() && z.EncExt(yy11) { + } else if yym12 { + z.EncBinaryMarshal(yy11) + } else if !yym12 && z.IsJSONHandle() { + z.EncJSONMarshal(yy11) + } else { + z.EncFallback(yy11) + } + } + } + if yyr2 || yy2arr2 { + z.EncSendContainerState(codecSelfer_containerArrayElem1234) + if yyq2[2] { + yym14 := z.EncBinary() + _ = yym14 + if false { + } else { + r.EncodeString(codecSelferC_UTF81234, string(x.Reason)) + } + } else { + r.EncodeString(codecSelferC_UTF81234, "") + } + } else { + if yyq2[2] { + z.EncSendContainerState(codecSelfer_containerMapKey1234) + r.EncodeString(codecSelferC_UTF81234, string("reason")) + z.EncSendContainerState(codecSelfer_containerMapValue1234) + yym15 := z.EncBinary() + _ = yym15 + if false { + } else { + r.EncodeString(codecSelferC_UTF81234, string(x.Reason)) + } + } + } + if yyr2 || yy2arr2 { + z.EncSendContainerState(codecSelfer_containerArrayElem1234) + if yyq2[3] { + yym17 := z.EncBinary() + _ = yym17 + if false { + } else { + r.EncodeString(codecSelferC_UTF81234, string(x.Message)) + } + } else { + r.EncodeString(codecSelferC_UTF81234, "") + } + } else { + if yyq2[3] { + z.EncSendContainerState(codecSelfer_containerMapKey1234) + r.EncodeString(codecSelferC_UTF81234, string("message")) + z.EncSendContainerState(codecSelfer_containerMapValue1234) + yym18 := z.EncBinary() + _ = yym18 + if false { + } else { + r.EncodeString(codecSelferC_UTF81234, string(x.Message)) + } + } + } + if yyr2 || yy2arr2 { + z.EncSendContainerState(codecSelfer_containerArrayEnd1234) + } else { + z.EncSendContainerState(codecSelfer_containerMapEnd1234) + } + } + } +} + +func (x *PreferAvoidPodsEntry) CodecDecodeSelf(d *codec1978.Decoder) { + var h codecSelfer1234 + z, r := codec1978.GenHelperDecoder(d) + _, _, _ = h, z, r + yym1 := z.DecBinary() + _ = yym1 + if false { + } else if z.HasExtensions() && z.DecExt(x) { + } else { + yyct2 := r.ContainerType() + if yyct2 == codecSelferValueTypeMap1234 { + yyl2 := r.ReadMapStart() + if yyl2 == 0 { + z.DecSendContainerState(codecSelfer_containerMapEnd1234) + } else { + x.codecDecodeSelfFromMap(yyl2, d) + } + } else if yyct2 == codecSelferValueTypeArray1234 { + yyl2 := r.ReadArrayStart() + if yyl2 == 0 { + z.DecSendContainerState(codecSelfer_containerArrayEnd1234) + } else { + x.codecDecodeSelfFromArray(yyl2, d) + } + } else { + panic(codecSelferOnlyMapOrArrayEncodeToStructErr1234) + } + } +} + +func (x *PreferAvoidPodsEntry) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) { + var h codecSelfer1234 + z, r := codec1978.GenHelperDecoder(d) + _, _, _ = h, z, r + var yys3Slc = z.DecScratchBuffer() // default slice to decode into + _ = yys3Slc + var yyhl3 bool = l >= 0 + for yyj3 := 0; ; yyj3++ { + if yyhl3 { + if yyj3 >= l { + break + } + } else { + if r.CheckBreak() { + break + } + } + z.DecSendContainerState(codecSelfer_containerMapKey1234) + yys3Slc = r.DecodeBytes(yys3Slc, true, true) + yys3 := string(yys3Slc) + z.DecSendContainerState(codecSelfer_containerMapValue1234) + switch yys3 { + case "podSignature": + if r.TryDecodeAsNil() { + x.PodSignature = PodSignature{} + } else { + yyv4 := &x.PodSignature + yyv4.CodecDecodeSelf(d) + } + case "evictionTime": + if r.TryDecodeAsNil() { + x.EvictionTime = pkg2_unversioned.Time{} + } else { + yyv5 := &x.EvictionTime + yym6 := z.DecBinary() + _ = yym6 + if false { + } else if z.HasExtensions() && z.DecExt(yyv5) { + } else if yym6 { + z.DecBinaryUnmarshal(yyv5) + } else if !yym6 && z.IsJSONHandle() { + z.DecJSONUnmarshal(yyv5) + } else { + z.DecFallback(yyv5, false) + } + } + case "reason": + if r.TryDecodeAsNil() { + x.Reason = "" + } else { + x.Reason = string(r.DecodeString()) + } + case "message": + if r.TryDecodeAsNil() { + x.Message = "" + } else { + x.Message = string(r.DecodeString()) + } + default: + z.DecStructFieldNotFound(-1, yys3) + } // end switch yys3 + } // end for yyj3 + z.DecSendContainerState(codecSelfer_containerMapEnd1234) +} + +func (x *PreferAvoidPodsEntry) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) { + var h codecSelfer1234 + z, r := codec1978.GenHelperDecoder(d) + _, _, _ = h, z, r + var yyj9 int + var yyb9 bool + var yyhl9 bool = l >= 0 + yyj9++ + if yyhl9 { + yyb9 = yyj9 > l + } else { + yyb9 = r.CheckBreak() + } + if yyb9 { + z.DecSendContainerState(codecSelfer_containerArrayEnd1234) + return + } + z.DecSendContainerState(codecSelfer_containerArrayElem1234) + if r.TryDecodeAsNil() { + x.PodSignature = PodSignature{} + } else { + yyv10 := &x.PodSignature + yyv10.CodecDecodeSelf(d) + } + yyj9++ + if yyhl9 { + yyb9 = yyj9 > l + } else { + yyb9 = r.CheckBreak() + } + if yyb9 { + z.DecSendContainerState(codecSelfer_containerArrayEnd1234) + return + } + z.DecSendContainerState(codecSelfer_containerArrayElem1234) + if r.TryDecodeAsNil() { + x.EvictionTime = pkg2_unversioned.Time{} + } else { + yyv11 := &x.EvictionTime + yym12 := z.DecBinary() + _ = yym12 + if false { + } else if z.HasExtensions() && z.DecExt(yyv11) { + } else if yym12 { + z.DecBinaryUnmarshal(yyv11) + } else if !yym12 && z.IsJSONHandle() { + z.DecJSONUnmarshal(yyv11) + } else { + z.DecFallback(yyv11, false) + } + } + yyj9++ + if yyhl9 { + yyb9 = yyj9 > l + } else { + yyb9 = r.CheckBreak() + } + if yyb9 { + z.DecSendContainerState(codecSelfer_containerArrayEnd1234) + return + } + z.DecSendContainerState(codecSelfer_containerArrayElem1234) + if r.TryDecodeAsNil() { + x.Reason = "" + } else { + x.Reason = string(r.DecodeString()) + } + yyj9++ + if yyhl9 { + yyb9 = yyj9 > l + } else { + yyb9 = r.CheckBreak() + } + if yyb9 { + z.DecSendContainerState(codecSelfer_containerArrayEnd1234) + return + } + z.DecSendContainerState(codecSelfer_containerArrayElem1234) + if r.TryDecodeAsNil() { + x.Message = "" + } else { + x.Message = string(r.DecodeString()) + } + for { + yyj9++ + if yyhl9 { + yyb9 = yyj9 > l + } else { + yyb9 = r.CheckBreak() + } + if yyb9 { + break + } + z.DecSendContainerState(codecSelfer_containerArrayElem1234) + z.DecStructFieldNotFound(yyj9-1, "") + } + z.DecSendContainerState(codecSelfer_containerArrayEnd1234) +} + +func (x *PodSignature) CodecEncodeSelf(e *codec1978.Encoder) { + var h codecSelfer1234 + z, r := codec1978.GenHelperEncoder(e) + _, _, _ = h, z, r + if x == nil { + r.EncodeNil() + } else { + yym1 := z.EncBinary() + _ = yym1 + if false { + } else if z.HasExtensions() && z.EncExt(x) { + } else { + yysep2 := !z.EncBinary() + yy2arr2 := z.EncBasicHandle().StructToArray + var yyq2 [1]bool + _, _, _ = yysep2, yyq2, yy2arr2 + const yyr2 bool = false + yyq2[0] = x.PodController != nil + var yynn2 int + if yyr2 || yy2arr2 { + r.EncodeArrayStart(1) + } else { + yynn2 = 0 + for _, b := range yyq2 { + if b { + yynn2++ + } + } + r.EncodeMapStart(yynn2) + yynn2 = 0 + } + if yyr2 || yy2arr2 { + z.EncSendContainerState(codecSelfer_containerArrayElem1234) + if yyq2[0] { + if x.PodController == nil { + r.EncodeNil() + } else { + x.PodController.CodecEncodeSelf(e) + } + } else { + r.EncodeNil() + } + } else { + if yyq2[0] { + z.EncSendContainerState(codecSelfer_containerMapKey1234) + r.EncodeString(codecSelferC_UTF81234, string("podController")) + z.EncSendContainerState(codecSelfer_containerMapValue1234) + if x.PodController == nil { + r.EncodeNil() + } else { + x.PodController.CodecEncodeSelf(e) + } + } + } + if yyr2 || yy2arr2 { + z.EncSendContainerState(codecSelfer_containerArrayEnd1234) + } else { + z.EncSendContainerState(codecSelfer_containerMapEnd1234) + } + } + } +} + +func (x *PodSignature) CodecDecodeSelf(d *codec1978.Decoder) { + var h codecSelfer1234 + z, r := codec1978.GenHelperDecoder(d) + _, _, _ = h, z, r + yym1 := z.DecBinary() + _ = yym1 + if false { + } else if z.HasExtensions() && z.DecExt(x) { + } else { + yyct2 := r.ContainerType() + if yyct2 == codecSelferValueTypeMap1234 { + yyl2 := r.ReadMapStart() + if yyl2 == 0 { + z.DecSendContainerState(codecSelfer_containerMapEnd1234) + } else { + x.codecDecodeSelfFromMap(yyl2, d) + } + } else if yyct2 == codecSelferValueTypeArray1234 { + yyl2 := r.ReadArrayStart() + if yyl2 == 0 { + z.DecSendContainerState(codecSelfer_containerArrayEnd1234) + } else { + x.codecDecodeSelfFromArray(yyl2, d) + } + } else { + panic(codecSelferOnlyMapOrArrayEncodeToStructErr1234) + } + } +} + +func (x *PodSignature) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) { + var h codecSelfer1234 + z, r := codec1978.GenHelperDecoder(d) + _, _, _ = h, z, r + var yys3Slc = z.DecScratchBuffer() // default slice to decode into + _ = yys3Slc + var yyhl3 bool = l >= 0 + for yyj3 := 0; ; yyj3++ { + if yyhl3 { + if yyj3 >= l { + break + } + } else { + if r.CheckBreak() { + break + } + } + z.DecSendContainerState(codecSelfer_containerMapKey1234) + yys3Slc = r.DecodeBytes(yys3Slc, true, true) + yys3 := string(yys3Slc) + z.DecSendContainerState(codecSelfer_containerMapValue1234) + switch yys3 { + case "podController": + if r.TryDecodeAsNil() { + if x.PodController != nil { + x.PodController = nil + } + } else { + if x.PodController == nil { + x.PodController = new(OwnerReference) + } + x.PodController.CodecDecodeSelf(d) + } + default: + z.DecStructFieldNotFound(-1, yys3) + } // end switch yys3 + } // end for yyj3 + z.DecSendContainerState(codecSelfer_containerMapEnd1234) +} + +func (x *PodSignature) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) { + var h codecSelfer1234 + z, r := codec1978.GenHelperDecoder(d) + _, _, _ = h, z, r + var yyj5 int + var yyb5 bool + var yyhl5 bool = l >= 0 + yyj5++ + if yyhl5 { + yyb5 = yyj5 > l + } else { + yyb5 = r.CheckBreak() + } + if yyb5 { + z.DecSendContainerState(codecSelfer_containerArrayEnd1234) + return + } + z.DecSendContainerState(codecSelfer_containerArrayElem1234) + if r.TryDecodeAsNil() { + if x.PodController != nil { + x.PodController = nil + } + } else { + if x.PodController == nil { + x.PodController = new(OwnerReference) + } + x.PodController.CodecDecodeSelf(d) + } + for { + yyj5++ + if yyhl5 { + yyb5 = yyj5 > l + } else { + yyb5 = r.CheckBreak() + } + if yyb5 { + break + } + z.DecSendContainerState(codecSelfer_containerArrayElem1234) + z.DecStructFieldNotFound(yyj5-1, "") + } + z.DecSendContainerState(codecSelfer_containerArrayEnd1234) +} + func (x *ContainerImage) CodecEncodeSelf(e *codec1978.Encoder) { var h codecSelfer1234 z, r := codec1978.GenHelperEncoder(e) @@ -57857,6 +58557,125 @@ func (x codecSelfer1234) decSliceAttachedVolume(v *[]AttachedVolume, d *codec197 } } +func (x codecSelfer1234) encSlicePreferAvoidPodsEntry(v []PreferAvoidPodsEntry, e *codec1978.Encoder) { + var h codecSelfer1234 + z, r := codec1978.GenHelperEncoder(e) + _, _, _ = h, z, r + r.EncodeArrayStart(len(v)) + for _, yyv1 := range v { + z.EncSendContainerState(codecSelfer_containerArrayElem1234) + yy2 := &yyv1 + yy2.CodecEncodeSelf(e) + } + z.EncSendContainerState(codecSelfer_containerArrayEnd1234) +} + +func (x codecSelfer1234) decSlicePreferAvoidPodsEntry(v *[]PreferAvoidPodsEntry, d *codec1978.Decoder) { + var h codecSelfer1234 + z, r := codec1978.GenHelperDecoder(d) + _, _, _ = h, z, r + + yyv1 := *v + yyh1, yyl1 := z.DecSliceHelperStart() + var yyc1 bool + _ = yyc1 + if yyl1 == 0 { + if yyv1 == nil { + yyv1 = []PreferAvoidPodsEntry{} + yyc1 = true + } else if len(yyv1) != 0 { + yyv1 = yyv1[:0] + yyc1 = true + } + } else if yyl1 > 0 { + var yyrr1, yyrl1 int + var yyrt1 bool + _, _ = yyrl1, yyrt1 + yyrr1 = yyl1 // len(yyv1) + if yyl1 > cap(yyv1) { + + yyrg1 := len(yyv1) > 0 + yyv21 := yyv1 + yyrl1, yyrt1 = z.DecInferLen(yyl1, z.DecBasicHandle().MaxInitLen, 64) + if yyrt1 { + if yyrl1 <= cap(yyv1) { + yyv1 = yyv1[:yyrl1] + } else { + yyv1 = make([]PreferAvoidPodsEntry, yyrl1) + } + } else { + yyv1 = make([]PreferAvoidPodsEntry, yyrl1) + } + yyc1 = true + yyrr1 = len(yyv1) + if yyrg1 { + copy(yyv1, yyv21) + } + } else if yyl1 != len(yyv1) { + yyv1 = yyv1[:yyl1] + yyc1 = true + } + yyj1 := 0 + for ; yyj1 < yyrr1; yyj1++ { + yyh1.ElemContainerState(yyj1) + if r.TryDecodeAsNil() { + yyv1[yyj1] = PreferAvoidPodsEntry{} + } else { + yyv2 := &yyv1[yyj1] + yyv2.CodecDecodeSelf(d) + } + + } + if yyrt1 { + for ; yyj1 < yyl1; yyj1++ { + yyv1 = append(yyv1, PreferAvoidPodsEntry{}) + yyh1.ElemContainerState(yyj1) + if r.TryDecodeAsNil() { + yyv1[yyj1] = PreferAvoidPodsEntry{} + } else { + yyv3 := &yyv1[yyj1] + yyv3.CodecDecodeSelf(d) + } + + } + } + + } else { + yyj1 := 0 + for ; !r.CheckBreak(); yyj1++ { + + if yyj1 >= len(yyv1) { + yyv1 = append(yyv1, PreferAvoidPodsEntry{}) // var yyz1 PreferAvoidPodsEntry + yyc1 = true + } + yyh1.ElemContainerState(yyj1) + if yyj1 < len(yyv1) { + if r.TryDecodeAsNil() { + yyv1[yyj1] = PreferAvoidPodsEntry{} + } else { + yyv4 := &yyv1[yyj1] + yyv4.CodecDecodeSelf(d) + } + + } else { + z.DecSwallow() + } + + } + if yyj1 < len(yyv1) { + yyv1 = yyv1[:yyj1] + yyc1 = true + } else if yyj1 == 0 && yyv1 == nil { + yyv1 = []PreferAvoidPodsEntry{} + yyc1 = true + } + } + yyh1.End() + if yyc1 { + *v = yyv1 + } +} + func (x codecSelfer1234) encResourceList(v ResourceList, e *codec1978.Encoder) { var h codecSelfer1234 z, r := codec1978.GenHelperEncoder(e) diff --git a/pkg/api/types.go b/pkg/api/types.go index b2588210bde..0f31cace915 100644 --- a/pkg/api/types.go +++ b/pkg/api/types.go @@ -2008,6 +2008,34 @@ type AttachedVolume struct { DevicePath string `json:"devicePath"` } +// AvoidPods describes pods that should avoid this node. This is the value for a +// Node annotation with key scheduler.alpha.kubernetes.io/preferAvoidPods and +// will eventually become a field of NodeStatus. +type AvoidPods struct { + // Bounded-sized list of signatures of pods that should avoid this node, sorted + // in timestamp order from oldest to newest. Size of the slice is unspecified. + PreferAvoidPods []PreferAvoidPodsEntry `json:"preferAvoidPods,omitempty"` +} + +// Describes a class of pods that should avoid this node. +type PreferAvoidPodsEntry struct { + // The class of pods. + PodSignature PodSignature `json:"podSignature"` + // Time at which this entry was added to the list. + EvictionTime unversioned.Time `json:"evictionTime,omitempty"` + // (brief) reason why this entry was added to the list. + Reason string `json:"reason,omitempty"` + // Human readable message indicating why this entry was added to the list. + Message string `json:"message,omitempty"` +} + +// Describes the class of pods that should avoid this node. +// Exactly one field should be set. +type PodSignature struct { + // Reference to controller whose pods should avoid this node. + PodController *OwnerReference `json:"podController,omitempty"` +} + // Describe a container image type ContainerImage struct { // Names by which this image is known. diff --git a/pkg/api/v1/generated.pb.go b/pkg/api/v1/generated.pb.go index 16ac125d584..80daf7bda79 100644 --- a/pkg/api/v1/generated.pb.go +++ b/pkg/api/v1/generated.pb.go @@ -28,6 +28,7 @@ limitations under the License. AWSElasticBlockStoreVolumeSource Affinity AttachedVolume + AvoidPods AzureFileVolumeSource Binding Capabilities @@ -130,6 +131,7 @@ limitations under the License. PodLogOptions PodProxyOptions PodSecurityContext + PodSignature PodSpec PodStatus PodStatusResult @@ -137,6 +139,7 @@ limitations under the License. PodTemplateList PodTemplateSpec Preconditions + PreferAvoidPodsEntry PreferredSchedulingTerm Probe RBDVolumeSource @@ -206,6 +209,10 @@ func (m *AttachedVolume) Reset() { *m = AttachedVolume{} } func (m *AttachedVolume) String() string { return proto.CompactTextString(m) } func (*AttachedVolume) ProtoMessage() {} +func (m *AvoidPods) Reset() { *m = AvoidPods{} } +func (m *AvoidPods) String() string { return proto.CompactTextString(m) } +func (*AvoidPods) ProtoMessage() {} + func (m *AzureFileVolumeSource) Reset() { *m = AzureFileVolumeSource{} } func (m *AzureFileVolumeSource) String() string { return proto.CompactTextString(m) } func (*AzureFileVolumeSource) ProtoMessage() {} @@ -614,6 +621,10 @@ func (m *PodSecurityContext) Reset() { *m = PodSecurityContext{} } func (m *PodSecurityContext) String() string { return proto.CompactTextString(m) } func (*PodSecurityContext) ProtoMessage() {} +func (m *PodSignature) Reset() { *m = PodSignature{} } +func (m *PodSignature) String() string { return proto.CompactTextString(m) } +func (*PodSignature) ProtoMessage() {} + func (m *PodSpec) Reset() { *m = PodSpec{} } func (m *PodSpec) String() string { return proto.CompactTextString(m) } func (*PodSpec) ProtoMessage() {} @@ -642,6 +653,10 @@ func (m *Preconditions) Reset() { *m = Preconditions{} } func (m *Preconditions) String() string { return proto.CompactTextString(m) } func (*Preconditions) ProtoMessage() {} +func (m *PreferAvoidPodsEntry) Reset() { *m = PreferAvoidPodsEntry{} } +func (m *PreferAvoidPodsEntry) String() string { return proto.CompactTextString(m) } +func (*PreferAvoidPodsEntry) ProtoMessage() {} + func (m *PreferredSchedulingTerm) Reset() { *m = PreferredSchedulingTerm{} } func (m *PreferredSchedulingTerm) String() string { return proto.CompactTextString(m) } func (*PreferredSchedulingTerm) ProtoMessage() {} @@ -794,6 +809,7 @@ func init() { proto.RegisterType((*AWSElasticBlockStoreVolumeSource)(nil), "k8s.io.kubernetes.pkg.api.v1.AWSElasticBlockStoreVolumeSource") proto.RegisterType((*Affinity)(nil), "k8s.io.kubernetes.pkg.api.v1.Affinity") proto.RegisterType((*AttachedVolume)(nil), "k8s.io.kubernetes.pkg.api.v1.AttachedVolume") + proto.RegisterType((*AvoidPods)(nil), "k8s.io.kubernetes.pkg.api.v1.AvoidPods") proto.RegisterType((*AzureFileVolumeSource)(nil), "k8s.io.kubernetes.pkg.api.v1.AzureFileVolumeSource") proto.RegisterType((*Binding)(nil), "k8s.io.kubernetes.pkg.api.v1.Binding") proto.RegisterType((*Capabilities)(nil), "k8s.io.kubernetes.pkg.api.v1.Capabilities") @@ -896,6 +912,7 @@ func init() { proto.RegisterType((*PodLogOptions)(nil), "k8s.io.kubernetes.pkg.api.v1.PodLogOptions") proto.RegisterType((*PodProxyOptions)(nil), "k8s.io.kubernetes.pkg.api.v1.PodProxyOptions") proto.RegisterType((*PodSecurityContext)(nil), "k8s.io.kubernetes.pkg.api.v1.PodSecurityContext") + proto.RegisterType((*PodSignature)(nil), "k8s.io.kubernetes.pkg.api.v1.PodSignature") proto.RegisterType((*PodSpec)(nil), "k8s.io.kubernetes.pkg.api.v1.PodSpec") proto.RegisterType((*PodStatus)(nil), "k8s.io.kubernetes.pkg.api.v1.PodStatus") proto.RegisterType((*PodStatusResult)(nil), "k8s.io.kubernetes.pkg.api.v1.PodStatusResult") @@ -903,6 +920,7 @@ func init() { proto.RegisterType((*PodTemplateList)(nil), "k8s.io.kubernetes.pkg.api.v1.PodTemplateList") proto.RegisterType((*PodTemplateSpec)(nil), "k8s.io.kubernetes.pkg.api.v1.PodTemplateSpec") proto.RegisterType((*Preconditions)(nil), "k8s.io.kubernetes.pkg.api.v1.Preconditions") + proto.RegisterType((*PreferAvoidPodsEntry)(nil), "k8s.io.kubernetes.pkg.api.v1.PreferAvoidPodsEntry") proto.RegisterType((*PreferredSchedulingTerm)(nil), "k8s.io.kubernetes.pkg.api.v1.PreferredSchedulingTerm") proto.RegisterType((*Probe)(nil), "k8s.io.kubernetes.pkg.api.v1.Probe") proto.RegisterType((*RBDVolumeSource)(nil), "k8s.io.kubernetes.pkg.api.v1.RBDVolumeSource") @@ -1052,6 +1070,36 @@ func (m *AttachedVolume) MarshalTo(data []byte) (int, error) { return i, nil } +func (m *AvoidPods) Marshal() (data []byte, err error) { + size := m.Size() + data = make([]byte, size) + n, err := m.MarshalTo(data) + if err != nil { + return nil, err + } + return data[:n], nil +} + +func (m *AvoidPods) MarshalTo(data []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if len(m.PreferAvoidPods) > 0 { + for _, msg := range m.PreferAvoidPods { + data[i] = 0xa + i++ + i = encodeVarintGenerated(data, i, uint64(msg.Size())) + n, err := msg.MarshalTo(data[i:]) + if err != nil { + return 0, err + } + i += n + } + } + return i, nil +} + func (m *AzureFileVolumeSource) Marshal() (data []byte, err error) { size := m.Size() data = make([]byte, size) @@ -5625,6 +5673,34 @@ func (m *PodSecurityContext) MarshalTo(data []byte) (int, error) { return i, nil } +func (m *PodSignature) Marshal() (data []byte, err error) { + size := m.Size() + data = make([]byte, size) + n, err := m.MarshalTo(data) + if err != nil { + return nil, err + } + return data[:n], nil +} + +func (m *PodSignature) MarshalTo(data []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if m.PodController != nil { + data[i] = 0xa + i++ + i = encodeVarintGenerated(data, i, uint64(m.PodController.Size())) + n114, err := m.PodController.MarshalTo(data[i:]) + if err != nil { + return 0, err + } + i += n114 + } + return i, nil +} + func (m *PodSpec) Marshal() (data []byte, err error) { size := m.Size() data = make([]byte, size) @@ -5739,11 +5815,11 @@ func (m *PodSpec) MarshalTo(data []byte) (int, error) { data[i] = 0x72 i++ i = encodeVarintGenerated(data, i, uint64(m.SecurityContext.Size())) - n114, err := m.SecurityContext.MarshalTo(data[i:]) + n115, err := m.SecurityContext.MarshalTo(data[i:]) if err != nil { return 0, err } - i += n114 + i += n115 } if len(m.ImagePullSecrets) > 0 { for _, msg := range m.ImagePullSecrets { @@ -5823,11 +5899,11 @@ func (m *PodStatus) MarshalTo(data []byte) (int, error) { data[i] = 0x3a i++ i = encodeVarintGenerated(data, i, uint64(m.StartTime.Size())) - n115, err := m.StartTime.MarshalTo(data[i:]) + n116, err := m.StartTime.MarshalTo(data[i:]) if err != nil { return 0, err } - i += n115 + i += n116 } if len(m.ContainerStatuses) > 0 { for _, msg := range m.ContainerStatuses { @@ -5862,19 +5938,19 @@ func (m *PodStatusResult) MarshalTo(data []byte) (int, error) { data[i] = 0xa i++ i = encodeVarintGenerated(data, i, uint64(m.ObjectMeta.Size())) - n116, err := m.ObjectMeta.MarshalTo(data[i:]) - if err != nil { - return 0, err - } - i += n116 - data[i] = 0x12 - i++ - i = encodeVarintGenerated(data, i, uint64(m.Status.Size())) - n117, err := m.Status.MarshalTo(data[i:]) + n117, err := m.ObjectMeta.MarshalTo(data[i:]) if err != nil { return 0, err } i += n117 + data[i] = 0x12 + i++ + i = encodeVarintGenerated(data, i, uint64(m.Status.Size())) + n118, err := m.Status.MarshalTo(data[i:]) + if err != nil { + return 0, err + } + i += n118 return i, nil } @@ -5896,19 +5972,19 @@ func (m *PodTemplate) MarshalTo(data []byte) (int, error) { data[i] = 0xa i++ i = encodeVarintGenerated(data, i, uint64(m.ObjectMeta.Size())) - n118, err := m.ObjectMeta.MarshalTo(data[i:]) - if err != nil { - return 0, err - } - i += n118 - data[i] = 0x12 - i++ - i = encodeVarintGenerated(data, i, uint64(m.Template.Size())) - n119, err := m.Template.MarshalTo(data[i:]) + n119, err := m.ObjectMeta.MarshalTo(data[i:]) if err != nil { return 0, err } i += n119 + data[i] = 0x12 + i++ + i = encodeVarintGenerated(data, i, uint64(m.Template.Size())) + n120, err := m.Template.MarshalTo(data[i:]) + if err != nil { + return 0, err + } + i += n120 return i, nil } @@ -5930,11 +6006,11 @@ func (m *PodTemplateList) MarshalTo(data []byte) (int, error) { data[i] = 0xa i++ i = encodeVarintGenerated(data, i, uint64(m.ListMeta.Size())) - n120, err := m.ListMeta.MarshalTo(data[i:]) + n121, err := m.ListMeta.MarshalTo(data[i:]) if err != nil { return 0, err } - i += n120 + i += n121 if len(m.Items) > 0 { for _, msg := range m.Items { data[i] = 0x12 @@ -5968,19 +6044,19 @@ func (m *PodTemplateSpec) MarshalTo(data []byte) (int, error) { data[i] = 0xa i++ i = encodeVarintGenerated(data, i, uint64(m.ObjectMeta.Size())) - n121, err := m.ObjectMeta.MarshalTo(data[i:]) - if err != nil { - return 0, err - } - i += n121 - data[i] = 0x12 - i++ - i = encodeVarintGenerated(data, i, uint64(m.Spec.Size())) - n122, err := m.Spec.MarshalTo(data[i:]) + n122, err := m.ObjectMeta.MarshalTo(data[i:]) if err != nil { return 0, err } i += n122 + data[i] = 0x12 + i++ + i = encodeVarintGenerated(data, i, uint64(m.Spec.Size())) + n123, err := m.Spec.MarshalTo(data[i:]) + if err != nil { + return 0, err + } + i += n123 return i, nil } @@ -6008,6 +6084,48 @@ func (m *Preconditions) MarshalTo(data []byte) (int, error) { return i, nil } +func (m *PreferAvoidPodsEntry) Marshal() (data []byte, err error) { + size := m.Size() + data = make([]byte, size) + n, err := m.MarshalTo(data) + if err != nil { + return nil, err + } + return data[:n], nil +} + +func (m *PreferAvoidPodsEntry) MarshalTo(data []byte) (int, error) { + var i int + _ = i + var l int + _ = l + data[i] = 0xa + i++ + i = encodeVarintGenerated(data, i, uint64(m.PodSignature.Size())) + n124, err := m.PodSignature.MarshalTo(data[i:]) + if err != nil { + return 0, err + } + i += n124 + data[i] = 0x12 + i++ + i = encodeVarintGenerated(data, i, uint64(m.EvictionTime.Size())) + n125, err := m.EvictionTime.MarshalTo(data[i:]) + if err != nil { + return 0, err + } + i += n125 + data[i] = 0x1a + i++ + i = encodeVarintGenerated(data, i, uint64(len(m.Reason))) + i += copy(data[i:], m.Reason) + data[i] = 0x22 + i++ + i = encodeVarintGenerated(data, i, uint64(len(m.Message))) + i += copy(data[i:], m.Message) + return i, nil +} + func (m *PreferredSchedulingTerm) Marshal() (data []byte, err error) { size := m.Size() data = make([]byte, size) @@ -6029,11 +6147,11 @@ func (m *PreferredSchedulingTerm) MarshalTo(data []byte) (int, error) { data[i] = 0x12 i++ i = encodeVarintGenerated(data, i, uint64(m.Preference.Size())) - n123, err := m.Preference.MarshalTo(data[i:]) + n126, err := m.Preference.MarshalTo(data[i:]) if err != nil { return 0, err } - i += n123 + i += n126 return i, nil } @@ -6055,11 +6173,11 @@ func (m *Probe) MarshalTo(data []byte) (int, error) { data[i] = 0xa i++ i = encodeVarintGenerated(data, i, uint64(m.Handler.Size())) - n124, err := m.Handler.MarshalTo(data[i:]) + n127, err := m.Handler.MarshalTo(data[i:]) if err != nil { return 0, err } - i += n124 + i += n127 data[i] = 0x10 i++ i = encodeVarintGenerated(data, i, uint64(m.InitialDelaySeconds)) @@ -6132,11 +6250,11 @@ func (m *RBDVolumeSource) MarshalTo(data []byte) (int, error) { data[i] = 0x3a i++ i = encodeVarintGenerated(data, i, uint64(m.SecretRef.Size())) - n125, err := m.SecretRef.MarshalTo(data[i:]) + n128, err := m.SecretRef.MarshalTo(data[i:]) if err != nil { return 0, err } - i += n125 + i += n128 } data[i] = 0x40 i++ @@ -6167,11 +6285,11 @@ func (m *RangeAllocation) MarshalTo(data []byte) (int, error) { data[i] = 0xa i++ i = encodeVarintGenerated(data, i, uint64(m.ObjectMeta.Size())) - n126, err := m.ObjectMeta.MarshalTo(data[i:]) + n129, err := m.ObjectMeta.MarshalTo(data[i:]) if err != nil { return 0, err } - i += n126 + i += n129 data[i] = 0x12 i++ i = encodeVarintGenerated(data, i, uint64(len(m.Range))) @@ -6203,27 +6321,27 @@ func (m *ReplicationController) MarshalTo(data []byte) (int, error) { data[i] = 0xa i++ i = encodeVarintGenerated(data, i, uint64(m.ObjectMeta.Size())) - n127, err := m.ObjectMeta.MarshalTo(data[i:]) + n130, err := m.ObjectMeta.MarshalTo(data[i:]) if err != nil { return 0, err } - i += n127 + i += n130 data[i] = 0x12 i++ i = encodeVarintGenerated(data, i, uint64(m.Spec.Size())) - n128, err := m.Spec.MarshalTo(data[i:]) + n131, err := m.Spec.MarshalTo(data[i:]) if err != nil { return 0, err } - i += n128 + i += n131 data[i] = 0x1a i++ i = encodeVarintGenerated(data, i, uint64(m.Status.Size())) - n129, err := m.Status.MarshalTo(data[i:]) + n132, err := m.Status.MarshalTo(data[i:]) if err != nil { return 0, err } - i += n129 + i += n132 return i, nil } @@ -6245,11 +6363,11 @@ func (m *ReplicationControllerList) MarshalTo(data []byte) (int, error) { data[i] = 0xa i++ i = encodeVarintGenerated(data, i, uint64(m.ListMeta.Size())) - n130, err := m.ListMeta.MarshalTo(data[i:]) + n133, err := m.ListMeta.MarshalTo(data[i:]) if err != nil { return 0, err } - i += n130 + i += n133 if len(m.Items) > 0 { for _, msg := range m.Items { data[i] = 0x12 @@ -6306,11 +6424,11 @@ func (m *ReplicationControllerSpec) MarshalTo(data []byte) (int, error) { data[i] = 0x1a i++ i = encodeVarintGenerated(data, i, uint64(m.Template.Size())) - n131, err := m.Template.MarshalTo(data[i:]) + n134, err := m.Template.MarshalTo(data[i:]) if err != nil { return 0, err } - i += n131 + i += n134 } return i, nil } @@ -6368,11 +6486,11 @@ func (m *ResourceFieldSelector) MarshalTo(data []byte) (int, error) { data[i] = 0x1a i++ i = encodeVarintGenerated(data, i, uint64(m.Divisor.Size())) - n132, err := m.Divisor.MarshalTo(data[i:]) + n135, err := m.Divisor.MarshalTo(data[i:]) if err != nil { return 0, err } - i += n132 + i += n135 return i, nil } @@ -6394,27 +6512,27 @@ func (m *ResourceQuota) MarshalTo(data []byte) (int, error) { data[i] = 0xa i++ i = encodeVarintGenerated(data, i, uint64(m.ObjectMeta.Size())) - n133, err := m.ObjectMeta.MarshalTo(data[i:]) + n136, err := m.ObjectMeta.MarshalTo(data[i:]) if err != nil { return 0, err } - i += n133 + i += n136 data[i] = 0x12 i++ i = encodeVarintGenerated(data, i, uint64(m.Spec.Size())) - n134, err := m.Spec.MarshalTo(data[i:]) + n137, err := m.Spec.MarshalTo(data[i:]) if err != nil { return 0, err } - i += n134 + i += n137 data[i] = 0x1a i++ i = encodeVarintGenerated(data, i, uint64(m.Status.Size())) - n135, err := m.Status.MarshalTo(data[i:]) + n138, err := m.Status.MarshalTo(data[i:]) if err != nil { return 0, err } - i += n135 + i += n138 return i, nil } @@ -6436,11 +6554,11 @@ func (m *ResourceQuotaList) MarshalTo(data []byte) (int, error) { data[i] = 0xa i++ i = encodeVarintGenerated(data, i, uint64(m.ListMeta.Size())) - n136, err := m.ListMeta.MarshalTo(data[i:]) + n139, err := m.ListMeta.MarshalTo(data[i:]) if err != nil { return 0, err } - i += n136 + i += n139 if len(m.Items) > 0 { for _, msg := range m.Items { data[i] = 0x12 @@ -6486,11 +6604,11 @@ func (m *ResourceQuotaSpec) MarshalTo(data []byte) (int, error) { data[i] = 0x12 i++ i = encodeVarintGenerated(data, i, uint64((&v).Size())) - n137, err := (&v).MarshalTo(data[i:]) + n140, err := (&v).MarshalTo(data[i:]) if err != nil { return 0, err } - i += n137 + i += n140 } } if len(m.Scopes) > 0 { @@ -6541,11 +6659,11 @@ func (m *ResourceQuotaStatus) MarshalTo(data []byte) (int, error) { data[i] = 0x12 i++ i = encodeVarintGenerated(data, i, uint64((&v).Size())) - n138, err := (&v).MarshalTo(data[i:]) + n141, err := (&v).MarshalTo(data[i:]) if err != nil { return 0, err } - i += n138 + i += n141 } } if len(m.Used) > 0 { @@ -6563,11 +6681,11 @@ func (m *ResourceQuotaStatus) MarshalTo(data []byte) (int, error) { data[i] = 0x12 i++ i = encodeVarintGenerated(data, i, uint64((&v).Size())) - n139, err := (&v).MarshalTo(data[i:]) + n142, err := (&v).MarshalTo(data[i:]) if err != nil { return 0, err } - i += n139 + i += n142 } } return i, nil @@ -6603,11 +6721,11 @@ func (m *ResourceRequirements) MarshalTo(data []byte) (int, error) { data[i] = 0x12 i++ i = encodeVarintGenerated(data, i, uint64((&v).Size())) - n140, err := (&v).MarshalTo(data[i:]) + n143, err := (&v).MarshalTo(data[i:]) if err != nil { return 0, err } - i += n140 + i += n143 } } if len(m.Requests) > 0 { @@ -6625,11 +6743,11 @@ func (m *ResourceRequirements) MarshalTo(data []byte) (int, error) { data[i] = 0x12 i++ i = encodeVarintGenerated(data, i, uint64((&v).Size())) - n141, err := (&v).MarshalTo(data[i:]) + n144, err := (&v).MarshalTo(data[i:]) if err != nil { return 0, err } - i += n141 + i += n144 } } return i, nil @@ -6687,11 +6805,11 @@ func (m *Secret) MarshalTo(data []byte) (int, error) { data[i] = 0xa i++ i = encodeVarintGenerated(data, i, uint64(m.ObjectMeta.Size())) - n142, err := m.ObjectMeta.MarshalTo(data[i:]) + n145, err := m.ObjectMeta.MarshalTo(data[i:]) if err != nil { return 0, err } - i += n142 + i += n145 if len(m.Data) > 0 { for k := range m.Data { data[i] = 0x12 @@ -6751,11 +6869,11 @@ func (m *SecretKeySelector) MarshalTo(data []byte) (int, error) { data[i] = 0xa i++ i = encodeVarintGenerated(data, i, uint64(m.LocalObjectReference.Size())) - n143, err := m.LocalObjectReference.MarshalTo(data[i:]) + n146, err := m.LocalObjectReference.MarshalTo(data[i:]) if err != nil { return 0, err } - i += n143 + i += n146 data[i] = 0x12 i++ i = encodeVarintGenerated(data, i, uint64(len(m.Key))) @@ -6781,11 +6899,11 @@ func (m *SecretList) MarshalTo(data []byte) (int, error) { data[i] = 0xa i++ i = encodeVarintGenerated(data, i, uint64(m.ListMeta.Size())) - n144, err := m.ListMeta.MarshalTo(data[i:]) + n147, err := m.ListMeta.MarshalTo(data[i:]) if err != nil { return 0, err } - i += n144 + i += n147 if len(m.Items) > 0 { for _, msg := range m.Items { data[i] = 0x12 @@ -6854,11 +6972,11 @@ func (m *SecurityContext) MarshalTo(data []byte) (int, error) { data[i] = 0xa i++ i = encodeVarintGenerated(data, i, uint64(m.Capabilities.Size())) - n145, err := m.Capabilities.MarshalTo(data[i:]) + n148, err := m.Capabilities.MarshalTo(data[i:]) if err != nil { return 0, err } - i += n145 + i += n148 } if m.Privileged != nil { data[i] = 0x10 @@ -6874,11 +6992,11 @@ func (m *SecurityContext) MarshalTo(data []byte) (int, error) { data[i] = 0x1a i++ i = encodeVarintGenerated(data, i, uint64(m.SELinuxOptions.Size())) - n146, err := m.SELinuxOptions.MarshalTo(data[i:]) + n149, err := m.SELinuxOptions.MarshalTo(data[i:]) if err != nil { return 0, err } - i += n146 + i += n149 } if m.RunAsUser != nil { data[i] = 0x20 @@ -6926,11 +7044,11 @@ func (m *SerializedReference) MarshalTo(data []byte) (int, error) { data[i] = 0xa i++ i = encodeVarintGenerated(data, i, uint64(m.Reference.Size())) - n147, err := m.Reference.MarshalTo(data[i:]) + n150, err := m.Reference.MarshalTo(data[i:]) if err != nil { return 0, err } - i += n147 + i += n150 return i, nil } @@ -6952,27 +7070,27 @@ func (m *Service) MarshalTo(data []byte) (int, error) { data[i] = 0xa i++ i = encodeVarintGenerated(data, i, uint64(m.ObjectMeta.Size())) - n148, err := m.ObjectMeta.MarshalTo(data[i:]) + n151, err := m.ObjectMeta.MarshalTo(data[i:]) if err != nil { return 0, err } - i += n148 + i += n151 data[i] = 0x12 i++ i = encodeVarintGenerated(data, i, uint64(m.Spec.Size())) - n149, err := m.Spec.MarshalTo(data[i:]) + n152, err := m.Spec.MarshalTo(data[i:]) if err != nil { return 0, err } - i += n149 + i += n152 data[i] = 0x1a i++ i = encodeVarintGenerated(data, i, uint64(m.Status.Size())) - n150, err := m.Status.MarshalTo(data[i:]) + n153, err := m.Status.MarshalTo(data[i:]) if err != nil { return 0, err } - i += n150 + i += n153 return i, nil } @@ -6994,11 +7112,11 @@ func (m *ServiceAccount) MarshalTo(data []byte) (int, error) { data[i] = 0xa i++ i = encodeVarintGenerated(data, i, uint64(m.ObjectMeta.Size())) - n151, err := m.ObjectMeta.MarshalTo(data[i:]) + n154, err := m.ObjectMeta.MarshalTo(data[i:]) if err != nil { return 0, err } - i += n151 + i += n154 if len(m.Secrets) > 0 { for _, msg := range m.Secrets { data[i] = 0x12 @@ -7044,11 +7162,11 @@ func (m *ServiceAccountList) MarshalTo(data []byte) (int, error) { data[i] = 0xa i++ i = encodeVarintGenerated(data, i, uint64(m.ListMeta.Size())) - n152, err := m.ListMeta.MarshalTo(data[i:]) + n155, err := m.ListMeta.MarshalTo(data[i:]) if err != nil { return 0, err } - i += n152 + i += n155 if len(m.Items) > 0 { for _, msg := range m.Items { data[i] = 0x12 @@ -7082,11 +7200,11 @@ func (m *ServiceList) MarshalTo(data []byte) (int, error) { data[i] = 0xa i++ i = encodeVarintGenerated(data, i, uint64(m.ListMeta.Size())) - n153, err := m.ListMeta.MarshalTo(data[i:]) + n156, err := m.ListMeta.MarshalTo(data[i:]) if err != nil { return 0, err } - i += n153 + i += n156 if len(m.Items) > 0 { for _, msg := range m.Items { data[i] = 0x12 @@ -7131,11 +7249,11 @@ func (m *ServicePort) MarshalTo(data []byte) (int, error) { data[i] = 0x22 i++ i = encodeVarintGenerated(data, i, uint64(m.TargetPort.Size())) - n154, err := m.TargetPort.MarshalTo(data[i:]) + n157, err := m.TargetPort.MarshalTo(data[i:]) if err != nil { return 0, err } - i += n154 + i += n157 data[i] = 0x28 i++ i = encodeVarintGenerated(data, i, uint64(m.NodePort)) @@ -7290,11 +7408,11 @@ func (m *ServiceStatus) MarshalTo(data []byte) (int, error) { data[i] = 0xa i++ i = encodeVarintGenerated(data, i, uint64(m.LoadBalancer.Size())) - n155, err := m.LoadBalancer.MarshalTo(data[i:]) + n158, err := m.LoadBalancer.MarshalTo(data[i:]) if err != nil { return 0, err } - i += n155 + i += n158 return i, nil } @@ -7316,11 +7434,11 @@ func (m *TCPSocketAction) MarshalTo(data []byte) (int, error) { data[i] = 0xa i++ i = encodeVarintGenerated(data, i, uint64(m.Port.Size())) - n156, err := m.Port.MarshalTo(data[i:]) + n159, err := m.Port.MarshalTo(data[i:]) if err != nil { return 0, err } - i += n156 + i += n159 return i, nil } @@ -7410,11 +7528,11 @@ func (m *Volume) MarshalTo(data []byte) (int, error) { data[i] = 0x12 i++ i = encodeVarintGenerated(data, i, uint64(m.VolumeSource.Size())) - n157, err := m.VolumeSource.MarshalTo(data[i:]) + n160, err := m.VolumeSource.MarshalTo(data[i:]) if err != nil { return 0, err } - i += n157 + i += n160 return i, nil } @@ -7475,163 +7593,163 @@ func (m *VolumeSource) MarshalTo(data []byte) (int, error) { data[i] = 0xa i++ i = encodeVarintGenerated(data, i, uint64(m.HostPath.Size())) - n158, err := m.HostPath.MarshalTo(data[i:]) - if err != nil { - return 0, err - } - i += n158 - } - if m.EmptyDir != nil { - data[i] = 0x12 - i++ - i = encodeVarintGenerated(data, i, uint64(m.EmptyDir.Size())) - n159, err := m.EmptyDir.MarshalTo(data[i:]) - if err != nil { - return 0, err - } - i += n159 - } - if m.GCEPersistentDisk != nil { - data[i] = 0x1a - i++ - i = encodeVarintGenerated(data, i, uint64(m.GCEPersistentDisk.Size())) - n160, err := m.GCEPersistentDisk.MarshalTo(data[i:]) - if err != nil { - return 0, err - } - i += n160 - } - if m.AWSElasticBlockStore != nil { - data[i] = 0x22 - i++ - i = encodeVarintGenerated(data, i, uint64(m.AWSElasticBlockStore.Size())) - n161, err := m.AWSElasticBlockStore.MarshalTo(data[i:]) + n161, err := m.HostPath.MarshalTo(data[i:]) if err != nil { return 0, err } i += n161 } - if m.GitRepo != nil { - data[i] = 0x2a + if m.EmptyDir != nil { + data[i] = 0x12 i++ - i = encodeVarintGenerated(data, i, uint64(m.GitRepo.Size())) - n162, err := m.GitRepo.MarshalTo(data[i:]) + i = encodeVarintGenerated(data, i, uint64(m.EmptyDir.Size())) + n162, err := m.EmptyDir.MarshalTo(data[i:]) if err != nil { return 0, err } i += n162 } - if m.Secret != nil { - data[i] = 0x32 + if m.GCEPersistentDisk != nil { + data[i] = 0x1a i++ - i = encodeVarintGenerated(data, i, uint64(m.Secret.Size())) - n163, err := m.Secret.MarshalTo(data[i:]) + i = encodeVarintGenerated(data, i, uint64(m.GCEPersistentDisk.Size())) + n163, err := m.GCEPersistentDisk.MarshalTo(data[i:]) if err != nil { return 0, err } i += n163 } - if m.NFS != nil { - data[i] = 0x3a + if m.AWSElasticBlockStore != nil { + data[i] = 0x22 i++ - i = encodeVarintGenerated(data, i, uint64(m.NFS.Size())) - n164, err := m.NFS.MarshalTo(data[i:]) + i = encodeVarintGenerated(data, i, uint64(m.AWSElasticBlockStore.Size())) + n164, err := m.AWSElasticBlockStore.MarshalTo(data[i:]) if err != nil { return 0, err } i += n164 } - if m.ISCSI != nil { - data[i] = 0x42 + if m.GitRepo != nil { + data[i] = 0x2a i++ - i = encodeVarintGenerated(data, i, uint64(m.ISCSI.Size())) - n165, err := m.ISCSI.MarshalTo(data[i:]) + i = encodeVarintGenerated(data, i, uint64(m.GitRepo.Size())) + n165, err := m.GitRepo.MarshalTo(data[i:]) if err != nil { return 0, err } i += n165 } - if m.Glusterfs != nil { - data[i] = 0x4a + if m.Secret != nil { + data[i] = 0x32 i++ - i = encodeVarintGenerated(data, i, uint64(m.Glusterfs.Size())) - n166, err := m.Glusterfs.MarshalTo(data[i:]) + i = encodeVarintGenerated(data, i, uint64(m.Secret.Size())) + n166, err := m.Secret.MarshalTo(data[i:]) if err != nil { return 0, err } i += n166 } - if m.PersistentVolumeClaim != nil { - data[i] = 0x52 + if m.NFS != nil { + data[i] = 0x3a i++ - i = encodeVarintGenerated(data, i, uint64(m.PersistentVolumeClaim.Size())) - n167, err := m.PersistentVolumeClaim.MarshalTo(data[i:]) + i = encodeVarintGenerated(data, i, uint64(m.NFS.Size())) + n167, err := m.NFS.MarshalTo(data[i:]) if err != nil { return 0, err } i += n167 } - if m.RBD != nil { - data[i] = 0x5a + if m.ISCSI != nil { + data[i] = 0x42 i++ - i = encodeVarintGenerated(data, i, uint64(m.RBD.Size())) - n168, err := m.RBD.MarshalTo(data[i:]) + i = encodeVarintGenerated(data, i, uint64(m.ISCSI.Size())) + n168, err := m.ISCSI.MarshalTo(data[i:]) if err != nil { return 0, err } i += n168 } - if m.FlexVolume != nil { - data[i] = 0x62 + if m.Glusterfs != nil { + data[i] = 0x4a i++ - i = encodeVarintGenerated(data, i, uint64(m.FlexVolume.Size())) - n169, err := m.FlexVolume.MarshalTo(data[i:]) + i = encodeVarintGenerated(data, i, uint64(m.Glusterfs.Size())) + n169, err := m.Glusterfs.MarshalTo(data[i:]) if err != nil { return 0, err } i += n169 } - if m.Cinder != nil { - data[i] = 0x6a + if m.PersistentVolumeClaim != nil { + data[i] = 0x52 i++ - i = encodeVarintGenerated(data, i, uint64(m.Cinder.Size())) - n170, err := m.Cinder.MarshalTo(data[i:]) + i = encodeVarintGenerated(data, i, uint64(m.PersistentVolumeClaim.Size())) + n170, err := m.PersistentVolumeClaim.MarshalTo(data[i:]) if err != nil { return 0, err } i += n170 } - if m.CephFS != nil { - data[i] = 0x72 + if m.RBD != nil { + data[i] = 0x5a i++ - i = encodeVarintGenerated(data, i, uint64(m.CephFS.Size())) - n171, err := m.CephFS.MarshalTo(data[i:]) + i = encodeVarintGenerated(data, i, uint64(m.RBD.Size())) + n171, err := m.RBD.MarshalTo(data[i:]) if err != nil { return 0, err } i += n171 } - if m.Flocker != nil { - data[i] = 0x7a + if m.FlexVolume != nil { + data[i] = 0x62 i++ - i = encodeVarintGenerated(data, i, uint64(m.Flocker.Size())) - n172, err := m.Flocker.MarshalTo(data[i:]) + i = encodeVarintGenerated(data, i, uint64(m.FlexVolume.Size())) + n172, err := m.FlexVolume.MarshalTo(data[i:]) if err != nil { return 0, err } i += n172 } + if m.Cinder != nil { + data[i] = 0x6a + i++ + i = encodeVarintGenerated(data, i, uint64(m.Cinder.Size())) + n173, err := m.Cinder.MarshalTo(data[i:]) + if err != nil { + return 0, err + } + i += n173 + } + if m.CephFS != nil { + data[i] = 0x72 + i++ + i = encodeVarintGenerated(data, i, uint64(m.CephFS.Size())) + n174, err := m.CephFS.MarshalTo(data[i:]) + if err != nil { + return 0, err + } + i += n174 + } + if m.Flocker != nil { + data[i] = 0x7a + i++ + i = encodeVarintGenerated(data, i, uint64(m.Flocker.Size())) + n175, err := m.Flocker.MarshalTo(data[i:]) + if err != nil { + return 0, err + } + i += n175 + } if m.DownwardAPI != nil { data[i] = 0x82 i++ data[i] = 0x1 i++ i = encodeVarintGenerated(data, i, uint64(m.DownwardAPI.Size())) - n173, err := m.DownwardAPI.MarshalTo(data[i:]) + n176, err := m.DownwardAPI.MarshalTo(data[i:]) if err != nil { return 0, err } - i += n173 + i += n176 } if m.FC != nil { data[i] = 0x8a @@ -7639,11 +7757,11 @@ func (m *VolumeSource) MarshalTo(data []byte) (int, error) { data[i] = 0x1 i++ i = encodeVarintGenerated(data, i, uint64(m.FC.Size())) - n174, err := m.FC.MarshalTo(data[i:]) + n177, err := m.FC.MarshalTo(data[i:]) if err != nil { return 0, err } - i += n174 + i += n177 } if m.AzureFile != nil { data[i] = 0x92 @@ -7651,11 +7769,11 @@ func (m *VolumeSource) MarshalTo(data []byte) (int, error) { data[i] = 0x1 i++ i = encodeVarintGenerated(data, i, uint64(m.AzureFile.Size())) - n175, err := m.AzureFile.MarshalTo(data[i:]) + n178, err := m.AzureFile.MarshalTo(data[i:]) if err != nil { return 0, err } - i += n175 + i += n178 } if m.ConfigMap != nil { data[i] = 0x9a @@ -7663,11 +7781,11 @@ func (m *VolumeSource) MarshalTo(data []byte) (int, error) { data[i] = 0x1 i++ i = encodeVarintGenerated(data, i, uint64(m.ConfigMap.Size())) - n176, err := m.ConfigMap.MarshalTo(data[i:]) + n179, err := m.ConfigMap.MarshalTo(data[i:]) if err != nil { return 0, err } - i += n176 + i += n179 } if m.VsphereVolume != nil { data[i] = 0xa2 @@ -7675,11 +7793,11 @@ func (m *VolumeSource) MarshalTo(data []byte) (int, error) { data[i] = 0x1 i++ i = encodeVarintGenerated(data, i, uint64(m.VsphereVolume.Size())) - n177, err := m.VsphereVolume.MarshalTo(data[i:]) + n180, err := m.VsphereVolume.MarshalTo(data[i:]) if err != nil { return 0, err } - i += n177 + i += n180 } return i, nil } @@ -7731,11 +7849,11 @@ func (m *WeightedPodAffinityTerm) MarshalTo(data []byte) (int, error) { data[i] = 0x12 i++ i = encodeVarintGenerated(data, i, uint64(m.PodAffinityTerm.Size())) - n178, err := m.PodAffinityTerm.MarshalTo(data[i:]) + n181, err := m.PodAffinityTerm.MarshalTo(data[i:]) if err != nil { return 0, err } - i += n178 + i += n181 return i, nil } @@ -7806,6 +7924,18 @@ func (m *AttachedVolume) Size() (n int) { return n } +func (m *AvoidPods) Size() (n int) { + var l int + _ = l + if len(m.PreferAvoidPods) > 0 { + for _, e := range m.PreferAvoidPods { + l = e.Size() + n += 1 + l + sovGenerated(uint64(l)) + } + } + return n +} + func (m *AzureFileVolumeSource) Size() (n int) { var l int _ = l @@ -9487,6 +9617,16 @@ func (m *PodSecurityContext) Size() (n int) { return n } +func (m *PodSignature) Size() (n int) { + var l int + _ = l + if m.PodController != nil { + l = m.PodController.Size() + n += 1 + l + sovGenerated(uint64(l)) + } + return n +} + func (m *PodSpec) Size() (n int) { var l int _ = l @@ -9632,6 +9772,20 @@ func (m *Preconditions) Size() (n int) { return n } +func (m *PreferAvoidPodsEntry) Size() (n int) { + var l int + _ = l + l = m.PodSignature.Size() + n += 1 + l + sovGenerated(uint64(l)) + l = m.EvictionTime.Size() + n += 1 + l + sovGenerated(uint64(l)) + l = len(m.Reason) + n += 1 + l + sovGenerated(uint64(l)) + l = len(m.Message) + n += 1 + l + sovGenerated(uint64(l)) + return n +} + func (m *PreferredSchedulingTerm) Size() (n int) { var l int _ = l @@ -10685,6 +10839,87 @@ func (m *AttachedVolume) Unmarshal(data []byte) error { } return nil } +func (m *AvoidPods) Unmarshal(data []byte) error { + l := len(data) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := data[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: AvoidPods: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: AvoidPods: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PreferAvoidPods", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := data[iNdEx] + iNdEx++ + msglen |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenerated + } + postIndex := iNdEx + msglen + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.PreferAvoidPods = append(m.PreferAvoidPods, PreferAvoidPodsEntry{}) + if err := m.PreferAvoidPods[len(m.PreferAvoidPods)-1].Unmarshal(data[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenerated(data[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthGenerated + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func (m *AzureFileVolumeSource) Unmarshal(data []byte) error { l := len(data) iNdEx := 0 @@ -26972,6 +27207,89 @@ func (m *PodSecurityContext) Unmarshal(data []byte) error { } return nil } +func (m *PodSignature) Unmarshal(data []byte) error { + l := len(data) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := data[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: PodSignature: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: PodSignature: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PodController", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := data[iNdEx] + iNdEx++ + msglen |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenerated + } + postIndex := iNdEx + msglen + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.PodController == nil { + m.PodController = &OwnerReference{} + } + if err := m.PodController.Unmarshal(data[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenerated(data[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthGenerated + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func (m *PodSpec) Unmarshal(data []byte) error { l := len(data) iNdEx := 0 @@ -28373,6 +28691,174 @@ func (m *Preconditions) Unmarshal(data []byte) error { } return nil } +func (m *PreferAvoidPodsEntry) Unmarshal(data []byte) error { + l := len(data) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := data[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: PreferAvoidPodsEntry: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: PreferAvoidPodsEntry: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PodSignature", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := data[iNdEx] + iNdEx++ + msglen |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenerated + } + postIndex := iNdEx + msglen + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.PodSignature.Unmarshal(data[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field EvictionTime", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := data[iNdEx] + iNdEx++ + msglen |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenerated + } + postIndex := iNdEx + msglen + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.EvictionTime.Unmarshal(data[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Reason", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := data[iNdEx] + iNdEx++ + stringLen |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenerated + } + postIndex := iNdEx + intStringLen + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Reason = string(data[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Message", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenerated + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := data[iNdEx] + iNdEx++ + stringLen |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenerated + } + postIndex := iNdEx + intStringLen + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Message = string(data[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenerated(data[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthGenerated + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func (m *PreferredSchedulingTerm) Unmarshal(data []byte) error { l := len(data) iNdEx := 0 diff --git a/pkg/api/v1/generated.proto b/pkg/api/v1/generated.proto index 060b6cac429..cc8d1baaca0 100644 --- a/pkg/api/v1/generated.proto +++ b/pkg/api/v1/generated.proto @@ -80,6 +80,15 @@ message AttachedVolume { optional string devicePath = 2; } +// AvoidPods describes pods that should avoid this node. This is the value for a +// Node annotation with key scheduler.alpha.kubernetes.io/preferAvoidPods and +// will eventually become a field of NodeStatus. +message AvoidPods { + // Bounded-sized list of signatures of pods that should avoid this node, sorted + // in timestamp order from oldest to newest. Size of the slice is unspecified. + repeated PreferAvoidPodsEntry preferAvoidPods = 1; +} + // AzureFile represents an Azure File Service mount on the host and bind mount to the pod. message AzureFileVolumeSource { // the name of secret that contains Azure Storage Account Name and Key @@ -2040,6 +2049,13 @@ message PodSecurityContext { optional int64 fsGroup = 5; } +// Describes the class of pods that should avoid this node. +// Exactly one field should be set. +message PodSignature { + // Reference to controller whose pods should avoid this node. + optional OwnerReference podController = 1; +} + // PodSpec is a description of a pod. message PodSpec { // List of volumes that can be mounted by containers belonging to the pod. @@ -2219,6 +2235,21 @@ message Preconditions { optional string uid = 1; } +// Describes a class of pods that should avoid this node. +message PreferAvoidPodsEntry { + // The class of pods. + optional PodSignature podSignature = 1; + + // Time at which this entry was added to the list. + optional k8s.io.kubernetes.pkg.api.unversioned.Time evictionTime = 2; + + // (brief) reason why this entry was added to the list. + optional string reason = 3; + + // Human readable message indicating why this entry was added to the list. + optional string message = 4; +} + // An empty preferred scheduling term matches all objects with implicit weight 0 // (i.e. it's a no-op). A null preferred scheduling term matches no objects (i.e. is also a no-op). message PreferredSchedulingTerm { diff --git a/pkg/api/v1/types.generated.go b/pkg/api/v1/types.generated.go index 93c45dadf2f..9891e9eb25b 100644 --- a/pkg/api/v1/types.generated.go +++ b/pkg/api/v1/types.generated.go @@ -37214,6 +37214,706 @@ func (x *AttachedVolume) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) { z.DecSendContainerState(codecSelfer_containerArrayEnd1234) } +func (x *AvoidPods) CodecEncodeSelf(e *codec1978.Encoder) { + var h codecSelfer1234 + z, r := codec1978.GenHelperEncoder(e) + _, _, _ = h, z, r + if x == nil { + r.EncodeNil() + } else { + yym1 := z.EncBinary() + _ = yym1 + if false { + } else if z.HasExtensions() && z.EncExt(x) { + } else { + yysep2 := !z.EncBinary() + yy2arr2 := z.EncBasicHandle().StructToArray + var yyq2 [1]bool + _, _, _ = yysep2, yyq2, yy2arr2 + const yyr2 bool = false + yyq2[0] = len(x.PreferAvoidPods) != 0 + var yynn2 int + if yyr2 || yy2arr2 { + r.EncodeArrayStart(1) + } else { + yynn2 = 0 + for _, b := range yyq2 { + if b { + yynn2++ + } + } + r.EncodeMapStart(yynn2) + yynn2 = 0 + } + if yyr2 || yy2arr2 { + z.EncSendContainerState(codecSelfer_containerArrayElem1234) + if yyq2[0] { + if x.PreferAvoidPods == nil { + r.EncodeNil() + } else { + yym4 := z.EncBinary() + _ = yym4 + if false { + } else { + h.encSlicePreferAvoidPodsEntry(([]PreferAvoidPodsEntry)(x.PreferAvoidPods), e) + } + } + } else { + r.EncodeNil() + } + } else { + if yyq2[0] { + z.EncSendContainerState(codecSelfer_containerMapKey1234) + r.EncodeString(codecSelferC_UTF81234, string("preferAvoidPods")) + z.EncSendContainerState(codecSelfer_containerMapValue1234) + if x.PreferAvoidPods == nil { + r.EncodeNil() + } else { + yym5 := z.EncBinary() + _ = yym5 + if false { + } else { + h.encSlicePreferAvoidPodsEntry(([]PreferAvoidPodsEntry)(x.PreferAvoidPods), e) + } + } + } + } + if yyr2 || yy2arr2 { + z.EncSendContainerState(codecSelfer_containerArrayEnd1234) + } else { + z.EncSendContainerState(codecSelfer_containerMapEnd1234) + } + } + } +} + +func (x *AvoidPods) CodecDecodeSelf(d *codec1978.Decoder) { + var h codecSelfer1234 + z, r := codec1978.GenHelperDecoder(d) + _, _, _ = h, z, r + yym1 := z.DecBinary() + _ = yym1 + if false { + } else if z.HasExtensions() && z.DecExt(x) { + } else { + yyct2 := r.ContainerType() + if yyct2 == codecSelferValueTypeMap1234 { + yyl2 := r.ReadMapStart() + if yyl2 == 0 { + z.DecSendContainerState(codecSelfer_containerMapEnd1234) + } else { + x.codecDecodeSelfFromMap(yyl2, d) + } + } else if yyct2 == codecSelferValueTypeArray1234 { + yyl2 := r.ReadArrayStart() + if yyl2 == 0 { + z.DecSendContainerState(codecSelfer_containerArrayEnd1234) + } else { + x.codecDecodeSelfFromArray(yyl2, d) + } + } else { + panic(codecSelferOnlyMapOrArrayEncodeToStructErr1234) + } + } +} + +func (x *AvoidPods) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) { + var h codecSelfer1234 + z, r := codec1978.GenHelperDecoder(d) + _, _, _ = h, z, r + var yys3Slc = z.DecScratchBuffer() // default slice to decode into + _ = yys3Slc + var yyhl3 bool = l >= 0 + for yyj3 := 0; ; yyj3++ { + if yyhl3 { + if yyj3 >= l { + break + } + } else { + if r.CheckBreak() { + break + } + } + z.DecSendContainerState(codecSelfer_containerMapKey1234) + yys3Slc = r.DecodeBytes(yys3Slc, true, true) + yys3 := string(yys3Slc) + z.DecSendContainerState(codecSelfer_containerMapValue1234) + switch yys3 { + case "preferAvoidPods": + if r.TryDecodeAsNil() { + x.PreferAvoidPods = nil + } else { + yyv4 := &x.PreferAvoidPods + yym5 := z.DecBinary() + _ = yym5 + if false { + } else { + h.decSlicePreferAvoidPodsEntry((*[]PreferAvoidPodsEntry)(yyv4), d) + } + } + default: + z.DecStructFieldNotFound(-1, yys3) + } // end switch yys3 + } // end for yyj3 + z.DecSendContainerState(codecSelfer_containerMapEnd1234) +} + +func (x *AvoidPods) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) { + var h codecSelfer1234 + z, r := codec1978.GenHelperDecoder(d) + _, _, _ = h, z, r + var yyj6 int + var yyb6 bool + var yyhl6 bool = l >= 0 + yyj6++ + if yyhl6 { + yyb6 = yyj6 > l + } else { + yyb6 = r.CheckBreak() + } + if yyb6 { + z.DecSendContainerState(codecSelfer_containerArrayEnd1234) + return + } + z.DecSendContainerState(codecSelfer_containerArrayElem1234) + if r.TryDecodeAsNil() { + x.PreferAvoidPods = nil + } else { + yyv7 := &x.PreferAvoidPods + yym8 := z.DecBinary() + _ = yym8 + if false { + } else { + h.decSlicePreferAvoidPodsEntry((*[]PreferAvoidPodsEntry)(yyv7), d) + } + } + for { + yyj6++ + if yyhl6 { + yyb6 = yyj6 > l + } else { + yyb6 = r.CheckBreak() + } + if yyb6 { + break + } + z.DecSendContainerState(codecSelfer_containerArrayElem1234) + z.DecStructFieldNotFound(yyj6-1, "") + } + z.DecSendContainerState(codecSelfer_containerArrayEnd1234) +} + +func (x *PreferAvoidPodsEntry) CodecEncodeSelf(e *codec1978.Encoder) { + var h codecSelfer1234 + z, r := codec1978.GenHelperEncoder(e) + _, _, _ = h, z, r + if x == nil { + r.EncodeNil() + } else { + yym1 := z.EncBinary() + _ = yym1 + if false { + } else if z.HasExtensions() && z.EncExt(x) { + } else { + yysep2 := !z.EncBinary() + yy2arr2 := z.EncBasicHandle().StructToArray + var yyq2 [4]bool + _, _, _ = yysep2, yyq2, yy2arr2 + const yyr2 bool = false + yyq2[1] = true + yyq2[2] = x.Reason != "" + yyq2[3] = x.Message != "" + var yynn2 int + if yyr2 || yy2arr2 { + r.EncodeArrayStart(4) + } else { + yynn2 = 1 + for _, b := range yyq2 { + if b { + yynn2++ + } + } + r.EncodeMapStart(yynn2) + yynn2 = 0 + } + if yyr2 || yy2arr2 { + z.EncSendContainerState(codecSelfer_containerArrayElem1234) + yy4 := &x.PodSignature + yy4.CodecEncodeSelf(e) + } else { + z.EncSendContainerState(codecSelfer_containerMapKey1234) + r.EncodeString(codecSelferC_UTF81234, string("podSignature")) + z.EncSendContainerState(codecSelfer_containerMapValue1234) + yy6 := &x.PodSignature + yy6.CodecEncodeSelf(e) + } + if yyr2 || yy2arr2 { + z.EncSendContainerState(codecSelfer_containerArrayElem1234) + if yyq2[1] { + yy9 := &x.EvictionTime + yym10 := z.EncBinary() + _ = yym10 + if false { + } else if z.HasExtensions() && z.EncExt(yy9) { + } else if yym10 { + z.EncBinaryMarshal(yy9) + } else if !yym10 && z.IsJSONHandle() { + z.EncJSONMarshal(yy9) + } else { + z.EncFallback(yy9) + } + } else { + r.EncodeNil() + } + } else { + if yyq2[1] { + z.EncSendContainerState(codecSelfer_containerMapKey1234) + r.EncodeString(codecSelferC_UTF81234, string("evictionTime")) + z.EncSendContainerState(codecSelfer_containerMapValue1234) + yy11 := &x.EvictionTime + yym12 := z.EncBinary() + _ = yym12 + if false { + } else if z.HasExtensions() && z.EncExt(yy11) { + } else if yym12 { + z.EncBinaryMarshal(yy11) + } else if !yym12 && z.IsJSONHandle() { + z.EncJSONMarshal(yy11) + } else { + z.EncFallback(yy11) + } + } + } + if yyr2 || yy2arr2 { + z.EncSendContainerState(codecSelfer_containerArrayElem1234) + if yyq2[2] { + yym14 := z.EncBinary() + _ = yym14 + if false { + } else { + r.EncodeString(codecSelferC_UTF81234, string(x.Reason)) + } + } else { + r.EncodeString(codecSelferC_UTF81234, "") + } + } else { + if yyq2[2] { + z.EncSendContainerState(codecSelfer_containerMapKey1234) + r.EncodeString(codecSelferC_UTF81234, string("reason")) + z.EncSendContainerState(codecSelfer_containerMapValue1234) + yym15 := z.EncBinary() + _ = yym15 + if false { + } else { + r.EncodeString(codecSelferC_UTF81234, string(x.Reason)) + } + } + } + if yyr2 || yy2arr2 { + z.EncSendContainerState(codecSelfer_containerArrayElem1234) + if yyq2[3] { + yym17 := z.EncBinary() + _ = yym17 + if false { + } else { + r.EncodeString(codecSelferC_UTF81234, string(x.Message)) + } + } else { + r.EncodeString(codecSelferC_UTF81234, "") + } + } else { + if yyq2[3] { + z.EncSendContainerState(codecSelfer_containerMapKey1234) + r.EncodeString(codecSelferC_UTF81234, string("message")) + z.EncSendContainerState(codecSelfer_containerMapValue1234) + yym18 := z.EncBinary() + _ = yym18 + if false { + } else { + r.EncodeString(codecSelferC_UTF81234, string(x.Message)) + } + } + } + if yyr2 || yy2arr2 { + z.EncSendContainerState(codecSelfer_containerArrayEnd1234) + } else { + z.EncSendContainerState(codecSelfer_containerMapEnd1234) + } + } + } +} + +func (x *PreferAvoidPodsEntry) CodecDecodeSelf(d *codec1978.Decoder) { + var h codecSelfer1234 + z, r := codec1978.GenHelperDecoder(d) + _, _, _ = h, z, r + yym1 := z.DecBinary() + _ = yym1 + if false { + } else if z.HasExtensions() && z.DecExt(x) { + } else { + yyct2 := r.ContainerType() + if yyct2 == codecSelferValueTypeMap1234 { + yyl2 := r.ReadMapStart() + if yyl2 == 0 { + z.DecSendContainerState(codecSelfer_containerMapEnd1234) + } else { + x.codecDecodeSelfFromMap(yyl2, d) + } + } else if yyct2 == codecSelferValueTypeArray1234 { + yyl2 := r.ReadArrayStart() + if yyl2 == 0 { + z.DecSendContainerState(codecSelfer_containerArrayEnd1234) + } else { + x.codecDecodeSelfFromArray(yyl2, d) + } + } else { + panic(codecSelferOnlyMapOrArrayEncodeToStructErr1234) + } + } +} + +func (x *PreferAvoidPodsEntry) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) { + var h codecSelfer1234 + z, r := codec1978.GenHelperDecoder(d) + _, _, _ = h, z, r + var yys3Slc = z.DecScratchBuffer() // default slice to decode into + _ = yys3Slc + var yyhl3 bool = l >= 0 + for yyj3 := 0; ; yyj3++ { + if yyhl3 { + if yyj3 >= l { + break + } + } else { + if r.CheckBreak() { + break + } + } + z.DecSendContainerState(codecSelfer_containerMapKey1234) + yys3Slc = r.DecodeBytes(yys3Slc, true, true) + yys3 := string(yys3Slc) + z.DecSendContainerState(codecSelfer_containerMapValue1234) + switch yys3 { + case "podSignature": + if r.TryDecodeAsNil() { + x.PodSignature = PodSignature{} + } else { + yyv4 := &x.PodSignature + yyv4.CodecDecodeSelf(d) + } + case "evictionTime": + if r.TryDecodeAsNil() { + x.EvictionTime = pkg2_unversioned.Time{} + } else { + yyv5 := &x.EvictionTime + yym6 := z.DecBinary() + _ = yym6 + if false { + } else if z.HasExtensions() && z.DecExt(yyv5) { + } else if yym6 { + z.DecBinaryUnmarshal(yyv5) + } else if !yym6 && z.IsJSONHandle() { + z.DecJSONUnmarshal(yyv5) + } else { + z.DecFallback(yyv5, false) + } + } + case "reason": + if r.TryDecodeAsNil() { + x.Reason = "" + } else { + x.Reason = string(r.DecodeString()) + } + case "message": + if r.TryDecodeAsNil() { + x.Message = "" + } else { + x.Message = string(r.DecodeString()) + } + default: + z.DecStructFieldNotFound(-1, yys3) + } // end switch yys3 + } // end for yyj3 + z.DecSendContainerState(codecSelfer_containerMapEnd1234) +} + +func (x *PreferAvoidPodsEntry) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) { + var h codecSelfer1234 + z, r := codec1978.GenHelperDecoder(d) + _, _, _ = h, z, r + var yyj9 int + var yyb9 bool + var yyhl9 bool = l >= 0 + yyj9++ + if yyhl9 { + yyb9 = yyj9 > l + } else { + yyb9 = r.CheckBreak() + } + if yyb9 { + z.DecSendContainerState(codecSelfer_containerArrayEnd1234) + return + } + z.DecSendContainerState(codecSelfer_containerArrayElem1234) + if r.TryDecodeAsNil() { + x.PodSignature = PodSignature{} + } else { + yyv10 := &x.PodSignature + yyv10.CodecDecodeSelf(d) + } + yyj9++ + if yyhl9 { + yyb9 = yyj9 > l + } else { + yyb9 = r.CheckBreak() + } + if yyb9 { + z.DecSendContainerState(codecSelfer_containerArrayEnd1234) + return + } + z.DecSendContainerState(codecSelfer_containerArrayElem1234) + if r.TryDecodeAsNil() { + x.EvictionTime = pkg2_unversioned.Time{} + } else { + yyv11 := &x.EvictionTime + yym12 := z.DecBinary() + _ = yym12 + if false { + } else if z.HasExtensions() && z.DecExt(yyv11) { + } else if yym12 { + z.DecBinaryUnmarshal(yyv11) + } else if !yym12 && z.IsJSONHandle() { + z.DecJSONUnmarshal(yyv11) + } else { + z.DecFallback(yyv11, false) + } + } + yyj9++ + if yyhl9 { + yyb9 = yyj9 > l + } else { + yyb9 = r.CheckBreak() + } + if yyb9 { + z.DecSendContainerState(codecSelfer_containerArrayEnd1234) + return + } + z.DecSendContainerState(codecSelfer_containerArrayElem1234) + if r.TryDecodeAsNil() { + x.Reason = "" + } else { + x.Reason = string(r.DecodeString()) + } + yyj9++ + if yyhl9 { + yyb9 = yyj9 > l + } else { + yyb9 = r.CheckBreak() + } + if yyb9 { + z.DecSendContainerState(codecSelfer_containerArrayEnd1234) + return + } + z.DecSendContainerState(codecSelfer_containerArrayElem1234) + if r.TryDecodeAsNil() { + x.Message = "" + } else { + x.Message = string(r.DecodeString()) + } + for { + yyj9++ + if yyhl9 { + yyb9 = yyj9 > l + } else { + yyb9 = r.CheckBreak() + } + if yyb9 { + break + } + z.DecSendContainerState(codecSelfer_containerArrayElem1234) + z.DecStructFieldNotFound(yyj9-1, "") + } + z.DecSendContainerState(codecSelfer_containerArrayEnd1234) +} + +func (x *PodSignature) CodecEncodeSelf(e *codec1978.Encoder) { + var h codecSelfer1234 + z, r := codec1978.GenHelperEncoder(e) + _, _, _ = h, z, r + if x == nil { + r.EncodeNil() + } else { + yym1 := z.EncBinary() + _ = yym1 + if false { + } else if z.HasExtensions() && z.EncExt(x) { + } else { + yysep2 := !z.EncBinary() + yy2arr2 := z.EncBasicHandle().StructToArray + var yyq2 [1]bool + _, _, _ = yysep2, yyq2, yy2arr2 + const yyr2 bool = false + yyq2[0] = x.PodController != nil + var yynn2 int + if yyr2 || yy2arr2 { + r.EncodeArrayStart(1) + } else { + yynn2 = 0 + for _, b := range yyq2 { + if b { + yynn2++ + } + } + r.EncodeMapStart(yynn2) + yynn2 = 0 + } + if yyr2 || yy2arr2 { + z.EncSendContainerState(codecSelfer_containerArrayElem1234) + if yyq2[0] { + if x.PodController == nil { + r.EncodeNil() + } else { + x.PodController.CodecEncodeSelf(e) + } + } else { + r.EncodeNil() + } + } else { + if yyq2[0] { + z.EncSendContainerState(codecSelfer_containerMapKey1234) + r.EncodeString(codecSelferC_UTF81234, string("podController")) + z.EncSendContainerState(codecSelfer_containerMapValue1234) + if x.PodController == nil { + r.EncodeNil() + } else { + x.PodController.CodecEncodeSelf(e) + } + } + } + if yyr2 || yy2arr2 { + z.EncSendContainerState(codecSelfer_containerArrayEnd1234) + } else { + z.EncSendContainerState(codecSelfer_containerMapEnd1234) + } + } + } +} + +func (x *PodSignature) CodecDecodeSelf(d *codec1978.Decoder) { + var h codecSelfer1234 + z, r := codec1978.GenHelperDecoder(d) + _, _, _ = h, z, r + yym1 := z.DecBinary() + _ = yym1 + if false { + } else if z.HasExtensions() && z.DecExt(x) { + } else { + yyct2 := r.ContainerType() + if yyct2 == codecSelferValueTypeMap1234 { + yyl2 := r.ReadMapStart() + if yyl2 == 0 { + z.DecSendContainerState(codecSelfer_containerMapEnd1234) + } else { + x.codecDecodeSelfFromMap(yyl2, d) + } + } else if yyct2 == codecSelferValueTypeArray1234 { + yyl2 := r.ReadArrayStart() + if yyl2 == 0 { + z.DecSendContainerState(codecSelfer_containerArrayEnd1234) + } else { + x.codecDecodeSelfFromArray(yyl2, d) + } + } else { + panic(codecSelferOnlyMapOrArrayEncodeToStructErr1234) + } + } +} + +func (x *PodSignature) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) { + var h codecSelfer1234 + z, r := codec1978.GenHelperDecoder(d) + _, _, _ = h, z, r + var yys3Slc = z.DecScratchBuffer() // default slice to decode into + _ = yys3Slc + var yyhl3 bool = l >= 0 + for yyj3 := 0; ; yyj3++ { + if yyhl3 { + if yyj3 >= l { + break + } + } else { + if r.CheckBreak() { + break + } + } + z.DecSendContainerState(codecSelfer_containerMapKey1234) + yys3Slc = r.DecodeBytes(yys3Slc, true, true) + yys3 := string(yys3Slc) + z.DecSendContainerState(codecSelfer_containerMapValue1234) + switch yys3 { + case "podController": + if r.TryDecodeAsNil() { + if x.PodController != nil { + x.PodController = nil + } + } else { + if x.PodController == nil { + x.PodController = new(OwnerReference) + } + x.PodController.CodecDecodeSelf(d) + } + default: + z.DecStructFieldNotFound(-1, yys3) + } // end switch yys3 + } // end for yyj3 + z.DecSendContainerState(codecSelfer_containerMapEnd1234) +} + +func (x *PodSignature) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) { + var h codecSelfer1234 + z, r := codec1978.GenHelperDecoder(d) + _, _, _ = h, z, r + var yyj5 int + var yyb5 bool + var yyhl5 bool = l >= 0 + yyj5++ + if yyhl5 { + yyb5 = yyj5 > l + } else { + yyb5 = r.CheckBreak() + } + if yyb5 { + z.DecSendContainerState(codecSelfer_containerArrayEnd1234) + return + } + z.DecSendContainerState(codecSelfer_containerArrayElem1234) + if r.TryDecodeAsNil() { + if x.PodController != nil { + x.PodController = nil + } + } else { + if x.PodController == nil { + x.PodController = new(OwnerReference) + } + x.PodController.CodecDecodeSelf(d) + } + for { + yyj5++ + if yyhl5 { + yyb5 = yyj5 > l + } else { + yyb5 = r.CheckBreak() + } + if yyb5 { + break + } + z.DecSendContainerState(codecSelfer_containerArrayElem1234) + z.DecStructFieldNotFound(yyj5-1, "") + } + z.DecSendContainerState(codecSelfer_containerArrayEnd1234) +} + func (x *ContainerImage) CodecEncodeSelf(e *codec1978.Encoder) { var h codecSelfer1234 z, r := codec1978.GenHelperEncoder(e) @@ -57978,6 +58678,125 @@ func (x codecSelfer1234) decSliceAttachedVolume(v *[]AttachedVolume, d *codec197 } } +func (x codecSelfer1234) encSlicePreferAvoidPodsEntry(v []PreferAvoidPodsEntry, e *codec1978.Encoder) { + var h codecSelfer1234 + z, r := codec1978.GenHelperEncoder(e) + _, _, _ = h, z, r + r.EncodeArrayStart(len(v)) + for _, yyv1 := range v { + z.EncSendContainerState(codecSelfer_containerArrayElem1234) + yy2 := &yyv1 + yy2.CodecEncodeSelf(e) + } + z.EncSendContainerState(codecSelfer_containerArrayEnd1234) +} + +func (x codecSelfer1234) decSlicePreferAvoidPodsEntry(v *[]PreferAvoidPodsEntry, d *codec1978.Decoder) { + var h codecSelfer1234 + z, r := codec1978.GenHelperDecoder(d) + _, _, _ = h, z, r + + yyv1 := *v + yyh1, yyl1 := z.DecSliceHelperStart() + var yyc1 bool + _ = yyc1 + if yyl1 == 0 { + if yyv1 == nil { + yyv1 = []PreferAvoidPodsEntry{} + yyc1 = true + } else if len(yyv1) != 0 { + yyv1 = yyv1[:0] + yyc1 = true + } + } else if yyl1 > 0 { + var yyrr1, yyrl1 int + var yyrt1 bool + _, _ = yyrl1, yyrt1 + yyrr1 = yyl1 // len(yyv1) + if yyl1 > cap(yyv1) { + + yyrg1 := len(yyv1) > 0 + yyv21 := yyv1 + yyrl1, yyrt1 = z.DecInferLen(yyl1, z.DecBasicHandle().MaxInitLen, 64) + if yyrt1 { + if yyrl1 <= cap(yyv1) { + yyv1 = yyv1[:yyrl1] + } else { + yyv1 = make([]PreferAvoidPodsEntry, yyrl1) + } + } else { + yyv1 = make([]PreferAvoidPodsEntry, yyrl1) + } + yyc1 = true + yyrr1 = len(yyv1) + if yyrg1 { + copy(yyv1, yyv21) + } + } else if yyl1 != len(yyv1) { + yyv1 = yyv1[:yyl1] + yyc1 = true + } + yyj1 := 0 + for ; yyj1 < yyrr1; yyj1++ { + yyh1.ElemContainerState(yyj1) + if r.TryDecodeAsNil() { + yyv1[yyj1] = PreferAvoidPodsEntry{} + } else { + yyv2 := &yyv1[yyj1] + yyv2.CodecDecodeSelf(d) + } + + } + if yyrt1 { + for ; yyj1 < yyl1; yyj1++ { + yyv1 = append(yyv1, PreferAvoidPodsEntry{}) + yyh1.ElemContainerState(yyj1) + if r.TryDecodeAsNil() { + yyv1[yyj1] = PreferAvoidPodsEntry{} + } else { + yyv3 := &yyv1[yyj1] + yyv3.CodecDecodeSelf(d) + } + + } + } + + } else { + yyj1 := 0 + for ; !r.CheckBreak(); yyj1++ { + + if yyj1 >= len(yyv1) { + yyv1 = append(yyv1, PreferAvoidPodsEntry{}) // var yyz1 PreferAvoidPodsEntry + yyc1 = true + } + yyh1.ElemContainerState(yyj1) + if yyj1 < len(yyv1) { + if r.TryDecodeAsNil() { + yyv1[yyj1] = PreferAvoidPodsEntry{} + } else { + yyv4 := &yyv1[yyj1] + yyv4.CodecDecodeSelf(d) + } + + } else { + z.DecSwallow() + } + + } + if yyj1 < len(yyv1) { + yyv1 = yyv1[:yyj1] + yyc1 = true + } else if yyj1 == 0 && yyv1 == nil { + yyv1 = []PreferAvoidPodsEntry{} + yyc1 = true + } + } + yyh1.End() + if yyc1 { + *v = yyv1 + } +} + func (x codecSelfer1234) encResourceList(v ResourceList, e *codec1978.Encoder) { var h codecSelfer1234 z, r := codec1978.GenHelperEncoder(e) diff --git a/pkg/api/v1/types.go b/pkg/api/v1/types.go index 42a0b987925..bb8e078a809 100644 --- a/pkg/api/v1/types.go +++ b/pkg/api/v1/types.go @@ -2408,6 +2408,34 @@ type AttachedVolume struct { DevicePath string `json:"devicePath" protobuf:"bytes,2,rep,name=devicePath"` } +// AvoidPods describes pods that should avoid this node. This is the value for a +// Node annotation with key scheduler.alpha.kubernetes.io/preferAvoidPods and +// will eventually become a field of NodeStatus. +type AvoidPods struct { + // Bounded-sized list of signatures of pods that should avoid this node, sorted + // in timestamp order from oldest to newest. Size of the slice is unspecified. + PreferAvoidPods []PreferAvoidPodsEntry `json:"preferAvoidPods,omitempty" protobuf:"bytes,1,rep,name=preferAvoidPods"` +} + +// Describes a class of pods that should avoid this node. +type PreferAvoidPodsEntry struct { + // The class of pods. + PodSignature PodSignature `json:"podSignature" protobuf:"bytes,1,opt,name=podSignature"` + // Time at which this entry was added to the list. + EvictionTime unversioned.Time `json:"evictionTime,omitempty" protobuf:"bytes,2,opt,name=evictionTime"` + // (brief) reason why this entry was added to the list. + Reason string `json:"reason,omitempty" protobuf:"bytes,3,opt,name=reason"` + // Human readable message indicating why this entry was added to the list. + Message string `json:"message,omitempty" protobuf:"bytes,4,opt,name=message"` +} + +// Describes the class of pods that should avoid this node. +// Exactly one field should be set. +type PodSignature struct { + // Reference to controller whose pods should avoid this node. + PodController *OwnerReference `json:"podController,omitempty" protobuf:"bytes,1,opt,name=podController"` +} + // Describe a container image type ContainerImage struct { // Names by which this image is known. diff --git a/pkg/api/v1/types_swagger_doc_generated.go b/pkg/api/v1/types_swagger_doc_generated.go index c5eb00db3fe..21e6b82c743 100644 --- a/pkg/api/v1/types_swagger_doc_generated.go +++ b/pkg/api/v1/types_swagger_doc_generated.go @@ -60,6 +60,15 @@ func (AttachedVolume) SwaggerDoc() map[string]string { return map_AttachedVolume } +var map_AvoidPods = map[string]string{ + "": "AvoidPods describes pods that should avoid this node. This is the value for a Node annotation with key scheduler.alpha.kubernetes.io/preferAvoidPods and will eventually become a field of NodeStatus.", + "preferAvoidPods": "Bounded-sized list of signatures of pods that should avoid this node, sorted in timestamp order from oldest to newest. Size of the slice is unspecified.", +} + +func (AvoidPods) SwaggerDoc() map[string]string { + return map_AvoidPods +} + var map_AzureFileVolumeSource = map[string]string{ "": "AzureFile represents an Azure File Service mount on the host and bind mount to the pod.", "secretName": "the name of secret that contains Azure Storage Account Name and Key", @@ -1227,6 +1236,15 @@ func (PodSecurityContext) SwaggerDoc() map[string]string { return map_PodSecurityContext } +var map_PodSignature = map[string]string{ + "": "Describes the class of pods that should avoid this node. Exactly one field should be set.", + "podController": "Reference to controller whose pods should avoid this node.", +} + +func (PodSignature) SwaggerDoc() map[string]string { + return map_PodSignature +} + var map_PodSpec = map[string]string{ "": "PodSpec is a description of a pod.", "volumes": "List of volumes that can be mounted by containers belonging to the pod. More info: http://releases.k8s.io/HEAD/docs/user-guide/volumes.md", @@ -1317,6 +1335,18 @@ func (Preconditions) SwaggerDoc() map[string]string { return map_Preconditions } +var map_PreferAvoidPodsEntry = map[string]string{ + "": "Describes a class of pods that should avoid this node.", + "podSignature": "The class of pods.", + "evictionTime": "Time at which this entry was added to the list.", + "reason": "(brief) reason why this entry was added to the list.", + "message": "Human readable message indicating why this entry was added to the list.", +} + +func (PreferAvoidPodsEntry) SwaggerDoc() map[string]string { + return map_PreferAvoidPodsEntry +} + var map_PreferredSchedulingTerm = map[string]string{ "": "An empty preferred scheduling term matches all objects with implicit weight 0 (i.e. it's a no-op). A null preferred scheduling term matches no objects (i.e. is also a no-op).", "weight": "Weight associated with matching the corresponding nodeSelectorTerm, in the range 1-100.", diff --git a/pkg/api/validation/validation.go b/pkg/api/validation/validation.go index 3854004d8f0..c1a3bff1db8 100644 --- a/pkg/api/validation/validation.go +++ b/pkg/api/validation/validation.go @@ -1724,6 +1724,41 @@ func ValidateNodeSelector(nodeSelector *api.NodeSelector, fldPath *field.Path) f return allErrs } +// ValidateAvoidPodsInNodeAnnotations tests that the serialized AvoidPods in Node.Annotations has valid data +func ValidateAvoidPodsInNodeAnnotations(annotations map[string]string, fldPath *field.Path) field.ErrorList { + allErrs := field.ErrorList{} + + avoids, err := api.GetAvoidPodsFromNodeAnnotations(annotations) + if err != nil { + allErrs = append(allErrs, field.Invalid(fldPath.Child("AvoidPods"), api.PreferAvoidPodsAnnotationKey, err.Error())) + return allErrs + } + + if len(avoids.PreferAvoidPods) != 0 { + for i, pa := range avoids.PreferAvoidPods { + idxPath := fldPath.Child(api.PreferAvoidPodsAnnotationKey).Index(i) + allErrs = append(allErrs, validatePreferAvoidPodsEntry(pa, idxPath)...) + } + } + + return allErrs +} + +// validatePreferAvoidPodsEntry tests if given PreferAvoidPodsEntry has valid data. +func validatePreferAvoidPodsEntry(avoidPodEntry api.PreferAvoidPodsEntry, fldPath *field.Path) field.ErrorList { + allErrors := field.ErrorList{} + if avoidPodEntry.PodSignature.PodController == nil { + allErrors = append(allErrors, field.Required(fldPath.Child("PodSignature"), "")) + } else { + if *(avoidPodEntry.PodSignature.PodController.Controller) != true { + allErrors = append(allErrors, + field.Invalid(fldPath.Child("PodSignature").Child("PodController").Child("Controller"), + *(avoidPodEntry.PodSignature.PodController.Controller), "must point to a controller")) + } + } + return allErrors +} + // ValidatePreferredSchedulingTerms tests that the specified SoftNodeAffinity fields has valid data func ValidatePreferredSchedulingTerms(terms []api.PreferredSchedulingTerm, fldPath *field.Path) field.ErrorList { allErrs := field.ErrorList{} @@ -2359,10 +2394,14 @@ func ValidateTaintsInNodeAnnotations(annotations map[string]string, fldPath *fie } func ValidateNodeSpecificAnnotations(annotations map[string]string, fldPath *field.Path) field.ErrorList { - if annotations[api.TaintsAnnotationKey] != "" { - return ValidateTaintsInNodeAnnotations(annotations, fldPath) + allErrs := field.ErrorList{} + if annotations[api.PreferAvoidPodsAnnotationKey] != "" { + allErrs = append(allErrs, ValidateAvoidPodsInNodeAnnotations(annotations, fldPath)...) } - return field.ErrorList{} + if annotations[api.TaintsAnnotationKey] != "" { + allErrs = append(allErrs, ValidateTaintsInNodeAnnotations(annotations, fldPath)...) + } + return allErrs } // ValidateNode tests if required fields in the node are set. diff --git a/pkg/api/validation/validation_test.go b/pkg/api/validation/validation_test.go index 3fe0547367a..53a3ef41c3d 100644 --- a/pkg/api/validation/validation_test.go +++ b/pkg/api/validation/validation_test.go @@ -4375,6 +4375,43 @@ func TestValidateNode(t *testing.T) { ExternalID: "external", }, }, + { + ObjectMeta: api.ObjectMeta{ + Name: "abc", + Annotations: map[string]string{ + api.PreferAvoidPodsAnnotationKey: ` + { + "preferAvoidPods": [ + { + "podSignature": { + "podController": { + "apiVersion": "v1", + "kind": "ReplicationController", + "name": "foo", + "uid": "abcdef123456", + "controller": true + } + }, + "reason": "some reason", + "message": "some message" + } + ] + }`, + }, + }, + Status: api.NodeStatus{ + Addresses: []api.NodeAddress{ + {Type: api.NodeLegacyHostIP, Address: "something"}, + }, + Capacity: api.ResourceList{ + api.ResourceName(api.ResourceCPU): resource.MustParse("10"), + api.ResourceName(api.ResourceMemory): resource.MustParse("0"), + }, + }, + Spec: api.NodeSpec{ + ExternalID: "external", + }, + }, } for _, successCase := range successCases { if errs := ValidateNode(&successCase); len(errs) != 0 { @@ -4539,6 +4576,67 @@ func TestValidateNode(t *testing.T) { ExternalID: "external", }, }, + "missing-podSignature": { + ObjectMeta: api.ObjectMeta{ + Name: "abc-123", + Annotations: map[string]string{ + api.PreferAvoidPodsAnnotationKey: ` + { + "preferAvoidPods": [ + { + "reason": "some reason", + "message": "some message" + } + ] + }`, + }, + }, + Status: api.NodeStatus{ + Addresses: []api.NodeAddress{}, + Capacity: api.ResourceList{ + api.ResourceName(api.ResourceCPU): resource.MustParse("10"), + api.ResourceName(api.ResourceMemory): resource.MustParse("0"), + }, + }, + Spec: api.NodeSpec{ + ExternalID: "external", + }, + }, + "invalid-podController": { + ObjectMeta: api.ObjectMeta{ + Name: "abc-123", + Annotations: map[string]string{ + api.PreferAvoidPodsAnnotationKey: ` + { + "preferAvoidPods": [ + { + "podSignature": { + "podController": { + "apiVersion": "v1", + "kind": "ReplicationController", + "name": "foo", + "uid": "abcdef123456", + "controller": false + } + }, + "reason": "some reason", + "message": "some message" + } + ] + }`, + }, + }, + Status: api.NodeStatus{ + Addresses: []api.NodeAddress{}, + Capacity: api.ResourceList{ + api.ResourceName(api.ResourceCPU): resource.MustParse("10"), + api.ResourceName(api.ResourceMemory): resource.MustParse("0"), + }, + }, + Spec: api.NodeSpec{ + ExternalID: "external", + }, + }, } for k, v := range errorCases { errs := ValidateNode(&v) @@ -4548,14 +4646,16 @@ func TestValidateNode(t *testing.T) { for i := range errs { field := errs[i].Field expectedFields := map[string]bool{ - "metadata.name": true, - "metadata.labels": true, - "metadata.annotations": true, - "metadata.namespace": true, - "spec.externalID": true, - "metadata.annotations.scheduler.alpha.kubernetes.io/taints[0].key": true, - "metadata.annotations.scheduler.alpha.kubernetes.io/taints[0].value": true, - "metadata.annotations.scheduler.alpha.kubernetes.io/taints[0].effect": true, + "metadata.name": true, + "metadata.labels": true, + "metadata.annotations": true, + "metadata.namespace": true, + "spec.externalID": true, + "metadata.annotations.scheduler.alpha.kubernetes.io/taints[0].key": true, + "metadata.annotations.scheduler.alpha.kubernetes.io/taints[0].value": true, + "metadata.annotations.scheduler.alpha.kubernetes.io/taints[0].effect": true, + "metadata.annotations.scheduler.alpha.kubernetes.io/preferAvoidPods[0].PodSignature": true, + "metadata.annotations.scheduler.alpha.kubernetes.io/preferAvoidPods[0].PodSignature.PodController.Controller": true, } if val, ok := expectedFields[field]; ok { if !val { @@ -4764,6 +4864,87 @@ func TestValidateNodeUpdate(t *testing.T) { }, }, }, true}, + {api.Node{ + ObjectMeta: api.ObjectMeta{ + Name: "foo", + }, + }, api.Node{ + ObjectMeta: api.ObjectMeta{ + Name: "foo", + Annotations: map[string]string{ + api.PreferAvoidPodsAnnotationKey: ` + { + "preferAvoidPods": [ + { + "podSignature": { + "podController": { + "apiVersion": "v1", + "kind": "ReplicationController", + "name": "foo", + "uid": "abcdef123456", + "controller": true + } + }, + "reason": "some reason", + "message": "some message" + } + ] + }`, + }, + }, + Spec: api.NodeSpec{ + Unschedulable: false, + }, + }, true}, + {api.Node{ + ObjectMeta: api.ObjectMeta{ + Name: "foo", + }, + }, api.Node{ + ObjectMeta: api.ObjectMeta{ + Name: "foo", + Annotations: map[string]string{ + api.PreferAvoidPodsAnnotationKey: ` + { + "preferAvoidPods": [ + { + "reason": "some reason", + "message": "some message" + } + ] + }`, + }, + }, + }, false}, + {api.Node{ + ObjectMeta: api.ObjectMeta{ + Name: "foo", + }, + }, api.Node{ + ObjectMeta: api.ObjectMeta{ + Name: "foo", + Annotations: map[string]string{ + api.PreferAvoidPodsAnnotationKey: ` + { + "preferAvoidPods": [ + { + "podSignature": { + "podController": { + "apiVersion": "v1", + "kind": "ReplicationController", + "name": "foo", + "uid": "abcdef123456", + "controller": false + } + }, + "reason": "some reason", + "message": "some message" + } + ] + }`, + }, + }, + }, false}, } for i, test := range tests { test.oldNode.ObjectMeta.ResourceVersion = "1" diff --git a/plugin/pkg/scheduler/algorithm/priorities/priorities.go b/plugin/pkg/scheduler/algorithm/priorities/priorities.go index 7c29d2569ab..171350dfc0a 100644 --- a/plugin/pkg/scheduler/algorithm/priorities/priorities.go +++ b/plugin/pkg/scheduler/algorithm/priorities/priorities.go @@ -277,3 +277,79 @@ func fractionOfCapacity(requested, capacity int64) float64 { } return float64(requested) / float64(capacity) } + +type NodePreferAvoidPod struct { + controllerLister algorithm.ControllerLister + replicaSetLister algorithm.ReplicaSetLister +} + +func NewNodePreferAvoidPodsPriority(controllerLister algorithm.ControllerLister, replicaSetLister algorithm.ReplicaSetLister) algorithm.PriorityFunction { + nodePreferAvoid := &NodePreferAvoidPod{ + controllerLister: controllerLister, + replicaSetLister: replicaSetLister, + } + return nodePreferAvoid.CalculateNodePreferAvoidPodsPriority +} + +func (npa *NodePreferAvoidPod) CalculateNodePreferAvoidPodsPriority(pod *api.Pod, nodeNameToInfo map[string]*schedulercache.NodeInfo, nodeLister algorithm.NodeLister) (schedulerapi.HostPriorityList, error) { + var score int + nodes, err := nodeLister.List() + if err != nil { + return nil, err + } + + result := []schedulerapi.HostPriority{} + + // TODO: Once we have ownerReference fully implemented, use it to find controller for the pod. + rcs, err := npa.controllerLister.GetPodControllers(pod) + rss, err := npa.replicaSetLister.GetPodReplicaSets(pod) + if len(rcs) == 0 && len(rss) == 0 { + for _, node := range nodes { + result = append(result, schedulerapi.HostPriority{Host: node.Name, Score: 10}) + } + return result, nil + } + + avoidNodes := map[string]bool{} + for _, node := range nodes { + avoidNodes[node.Name] = false + + avoids, err := api.GetAvoidPodsFromNodeAnnotations(node.Annotations) + if err != nil { + continue + } + + for _, avoid := range avoids.PreferAvoidPods { + for _, rc := range rcs { + if avoid.PodSignature.PodController.Kind == "ReplicationController" && avoid.PodSignature.PodController.UID == rc.UID { + avoidNodes[node.Name] = true + break + } + } + if avoidNodes[node.Name] { + break + } + for _, rs := range rss { + if avoid.PodSignature.PodController.Kind == "ReplicaSet" && avoid.PodSignature.PodController.UID == rs.UID { + avoidNodes[node.Name] = true + break + } + } + if avoidNodes[node.Name] { + break + } + } + } + + //score int - scale of 0-10 + // 0 being the lowest priority and 10 being the highest + for nodeName, shouldAvoid := range avoidNodes { + if shouldAvoid { + score = 0 + } else { + score = 10 + } + result = append(result, schedulerapi.HostPriority{Host: nodeName, Score: score}) + } + return result, nil +} diff --git a/plugin/pkg/scheduler/algorithm/priorities/priorities_test.go b/plugin/pkg/scheduler/algorithm/priorities/priorities_test.go index 474b733de75..5bc0f8d6a3b 100644 --- a/plugin/pkg/scheduler/algorithm/priorities/priorities_test.go +++ b/plugin/pkg/scheduler/algorithm/priorities/priorities_test.go @@ -26,6 +26,7 @@ import ( "k8s.io/kubernetes/cmd/libs/go2idl/types" "k8s.io/kubernetes/pkg/api" "k8s.io/kubernetes/pkg/api/resource" + "k8s.io/kubernetes/pkg/api/unversioned" "k8s.io/kubernetes/pkg/apis/extensions" "k8s.io/kubernetes/pkg/util/codeinspector" "k8s.io/kubernetes/plugin/pkg/scheduler" @@ -930,3 +931,137 @@ func TestPrioritiesRegistered(t *testing.T) { } } } + +func TestNodePreferAvoidPriority(t *testing.T) { + label1 := map[string]string{"foo": "bar"} + label2 := map[string]string{"bar": "foo"} + annotations1 := map[string]string{ + api.PreferAvoidPodsAnnotationKey: ` + { + "preferAvoidPods": [ + { + "podSignature": { + "podController": { + "apiVersion": "v1", + "kind": "ReplicationController", + "name": "foo", + "uid": "abcdef123456", + "controller": true + } + }, + "reason": "some reason", + "message": "some message" + } + ] + }`, + } + annotations2 := map[string]string{ + api.PreferAvoidPodsAnnotationKey: ` + { + "preferAvoidPods": [ + { + "podSignature": { + "podController": { + "apiVersion": "v1", + "kind": "ReplicaSet", + "name": "foo", + "uid": "qwert12345", + "controller": true + } + }, + "reason": "some reason", + "message": "some message" + } + ] + }`, + } + testNodes := []*api.Node{ + { + ObjectMeta: api.ObjectMeta{Name: "machine1", Annotations: annotations1}, + }, + { + ObjectMeta: api.ObjectMeta{Name: "machine2", Annotations: annotations2}, + }, + { + ObjectMeta: api.ObjectMeta{Name: "machine3"}, + }, + } + tests := []struct { + pod *api.Pod + rcs []api.ReplicationController + rss []extensions.ReplicaSet + nodes []*api.Node + expectedList schedulerapi.HostPriorityList + test string + }{ + { + pod: &api.Pod{ObjectMeta: api.ObjectMeta{Namespace: "default", Labels: label1}}, + rcs: []api.ReplicationController{ + { + ObjectMeta: api.ObjectMeta{ + Namespace: "default", + Name: "foo", + UID: "abcdef123456", + }, + Spec: api.ReplicationControllerSpec{Selector: label1}, + }, + }, + nodes: testNodes, + expectedList: []schedulerapi.HostPriority{{"machine1", 0}, {"machine2", 10}, {"machine3", 10}}, + test: "pod managed by ReplicationController should avoid a node, this node get lowest priority score", + }, + { + pod: &api.Pod{ObjectMeta: api.ObjectMeta{Namespace: "default", Labels: label2}}, + rss: []extensions.ReplicaSet{ + { + TypeMeta: unversioned.TypeMeta{ + APIVersion: "v1", + Kind: "ReplicaSet", + }, + ObjectMeta: api.ObjectMeta{ + Namespace: "default", + Name: "bar", + UID: "qwert12345", + }, + Spec: extensions.ReplicaSetSpec{Selector: &unversioned.LabelSelector{MatchLabels: label2}}, + }, + }, + nodes: testNodes, + expectedList: []schedulerapi.HostPriority{{"machine1", 10}, {"machine2", 0}, {"machine3", 10}}, + test: "pod managed by ReplicaSet should avoid a node, this node get lowest priority score", + }, + { + pod: &api.Pod{ObjectMeta: api.ObjectMeta{Namespace: "default"}}, + rcs: []api.ReplicationController{ + { + ObjectMeta: api.ObjectMeta{ + Namespace: "default", + Name: "foo", + UID: "abcdef123456", + }, + Spec: api.ReplicationControllerSpec{Selector: label1}, + }, + }, + nodes: testNodes, + expectedList: []schedulerapi.HostPriority{{"machine1", 10}, {"machine2", 10}, {"machine3", 10}}, + test: "pod should not avoid these nodes, all nodes get highest priority score", + }, + } + + for _, test := range tests { + prioritizer := NodePreferAvoidPod{ + controllerLister: algorithm.FakeControllerLister(test.rcs), + replicaSetLister: algorithm.FakeReplicaSetLister(test.rss), + } + list, err := prioritizer.CalculateNodePreferAvoidPodsPriority(test.pod, map[string]*schedulercache.NodeInfo{}, algorithm.FakeNodeLister(test.nodes)) + if err != nil { + t.Errorf("unexpected error: %v", err) + } + // sort the two lists to avoid failures on account of different ordering + sort.Sort(test.expectedList) + sort.Sort(list) + if !reflect.DeepEqual(test.expectedList, list) { + t.Errorf("%s: expected %#v, got %#v", test.test, test.expectedList, list) + } + } +} diff --git a/plugin/pkg/scheduler/algorithmprovider/defaults/defaults.go b/plugin/pkg/scheduler/algorithmprovider/defaults/defaults.go index dbedff3f5d2..151adf070ff 100644 --- a/plugin/pkg/scheduler/algorithmprovider/defaults/defaults.go +++ b/plugin/pkg/scheduler/algorithmprovider/defaults/defaults.go @@ -170,6 +170,17 @@ func defaultPriorities() sets.String { Weight: 1, }, ), + factory.RegisterPriorityConfigFactory( + "NodePreferAvoidPodsPriority", + factory.PriorityConfigFactory{ + Function: func(args factory.PluginFactoryArgs) algorithm.PriorityFunction { + return priorities.NewNodePreferAvoidPodsPriority(args.ControllerLister, args.ReplicaSetLister) + }, + // Set this weight large enough to override all other priority functions. + // TODO: Figure out a better way to do this, maybe at same time as fixing #24720. + Weight: 10000, + }, + ), factory.RegisterPriorityFunction("NodeAffinityPriority", priorities.CalculateNodeAffinityPriority, 1), factory.RegisterPriorityFunction("TaintTolerationPriority", priorities.ComputeTaintTolerationPriority, 1), )