diff --git a/pkg/api/types.generated.go b/pkg/api/types.generated.go deleted file mode 100644 index ba0b0a5cb8..0000000000 --- a/pkg/api/types.generated.go +++ /dev/null @@ -1,1325 +0,0 @@ -/* -Copyright 2017 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by codecgen - DO NOT EDIT. - -package api - -import ( - "errors" - "fmt" - codec1978 "github.com/ugorji/go/codec" - pkg2_v1 "k8s.io/api/core/v1" - pkg1_v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "reflect" - "runtime" -) - -const ( - // ----- content types ---- - codecSelferCcUTF81234 = 1 - codecSelferCcRAW1234 = 0 - // ----- value types used ---- - codecSelferValueTypeArray1234 = 10 - codecSelferValueTypeMap1234 = 9 - codecSelferValueTypeString1234 = 6 - codecSelferValueTypeInt1234 = 2 - codecSelferValueTypeUint1234 = 3 - codecSelferValueTypeFloat1234 = 4 -) - -var ( - codecSelferBitsize1234 = uint8(reflect.TypeOf(uint(0)).Bits()) - errCodecSelferOnlyMapOrArrayEncodeToStruct1234 = errors.New(`only encoded map or array can be decoded into a struct`) -) - -type codecSelfer1234 struct{} - -func init() { - if codec1978.GenVersion != 8 { - _, file, _, _ := runtime.Caller(0) - err := fmt.Errorf("codecgen version mismatch: current: %v, need %v. Re-generate file: %v", - 8, codec1978.GenVersion, file) - panic(err) - } - if false { // reference the types, but skip this branch at build/run time - var v0 pkg2_v1.ResourceName - var v1 pkg1_v1.TypeMeta - _, _ = v0, v1 - } -} - -func (x *DeschedulerPolicy) 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 yyxt1 := z.Extension(z.I2Rtid(x)); yyxt1 != nil { - z.EncExtension(x, yyxt1) - } else { - yysep2 := !z.EncBinary() - yy2arr2 := z.EncBasicHandle().StructToArray - var yyq2 [3]bool - _ = yyq2 - _, _ = yysep2, yy2arr2 - const yyr2 bool = false - yyq2[0] = x.Kind != "" - yyq2[1] = x.APIVersion != "" - if yyr2 || yy2arr2 { - r.WriteArrayStart(3) - } else { - var yynn2 = 1 - for _, b := range yyq2 { - if b { - yynn2++ - } - } - r.WriteMapStart(yynn2) - yynn2 = 0 - } - if yyr2 || yy2arr2 { - r.WriteArrayElem() - if yyq2[0] { - yym4 := z.EncBinary() - _ = yym4 - if false { - } else { - r.EncodeString(codecSelferCcUTF81234, string(x.Kind)) - } - } else { - r.EncodeString(codecSelferCcUTF81234, "") - } - } else { - if yyq2[0] { - r.WriteMapElemKey() - r.EncStructFieldKey(codecSelferValueTypeString1234, `kind`) - r.WriteMapElemValue() - yym5 := z.EncBinary() - _ = yym5 - if false { - } else { - r.EncodeString(codecSelferCcUTF81234, string(x.Kind)) - } - } - } - if yyr2 || yy2arr2 { - r.WriteArrayElem() - if yyq2[1] { - yym7 := z.EncBinary() - _ = yym7 - if false { - } else { - r.EncodeString(codecSelferCcUTF81234, string(x.APIVersion)) - } - } else { - r.EncodeString(codecSelferCcUTF81234, "") - } - } else { - if yyq2[1] { - r.WriteMapElemKey() - r.EncStructFieldKey(codecSelferValueTypeString1234, `apiVersion`) - r.WriteMapElemValue() - yym8 := z.EncBinary() - _ = yym8 - if false { - } else { - r.EncodeString(codecSelferCcUTF81234, string(x.APIVersion)) - } - } - } - if yyr2 || yy2arr2 { - r.WriteArrayElem() - if x.Strategies == nil { - r.EncodeNil() - } else { - x.Strategies.CodecEncodeSelf(e) - } - } else { - r.WriteMapElemKey() - r.EncStructFieldKey(codecSelferValueTypeString1234, `Strategies`) - r.WriteMapElemValue() - if x.Strategies == nil { - r.EncodeNil() - } else { - x.Strategies.CodecEncodeSelf(e) - } - } - if yyr2 || yy2arr2 { - r.WriteArrayEnd() - } else { - r.WriteMapEnd() - } - } - } -} - -func (x *DeschedulerPolicy) CodecDecodeSelf(d *codec1978.Decoder) { - var h codecSelfer1234 - z, r := codec1978.GenHelperDecoder(d) - _, _, _ = h, z, r - yym1 := z.DecBinary() - _ = yym1 - if false { - } else if yyxt1 := z.Extension(z.I2Rtid(x)); yyxt1 != nil { - z.DecExtension(x, yyxt1) - } else { - yyct2 := r.ContainerType() - if yyct2 == codecSelferValueTypeMap1234 { - yyl2 := r.ReadMapStart() - if yyl2 == 0 { - r.ReadMapEnd() - } else { - x.codecDecodeSelfFromMap(yyl2, d) - } - } else if yyct2 == codecSelferValueTypeArray1234 { - yyl2 := r.ReadArrayStart() - if yyl2 == 0 { - r.ReadArrayEnd() - } else { - x.codecDecodeSelfFromArray(yyl2, d) - } - } else { - panic(errCodecSelferOnlyMapOrArrayEncodeToStruct1234) - } - } -} - -func (x *DeschedulerPolicy) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) { - var h codecSelfer1234 - z, r := codec1978.GenHelperDecoder(d) - _, _, _ = h, z, r - var yyhl3 bool = l >= 0 - for yyj3 := 0; ; yyj3++ { - if yyhl3 { - if yyj3 >= l { - break - } - } else { - if r.CheckBreak() { - break - } - } - r.ReadMapElemKey() - yys3 := z.StringView(r.DecStructFieldKey(codecSelferValueTypeString1234, z.DecScratchArrayBuffer())) - r.ReadMapElemValue() - switch yys3 { - case "kind": - if r.TryDecodeAsNil() { - x.Kind = "" - } else { - yyv4 := &x.Kind - yym5 := z.DecBinary() - _ = yym5 - if false { - } else { - *((*string)(yyv4)) = r.DecodeString() - } - } - case "apiVersion": - if r.TryDecodeAsNil() { - x.APIVersion = "" - } else { - yyv6 := &x.APIVersion - yym7 := z.DecBinary() - _ = yym7 - if false { - } else { - *((*string)(yyv6)) = r.DecodeString() - } - } - case "Strategies": - if r.TryDecodeAsNil() { - x.Strategies = nil - } else { - yyv8 := &x.Strategies - yyv8.CodecDecodeSelf(d) - } - default: - z.DecStructFieldNotFound(-1, yys3) - } // end switch yys3 - } // end for yyj3 - r.ReadMapEnd() -} - -func (x *DeschedulerPolicy) 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 { - r.ReadArrayEnd() - return - } - r.ReadArrayElem() - if r.TryDecodeAsNil() { - x.Kind = "" - } else { - yyv10 := &x.Kind - yym11 := z.DecBinary() - _ = yym11 - if false { - } else { - *((*string)(yyv10)) = r.DecodeString() - } - } - yyj9++ - if yyhl9 { - yyb9 = yyj9 > l - } else { - yyb9 = r.CheckBreak() - } - if yyb9 { - r.ReadArrayEnd() - return - } - r.ReadArrayElem() - if r.TryDecodeAsNil() { - x.APIVersion = "" - } else { - yyv12 := &x.APIVersion - yym13 := z.DecBinary() - _ = yym13 - if false { - } else { - *((*string)(yyv12)) = r.DecodeString() - } - } - yyj9++ - if yyhl9 { - yyb9 = yyj9 > l - } else { - yyb9 = r.CheckBreak() - } - if yyb9 { - r.ReadArrayEnd() - return - } - r.ReadArrayElem() - if r.TryDecodeAsNil() { - x.Strategies = nil - } else { - yyv14 := &x.Strategies - yyv14.CodecDecodeSelf(d) - } - for { - yyj9++ - if yyhl9 { - yyb9 = yyj9 > l - } else { - yyb9 = r.CheckBreak() - } - if yyb9 { - break - } - r.ReadArrayElem() - z.DecStructFieldNotFound(yyj9-1, "") - } - r.ReadArrayEnd() -} - -func (x StrategyName) CodecEncodeSelf(e *codec1978.Encoder) { - var h codecSelfer1234 - z, r := codec1978.GenHelperEncoder(e) - _, _, _ = h, z, r - yym1 := z.EncBinary() - _ = yym1 - if false { - } else if yyxt1 := z.Extension(z.I2Rtid(x)); yyxt1 != nil { - z.EncExtension(x, yyxt1) - } else { - r.EncodeString(codecSelferCcUTF81234, string(x)) - } -} - -func (x *StrategyName) CodecDecodeSelf(d *codec1978.Decoder) { - var h codecSelfer1234 - z, r := codec1978.GenHelperDecoder(d) - _, _, _ = h, z, r - yym1 := z.DecBinary() - _ = yym1 - if false { - } else if yyxt1 := z.Extension(z.I2Rtid(x)); yyxt1 != nil { - z.DecExtension(x, yyxt1) - } else { - *((*string)(x)) = r.DecodeString() - } -} - -func (x StrategyList) 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 yyxt1 := z.Extension(z.I2Rtid(x)); yyxt1 != nil { - z.EncExtension(x, yyxt1) - } else { - h.encStrategyList((StrategyList)(x), e) - } - } -} - -func (x *StrategyList) CodecDecodeSelf(d *codec1978.Decoder) { - var h codecSelfer1234 - z, r := codec1978.GenHelperDecoder(d) - _, _, _ = h, z, r - yym1 := z.DecBinary() - _ = yym1 - if false { - } else if yyxt1 := z.Extension(z.I2Rtid(x)); yyxt1 != nil { - z.DecExtension(x, yyxt1) - } else { - h.decStrategyList((*StrategyList)(x), d) - } -} - -func (x *DeschedulerStrategy) 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 yyxt1 := z.Extension(z.I2Rtid(x)); yyxt1 != nil { - z.EncExtension(x, yyxt1) - } else { - yysep2 := !z.EncBinary() - yy2arr2 := z.EncBasicHandle().StructToArray - _, _ = yysep2, yy2arr2 - const yyr2 bool = false - if yyr2 || yy2arr2 { - r.WriteArrayStart(3) - } else { - r.WriteMapStart(3) - } - if yyr2 || yy2arr2 { - r.WriteArrayElem() - yym4 := z.EncBinary() - _ = yym4 - if false { - } else { - r.EncodeBool(bool(x.Enabled)) - } - } else { - r.WriteMapElemKey() - r.EncStructFieldKey(codecSelferValueTypeString1234, `Enabled`) - r.WriteMapElemValue() - yym5 := z.EncBinary() - _ = yym5 - if false { - } else { - r.EncodeBool(bool(x.Enabled)) - } - } - if yyr2 || yy2arr2 { - r.WriteArrayElem() - yym7 := z.EncBinary() - _ = yym7 - if false { - } else { - r.EncodeInt(int64(x.Weight)) - } - } else { - r.WriteMapElemKey() - r.EncStructFieldKey(codecSelferValueTypeString1234, `Weight`) - r.WriteMapElemValue() - yym8 := z.EncBinary() - _ = yym8 - if false { - } else { - r.EncodeInt(int64(x.Weight)) - } - } - if yyr2 || yy2arr2 { - r.WriteArrayElem() - yy10 := &x.Params - yy10.CodecEncodeSelf(e) - } else { - r.WriteMapElemKey() - r.EncStructFieldKey(codecSelferValueTypeString1234, `Params`) - r.WriteMapElemValue() - yy12 := &x.Params - yy12.CodecEncodeSelf(e) - } - if yyr2 || yy2arr2 { - r.WriteArrayEnd() - } else { - r.WriteMapEnd() - } - } - } -} - -func (x *DeschedulerStrategy) CodecDecodeSelf(d *codec1978.Decoder) { - var h codecSelfer1234 - z, r := codec1978.GenHelperDecoder(d) - _, _, _ = h, z, r - yym1 := z.DecBinary() - _ = yym1 - if false { - } else if yyxt1 := z.Extension(z.I2Rtid(x)); yyxt1 != nil { - z.DecExtension(x, yyxt1) - } else { - yyct2 := r.ContainerType() - if yyct2 == codecSelferValueTypeMap1234 { - yyl2 := r.ReadMapStart() - if yyl2 == 0 { - r.ReadMapEnd() - } else { - x.codecDecodeSelfFromMap(yyl2, d) - } - } else if yyct2 == codecSelferValueTypeArray1234 { - yyl2 := r.ReadArrayStart() - if yyl2 == 0 { - r.ReadArrayEnd() - } else { - x.codecDecodeSelfFromArray(yyl2, d) - } - } else { - panic(errCodecSelferOnlyMapOrArrayEncodeToStruct1234) - } - } -} - -func (x *DeschedulerStrategy) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) { - var h codecSelfer1234 - z, r := codec1978.GenHelperDecoder(d) - _, _, _ = h, z, r - var yyhl3 bool = l >= 0 - for yyj3 := 0; ; yyj3++ { - if yyhl3 { - if yyj3 >= l { - break - } - } else { - if r.CheckBreak() { - break - } - } - r.ReadMapElemKey() - yys3 := z.StringView(r.DecStructFieldKey(codecSelferValueTypeString1234, z.DecScratchArrayBuffer())) - r.ReadMapElemValue() - switch yys3 { - case "Enabled": - if r.TryDecodeAsNil() { - x.Enabled = false - } else { - yyv4 := &x.Enabled - yym5 := z.DecBinary() - _ = yym5 - if false { - } else { - *((*bool)(yyv4)) = r.DecodeBool() - } - } - case "Weight": - if r.TryDecodeAsNil() { - x.Weight = 0 - } else { - yyv6 := &x.Weight - yym7 := z.DecBinary() - _ = yym7 - if false { - } else { - *((*int)(yyv6)) = int(r.DecodeInt(codecSelferBitsize1234)) - } - } - case "Params": - if r.TryDecodeAsNil() { - x.Params = StrategyParameters{} - } else { - yyv8 := &x.Params - yyv8.CodecDecodeSelf(d) - } - default: - z.DecStructFieldNotFound(-1, yys3) - } // end switch yys3 - } // end for yyj3 - r.ReadMapEnd() -} - -func (x *DeschedulerStrategy) 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 { - r.ReadArrayEnd() - return - } - r.ReadArrayElem() - if r.TryDecodeAsNil() { - x.Enabled = false - } else { - yyv10 := &x.Enabled - yym11 := z.DecBinary() - _ = yym11 - if false { - } else { - *((*bool)(yyv10)) = r.DecodeBool() - } - } - yyj9++ - if yyhl9 { - yyb9 = yyj9 > l - } else { - yyb9 = r.CheckBreak() - } - if yyb9 { - r.ReadArrayEnd() - return - } - r.ReadArrayElem() - if r.TryDecodeAsNil() { - x.Weight = 0 - } else { - yyv12 := &x.Weight - yym13 := z.DecBinary() - _ = yym13 - if false { - } else { - *((*int)(yyv12)) = int(r.DecodeInt(codecSelferBitsize1234)) - } - } - yyj9++ - if yyhl9 { - yyb9 = yyj9 > l - } else { - yyb9 = r.CheckBreak() - } - if yyb9 { - r.ReadArrayEnd() - return - } - r.ReadArrayElem() - if r.TryDecodeAsNil() { - x.Params = StrategyParameters{} - } else { - yyv14 := &x.Params - yyv14.CodecDecodeSelf(d) - } - for { - yyj9++ - if yyhl9 { - yyb9 = yyj9 > l - } else { - yyb9 = r.CheckBreak() - } - if yyb9 { - break - } - r.ReadArrayElem() - z.DecStructFieldNotFound(yyj9-1, "") - } - r.ReadArrayEnd() -} - -func (x *StrategyParameters) 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 yyxt1 := z.Extension(z.I2Rtid(x)); yyxt1 != nil { - z.EncExtension(x, yyxt1) - } else { - yysep2 := !z.EncBinary() - yy2arr2 := z.EncBasicHandle().StructToArray - _, _ = yysep2, yy2arr2 - const yyr2 bool = false - if yyr2 || yy2arr2 { - r.WriteArrayStart(2) - } else { - r.WriteMapStart(2) - } - if yyr2 || yy2arr2 { - r.WriteArrayElem() - yy4 := &x.NodeResourceUtilizationThresholds - yy4.CodecEncodeSelf(e) - } else { - r.WriteMapElemKey() - r.EncStructFieldKey(codecSelferValueTypeString1234, `NodeResourceUtilizationThresholds`) - r.WriteMapElemValue() - yy6 := &x.NodeResourceUtilizationThresholds - yy6.CodecEncodeSelf(e) - } - if yyr2 || yy2arr2 { - r.WriteArrayElem() - if x.NodeAffinityType == nil { - r.EncodeNil() - } else { - yym9 := z.EncBinary() - _ = yym9 - if false { - } else { - z.F.EncSliceStringV(x.NodeAffinityType, e) - } - } - } else { - r.WriteMapElemKey() - r.EncStructFieldKey(codecSelferValueTypeString1234, `NodeAffinityType`) - r.WriteMapElemValue() - if x.NodeAffinityType == nil { - r.EncodeNil() - } else { - yym10 := z.EncBinary() - _ = yym10 - if false { - } else { - z.F.EncSliceStringV(x.NodeAffinityType, e) - } - } - } - if yyr2 || yy2arr2 { - r.WriteArrayEnd() - } else { - r.WriteMapEnd() - } - } - } -} - -func (x *StrategyParameters) CodecDecodeSelf(d *codec1978.Decoder) { - var h codecSelfer1234 - z, r := codec1978.GenHelperDecoder(d) - _, _, _ = h, z, r - yym1 := z.DecBinary() - _ = yym1 - if false { - } else if yyxt1 := z.Extension(z.I2Rtid(x)); yyxt1 != nil { - z.DecExtension(x, yyxt1) - } else { - yyct2 := r.ContainerType() - if yyct2 == codecSelferValueTypeMap1234 { - yyl2 := r.ReadMapStart() - if yyl2 == 0 { - r.ReadMapEnd() - } else { - x.codecDecodeSelfFromMap(yyl2, d) - } - } else if yyct2 == codecSelferValueTypeArray1234 { - yyl2 := r.ReadArrayStart() - if yyl2 == 0 { - r.ReadArrayEnd() - } else { - x.codecDecodeSelfFromArray(yyl2, d) - } - } else { - panic(errCodecSelferOnlyMapOrArrayEncodeToStruct1234) - } - } -} - -func (x *StrategyParameters) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) { - var h codecSelfer1234 - z, r := codec1978.GenHelperDecoder(d) - _, _, _ = h, z, r - var yyhl3 bool = l >= 0 - for yyj3 := 0; ; yyj3++ { - if yyhl3 { - if yyj3 >= l { - break - } - } else { - if r.CheckBreak() { - break - } - } - r.ReadMapElemKey() - yys3 := z.StringView(r.DecStructFieldKey(codecSelferValueTypeString1234, z.DecScratchArrayBuffer())) - r.ReadMapElemValue() - switch yys3 { - case "NodeResourceUtilizationThresholds": - if r.TryDecodeAsNil() { - x.NodeResourceUtilizationThresholds = NodeResourceUtilizationThresholds{} - } else { - yyv4 := &x.NodeResourceUtilizationThresholds - yyv4.CodecDecodeSelf(d) - } - case "NodeAffinityType": - if r.TryDecodeAsNil() { - x.NodeAffinityType = nil - } else { - yyv5 := &x.NodeAffinityType - yym6 := z.DecBinary() - _ = yym6 - if false { - } else { - z.F.DecSliceStringX(yyv5, d) - } - } - default: - z.DecStructFieldNotFound(-1, yys3) - } // end switch yys3 - } // end for yyj3 - r.ReadMapEnd() -} - -func (x *StrategyParameters) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) { - var h codecSelfer1234 - z, r := codec1978.GenHelperDecoder(d) - _, _, _ = h, z, r - var yyj7 int - var yyb7 bool - var yyhl7 bool = l >= 0 - yyj7++ - if yyhl7 { - yyb7 = yyj7 > l - } else { - yyb7 = r.CheckBreak() - } - if yyb7 { - r.ReadArrayEnd() - return - } - r.ReadArrayElem() - if r.TryDecodeAsNil() { - x.NodeResourceUtilizationThresholds = NodeResourceUtilizationThresholds{} - } else { - yyv8 := &x.NodeResourceUtilizationThresholds - yyv8.CodecDecodeSelf(d) - } - yyj7++ - if yyhl7 { - yyb7 = yyj7 > l - } else { - yyb7 = r.CheckBreak() - } - if yyb7 { - r.ReadArrayEnd() - return - } - r.ReadArrayElem() - if r.TryDecodeAsNil() { - x.NodeAffinityType = nil - } else { - yyv9 := &x.NodeAffinityType - yym10 := z.DecBinary() - _ = yym10 - if false { - } else { - z.F.DecSliceStringX(yyv9, d) - } - } - for { - yyj7++ - if yyhl7 { - yyb7 = yyj7 > l - } else { - yyb7 = r.CheckBreak() - } - if yyb7 { - break - } - r.ReadArrayElem() - z.DecStructFieldNotFound(yyj7-1, "") - } - r.ReadArrayEnd() -} - -func (x Percentage) CodecEncodeSelf(e *codec1978.Encoder) { - var h codecSelfer1234 - z, r := codec1978.GenHelperEncoder(e) - _, _, _ = h, z, r - yym1 := z.EncBinary() - _ = yym1 - if false { - } else if yyxt1 := z.Extension(z.I2Rtid(x)); yyxt1 != nil { - z.EncExtension(x, yyxt1) - } else { - r.EncodeFloat64(float64(x)) - } -} - -func (x *Percentage) CodecDecodeSelf(d *codec1978.Decoder) { - var h codecSelfer1234 - z, r := codec1978.GenHelperDecoder(d) - _, _, _ = h, z, r - yym1 := z.DecBinary() - _ = yym1 - if false { - } else if yyxt1 := z.Extension(z.I2Rtid(x)); yyxt1 != nil { - z.DecExtension(x, yyxt1) - } else { - *((*float64)(x)) = r.DecodeFloat64() - } -} - -func (x ResourceThresholds) 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 yyxt1 := z.Extension(z.I2Rtid(x)); yyxt1 != nil { - z.EncExtension(x, yyxt1) - } else { - h.encResourceThresholds((ResourceThresholds)(x), e) - } - } -} - -func (x *ResourceThresholds) CodecDecodeSelf(d *codec1978.Decoder) { - var h codecSelfer1234 - z, r := codec1978.GenHelperDecoder(d) - _, _, _ = h, z, r - yym1 := z.DecBinary() - _ = yym1 - if false { - } else if yyxt1 := z.Extension(z.I2Rtid(x)); yyxt1 != nil { - z.DecExtension(x, yyxt1) - } else { - h.decResourceThresholds((*ResourceThresholds)(x), d) - } -} - -func (x *NodeResourceUtilizationThresholds) 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 yyxt1 := z.Extension(z.I2Rtid(x)); yyxt1 != nil { - z.EncExtension(x, yyxt1) - } else { - yysep2 := !z.EncBinary() - yy2arr2 := z.EncBasicHandle().StructToArray - _, _ = yysep2, yy2arr2 - const yyr2 bool = false - if yyr2 || yy2arr2 { - r.WriteArrayStart(3) - } else { - r.WriteMapStart(3) - } - if yyr2 || yy2arr2 { - r.WriteArrayElem() - if x.Thresholds == nil { - r.EncodeNil() - } else { - x.Thresholds.CodecEncodeSelf(e) - } - } else { - r.WriteMapElemKey() - r.EncStructFieldKey(codecSelferValueTypeString1234, `Thresholds`) - r.WriteMapElemValue() - if x.Thresholds == nil { - r.EncodeNil() - } else { - x.Thresholds.CodecEncodeSelf(e) - } - } - if yyr2 || yy2arr2 { - r.WriteArrayElem() - if x.TargetThresholds == nil { - r.EncodeNil() - } else { - x.TargetThresholds.CodecEncodeSelf(e) - } - } else { - r.WriteMapElemKey() - r.EncStructFieldKey(codecSelferValueTypeString1234, `TargetThresholds`) - r.WriteMapElemValue() - if x.TargetThresholds == nil { - r.EncodeNil() - } else { - x.TargetThresholds.CodecEncodeSelf(e) - } - } - if yyr2 || yy2arr2 { - r.WriteArrayElem() - yym10 := z.EncBinary() - _ = yym10 - if false { - } else { - r.EncodeInt(int64(x.NumberOfNodes)) - } - } else { - r.WriteMapElemKey() - r.EncStructFieldKey(codecSelferValueTypeString1234, `NumberOfNodes`) - r.WriteMapElemValue() - yym11 := z.EncBinary() - _ = yym11 - if false { - } else { - r.EncodeInt(int64(x.NumberOfNodes)) - } - } - if yyr2 || yy2arr2 { - r.WriteArrayEnd() - } else { - r.WriteMapEnd() - } - } - } -} - -func (x *NodeResourceUtilizationThresholds) CodecDecodeSelf(d *codec1978.Decoder) { - var h codecSelfer1234 - z, r := codec1978.GenHelperDecoder(d) - _, _, _ = h, z, r - yym1 := z.DecBinary() - _ = yym1 - if false { - } else if yyxt1 := z.Extension(z.I2Rtid(x)); yyxt1 != nil { - z.DecExtension(x, yyxt1) - } else { - yyct2 := r.ContainerType() - if yyct2 == codecSelferValueTypeMap1234 { - yyl2 := r.ReadMapStart() - if yyl2 == 0 { - r.ReadMapEnd() - } else { - x.codecDecodeSelfFromMap(yyl2, d) - } - } else if yyct2 == codecSelferValueTypeArray1234 { - yyl2 := r.ReadArrayStart() - if yyl2 == 0 { - r.ReadArrayEnd() - } else { - x.codecDecodeSelfFromArray(yyl2, d) - } - } else { - panic(errCodecSelferOnlyMapOrArrayEncodeToStruct1234) - } - } -} - -func (x *NodeResourceUtilizationThresholds) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) { - var h codecSelfer1234 - z, r := codec1978.GenHelperDecoder(d) - _, _, _ = h, z, r - var yyhl3 bool = l >= 0 - for yyj3 := 0; ; yyj3++ { - if yyhl3 { - if yyj3 >= l { - break - } - } else { - if r.CheckBreak() { - break - } - } - r.ReadMapElemKey() - yys3 := z.StringView(r.DecStructFieldKey(codecSelferValueTypeString1234, z.DecScratchArrayBuffer())) - r.ReadMapElemValue() - switch yys3 { - case "Thresholds": - if r.TryDecodeAsNil() { - x.Thresholds = nil - } else { - yyv4 := &x.Thresholds - yyv4.CodecDecodeSelf(d) - } - case "TargetThresholds": - if r.TryDecodeAsNil() { - x.TargetThresholds = nil - } else { - yyv5 := &x.TargetThresholds - yyv5.CodecDecodeSelf(d) - } - case "NumberOfNodes": - if r.TryDecodeAsNil() { - x.NumberOfNodes = 0 - } else { - yyv6 := &x.NumberOfNodes - yym7 := z.DecBinary() - _ = yym7 - if false { - } else { - *((*int)(yyv6)) = int(r.DecodeInt(codecSelferBitsize1234)) - } - } - default: - z.DecStructFieldNotFound(-1, yys3) - } // end switch yys3 - } // end for yyj3 - r.ReadMapEnd() -} - -func (x *NodeResourceUtilizationThresholds) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) { - var h codecSelfer1234 - z, r := codec1978.GenHelperDecoder(d) - _, _, _ = h, z, r - var yyj8 int - var yyb8 bool - var yyhl8 bool = l >= 0 - yyj8++ - if yyhl8 { - yyb8 = yyj8 > l - } else { - yyb8 = r.CheckBreak() - } - if yyb8 { - r.ReadArrayEnd() - return - } - r.ReadArrayElem() - if r.TryDecodeAsNil() { - x.Thresholds = nil - } else { - yyv9 := &x.Thresholds - yyv9.CodecDecodeSelf(d) - } - yyj8++ - if yyhl8 { - yyb8 = yyj8 > l - } else { - yyb8 = r.CheckBreak() - } - if yyb8 { - r.ReadArrayEnd() - return - } - r.ReadArrayElem() - if r.TryDecodeAsNil() { - x.TargetThresholds = nil - } else { - yyv10 := &x.TargetThresholds - yyv10.CodecDecodeSelf(d) - } - yyj8++ - if yyhl8 { - yyb8 = yyj8 > l - } else { - yyb8 = r.CheckBreak() - } - if yyb8 { - r.ReadArrayEnd() - return - } - r.ReadArrayElem() - if r.TryDecodeAsNil() { - x.NumberOfNodes = 0 - } else { - yyv11 := &x.NumberOfNodes - yym12 := z.DecBinary() - _ = yym12 - if false { - } else { - *((*int)(yyv11)) = int(r.DecodeInt(codecSelferBitsize1234)) - } - } - for { - yyj8++ - if yyhl8 { - yyb8 = yyj8 > l - } else { - yyb8 = r.CheckBreak() - } - if yyb8 { - break - } - r.ReadArrayElem() - z.DecStructFieldNotFound(yyj8-1, "") - } - r.ReadArrayEnd() -} - -func (x codecSelfer1234) encStrategyList(v StrategyList, e *codec1978.Encoder) { - var h codecSelfer1234 - z, r := codec1978.GenHelperEncoder(e) - _, _, _ = h, z, r - r.WriteMapStart(len(v)) - for yyk1, yyv1 := range v { - r.WriteMapElemKey() - yyk1.CodecEncodeSelf(e) - r.WriteMapElemValue() - yy3 := &yyv1 - yy3.CodecEncodeSelf(e) - } - r.WriteMapEnd() -} - -func (x codecSelfer1234) decStrategyList(v *StrategyList, d *codec1978.Decoder) { - var h codecSelfer1234 - z, r := codec1978.GenHelperDecoder(d) - _, _, _ = h, z, r - - yyv1 := *v - yyl1 := r.ReadMapStart() - yybh1 := z.DecBasicHandle() - if yyv1 == nil { - yyrl1 := z.DecInferLen(yyl1, yybh1.MaxInitLen, 80) - yyv1 = make(map[StrategyName]DeschedulerStrategy, yyrl1) - *v = yyv1 - } - var yymk1 StrategyName - var yymv1 DeschedulerStrategy - var yymg1, yymdn1 bool - if yybh1.MapValueReset { - yymg1 = true - } - if yyl1 != 0 { - yyhl1 := yyl1 > 0 - for yyj1 := 0; (yyhl1 && yyj1 < yyl1) || !(yyhl1 || r.CheckBreak()); yyj1++ { - r.ReadMapElemKey() - if r.TryDecodeAsNil() { - yymk1 = "" - } else { - yyv2 := &yymk1 - yyv2.CodecDecodeSelf(d) - } - - if yymg1 { - yymv1 = yyv1[yymk1] - } else { - yymv1 = DeschedulerStrategy{} - } - r.ReadMapElemValue() - yymdn1 = false - if r.TryDecodeAsNil() { - yymdn1 = true - } else { - yyv3 := &yymv1 - yyv3.CodecDecodeSelf(d) - } - - if yymdn1 { - if yybh1.DeleteOnNilMapValue { - delete(yyv1, yymk1) - } else { - yyv1[yymk1] = DeschedulerStrategy{} - } - } else if yyv1 != nil { - yyv1[yymk1] = yymv1 - } - } - } // else len==0: TODO: Should we clear map entries? - r.ReadMapEnd() -} - -func (x codecSelfer1234) encResourceThresholds(v ResourceThresholds, e *codec1978.Encoder) { - var h codecSelfer1234 - z, r := codec1978.GenHelperEncoder(e) - _, _, _ = h, z, r - r.WriteMapStart(len(v)) - for yyk1, yyv1 := range v { - r.WriteMapElemKey() - yym2 := z.EncBinary() - _ = yym2 - if false { - } else if yyxt2 := z.Extension(z.I2Rtid(yyk1)); yyxt2 != nil { - z.EncExtension(yyk1, yyxt2) - } else { - r.EncodeString(codecSelferCcUTF81234, string(yyk1)) - } - r.WriteMapElemValue() - yyv1.CodecEncodeSelf(e) - } - r.WriteMapEnd() -} - -func (x codecSelfer1234) decResourceThresholds(v *ResourceThresholds, d *codec1978.Decoder) { - var h codecSelfer1234 - z, r := codec1978.GenHelperDecoder(d) - _, _, _ = h, z, r - - yyv1 := *v - yyl1 := r.ReadMapStart() - yybh1 := z.DecBasicHandle() - if yyv1 == nil { - yyrl1 := z.DecInferLen(yyl1, yybh1.MaxInitLen, 24) - yyv1 = make(map[pkg2_v1.ResourceName]Percentage, yyrl1) - *v = yyv1 - } - var yymk1 pkg2_v1.ResourceName - var yymv1 Percentage - var yymg1, yymdn1 bool - if yybh1.MapValueReset { - } - if yyl1 != 0 { - yyhl1 := yyl1 > 0 - for yyj1 := 0; (yyhl1 && yyj1 < yyl1) || !(yyhl1 || r.CheckBreak()); yyj1++ { - r.ReadMapElemKey() - if r.TryDecodeAsNil() { - yymk1 = "" - } else { - yyv2 := &yymk1 - yym3 := z.DecBinary() - _ = yym3 - if false { - } else if yyxt3 := z.Extension(z.I2Rtid(yyv2)); yyxt3 != nil { - z.DecExtension(yyv2, yyxt3) - } else { - *((*string)(yyv2)) = r.DecodeString() - } - } - - if yymg1 { - yymv1 = yyv1[yymk1] - } - r.ReadMapElemValue() - yymdn1 = false - if r.TryDecodeAsNil() { - yymdn1 = true - } else { - yyv4 := &yymv1 - yyv4.CodecDecodeSelf(d) - } - - if yymdn1 { - if yybh1.DeleteOnNilMapValue { - delete(yyv1, yymk1) - } else { - yyv1[yymk1] = 0 - } - } else if yyv1 != nil { - yyv1[yymk1] = yymv1 - } - } - } // else len==0: TODO: Should we clear map entries? - r.ReadMapEnd() -} diff --git a/pkg/api/types.go b/pkg/api/types.go index 5b1d1c30ce..d19e783409 100644 --- a/pkg/api/types.go +++ b/pkg/api/types.go @@ -48,6 +48,9 @@ type DeschedulerStrategy struct { type StrategyParameters struct { NodeResourceUtilizationThresholds NodeResourceUtilizationThresholds NodeAffinityType []string + // TopologySpreadConstraints describes how a group of pods should be spread across topology + // domains. Descheduler will use these constraints to decide which pods to evict. + NamespacedTopologySpreadConstraints []NamespacedTopologySpreadConstraint } type Percentage float64 @@ -58,3 +61,32 @@ type NodeResourceUtilizationThresholds struct { TargetThresholds ResourceThresholds NumberOfNodes int } + +type NamespacedTopologySpreadConstraint struct { + Namespace string + TopologySpreadConstraints []TopologySpreadConstraint +} + +type TopologySpreadConstraint struct { + // MaxSkew describes the degree to which pods may be unevenly distributed. + // It's the maximum permitted difference between the number of matching pods in + // any two topology domains of a given topology type. + // For example, in a 3-zone cluster, currently pods with the same labelSelector + // are "spread" such that zone1 and zone2 each have one pod, but not zone3. + // - if MaxSkew is 1, incoming pod can only be scheduled to zone3 to become 1/1/1; + // scheduling it onto zone1(zone2) would make the ActualSkew(2) violate MaxSkew(1) + // - if MaxSkew is 2, incoming pod can be scheduled to any zone. + // It's a required value. Default value is 1 and 0 is not allowed. + MaxSkew int32 + // TopologyKey is the key of node labels. Nodes that have a label with this key + // and identical values are considered to be in the same topology. + // We consider each as a "bucket", and try to put balanced number + // of pods into each bucket. + // It's a required field. + TopologyKey string + // LabelSelector is used to find matching pods. + // Pods that match this label selector are counted to determine the number of pods + // in their corresponding topology domain. + // +optional + LabelSelector *metav1.LabelSelector +} diff --git a/pkg/api/v1alpha1/types.generated.go b/pkg/api/v1alpha1/types.generated.go deleted file mode 100644 index 25c569a0d0..0000000000 --- a/pkg/api/v1alpha1/types.generated.go +++ /dev/null @@ -1,1415 +0,0 @@ -/* -Copyright 2017 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by codecgen - DO NOT EDIT. - -package v1alpha1 - -import ( - "errors" - "fmt" - codec1978 "github.com/ugorji/go/codec" - pkg2_v1 "k8s.io/api/core/v1" - pkg1_v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "reflect" - "runtime" -) - -const ( - // ----- content types ---- - codecSelferCcUTF81234 = 1 - codecSelferCcRAW1234 = 0 - // ----- value types used ---- - codecSelferValueTypeArray1234 = 10 - codecSelferValueTypeMap1234 = 9 - codecSelferValueTypeString1234 = 6 - codecSelferValueTypeInt1234 = 2 - codecSelferValueTypeUint1234 = 3 - codecSelferValueTypeFloat1234 = 4 -) - -var ( - codecSelferBitsize1234 = uint8(reflect.TypeOf(uint(0)).Bits()) - errCodecSelferOnlyMapOrArrayEncodeToStruct1234 = errors.New(`only encoded map or array can be decoded into a struct`) -) - -type codecSelfer1234 struct{} - -func init() { - if codec1978.GenVersion != 8 { - _, file, _, _ := runtime.Caller(0) - err := fmt.Errorf("codecgen version mismatch: current: %v, need %v. Re-generate file: %v", - 8, codec1978.GenVersion, file) - panic(err) - } - if false { // reference the types, but skip this branch at build/run time - var v0 pkg2_v1.ResourceName - var v1 pkg1_v1.TypeMeta - _, _ = v0, v1 - } -} - -func (x *DeschedulerPolicy) 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 yyxt1 := z.Extension(z.I2Rtid(x)); yyxt1 != nil { - z.EncExtension(x, yyxt1) - } else { - yysep2 := !z.EncBinary() - yy2arr2 := z.EncBasicHandle().StructToArray - var yyq2 [3]bool - _ = yyq2 - _, _ = yysep2, yy2arr2 - const yyr2 bool = false - yyq2[0] = x.Kind != "" - yyq2[1] = x.APIVersion != "" - yyq2[2] = len(x.Strategies) != 0 - if yyr2 || yy2arr2 { - r.WriteArrayStart(3) - } else { - var yynn2 = 0 - for _, b := range yyq2 { - if b { - yynn2++ - } - } - r.WriteMapStart(yynn2) - yynn2 = 0 - } - if yyr2 || yy2arr2 { - r.WriteArrayElem() - if yyq2[0] { - yym4 := z.EncBinary() - _ = yym4 - if false { - } else { - r.EncodeString(codecSelferCcUTF81234, string(x.Kind)) - } - } else { - r.EncodeString(codecSelferCcUTF81234, "") - } - } else { - if yyq2[0] { - r.WriteMapElemKey() - r.EncStructFieldKey(codecSelferValueTypeString1234, `kind`) - r.WriteMapElemValue() - yym5 := z.EncBinary() - _ = yym5 - if false { - } else { - r.EncodeString(codecSelferCcUTF81234, string(x.Kind)) - } - } - } - if yyr2 || yy2arr2 { - r.WriteArrayElem() - if yyq2[1] { - yym7 := z.EncBinary() - _ = yym7 - if false { - } else { - r.EncodeString(codecSelferCcUTF81234, string(x.APIVersion)) - } - } else { - r.EncodeString(codecSelferCcUTF81234, "") - } - } else { - if yyq2[1] { - r.WriteMapElemKey() - r.EncStructFieldKey(codecSelferValueTypeString1234, `apiVersion`) - r.WriteMapElemValue() - yym8 := z.EncBinary() - _ = yym8 - if false { - } else { - r.EncodeString(codecSelferCcUTF81234, string(x.APIVersion)) - } - } - } - if yyr2 || yy2arr2 { - r.WriteArrayElem() - if yyq2[2] { - if x.Strategies == nil { - r.EncodeNil() - } else { - x.Strategies.CodecEncodeSelf(e) - } - } else { - r.EncodeNil() - } - } else { - if yyq2[2] { - r.WriteMapElemKey() - r.EncStructFieldKey(codecSelferValueTypeString1234, `strategies`) - r.WriteMapElemValue() - if x.Strategies == nil { - r.EncodeNil() - } else { - x.Strategies.CodecEncodeSelf(e) - } - } - } - if yyr2 || yy2arr2 { - r.WriteArrayEnd() - } else { - r.WriteMapEnd() - } - } - } -} - -func (x *DeschedulerPolicy) CodecDecodeSelf(d *codec1978.Decoder) { - var h codecSelfer1234 - z, r := codec1978.GenHelperDecoder(d) - _, _, _ = h, z, r - yym1 := z.DecBinary() - _ = yym1 - if false { - } else if yyxt1 := z.Extension(z.I2Rtid(x)); yyxt1 != nil { - z.DecExtension(x, yyxt1) - } else { - yyct2 := r.ContainerType() - if yyct2 == codecSelferValueTypeMap1234 { - yyl2 := r.ReadMapStart() - if yyl2 == 0 { - r.ReadMapEnd() - } else { - x.codecDecodeSelfFromMap(yyl2, d) - } - } else if yyct2 == codecSelferValueTypeArray1234 { - yyl2 := r.ReadArrayStart() - if yyl2 == 0 { - r.ReadArrayEnd() - } else { - x.codecDecodeSelfFromArray(yyl2, d) - } - } else { - panic(errCodecSelferOnlyMapOrArrayEncodeToStruct1234) - } - } -} - -func (x *DeschedulerPolicy) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) { - var h codecSelfer1234 - z, r := codec1978.GenHelperDecoder(d) - _, _, _ = h, z, r - var yyhl3 bool = l >= 0 - for yyj3 := 0; ; yyj3++ { - if yyhl3 { - if yyj3 >= l { - break - } - } else { - if r.CheckBreak() { - break - } - } - r.ReadMapElemKey() - yys3 := z.StringView(r.DecStructFieldKey(codecSelferValueTypeString1234, z.DecScratchArrayBuffer())) - r.ReadMapElemValue() - switch yys3 { - case "kind": - if r.TryDecodeAsNil() { - x.Kind = "" - } else { - yyv4 := &x.Kind - yym5 := z.DecBinary() - _ = yym5 - if false { - } else { - *((*string)(yyv4)) = r.DecodeString() - } - } - case "apiVersion": - if r.TryDecodeAsNil() { - x.APIVersion = "" - } else { - yyv6 := &x.APIVersion - yym7 := z.DecBinary() - _ = yym7 - if false { - } else { - *((*string)(yyv6)) = r.DecodeString() - } - } - case "strategies": - if r.TryDecodeAsNil() { - x.Strategies = nil - } else { - yyv8 := &x.Strategies - yyv8.CodecDecodeSelf(d) - } - default: - z.DecStructFieldNotFound(-1, yys3) - } // end switch yys3 - } // end for yyj3 - r.ReadMapEnd() -} - -func (x *DeschedulerPolicy) 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 { - r.ReadArrayEnd() - return - } - r.ReadArrayElem() - if r.TryDecodeAsNil() { - x.Kind = "" - } else { - yyv10 := &x.Kind - yym11 := z.DecBinary() - _ = yym11 - if false { - } else { - *((*string)(yyv10)) = r.DecodeString() - } - } - yyj9++ - if yyhl9 { - yyb9 = yyj9 > l - } else { - yyb9 = r.CheckBreak() - } - if yyb9 { - r.ReadArrayEnd() - return - } - r.ReadArrayElem() - if r.TryDecodeAsNil() { - x.APIVersion = "" - } else { - yyv12 := &x.APIVersion - yym13 := z.DecBinary() - _ = yym13 - if false { - } else { - *((*string)(yyv12)) = r.DecodeString() - } - } - yyj9++ - if yyhl9 { - yyb9 = yyj9 > l - } else { - yyb9 = r.CheckBreak() - } - if yyb9 { - r.ReadArrayEnd() - return - } - r.ReadArrayElem() - if r.TryDecodeAsNil() { - x.Strategies = nil - } else { - yyv14 := &x.Strategies - yyv14.CodecDecodeSelf(d) - } - for { - yyj9++ - if yyhl9 { - yyb9 = yyj9 > l - } else { - yyb9 = r.CheckBreak() - } - if yyb9 { - break - } - r.ReadArrayElem() - z.DecStructFieldNotFound(yyj9-1, "") - } - r.ReadArrayEnd() -} - -func (x StrategyName) CodecEncodeSelf(e *codec1978.Encoder) { - var h codecSelfer1234 - z, r := codec1978.GenHelperEncoder(e) - _, _, _ = h, z, r - yym1 := z.EncBinary() - _ = yym1 - if false { - } else if yyxt1 := z.Extension(z.I2Rtid(x)); yyxt1 != nil { - z.EncExtension(x, yyxt1) - } else { - r.EncodeString(codecSelferCcUTF81234, string(x)) - } -} - -func (x *StrategyName) CodecDecodeSelf(d *codec1978.Decoder) { - var h codecSelfer1234 - z, r := codec1978.GenHelperDecoder(d) - _, _, _ = h, z, r - yym1 := z.DecBinary() - _ = yym1 - if false { - } else if yyxt1 := z.Extension(z.I2Rtid(x)); yyxt1 != nil { - z.DecExtension(x, yyxt1) - } else { - *((*string)(x)) = r.DecodeString() - } -} - -func (x StrategyList) 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 yyxt1 := z.Extension(z.I2Rtid(x)); yyxt1 != nil { - z.EncExtension(x, yyxt1) - } else { - h.encStrategyList((StrategyList)(x), e) - } - } -} - -func (x *StrategyList) CodecDecodeSelf(d *codec1978.Decoder) { - var h codecSelfer1234 - z, r := codec1978.GenHelperDecoder(d) - _, _, _ = h, z, r - yym1 := z.DecBinary() - _ = yym1 - if false { - } else if yyxt1 := z.Extension(z.I2Rtid(x)); yyxt1 != nil { - z.DecExtension(x, yyxt1) - } else { - h.decStrategyList((*StrategyList)(x), d) - } -} - -func (x *DeschedulerStrategy) 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 yyxt1 := z.Extension(z.I2Rtid(x)); yyxt1 != nil { - z.EncExtension(x, yyxt1) - } else { - yysep2 := !z.EncBinary() - yy2arr2 := z.EncBasicHandle().StructToArray - var yyq2 [3]bool - _ = yyq2 - _, _ = yysep2, yy2arr2 - const yyr2 bool = false - yyq2[0] = x.Enabled != false - yyq2[1] = x.Weight != 0 - yyq2[2] = true - if yyr2 || yy2arr2 { - r.WriteArrayStart(3) - } else { - var yynn2 = 0 - for _, b := range yyq2 { - if b { - yynn2++ - } - } - r.WriteMapStart(yynn2) - yynn2 = 0 - } - if yyr2 || yy2arr2 { - r.WriteArrayElem() - if yyq2[0] { - yym4 := z.EncBinary() - _ = yym4 - if false { - } else { - r.EncodeBool(bool(x.Enabled)) - } - } else { - r.EncodeBool(false) - } - } else { - if yyq2[0] { - r.WriteMapElemKey() - r.EncStructFieldKey(codecSelferValueTypeString1234, `enabled`) - r.WriteMapElemValue() - yym5 := z.EncBinary() - _ = yym5 - if false { - } else { - r.EncodeBool(bool(x.Enabled)) - } - } - } - if yyr2 || yy2arr2 { - r.WriteArrayElem() - if yyq2[1] { - yym7 := z.EncBinary() - _ = yym7 - if false { - } else { - r.EncodeInt(int64(x.Weight)) - } - } else { - r.EncodeInt(0) - } - } else { - if yyq2[1] { - r.WriteMapElemKey() - r.EncStructFieldKey(codecSelferValueTypeString1234, `weight`) - r.WriteMapElemValue() - yym8 := z.EncBinary() - _ = yym8 - if false { - } else { - r.EncodeInt(int64(x.Weight)) - } - } - } - if yyr2 || yy2arr2 { - r.WriteArrayElem() - if yyq2[2] { - yy10 := &x.Params - yy10.CodecEncodeSelf(e) - } else { - r.EncodeNil() - } - } else { - if yyq2[2] { - r.WriteMapElemKey() - r.EncStructFieldKey(codecSelferValueTypeString1234, `params`) - r.WriteMapElemValue() - yy12 := &x.Params - yy12.CodecEncodeSelf(e) - } - } - if yyr2 || yy2arr2 { - r.WriteArrayEnd() - } else { - r.WriteMapEnd() - } - } - } -} - -func (x *DeschedulerStrategy) CodecDecodeSelf(d *codec1978.Decoder) { - var h codecSelfer1234 - z, r := codec1978.GenHelperDecoder(d) - _, _, _ = h, z, r - yym1 := z.DecBinary() - _ = yym1 - if false { - } else if yyxt1 := z.Extension(z.I2Rtid(x)); yyxt1 != nil { - z.DecExtension(x, yyxt1) - } else { - yyct2 := r.ContainerType() - if yyct2 == codecSelferValueTypeMap1234 { - yyl2 := r.ReadMapStart() - if yyl2 == 0 { - r.ReadMapEnd() - } else { - x.codecDecodeSelfFromMap(yyl2, d) - } - } else if yyct2 == codecSelferValueTypeArray1234 { - yyl2 := r.ReadArrayStart() - if yyl2 == 0 { - r.ReadArrayEnd() - } else { - x.codecDecodeSelfFromArray(yyl2, d) - } - } else { - panic(errCodecSelferOnlyMapOrArrayEncodeToStruct1234) - } - } -} - -func (x *DeschedulerStrategy) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) { - var h codecSelfer1234 - z, r := codec1978.GenHelperDecoder(d) - _, _, _ = h, z, r - var yyhl3 bool = l >= 0 - for yyj3 := 0; ; yyj3++ { - if yyhl3 { - if yyj3 >= l { - break - } - } else { - if r.CheckBreak() { - break - } - } - r.ReadMapElemKey() - yys3 := z.StringView(r.DecStructFieldKey(codecSelferValueTypeString1234, z.DecScratchArrayBuffer())) - r.ReadMapElemValue() - switch yys3 { - case "enabled": - if r.TryDecodeAsNil() { - x.Enabled = false - } else { - yyv4 := &x.Enabled - yym5 := z.DecBinary() - _ = yym5 - if false { - } else { - *((*bool)(yyv4)) = r.DecodeBool() - } - } - case "weight": - if r.TryDecodeAsNil() { - x.Weight = 0 - } else { - yyv6 := &x.Weight - yym7 := z.DecBinary() - _ = yym7 - if false { - } else { - *((*int)(yyv6)) = int(r.DecodeInt(codecSelferBitsize1234)) - } - } - case "params": - if r.TryDecodeAsNil() { - x.Params = StrategyParameters{} - } else { - yyv8 := &x.Params - yyv8.CodecDecodeSelf(d) - } - default: - z.DecStructFieldNotFound(-1, yys3) - } // end switch yys3 - } // end for yyj3 - r.ReadMapEnd() -} - -func (x *DeschedulerStrategy) 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 { - r.ReadArrayEnd() - return - } - r.ReadArrayElem() - if r.TryDecodeAsNil() { - x.Enabled = false - } else { - yyv10 := &x.Enabled - yym11 := z.DecBinary() - _ = yym11 - if false { - } else { - *((*bool)(yyv10)) = r.DecodeBool() - } - } - yyj9++ - if yyhl9 { - yyb9 = yyj9 > l - } else { - yyb9 = r.CheckBreak() - } - if yyb9 { - r.ReadArrayEnd() - return - } - r.ReadArrayElem() - if r.TryDecodeAsNil() { - x.Weight = 0 - } else { - yyv12 := &x.Weight - yym13 := z.DecBinary() - _ = yym13 - if false { - } else { - *((*int)(yyv12)) = int(r.DecodeInt(codecSelferBitsize1234)) - } - } - yyj9++ - if yyhl9 { - yyb9 = yyj9 > l - } else { - yyb9 = r.CheckBreak() - } - if yyb9 { - r.ReadArrayEnd() - return - } - r.ReadArrayElem() - if r.TryDecodeAsNil() { - x.Params = StrategyParameters{} - } else { - yyv14 := &x.Params - yyv14.CodecDecodeSelf(d) - } - for { - yyj9++ - if yyhl9 { - yyb9 = yyj9 > l - } else { - yyb9 = r.CheckBreak() - } - if yyb9 { - break - } - r.ReadArrayElem() - z.DecStructFieldNotFound(yyj9-1, "") - } - r.ReadArrayEnd() -} - -func (x *StrategyParameters) 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 yyxt1 := z.Extension(z.I2Rtid(x)); yyxt1 != nil { - z.EncExtension(x, yyxt1) - } else { - yysep2 := !z.EncBinary() - yy2arr2 := z.EncBasicHandle().StructToArray - var yyq2 [2]bool - _ = yyq2 - _, _ = yysep2, yy2arr2 - const yyr2 bool = false - yyq2[0] = true - yyq2[1] = len(x.NodeAffinityType) != 0 - if yyr2 || yy2arr2 { - r.WriteArrayStart(2) - } else { - var yynn2 = 0 - for _, b := range yyq2 { - if b { - yynn2++ - } - } - r.WriteMapStart(yynn2) - yynn2 = 0 - } - if yyr2 || yy2arr2 { - r.WriteArrayElem() - if yyq2[0] { - yy4 := &x.NodeResourceUtilizationThresholds - yy4.CodecEncodeSelf(e) - } else { - r.EncodeNil() - } - } else { - if yyq2[0] { - r.WriteMapElemKey() - r.EncStructFieldKey(codecSelferValueTypeString1234, `nodeResourceUtilizationThresholds`) - r.WriteMapElemValue() - yy6 := &x.NodeResourceUtilizationThresholds - yy6.CodecEncodeSelf(e) - } - } - if yyr2 || yy2arr2 { - r.WriteArrayElem() - if yyq2[1] { - if x.NodeAffinityType == nil { - r.EncodeNil() - } else { - yym9 := z.EncBinary() - _ = yym9 - if false { - } else { - z.F.EncSliceStringV(x.NodeAffinityType, e) - } - } - } else { - r.EncodeNil() - } - } else { - if yyq2[1] { - r.WriteMapElemKey() - r.EncStructFieldKey(codecSelferValueTypeString1234, `nodeAffinityType`) - r.WriteMapElemValue() - if x.NodeAffinityType == nil { - r.EncodeNil() - } else { - yym10 := z.EncBinary() - _ = yym10 - if false { - } else { - z.F.EncSliceStringV(x.NodeAffinityType, e) - } - } - } - } - if yyr2 || yy2arr2 { - r.WriteArrayEnd() - } else { - r.WriteMapEnd() - } - } - } -} - -func (x *StrategyParameters) CodecDecodeSelf(d *codec1978.Decoder) { - var h codecSelfer1234 - z, r := codec1978.GenHelperDecoder(d) - _, _, _ = h, z, r - yym1 := z.DecBinary() - _ = yym1 - if false { - } else if yyxt1 := z.Extension(z.I2Rtid(x)); yyxt1 != nil { - z.DecExtension(x, yyxt1) - } else { - yyct2 := r.ContainerType() - if yyct2 == codecSelferValueTypeMap1234 { - yyl2 := r.ReadMapStart() - if yyl2 == 0 { - r.ReadMapEnd() - } else { - x.codecDecodeSelfFromMap(yyl2, d) - } - } else if yyct2 == codecSelferValueTypeArray1234 { - yyl2 := r.ReadArrayStart() - if yyl2 == 0 { - r.ReadArrayEnd() - } else { - x.codecDecodeSelfFromArray(yyl2, d) - } - } else { - panic(errCodecSelferOnlyMapOrArrayEncodeToStruct1234) - } - } -} - -func (x *StrategyParameters) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) { - var h codecSelfer1234 - z, r := codec1978.GenHelperDecoder(d) - _, _, _ = h, z, r - var yyhl3 bool = l >= 0 - for yyj3 := 0; ; yyj3++ { - if yyhl3 { - if yyj3 >= l { - break - } - } else { - if r.CheckBreak() { - break - } - } - r.ReadMapElemKey() - yys3 := z.StringView(r.DecStructFieldKey(codecSelferValueTypeString1234, z.DecScratchArrayBuffer())) - r.ReadMapElemValue() - switch yys3 { - case "nodeResourceUtilizationThresholds": - if r.TryDecodeAsNil() { - x.NodeResourceUtilizationThresholds = NodeResourceUtilizationThresholds{} - } else { - yyv4 := &x.NodeResourceUtilizationThresholds - yyv4.CodecDecodeSelf(d) - } - case "nodeAffinityType": - if r.TryDecodeAsNil() { - x.NodeAffinityType = nil - } else { - yyv5 := &x.NodeAffinityType - yym6 := z.DecBinary() - _ = yym6 - if false { - } else { - z.F.DecSliceStringX(yyv5, d) - } - } - default: - z.DecStructFieldNotFound(-1, yys3) - } // end switch yys3 - } // end for yyj3 - r.ReadMapEnd() -} - -func (x *StrategyParameters) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) { - var h codecSelfer1234 - z, r := codec1978.GenHelperDecoder(d) - _, _, _ = h, z, r - var yyj7 int - var yyb7 bool - var yyhl7 bool = l >= 0 - yyj7++ - if yyhl7 { - yyb7 = yyj7 > l - } else { - yyb7 = r.CheckBreak() - } - if yyb7 { - r.ReadArrayEnd() - return - } - r.ReadArrayElem() - if r.TryDecodeAsNil() { - x.NodeResourceUtilizationThresholds = NodeResourceUtilizationThresholds{} - } else { - yyv8 := &x.NodeResourceUtilizationThresholds - yyv8.CodecDecodeSelf(d) - } - yyj7++ - if yyhl7 { - yyb7 = yyj7 > l - } else { - yyb7 = r.CheckBreak() - } - if yyb7 { - r.ReadArrayEnd() - return - } - r.ReadArrayElem() - if r.TryDecodeAsNil() { - x.NodeAffinityType = nil - } else { - yyv9 := &x.NodeAffinityType - yym10 := z.DecBinary() - _ = yym10 - if false { - } else { - z.F.DecSliceStringX(yyv9, d) - } - } - for { - yyj7++ - if yyhl7 { - yyb7 = yyj7 > l - } else { - yyb7 = r.CheckBreak() - } - if yyb7 { - break - } - r.ReadArrayElem() - z.DecStructFieldNotFound(yyj7-1, "") - } - r.ReadArrayEnd() -} - -func (x Percentage) CodecEncodeSelf(e *codec1978.Encoder) { - var h codecSelfer1234 - z, r := codec1978.GenHelperEncoder(e) - _, _, _ = h, z, r - yym1 := z.EncBinary() - _ = yym1 - if false { - } else if yyxt1 := z.Extension(z.I2Rtid(x)); yyxt1 != nil { - z.EncExtension(x, yyxt1) - } else { - r.EncodeFloat64(float64(x)) - } -} - -func (x *Percentage) CodecDecodeSelf(d *codec1978.Decoder) { - var h codecSelfer1234 - z, r := codec1978.GenHelperDecoder(d) - _, _, _ = h, z, r - yym1 := z.DecBinary() - _ = yym1 - if false { - } else if yyxt1 := z.Extension(z.I2Rtid(x)); yyxt1 != nil { - z.DecExtension(x, yyxt1) - } else { - *((*float64)(x)) = r.DecodeFloat64() - } -} - -func (x ResourceThresholds) 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 yyxt1 := z.Extension(z.I2Rtid(x)); yyxt1 != nil { - z.EncExtension(x, yyxt1) - } else { - h.encResourceThresholds((ResourceThresholds)(x), e) - } - } -} - -func (x *ResourceThresholds) CodecDecodeSelf(d *codec1978.Decoder) { - var h codecSelfer1234 - z, r := codec1978.GenHelperDecoder(d) - _, _, _ = h, z, r - yym1 := z.DecBinary() - _ = yym1 - if false { - } else if yyxt1 := z.Extension(z.I2Rtid(x)); yyxt1 != nil { - z.DecExtension(x, yyxt1) - } else { - h.decResourceThresholds((*ResourceThresholds)(x), d) - } -} - -func (x *NodeResourceUtilizationThresholds) 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 yyxt1 := z.Extension(z.I2Rtid(x)); yyxt1 != nil { - z.EncExtension(x, yyxt1) - } else { - yysep2 := !z.EncBinary() - yy2arr2 := z.EncBasicHandle().StructToArray - var yyq2 [3]bool - _ = yyq2 - _, _ = yysep2, yy2arr2 - const yyr2 bool = false - yyq2[0] = len(x.Thresholds) != 0 - yyq2[1] = len(x.TargetThresholds) != 0 - yyq2[2] = x.NumberOfNodes != 0 - if yyr2 || yy2arr2 { - r.WriteArrayStart(3) - } else { - var yynn2 = 0 - for _, b := range yyq2 { - if b { - yynn2++ - } - } - r.WriteMapStart(yynn2) - yynn2 = 0 - } - if yyr2 || yy2arr2 { - r.WriteArrayElem() - if yyq2[0] { - if x.Thresholds == nil { - r.EncodeNil() - } else { - x.Thresholds.CodecEncodeSelf(e) - } - } else { - r.EncodeNil() - } - } else { - if yyq2[0] { - r.WriteMapElemKey() - r.EncStructFieldKey(codecSelferValueTypeString1234, `thresholds`) - r.WriteMapElemValue() - if x.Thresholds == nil { - r.EncodeNil() - } else { - x.Thresholds.CodecEncodeSelf(e) - } - } - } - if yyr2 || yy2arr2 { - r.WriteArrayElem() - if yyq2[1] { - if x.TargetThresholds == nil { - r.EncodeNil() - } else { - x.TargetThresholds.CodecEncodeSelf(e) - } - } else { - r.EncodeNil() - } - } else { - if yyq2[1] { - r.WriteMapElemKey() - r.EncStructFieldKey(codecSelferValueTypeString1234, `targetThresholds`) - r.WriteMapElemValue() - if x.TargetThresholds == nil { - r.EncodeNil() - } else { - x.TargetThresholds.CodecEncodeSelf(e) - } - } - } - if yyr2 || yy2arr2 { - r.WriteArrayElem() - if yyq2[2] { - yym10 := z.EncBinary() - _ = yym10 - if false { - } else { - r.EncodeInt(int64(x.NumberOfNodes)) - } - } else { - r.EncodeInt(0) - } - } else { - if yyq2[2] { - r.WriteMapElemKey() - r.EncStructFieldKey(codecSelferValueTypeString1234, `numberOfNodes`) - r.WriteMapElemValue() - yym11 := z.EncBinary() - _ = yym11 - if false { - } else { - r.EncodeInt(int64(x.NumberOfNodes)) - } - } - } - if yyr2 || yy2arr2 { - r.WriteArrayEnd() - } else { - r.WriteMapEnd() - } - } - } -} - -func (x *NodeResourceUtilizationThresholds) CodecDecodeSelf(d *codec1978.Decoder) { - var h codecSelfer1234 - z, r := codec1978.GenHelperDecoder(d) - _, _, _ = h, z, r - yym1 := z.DecBinary() - _ = yym1 - if false { - } else if yyxt1 := z.Extension(z.I2Rtid(x)); yyxt1 != nil { - z.DecExtension(x, yyxt1) - } else { - yyct2 := r.ContainerType() - if yyct2 == codecSelferValueTypeMap1234 { - yyl2 := r.ReadMapStart() - if yyl2 == 0 { - r.ReadMapEnd() - } else { - x.codecDecodeSelfFromMap(yyl2, d) - } - } else if yyct2 == codecSelferValueTypeArray1234 { - yyl2 := r.ReadArrayStart() - if yyl2 == 0 { - r.ReadArrayEnd() - } else { - x.codecDecodeSelfFromArray(yyl2, d) - } - } else { - panic(errCodecSelferOnlyMapOrArrayEncodeToStruct1234) - } - } -} - -func (x *NodeResourceUtilizationThresholds) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) { - var h codecSelfer1234 - z, r := codec1978.GenHelperDecoder(d) - _, _, _ = h, z, r - var yyhl3 bool = l >= 0 - for yyj3 := 0; ; yyj3++ { - if yyhl3 { - if yyj3 >= l { - break - } - } else { - if r.CheckBreak() { - break - } - } - r.ReadMapElemKey() - yys3 := z.StringView(r.DecStructFieldKey(codecSelferValueTypeString1234, z.DecScratchArrayBuffer())) - r.ReadMapElemValue() - switch yys3 { - case "thresholds": - if r.TryDecodeAsNil() { - x.Thresholds = nil - } else { - yyv4 := &x.Thresholds - yyv4.CodecDecodeSelf(d) - } - case "targetThresholds": - if r.TryDecodeAsNil() { - x.TargetThresholds = nil - } else { - yyv5 := &x.TargetThresholds - yyv5.CodecDecodeSelf(d) - } - case "numberOfNodes": - if r.TryDecodeAsNil() { - x.NumberOfNodes = 0 - } else { - yyv6 := &x.NumberOfNodes - yym7 := z.DecBinary() - _ = yym7 - if false { - } else { - *((*int)(yyv6)) = int(r.DecodeInt(codecSelferBitsize1234)) - } - } - default: - z.DecStructFieldNotFound(-1, yys3) - } // end switch yys3 - } // end for yyj3 - r.ReadMapEnd() -} - -func (x *NodeResourceUtilizationThresholds) codecDecodeSelfFromArray(l int, d *codec1978.Decoder) { - var h codecSelfer1234 - z, r := codec1978.GenHelperDecoder(d) - _, _, _ = h, z, r - var yyj8 int - var yyb8 bool - var yyhl8 bool = l >= 0 - yyj8++ - if yyhl8 { - yyb8 = yyj8 > l - } else { - yyb8 = r.CheckBreak() - } - if yyb8 { - r.ReadArrayEnd() - return - } - r.ReadArrayElem() - if r.TryDecodeAsNil() { - x.Thresholds = nil - } else { - yyv9 := &x.Thresholds - yyv9.CodecDecodeSelf(d) - } - yyj8++ - if yyhl8 { - yyb8 = yyj8 > l - } else { - yyb8 = r.CheckBreak() - } - if yyb8 { - r.ReadArrayEnd() - return - } - r.ReadArrayElem() - if r.TryDecodeAsNil() { - x.TargetThresholds = nil - } else { - yyv10 := &x.TargetThresholds - yyv10.CodecDecodeSelf(d) - } - yyj8++ - if yyhl8 { - yyb8 = yyj8 > l - } else { - yyb8 = r.CheckBreak() - } - if yyb8 { - r.ReadArrayEnd() - return - } - r.ReadArrayElem() - if r.TryDecodeAsNil() { - x.NumberOfNodes = 0 - } else { - yyv11 := &x.NumberOfNodes - yym12 := z.DecBinary() - _ = yym12 - if false { - } else { - *((*int)(yyv11)) = int(r.DecodeInt(codecSelferBitsize1234)) - } - } - for { - yyj8++ - if yyhl8 { - yyb8 = yyj8 > l - } else { - yyb8 = r.CheckBreak() - } - if yyb8 { - break - } - r.ReadArrayElem() - z.DecStructFieldNotFound(yyj8-1, "") - } - r.ReadArrayEnd() -} - -func (x codecSelfer1234) encStrategyList(v StrategyList, e *codec1978.Encoder) { - var h codecSelfer1234 - z, r := codec1978.GenHelperEncoder(e) - _, _, _ = h, z, r - r.WriteMapStart(len(v)) - for yyk1, yyv1 := range v { - r.WriteMapElemKey() - yyk1.CodecEncodeSelf(e) - r.WriteMapElemValue() - yy3 := &yyv1 - yy3.CodecEncodeSelf(e) - } - r.WriteMapEnd() -} - -func (x codecSelfer1234) decStrategyList(v *StrategyList, d *codec1978.Decoder) { - var h codecSelfer1234 - z, r := codec1978.GenHelperDecoder(d) - _, _, _ = h, z, r - - yyv1 := *v - yyl1 := r.ReadMapStart() - yybh1 := z.DecBasicHandle() - if yyv1 == nil { - yyrl1 := z.DecInferLen(yyl1, yybh1.MaxInitLen, 80) - yyv1 = make(map[StrategyName]DeschedulerStrategy, yyrl1) - *v = yyv1 - } - var yymk1 StrategyName - var yymv1 DeschedulerStrategy - var yymg1, yymdn1 bool - if yybh1.MapValueReset { - yymg1 = true - } - if yyl1 != 0 { - yyhl1 := yyl1 > 0 - for yyj1 := 0; (yyhl1 && yyj1 < yyl1) || !(yyhl1 || r.CheckBreak()); yyj1++ { - r.ReadMapElemKey() - if r.TryDecodeAsNil() { - yymk1 = "" - } else { - yyv2 := &yymk1 - yyv2.CodecDecodeSelf(d) - } - - if yymg1 { - yymv1 = yyv1[yymk1] - } else { - yymv1 = DeschedulerStrategy{} - } - r.ReadMapElemValue() - yymdn1 = false - if r.TryDecodeAsNil() { - yymdn1 = true - } else { - yyv3 := &yymv1 - yyv3.CodecDecodeSelf(d) - } - - if yymdn1 { - if yybh1.DeleteOnNilMapValue { - delete(yyv1, yymk1) - } else { - yyv1[yymk1] = DeschedulerStrategy{} - } - } else if yyv1 != nil { - yyv1[yymk1] = yymv1 - } - } - } // else len==0: TODO: Should we clear map entries? - r.ReadMapEnd() -} - -func (x codecSelfer1234) encResourceThresholds(v ResourceThresholds, e *codec1978.Encoder) { - var h codecSelfer1234 - z, r := codec1978.GenHelperEncoder(e) - _, _, _ = h, z, r - r.WriteMapStart(len(v)) - for yyk1, yyv1 := range v { - r.WriteMapElemKey() - yym2 := z.EncBinary() - _ = yym2 - if false { - } else if yyxt2 := z.Extension(z.I2Rtid(yyk1)); yyxt2 != nil { - z.EncExtension(yyk1, yyxt2) - } else { - r.EncodeString(codecSelferCcUTF81234, string(yyk1)) - } - r.WriteMapElemValue() - yyv1.CodecEncodeSelf(e) - } - r.WriteMapEnd() -} - -func (x codecSelfer1234) decResourceThresholds(v *ResourceThresholds, d *codec1978.Decoder) { - var h codecSelfer1234 - z, r := codec1978.GenHelperDecoder(d) - _, _, _ = h, z, r - - yyv1 := *v - yyl1 := r.ReadMapStart() - yybh1 := z.DecBasicHandle() - if yyv1 == nil { - yyrl1 := z.DecInferLen(yyl1, yybh1.MaxInitLen, 24) - yyv1 = make(map[pkg2_v1.ResourceName]Percentage, yyrl1) - *v = yyv1 - } - var yymk1 pkg2_v1.ResourceName - var yymv1 Percentage - var yymg1, yymdn1 bool - if yybh1.MapValueReset { - } - if yyl1 != 0 { - yyhl1 := yyl1 > 0 - for yyj1 := 0; (yyhl1 && yyj1 < yyl1) || !(yyhl1 || r.CheckBreak()); yyj1++ { - r.ReadMapElemKey() - if r.TryDecodeAsNil() { - yymk1 = "" - } else { - yyv2 := &yymk1 - yym3 := z.DecBinary() - _ = yym3 - if false { - } else if yyxt3 := z.Extension(z.I2Rtid(yyv2)); yyxt3 != nil { - z.DecExtension(yyv2, yyxt3) - } else { - *((*string)(yyv2)) = r.DecodeString() - } - } - - if yymg1 { - yymv1 = yyv1[yymk1] - } - r.ReadMapElemValue() - yymdn1 = false - if r.TryDecodeAsNil() { - yymdn1 = true - } else { - yyv4 := &yymv1 - yyv4.CodecDecodeSelf(d) - } - - if yymdn1 { - if yybh1.DeleteOnNilMapValue { - delete(yyv1, yymk1) - } else { - yyv1[yymk1] = 0 - } - } else if yyv1 != nil { - yyv1[yymk1] = yymv1 - } - } - } // else len==0: TODO: Should we clear map entries? - r.ReadMapEnd() -} diff --git a/pkg/api/v1alpha1/types.go b/pkg/api/v1alpha1/types.go index 1ca0cac9bd..1fd44ff253 100644 --- a/pkg/api/v1alpha1/types.go +++ b/pkg/api/v1alpha1/types.go @@ -46,8 +46,9 @@ type DeschedulerStrategy struct { // Only one of its members may be specified type StrategyParameters struct { - NodeResourceUtilizationThresholds NodeResourceUtilizationThresholds `json:"nodeResourceUtilizationThresholds,omitempty"` - NodeAffinityType []string `json:"nodeAffinityType,omitempty"` + NodeResourceUtilizationThresholds NodeResourceUtilizationThresholds `json:"nodeResourceUtilizationThresholds,omitempty"` + NodeAffinityType []string `json:"nodeAffinityType,omitempty"` + NamespacedTopologySpreadConstraints []NamespacedTopologySpreadConstraint } type Percentage float64 @@ -58,3 +59,32 @@ type NodeResourceUtilizationThresholds struct { TargetThresholds ResourceThresholds `json:"targetThresholds,omitempty"` NumberOfNodes int `json:"numberOfNodes,omitempty"` } + +type NamespacedTopologySpreadConstraint struct { + Namespace string + TopologySpreadConstraints []TopologySpreadConstraint +} + +type TopologySpreadConstraint struct { + // MaxSkew describes the degree to which pods may be unevenly distributed. + // It's the maximum permitted difference between the number of matching pods in + // any two topology domains of a given topology type. + // For example, in a 3-zone cluster, currently pods with the same labelSelector + // are "spread" such that zone1 and zone2 each have one pod, but not zone3. + // - if MaxSkew is 1, incoming pod can only be scheduled to zone3 to become 1/1/1; + // scheduling it onto zone1(zone2) would make the ActualSkew(2) violate MaxSkew(1) + // - if MaxSkew is 2, incoming pod can be scheduled to any zone. + // It's a required value. Default value is 1 and 0 is not allowed. + MaxSkew int32 + // TopologyKey is the key of node labels. Nodes that have a label with this key + // and identical values are considered to be in the same topology. + // We consider each as a "bucket", and try to put balanced number + // of pods into each bucket. + // It's a required field. + TopologyKey string + // LabelSelector is used to find matching pods. + // Pods that match this label selector are counted to determine the number of pods + // in their corresponding topology domain. + // +optional + LabelSelector *metav1.LabelSelector +} diff --git a/pkg/api/v1alpha1/zz_generated.conversion.go b/pkg/api/v1alpha1/zz_generated.conversion.go index 315bc6860b..98008e5d07 100644 --- a/pkg/api/v1alpha1/zz_generated.conversion.go +++ b/pkg/api/v1alpha1/zz_generated.conversion.go @@ -1,7 +1,7 @@ // +build !ignore_autogenerated /* -Copyright 2018 The Kubernetes Authors. +Copyright 2019 The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -24,6 +24,7 @@ import ( unsafe "unsafe" api "github.com/kubernetes-incubator/descheduler/pkg/api" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" conversion "k8s.io/apimachinery/pkg/conversion" runtime "k8s.io/apimachinery/pkg/runtime" ) @@ -40,10 +41,14 @@ func RegisterConversions(scheme *runtime.Scheme) error { Convert_api_DeschedulerPolicy_To_v1alpha1_DeschedulerPolicy, Convert_v1alpha1_DeschedulerStrategy_To_api_DeschedulerStrategy, Convert_api_DeschedulerStrategy_To_v1alpha1_DeschedulerStrategy, + Convert_v1alpha1_NamespacedTopologySpreadConstraint_To_api_NamespacedTopologySpreadConstraint, + Convert_api_NamespacedTopologySpreadConstraint_To_v1alpha1_NamespacedTopologySpreadConstraint, Convert_v1alpha1_NodeResourceUtilizationThresholds_To_api_NodeResourceUtilizationThresholds, Convert_api_NodeResourceUtilizationThresholds_To_v1alpha1_NodeResourceUtilizationThresholds, Convert_v1alpha1_StrategyParameters_To_api_StrategyParameters, Convert_api_StrategyParameters_To_v1alpha1_StrategyParameters, + Convert_v1alpha1_TopologySpreadConstraint_To_api_TopologySpreadConstraint, + Convert_api_TopologySpreadConstraint_To_v1alpha1_TopologySpreadConstraint, ) } @@ -95,6 +100,28 @@ func Convert_api_DeschedulerStrategy_To_v1alpha1_DeschedulerStrategy(in *api.Des return autoConvert_api_DeschedulerStrategy_To_v1alpha1_DeschedulerStrategy(in, out, s) } +func autoConvert_v1alpha1_NamespacedTopologySpreadConstraint_To_api_NamespacedTopologySpreadConstraint(in *NamespacedTopologySpreadConstraint, out *api.NamespacedTopologySpreadConstraint, s conversion.Scope) error { + out.Namespace = in.Namespace + out.TopologySpreadConstraints = *(*[]api.TopologySpreadConstraint)(unsafe.Pointer(&in.TopologySpreadConstraints)) + return nil +} + +// Convert_v1alpha1_NamespacedTopologySpreadConstraint_To_api_NamespacedTopologySpreadConstraint is an autogenerated conversion function. +func Convert_v1alpha1_NamespacedTopologySpreadConstraint_To_api_NamespacedTopologySpreadConstraint(in *NamespacedTopologySpreadConstraint, out *api.NamespacedTopologySpreadConstraint, s conversion.Scope) error { + return autoConvert_v1alpha1_NamespacedTopologySpreadConstraint_To_api_NamespacedTopologySpreadConstraint(in, out, s) +} + +func autoConvert_api_NamespacedTopologySpreadConstraint_To_v1alpha1_NamespacedTopologySpreadConstraint(in *api.NamespacedTopologySpreadConstraint, out *NamespacedTopologySpreadConstraint, s conversion.Scope) error { + out.Namespace = in.Namespace + out.TopologySpreadConstraints = *(*[]TopologySpreadConstraint)(unsafe.Pointer(&in.TopologySpreadConstraints)) + return nil +} + +// Convert_api_NamespacedTopologySpreadConstraint_To_v1alpha1_NamespacedTopologySpreadConstraint is an autogenerated conversion function. +func Convert_api_NamespacedTopologySpreadConstraint_To_v1alpha1_NamespacedTopologySpreadConstraint(in *api.NamespacedTopologySpreadConstraint, out *NamespacedTopologySpreadConstraint, s conversion.Scope) error { + return autoConvert_api_NamespacedTopologySpreadConstraint_To_v1alpha1_NamespacedTopologySpreadConstraint(in, out, s) +} + func autoConvert_v1alpha1_NodeResourceUtilizationThresholds_To_api_NodeResourceUtilizationThresholds(in *NodeResourceUtilizationThresholds, out *api.NodeResourceUtilizationThresholds, s conversion.Scope) error { out.Thresholds = *(*api.ResourceThresholds)(unsafe.Pointer(&in.Thresholds)) out.TargetThresholds = *(*api.ResourceThresholds)(unsafe.Pointer(&in.TargetThresholds)) @@ -124,6 +151,7 @@ func autoConvert_v1alpha1_StrategyParameters_To_api_StrategyParameters(in *Strat return err } out.NodeAffinityType = *(*[]string)(unsafe.Pointer(&in.NodeAffinityType)) + out.NamespacedTopologySpreadConstraints = *(*[]api.NamespacedTopologySpreadConstraint)(unsafe.Pointer(&in.NamespacedTopologySpreadConstraints)) return nil } @@ -137,6 +165,7 @@ func autoConvert_api_StrategyParameters_To_v1alpha1_StrategyParameters(in *api.S return err } out.NodeAffinityType = *(*[]string)(unsafe.Pointer(&in.NodeAffinityType)) + out.NamespacedTopologySpreadConstraints = *(*[]NamespacedTopologySpreadConstraint)(unsafe.Pointer(&in.NamespacedTopologySpreadConstraints)) return nil } @@ -144,3 +173,27 @@ func autoConvert_api_StrategyParameters_To_v1alpha1_StrategyParameters(in *api.S func Convert_api_StrategyParameters_To_v1alpha1_StrategyParameters(in *api.StrategyParameters, out *StrategyParameters, s conversion.Scope) error { return autoConvert_api_StrategyParameters_To_v1alpha1_StrategyParameters(in, out, s) } + +func autoConvert_v1alpha1_TopologySpreadConstraint_To_api_TopologySpreadConstraint(in *TopologySpreadConstraint, out *api.TopologySpreadConstraint, s conversion.Scope) error { + out.MaxSkew = in.MaxSkew + out.TopologyKey = in.TopologyKey + out.LabelSelector = (*v1.LabelSelector)(unsafe.Pointer(in.LabelSelector)) + return nil +} + +// Convert_v1alpha1_TopologySpreadConstraint_To_api_TopologySpreadConstraint is an autogenerated conversion function. +func Convert_v1alpha1_TopologySpreadConstraint_To_api_TopologySpreadConstraint(in *TopologySpreadConstraint, out *api.TopologySpreadConstraint, s conversion.Scope) error { + return autoConvert_v1alpha1_TopologySpreadConstraint_To_api_TopologySpreadConstraint(in, out, s) +} + +func autoConvert_api_TopologySpreadConstraint_To_v1alpha1_TopologySpreadConstraint(in *api.TopologySpreadConstraint, out *TopologySpreadConstraint, s conversion.Scope) error { + out.MaxSkew = in.MaxSkew + out.TopologyKey = in.TopologyKey + out.LabelSelector = (*v1.LabelSelector)(unsafe.Pointer(in.LabelSelector)) + return nil +} + +// Convert_api_TopologySpreadConstraint_To_v1alpha1_TopologySpreadConstraint is an autogenerated conversion function. +func Convert_api_TopologySpreadConstraint_To_v1alpha1_TopologySpreadConstraint(in *api.TopologySpreadConstraint, out *TopologySpreadConstraint, s conversion.Scope) error { + return autoConvert_api_TopologySpreadConstraint_To_v1alpha1_TopologySpreadConstraint(in, out, s) +} diff --git a/pkg/api/v1alpha1/zz_generated.deepcopy.go b/pkg/api/v1alpha1/zz_generated.deepcopy.go index eccebf83fe..b3c7253dc1 100644 --- a/pkg/api/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/api/v1alpha1/zz_generated.deepcopy.go @@ -1,7 +1,7 @@ // +build !ignore_autogenerated /* -Copyright 2018 The Kubernetes Authors. +Copyright 2019 The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -21,6 +21,7 @@ limitations under the License. package v1alpha1 import ( + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" ) @@ -76,6 +77,29 @@ func (in *DeschedulerStrategy) DeepCopy() *DeschedulerStrategy { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *NamespacedTopologySpreadConstraint) DeepCopyInto(out *NamespacedTopologySpreadConstraint) { + *out = *in + if in.TopologySpreadConstraints != nil { + in, out := &in.TopologySpreadConstraints, &out.TopologySpreadConstraints + *out = make([]TopologySpreadConstraint, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NamespacedTopologySpreadConstraint. +func (in *NamespacedTopologySpreadConstraint) DeepCopy() *NamespacedTopologySpreadConstraint { + if in == nil { + return nil + } + out := new(NamespacedTopologySpreadConstraint) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *NodeResourceUtilizationThresholds) DeepCopyInto(out *NodeResourceUtilizationThresholds) { *out = *in @@ -115,6 +139,13 @@ func (in *StrategyParameters) DeepCopyInto(out *StrategyParameters) { *out = make([]string, len(*in)) copy(*out, *in) } + if in.NamespacedTopologySpreadConstraints != nil { + in, out := &in.NamespacedTopologySpreadConstraints, &out.NamespacedTopologySpreadConstraints + *out = make([]NamespacedTopologySpreadConstraint, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } return } @@ -127,3 +158,28 @@ func (in *StrategyParameters) DeepCopy() *StrategyParameters { in.DeepCopyInto(out) return out } + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TopologySpreadConstraint) DeepCopyInto(out *TopologySpreadConstraint) { + *out = *in + if in.LabelSelector != nil { + in, out := &in.LabelSelector, &out.LabelSelector + if *in == nil { + *out = nil + } else { + *out = new(v1.LabelSelector) + (*in).DeepCopyInto(*out) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TopologySpreadConstraint. +func (in *TopologySpreadConstraint) DeepCopy() *TopologySpreadConstraint { + if in == nil { + return nil + } + out := new(TopologySpreadConstraint) + in.DeepCopyInto(out) + return out +} diff --git a/pkg/api/v1alpha1/zz_generated.defaults.go b/pkg/api/v1alpha1/zz_generated.defaults.go index 5e24d22cac..17fd867f41 100644 --- a/pkg/api/v1alpha1/zz_generated.defaults.go +++ b/pkg/api/v1alpha1/zz_generated.defaults.go @@ -1,7 +1,7 @@ // +build !ignore_autogenerated /* -Copyright 2018 The Kubernetes Authors. +Copyright 2019 The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/pkg/api/zz_generated.deepcopy.go b/pkg/api/zz_generated.deepcopy.go index ccbbe6cb64..94f89ec09e 100644 --- a/pkg/api/zz_generated.deepcopy.go +++ b/pkg/api/zz_generated.deepcopy.go @@ -1,7 +1,7 @@ // +build !ignore_autogenerated /* -Copyright 2018 The Kubernetes Authors. +Copyright 2019 The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -21,6 +21,7 @@ limitations under the License. package api import ( + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" ) @@ -76,6 +77,29 @@ func (in *DeschedulerStrategy) DeepCopy() *DeschedulerStrategy { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *NamespacedTopologySpreadConstraint) DeepCopyInto(out *NamespacedTopologySpreadConstraint) { + *out = *in + if in.TopologySpreadConstraints != nil { + in, out := &in.TopologySpreadConstraints, &out.TopologySpreadConstraints + *out = make([]TopologySpreadConstraint, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NamespacedTopologySpreadConstraint. +func (in *NamespacedTopologySpreadConstraint) DeepCopy() *NamespacedTopologySpreadConstraint { + if in == nil { + return nil + } + out := new(NamespacedTopologySpreadConstraint) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *NodeResourceUtilizationThresholds) DeepCopyInto(out *NodeResourceUtilizationThresholds) { *out = *in @@ -115,6 +139,13 @@ func (in *StrategyParameters) DeepCopyInto(out *StrategyParameters) { *out = make([]string, len(*in)) copy(*out, *in) } + if in.NamespacedTopologySpreadConstraints != nil { + in, out := &in.NamespacedTopologySpreadConstraints, &out.NamespacedTopologySpreadConstraints + *out = make([]NamespacedTopologySpreadConstraint, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } return } @@ -127,3 +158,28 @@ func (in *StrategyParameters) DeepCopy() *StrategyParameters { in.DeepCopyInto(out) return out } + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TopologySpreadConstraint) DeepCopyInto(out *TopologySpreadConstraint) { + *out = *in + if in.LabelSelector != nil { + in, out := &in.LabelSelector, &out.LabelSelector + if *in == nil { + *out = nil + } else { + *out = new(v1.LabelSelector) + (*in).DeepCopyInto(*out) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TopologySpreadConstraint. +func (in *TopologySpreadConstraint) DeepCopy() *TopologySpreadConstraint { + if in == nil { + return nil + } + out := new(TopologySpreadConstraint) + in.DeepCopyInto(out) + return out +} diff --git a/pkg/apis/componentconfig/v1alpha1/zz_generated.conversion.go b/pkg/apis/componentconfig/v1alpha1/zz_generated.conversion.go index 98f7cfddc3..3b806ff2a1 100644 --- a/pkg/apis/componentconfig/v1alpha1/zz_generated.conversion.go +++ b/pkg/apis/componentconfig/v1alpha1/zz_generated.conversion.go @@ -1,7 +1,7 @@ // +build !ignore_autogenerated /* -Copyright 2018 The Kubernetes Authors. +Copyright 2019 The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/pkg/apis/componentconfig/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/componentconfig/v1alpha1/zz_generated.deepcopy.go index 2173d89151..8a07946eec 100644 --- a/pkg/apis/componentconfig/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/componentconfig/v1alpha1/zz_generated.deepcopy.go @@ -1,7 +1,7 @@ // +build !ignore_autogenerated /* -Copyright 2018 The Kubernetes Authors. +Copyright 2019 The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/pkg/apis/componentconfig/v1alpha1/zz_generated.defaults.go b/pkg/apis/componentconfig/v1alpha1/zz_generated.defaults.go index 5e24d22cac..17fd867f41 100644 --- a/pkg/apis/componentconfig/v1alpha1/zz_generated.defaults.go +++ b/pkg/apis/componentconfig/v1alpha1/zz_generated.defaults.go @@ -1,7 +1,7 @@ // +build !ignore_autogenerated /* -Copyright 2018 The Kubernetes Authors. +Copyright 2019 The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/pkg/apis/componentconfig/zz_generated.deepcopy.go b/pkg/apis/componentconfig/zz_generated.deepcopy.go index f129854d0a..34dfbb15da 100644 --- a/pkg/apis/componentconfig/zz_generated.deepcopy.go +++ b/pkg/apis/componentconfig/zz_generated.deepcopy.go @@ -1,7 +1,7 @@ // +build !ignore_autogenerated /* -Copyright 2018 The Kubernetes Authors. +Copyright 2019 The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/pkg/descheduler/descheduler.go b/pkg/descheduler/descheduler.go index 07d73c395b..6c01833f8d 100644 --- a/pkg/descheduler/descheduler.go +++ b/pkg/descheduler/descheduler.go @@ -60,11 +60,13 @@ func Run(rs *options.DeschedulerServer) error { return nil } + glog.V(1).Infof("Reached here \n") nodePodCount := strategies.InitializeNodePodCount(nodes) strategies.RemoveDuplicatePods(rs, deschedulerPolicy.Strategies["RemoveDuplicates"], evictionPolicyGroupVersion, nodes, nodePodCount) strategies.LowNodeUtilization(rs, deschedulerPolicy.Strategies["LowNodeUtilization"], evictionPolicyGroupVersion, nodes, nodePodCount) strategies.RemovePodsViolatingInterPodAntiAffinity(rs, deschedulerPolicy.Strategies["RemovePodsViolatingInterPodAntiAffinity"], evictionPolicyGroupVersion, nodes, nodePodCount) strategies.RemovePodsViolatingNodeAffinity(rs, deschedulerPolicy.Strategies["RemovePodsViolatingNodeAffinity"], evictionPolicyGroupVersion, nodes, nodePodCount) + strategies.TopologySpreadConstraint(rs, deschedulerPolicy.Strategies["TopologySpreadConstraint"], evictionPolicyGroupVersion, nodes, nodePodCount) return nil } diff --git a/pkg/descheduler/pod/pods.go b/pkg/descheduler/pod/pods.go index 26b85f400b..7aa3e16aee 100644 --- a/pkg/descheduler/pod/pods.go +++ b/pkg/descheduler/pod/pods.go @@ -62,7 +62,12 @@ func IsEvictable(pod *v1.Pod, evictLocalStoragePods bool) bool { // ListEvictablePodsOnNode returns the list of evictable pods on node. func ListEvictablePodsOnNode(client clientset.Interface, node *v1.Node, evictLocalStoragePods bool) ([]*v1.Pod, error) { - pods, err := ListPodsOnANode(client, node) + return ListEvictablePodsOnNodeByNamespace(client, node, evictLocalStoragePods, v1.NamespaceAll) +} + +// ListEvictablePodsOnNode returns the list of evictable pods on node. +func ListEvictablePodsOnNodeByNamespace(client clientset.Interface, node *v1.Node, evictLocalStoragePods bool, namespace string) ([]*v1.Pod, error) { + pods, err := ListPodsOnANodeByNamespace(client, node, namespace) if err != nil { return []*v1.Pod{}, err } @@ -78,12 +83,35 @@ func ListEvictablePodsOnNode(client clientset.Interface, node *v1.Node, evictLoc } func ListPodsOnANode(client clientset.Interface, node *v1.Node) ([]*v1.Pod, error) { + return ListPodsOnANodeByNamespace(client, node, v1.NamespaceAll) +} + +func ListPodsOnANodeByNamespace(client clientset.Interface, node *v1.Node, namespace string) ([]*v1.Pod, error) { fieldSelector, err := fields.ParseSelector("spec.nodeName=" + node.Name + ",status.phase!=" + string(api.PodSucceeded) + ",status.phase!=" + string(api.PodFailed)) if err != nil { return []*v1.Pod{}, err } - podList, err := client.CoreV1().Pods(v1.NamespaceAll).List( + podList, err := client.CoreV1().Pods(namespace).List( + metav1.ListOptions{FieldSelector: fieldSelector.String()}) + if err != nil { + return []*v1.Pod{}, err + } + + pods := make([]*v1.Pod, 0) + for i := range podList.Items { + pods = append(pods, &podList.Items[i]) + } + return pods, nil +} + +func ListPodsByNamespace(client clientset.Interface, namespace string) ([]*v1.Pod, error) { + fieldSelector, err := fields.ParseSelector("status.phase!=" + string(api.PodSucceeded) + ",status.phase!=" + string(api.PodFailed)) + if err != nil { + return []*v1.Pod{}, err + } + + podList, err := client.CoreV1().Pods(namespace).List( metav1.ListOptions{FieldSelector: fieldSelector.String()}) if err != nil { return []*v1.Pod{}, err @@ -96,6 +124,23 @@ func ListPodsOnANode(client clientset.Interface, node *v1.Node) ([]*v1.Pod, erro return pods, nil } +// ListEvictablePodsOnNode returns the list of evictable pods on node. +func ListEvictablePodsByNamespace(client clientset.Interface, evictLocalStoragePods bool, namespace string) ([]*v1.Pod, error) { + pods, err := ListPodsByNamespace(client, namespace) + if err != nil { + return []*v1.Pod{}, err + } + evictablePods := make([]*v1.Pod, 0) + for _, pod := range pods { + if !IsEvictable(pod, evictLocalStoragePods) { + continue + } else { + evictablePods = append(evictablePods, pod) + } + } + return evictablePods, nil +} + func IsCriticalPod(pod *v1.Pod) bool { return types.IsCriticalPod(pod) } diff --git a/pkg/descheduler/strategies/.pod_antiaffinity.go.swp b/pkg/descheduler/strategies/.pod_antiaffinity.go.swp new file mode 100644 index 0000000000..04b675498d Binary files /dev/null and b/pkg/descheduler/strategies/.pod_antiaffinity.go.swp differ diff --git a/pkg/descheduler/strategies/topologyspreadyconstraint.go b/pkg/descheduler/strategies/topologyspreadyconstraint.go new file mode 100644 index 0000000000..6a01450b0c --- /dev/null +++ b/pkg/descheduler/strategies/topologyspreadyconstraint.go @@ -0,0 +1,247 @@ +/* +Copyright 2019 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package strategies + +import ( + "math" + + "github.com/golang/glog" + "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/labels" + clientset "k8s.io/client-go/kubernetes" + + "github.com/kubernetes-incubator/descheduler/cmd/descheduler/app/options" + "github.com/kubernetes-incubator/descheduler/pkg/api" + "github.com/kubernetes-incubator/descheduler/pkg/descheduler/evictions" + podutil "github.com/kubernetes-incubator/descheduler/pkg/descheduler/pod" +) + +func TopologySpreadConstraint(ds *options.DeschedulerServer, strategy api.DeschedulerStrategy, policyGroupVersion string, nodes []*v1.Node, nodePodCount nodePodEvictedCount) { + if !strategy.Enabled { + return + } + + glog.Infof("Found following parameters for TopologySpreadConstraint %v", strategy) + evictPodsViolatingSpreadConstraints(ds.Client, policyGroupVersion, nodes, ds.DryRun, nodePodCount, strategy.Params.NamespacedTopologySpreadConstraints) + +} + +// AntiAffinityTerm's topology key value used in predicate metadata +type topologyPair struct { + key string + value string +} + +type podSet map[*v1.Pod]struct{} + +// for each topology pair, what is the set of pods +type topologyPairToPodSetMap map[topologyPair]podSet + +// for each topologyKey, what is the map of topologyKey pairs to pods +type topologyKeyToTopologyPairSetMap map[string]topologyPairToPodSetMap + +// Create a map of Node Name to v1.Node +// for each namespace for which there is Topology Constraint +// for each TopologySpreadyConstraint in that namespace +// find all evictable pods in that namespace +// for each evictable pod in that namespace +// If the pod matches this TopologySpreadConstraint LabelSelector +// If the pod nodeName is present in the nodeMap +// create a topoPair with key as this TopologySpreadConstraint.TopologyKey and value as this pod's Node Label Value for this TopologyKey +// add the pod with key as this topoPair +// find the min number of pods in any topoPair for this topologyKey +// iterate through all topoPairs for this topologyKey and diff currentPods -minPods <=maxSkew +// if diff > maxSkew, add this pod in the current bucket for eviction + +// We get N podLists , one for each TopologyKey in a given Namespace +// Find the pods which are common to each of these podLists +// Evict these Pods +// TODO: Break this down into UT'able functions +func evictPodsViolatingSpreadConstraints( + client clientset.Interface, + policyGroupVersion string, + nodes []*v1.Node, dryRun bool, + nodePodCount nodePodEvictedCount, + namespacedTopologySpreadConstraints []api.NamespacedTopologySpreadConstraint, +) { + + namespaceToTopologyKeySet := make(map[string]topologyKeyToTopologyPairSetMap) + + // create a node map matching nodeName to v1.Node + nodeMap := make(map[string]*v1.Node) + for _, node := range nodes { + nodeMap[node.Name] = node + } + for _, namespacedConstraint := range namespacedTopologySpreadConstraints { + if namespaceToTopologyKeySet[namespacedConstraint.Namespace] == nil { + namespaceToTopologyKeySet[namespacedConstraint.Namespace] = make(topologyKeyToTopologyPairSetMap) + } + for _, topoConstraint := range namespacedConstraint.TopologySpreadConstraints { + if namespaceToTopologyKeySet[namespacedConstraint.Namespace][topoConstraint.TopologyKey] == nil { + namespaceToTopologyKeySet[namespacedConstraint.Namespace][topoConstraint.TopologyKey] = make(topologyPairToPodSetMap) + } + for _, node := range nodes { + if node.Labels[topoConstraint.TopologyKey] == "" { + continue + } + pair := topologyPair{key: topoConstraint.TopologyKey, value: node.Labels[topoConstraint.TopologyKey]} + if namespaceToTopologyKeySet[namespacedConstraint.Namespace][topoConstraint.TopologyKey][pair] == nil { + // this ensures that nodes which match topokey but no pods are accounted for + namespaceToTopologyKeySet[namespacedConstraint.Namespace][topoConstraint.TopologyKey][pair] = make(podSet) + } + } + pods, err := podutil.ListEvictablePodsByNamespace(client, false, namespacedConstraint.Namespace) + if err != nil || len(pods) == 0 { + glog.V(1).Infof("No Evictable pods found for Namespace %v", namespacedConstraint.Namespace) + continue + } + + for _, pod := range pods { + glog.V(2).Infof("Processing pod %v", pod.Name) + // does this pod labels match the constraint label selector + selector, err := metav1.LabelSelectorAsSelector(topoConstraint.LabelSelector) + if err != nil { + glog.V(2).Infof("Pod Labels dont match for %v", pod.Name) + continue + } + if !selector.Matches(labels.Set(pod.Labels)) { + glog.V(2).Infof("Pod Labels dont match for %v", pod.Name) + continue + } + glog.V(1).Infof("Pod %v matched labels", pod.Name) + // TODO: Need to determine if the topokey already present in the node or not + if pod.Spec.NodeName == "" { + continue + } + // see of this pods NodeName exists in the candidates nodes, else ignore + _, ok := nodeMap[pod.Spec.NodeName] + if !ok { + glog.V(2).Infof("Found a node %v in pod %v, which is not present in our map, ignoring it...", pod.Spec.NodeName, pod.Name) + continue + } + pair := topologyPair{key: topoConstraint.TopologyKey, value: nodeMap[pod.Spec.NodeName].Labels[topoConstraint.TopologyKey]} + if namespaceToTopologyKeySet[namespacedConstraint.Namespace][topoConstraint.TopologyKey][pair] == nil { + // this ensures that nodes which match topokey but no pods are accounted for + namespaceToTopologyKeySet[namespacedConstraint.Namespace][topoConstraint.TopologyKey][pair] = make(podSet) + } + namespaceToTopologyKeySet[namespacedConstraint.Namespace][topoConstraint.TopologyKey][pair][pod] = struct{}{} + glog.V(2).Infof("Topo Pair %v, Count %v", pair, len(namespaceToTopologyKeySet[namespacedConstraint.Namespace][topoConstraint.TopologyKey][pair])) + + } + } + } + + // finalPodsToEvict := []*v1.Pod{} + for _, namespacedConstraint := range namespacedTopologySpreadConstraints { + allPodsToEvictPerTopoKey := make(map[string][]*v1.Pod) + for _, topoConstraint := range namespacedConstraint.TopologySpreadConstraints { + minPodsForGivenTopo := math.MaxInt32 + for _, v := range namespaceToTopologyKeySet[namespacedConstraint.Namespace][topoConstraint.TopologyKey] { + if len(v) < minPodsForGivenTopo { + minPodsForGivenTopo = len(v) + } + } + + topologyPairToPods := namespaceToTopologyKeySet[namespacedConstraint.Namespace][topoConstraint.TopologyKey] + for pair, v := range topologyPairToPods { + podsInTopo := len(v) + glog.V(1).Infof("Min Pods in Any Pair %v, pair %v, PodCount %v", minPodsForGivenTopo, pair, podsInTopo) + + if int32(podsInTopo-minPodsForGivenTopo) > topoConstraint.MaxSkew { + countToEvict := int32(podsInTopo-minPodsForGivenTopo) - topoConstraint.MaxSkew + glog.V(1).Infof("pair %v, Count to evict %v", pair, countToEvict) + podsListToEvict := getPodsToEvict(countToEvict, v) + allPodsToEvictPerTopoKey[topoConstraint.TopologyKey] = append(allPodsToEvictPerTopoKey[topoConstraint.TopologyKey], podsListToEvict...) + + } + } + + } + + // TODO: Sometimes we will have hierarchical TopoKeys, like a Building has Rooms and Rooms have Racks + // Our Current Definition of TopologySpreadConstraint Doesnt allow you to capture that Constraint + // If we could capture that Hierarchy, I would do the following:- + // - Create a List of Pods to Evict per TopologyKey + // - Take intersection of all lists to produce a list of pods to evict + // This is because in hierarchical topologyKeys, if we make an indepdent decision of evicting only by + // Rack, but didnt consider the Room spreading at all,we might mess up the Room Spreading. This is too + // constrained though since, if we consider an intersection of all hierarchies, we would not even balance + // properly. So we would need to define some sorta importance of which topologyKey has what weight, etc + // finalPodsToEvict = intersectAllPodsList(allPodsToEvictPerTopoKey) + + // defer the decision as late as possible to cause less schedulings + for topoKey, podList := range allPodsToEvictPerTopoKey { + glog.V(1).Infof("Total pods to evict in TopoKey %v is %v", topoKey, len(podList)) + evictPodsSimple(client, podList, policyGroupVersion, dryRun) + } + } + +} + +func evictPodsSimple(client clientset.Interface, podsListToEvict []*v1.Pod, policyGroupVersion string, dryRun bool) { + for _, podToEvict := range podsListToEvict { + glog.V(1).Infof("Evicting pods %v", podToEvict.Name) + success, err := evictions.EvictPod(client, podToEvict, policyGroupVersion, dryRun) + if !success { + glog.Infof("Error when evicting pod: %#v (%#v)\n", podToEvict.Name, err) + } else { + + } + } +} + +func intersectAllPodsList(allPodsToEvictPerTopoKey map[string][]*v1.Pod) []*v1.Pod { + // increment each pod's count by 1 + // if the pod count reaches the number of topoKeys, it should be evicted + perPodCount := make(map[string]int) + + finalList := []*v1.Pod{} + totalTopoKeys := len(allPodsToEvictPerTopoKey) + glog.V(1).Infof("Total topokeys found %v", totalTopoKeys) + for _, podList := range allPodsToEvictPerTopoKey { + for _, pod := range podList { + key := pod.Name + "-" + pod.Namespace + perPodCount[key] = perPodCount[key] + 1 + if perPodCount[key] == len(allPodsToEvictPerTopoKey) { + finalList = append(finalList, pod) + } + } + } + return finalList +} + +func getPodsToEvict(countToEvict int32, podMap map[*v1.Pod]struct{}) []*v1.Pod { + count := int32(0) + podList := []*v1.Pod{} + for k := range podMap { + if count == countToEvict { + break + } + podList = append(podList, k) + count++ + } + + return podList +} + +func addTopologyPair(topoMap map[topologyPair]podSet, pair topologyPair, pod *v1.Pod) { + if topoMap[pair] == nil { + topoMap[pair] = make(map[*v1.Pod]struct{}) + } + topoMap[pair][pod] = struct{}{} +}