code
stringlengths
12
335k
docstring
stringlengths
20
20.8k
func_name
stringlengths
1
105
language
stringclasses
1 value
repo
stringclasses
498 values
path
stringlengths
5
172
url
stringlengths
43
235
license
stringclasses
4 values
func ParseQuantity(str string) (Quantity, error) { if len(str) == 0 { return Quantity{}, ErrFormatWrong } if str == "0" { return Quantity{Format: DecimalSI, s: str}, nil } positive, value, num, denom, suf, err := parseQuantityString(str) if err != nil { return Quantity{}, err } base, exponent, format, ok := quantitySuffixer.interpret(suffix(suf)) if !ok { return Quantity{}, ErrSuffix } precision := int32(0) scale := int32(0) mantissa := int64(1) switch format { case DecimalExponent, DecimalSI: scale = exponent precision = maxInt64Factors - int32(len(num)+len(denom)) case BinarySI: scale = 0 switch { case exponent >= 0 && len(denom) == 0: // only handle positive binary numbers with the fast path mantissa = int64(int64(mantissa) << uint64(exponent)) // 1Mi (2^20) has ~6 digits of decimal precision, so exponent*3/10 -1 is roughly the precision precision = 15 - int32(len(num)) - int32(float32(exponent)*3/10) - 1 default: precision = -1 } } if precision >= 0 { // if we have a denominator, shift the entire value to the left by the number of places in the // denominator scale -= int32(len(denom)) if scale >= int32(Nano) { shifted := num + denom var value int64 value, err := strconv.ParseInt(shifted, 10, 64) if err != nil { return Quantity{}, ErrNumeric } if result, ok := int64Multiply(value, int64(mantissa)); ok { if !positive { result = -result } // if the number is in canonical form, reuse the string switch format { case BinarySI: if exponent%10 == 0 && (value&0x07 != 0) { return Quantity{i: int64Amount{value: result, scale: Scale(scale)}, Format: format, s: str}, nil } default: if scale%3 == 0 && !strings.HasSuffix(shifted, "000") && shifted[0] != '0' { return Quantity{i: int64Amount{value: result, scale: Scale(scale)}, Format: format, s: str}, nil } } return Quantity{i: int64Amount{value: result, scale: Scale(scale)}, Format: format}, nil } } } amount := new(inf.Dec) if _, ok := amount.SetString(value); !ok { return Quantity{}, ErrNumeric } // So that no one but us has to think about suffixes, remove it. if base == 10 { amount.SetScale(amount.Scale() + Scale(exponent).infScale()) } else if base == 2 { // numericSuffix = 2 ** exponent numericSuffix := big.NewInt(1).Lsh(bigOne, uint(exponent)) ub := amount.UnscaledBig() amount.SetUnscaledBig(ub.Mul(ub, numericSuffix)) } // Cap at min/max bounds. sign := amount.Sign() if sign == -1 { amount.Neg(amount) } // This rounds non-zero values up to the minimum representable value, under the theory that // if you want some resources, you should get some resources, even if you asked for way too small // of an amount. Arguably, this should be inf.RoundHalfUp (normal rounding), but that would have // the side effect of rounding values < .5n to zero. if v, ok := amount.Unscaled(); v != int64(0) || !ok { amount.Round(amount, Nano.infScale(), inf.RoundUp) } // The max is just a simple cap. // TODO: this prevents accumulating quantities greater than int64, for instance quota across a cluster if format == BinarySI && amount.Cmp(maxAllowed.Dec) > 0 { amount.Set(maxAllowed.Dec) } if format == BinarySI && amount.Cmp(decOne) < 0 && amount.Cmp(decZero) > 0 { // This avoids rounding and hopefully confusion, too. format = DecimalSI } if sign == -1 { amount.Neg(amount) } return Quantity{d: infDecAmount{amount}, Format: format}, nil }
ParseQuantity turns str into a Quantity, or returns an error.
ParseQuantity
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
Apache-2.0
func (q Quantity) DeepCopy() Quantity { if q.d.Dec != nil { tmp := &inf.Dec{} q.d.Dec = tmp.Set(q.d.Dec) } return q }
DeepCopy returns a deep-copy of the Quantity value. Note that the method receiver is a value, so we can mutate it in-place and return it.
DeepCopy
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
Apache-2.0
func (_ Quantity) OpenAPISchemaType() []string { return []string{"string"} }
OpenAPISchemaType is used by the kube-openapi generator when constructing the OpenAPI spec of this type. See: https://github.com/kubernetes/kube-openapi/tree/master/pkg/generators
OpenAPISchemaType
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
Apache-2.0
func (_ Quantity) OpenAPISchemaFormat() string { return "" }
OpenAPISchemaFormat is used by the kube-openapi generator when constructing the OpenAPI spec of this type.
OpenAPISchemaFormat
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
Apache-2.0
func (Quantity) OpenAPIV3OneOfTypes() []string { return []string{"string", "number"} }
OpenAPIV3OneOfTypes is used by the kube-openapi generator when constructing the OpenAPI v3 spec of this type.
OpenAPIV3OneOfTypes
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
Apache-2.0
func (q *Quantity) CanonicalizeBytes(out []byte) (result, suffix []byte) { if q.IsZero() { return zeroBytes, nil } var rounded CanonicalValue format := q.Format switch format { case DecimalExponent, DecimalSI: case BinarySI: if q.CmpInt64(-1024) > 0 && q.CmpInt64(1024) < 0 { // This avoids rounding and hopefully confusion, too. format = DecimalSI } else { var exact bool if rounded, exact = q.AsScale(0); !exact { // Don't lose precision-- show as DecimalSI format = DecimalSI } } default: format = DecimalExponent } // TODO: If BinarySI formatting is requested but would cause rounding, upgrade to // one of the other formats. switch format { case DecimalExponent, DecimalSI: number, exponent := q.AsCanonicalBytes(out) suffix, _ := quantitySuffixer.constructBytes(10, exponent, format) return number, suffix default: // format must be BinarySI number, exponent := rounded.AsCanonicalBase1024Bytes(out) suffix, _ := quantitySuffixer.constructBytes(2, exponent*10, format) return number, suffix } }
CanonicalizeBytes returns the canonical form of q and its suffix (see comment on Quantity). Note about BinarySI: - If q.Format is set to BinarySI and q.Amount represents a non-zero value between -1 and +1, it will be emitted as if q.Format were DecimalSI. - Otherwise, if q.Format is set to BinarySI, fractional parts of q.Amount will be rounded up. (1.1i becomes 2i.)
CanonicalizeBytes
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
Apache-2.0
func (q *Quantity) AsApproximateFloat64() float64 { var base float64 var exponent int if q.d.Dec != nil { base, _ = big.NewFloat(0).SetInt(q.d.Dec.UnscaledBig()).Float64() exponent = int(-q.d.Dec.Scale()) } else { base = float64(q.i.value) exponent = int(q.i.scale) } if exponent == 0 { return base } return base * math.Pow10(exponent) }
AsApproximateFloat64 returns a float64 representation of the quantity which may lose precision. If the value of the quantity is outside the range of a float64 +Inf/-Inf will be returned.
AsApproximateFloat64
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
Apache-2.0
func (q *Quantity) AsInt64() (int64, bool) { if q.d.Dec != nil { return 0, false } return q.i.AsInt64() }
AsInt64 returns a representation of the current value as an int64 if a fast conversion is possible. If false is returned, callers must use the inf.Dec form of this quantity.
AsInt64
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
Apache-2.0
func (q *Quantity) ToDec() *Quantity { if q.d.Dec == nil { q.d.Dec = q.i.AsDec() q.i = int64Amount{} } return q }
ToDec promotes the quantity in place to use an inf.Dec representation and returns itself.
ToDec
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
Apache-2.0
func (q *Quantity) AsDec() *inf.Dec { if q.d.Dec != nil { return q.d.Dec } q.d.Dec = q.i.AsDec() q.i = int64Amount{} return q.d.Dec }
AsDec returns the quantity as represented by a scaled inf.Dec.
AsDec
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
Apache-2.0
func (q *Quantity) AsCanonicalBytes(out []byte) (result []byte, exponent int32) { if q.d.Dec != nil { return q.d.AsCanonicalBytes(out) } return q.i.AsCanonicalBytes(out) }
AsCanonicalBytes returns the canonical byte representation of this quantity as a mantissa and base 10 exponent. The out byte slice may be passed to the method to avoid an extra allocation.
AsCanonicalBytes
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
Apache-2.0
func (q *Quantity) IsZero() bool { if q.d.Dec != nil { return q.d.Dec.Sign() == 0 } return q.i.value == 0 }
IsZero returns true if the quantity is equal to zero.
IsZero
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
Apache-2.0
func (q *Quantity) Sign() int { if q.d.Dec != nil { return q.d.Dec.Sign() } return q.i.Sign() }
Sign returns 0 if the quantity is zero, -1 if the quantity is less than zero, or 1 if the quantity is greater than zero.
Sign
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
Apache-2.0
func (q *Quantity) AsScale(scale Scale) (CanonicalValue, bool) { if q.d.Dec != nil { return q.d.AsScale(scale) } return q.i.AsScale(scale) }
AsScale returns the current value, rounded up to the provided scale, and returns false if the scale resulted in a loss of precision.
AsScale
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
Apache-2.0
func (q *Quantity) RoundUp(scale Scale) bool { if q.d.Dec != nil { q.s = "" d, exact := q.d.AsScale(scale) q.d = d return exact } // avoid clearing the string value if we have already calculated it if q.i.scale >= scale { return true } q.s = "" i, exact := q.i.AsScale(scale) q.i = i return exact }
RoundUp updates the quantity to the provided scale, ensuring that the value is at least 1. False is returned if the rounding operation resulted in a loss of precision. Negative numbers are rounded away from zero (-9 scale 1 rounds to -10).
RoundUp
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
Apache-2.0
func (q *Quantity) Add(y Quantity) { q.s = "" if q.d.Dec == nil && y.d.Dec == nil { if q.i.value == 0 { q.Format = y.Format } if q.i.Add(y.i) { return } } else if q.IsZero() { q.Format = y.Format } q.ToDec().d.Dec.Add(q.d.Dec, y.AsDec()) }
Add adds the provide y quantity to the current value. If the current value is zero, the format of the quantity will be updated to the format of y.
Add
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
Apache-2.0
func (q *Quantity) Sub(y Quantity) { q.s = "" if q.IsZero() { q.Format = y.Format } if q.d.Dec == nil && y.d.Dec == nil && q.i.Sub(y.i) { return } q.ToDec().d.Dec.Sub(q.d.Dec, y.AsDec()) }
Sub subtracts the provided quantity from the current value in place. If the current value is zero, the format of the quantity will be updated to the format of y.
Sub
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
Apache-2.0
func (q *Quantity) Mul(y int64) bool { q.s = "" if q.d.Dec == nil && q.i.Mul(y) { return true } return q.ToDec().d.Dec.Mul(q.d.Dec, inf.NewDec(y, inf.Scale(0))).UnscaledBig().IsInt64() }
Mul multiplies the provided y to the current value. It will return false if the result is inexact. Otherwise, it will return true.
Mul
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
Apache-2.0
func (q *Quantity) Cmp(y Quantity) int { if q.d.Dec == nil && y.d.Dec == nil { return q.i.Cmp(y.i) } return q.AsDec().Cmp(y.AsDec()) }
Cmp returns 0 if the quantity is equal to y, -1 if the quantity is less than y, or 1 if the quantity is greater than y.
Cmp
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
Apache-2.0
func (q *Quantity) CmpInt64(y int64) int { if q.d.Dec != nil { return q.d.Dec.Cmp(inf.NewDec(y, inf.Scale(0))) } return q.i.Cmp(int64Amount{value: y}) }
CmpInt64 returns 0 if the quantity is equal to y, -1 if the quantity is less than y, or 1 if the quantity is greater than y.
CmpInt64
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
Apache-2.0
func (q *Quantity) Neg() { q.s = "" if q.d.Dec == nil { q.i.value = -q.i.value return } q.d.Dec.Neg(q.d.Dec) }
Neg sets quantity to be the negative value of itself.
Neg
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
Apache-2.0
func (q Quantity) Equal(v Quantity) bool { return q.Cmp(v) == 0 }
Equal checks equality of two Quantities. This is useful for testing with cmp.Equal.
Equal
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
Apache-2.0
func (q *Quantity) String() string { if q == nil { return "<nil>" } if len(q.s) == 0 { result := make([]byte, 0, int64QuantityExpectedBytes) number, suffix := q.CanonicalizeBytes(result) number = append(number, suffix...) q.s = string(number) } return q.s }
String formats the Quantity as a string, caching the result if not calculated. String is an expensive operation and caching this result significantly reduces the cost of normal parse / marshal operations on Quantity.
String
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
Apache-2.0
func (q Quantity) MarshalJSON() ([]byte, error) { if len(q.s) > 0 { out := make([]byte, len(q.s)+2) out[0], out[len(out)-1] = '"', '"' copy(out[1:], q.s) return out, nil } result := make([]byte, int64QuantityExpectedBytes) result[0] = '"' number, suffix := q.CanonicalizeBytes(result[1:1]) // if the same slice was returned to us that we passed in, avoid another allocation by copying number into // the source slice and returning that if len(number) > 0 && &number[0] == &result[1] && (len(number)+len(suffix)+2) <= int64QuantityExpectedBytes { number = append(number, suffix...) number = append(number, '"') return result[:1+len(number)], nil } // if CanonicalizeBytes needed more space than our slice provided, we may need to allocate again so use // append result = result[:1] result = append(result, number...) result = append(result, suffix...) result = append(result, '"') return result, nil }
MarshalJSON implements the json.Marshaller interface.
MarshalJSON
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
Apache-2.0
func (q Quantity) ToUnstructured() interface{} { return q.String() }
ToUnstructured implements the value.UnstructuredConverter interface.
ToUnstructured
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
Apache-2.0
func (q *Quantity) UnmarshalJSON(value []byte) error { l := len(value) if l == 4 && bytes.Equal(value, []byte("null")) { q.d.Dec = nil q.i = int64Amount{} return nil } if l >= 2 && value[0] == '"' && value[l-1] == '"' { value = value[1 : l-1] } parsed, err := ParseQuantity(strings.TrimSpace(string(value))) if err != nil { return err } // This copy is safe because parsed will not be referred to again. *q = parsed return nil }
UnmarshalJSON implements the json.Unmarshaller interface. TODO: Remove support for leading/trailing whitespace
UnmarshalJSON
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
Apache-2.0
func NewDecimalQuantity(b inf.Dec, format Format) *Quantity { return &Quantity{ d: infDecAmount{&b}, Format: format, } }
NewDecimalQuantity returns a new Quantity representing the given value in the given format.
NewDecimalQuantity
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
Apache-2.0
func NewQuantity(value int64, format Format) *Quantity { return &Quantity{ i: int64Amount{value: value}, Format: format, } }
NewQuantity returns a new Quantity representing the given value in the given format.
NewQuantity
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
Apache-2.0
func NewMilliQuantity(value int64, format Format) *Quantity { return &Quantity{ i: int64Amount{value: value, scale: -3}, Format: format, } }
NewMilliQuantity returns a new Quantity representing the given value * 1/1000 in the given format. Note that BinarySI formatting will round fractional values, and will be changed to DecimalSI for values x where (-1 < x < 1) && (x != 0).
NewMilliQuantity
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
Apache-2.0
func NewScaledQuantity(value int64, scale Scale) *Quantity { return &Quantity{ i: int64Amount{value: value, scale: scale}, Format: DecimalSI, } }
NewScaledQuantity returns a new Quantity representing the given value * 10^scale in DecimalSI format.
NewScaledQuantity
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
Apache-2.0
func (q *Quantity) Value() int64 { return q.ScaledValue(0) }
Value returns the unscaled value of q rounded up to the nearest integer away from 0.
Value
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
Apache-2.0
func (q *Quantity) MilliValue() int64 { return q.ScaledValue(Milli) }
MilliValue returns the value of ceil(q * 1000); this could overflow an int64; if that's a concern, call Value() first to verify the number is small enough.
MilliValue
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
Apache-2.0
func (q *Quantity) ScaledValue(scale Scale) int64 { if q.d.Dec == nil { i, _ := q.i.AsScaledInt64(scale) return i } dec := q.d.Dec return scaledValue(dec.UnscaledBig(), int(dec.Scale()), int(scale.infScale())) }
ScaledValue returns the value of ceil(q / 10^scale). For example, NewQuantity(1, DecimalSI).ScaledValue(Milli) returns 1000. This could overflow an int64. To detect overflow, call Value() first and verify the expected magnitude.
ScaledValue
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
Apache-2.0
func (q *Quantity) Set(value int64) { q.SetScaled(value, 0) }
Set sets q's value to be value.
Set
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
Apache-2.0
func (q *Quantity) SetMilli(value int64) { q.SetScaled(value, Milli) }
SetMilli sets q's value to be value * 1/1000.
SetMilli
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
Apache-2.0
func (q *Quantity) SetScaled(value int64, scale Scale) { q.s = "" q.d.Dec = nil q.i = int64Amount{value: value, scale: scale} }
SetScaled sets q's value to be value * 10^scale
SetScaled
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
Apache-2.0
func (q *QuantityValue) Set(s string) error { quantity, err := ParseQuantity(s) if err != nil { return err } q.Quantity = quantity return nil }
Set implements pflag.Value.Set and Go flag.Value.Set.
Set
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
Apache-2.0
func (q QuantityValue) Type() string { return "quantity" }
Type implements pflag.Value.Type.
Type
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/quantity.go
Apache-2.0
func (s Scale) infScale() inf.Scale { return inf.Scale(-s) // inf.Scale is upside-down }
infScale adapts a Scale value to an inf.Scale value.
infScale
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/resource/amount.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/amount.go
Apache-2.0
func (a int64Amount) Sign() int { switch { case a.value == 0: return 0 case a.value > 0: return 1 default: return -1 } }
Sign returns 0 if the value is zero, -1 if it is less than 0, or 1 if it is greater than 0.
Sign
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/resource/amount.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/amount.go
Apache-2.0
func (a int64Amount) AsInt64() (int64, bool) { if a.scale == 0 { return a.value, true } if a.scale < 0 { // TODO: attempt to reduce factors, although it is assumed that factors are reduced prior // to the int64Amount being created. return 0, false } return positiveScaleInt64(a.value, a.scale) }
AsInt64 returns the current amount as an int64 at scale 0, or false if the value cannot be represented in an int64 OR would result in a loss of precision. This method is intended as an optimization to avoid calling AsDec.
AsInt64
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/resource/amount.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/amount.go
Apache-2.0
func (a int64Amount) AsScaledInt64(scale Scale) (result int64, ok bool) { if a.scale < scale { result, _ = negativeScaleInt64(a.value, scale-a.scale) return result, true } return positiveScaleInt64(a.value, a.scale-scale) }
AsScaledInt64 returns an int64 representing the value of this amount at the specified scale, rounding up, or false if that would result in overflow. (1e20).AsScaledInt64(1) would result in overflow because 1e19 is not representable as an int64. Note that setting a scale larger than the current value may result in loss of precision - i.e. (1e-6).AsScaledInt64(0) would return 1, because 0.000001 is rounded up to 1.
AsScaledInt64
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/resource/amount.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/amount.go
Apache-2.0
func (a int64Amount) AsDec() *inf.Dec { var base inf.Dec base.SetUnscaled(a.value) base.SetScale(inf.Scale(-a.scale)) return &base }
AsDec returns an inf.Dec representation of this value.
AsDec
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/resource/amount.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/amount.go
Apache-2.0
func (a int64Amount) Cmp(b int64Amount) int { switch { case a.scale == b.scale: // compare only the unscaled portion case a.scale > b.scale: result, remainder, exact := divideByScaleInt64(b.value, a.scale-b.scale) if !exact { return a.AsDec().Cmp(b.AsDec()) } if result == a.value { switch { case remainder == 0: return 0 case remainder > 0: return -1 default: return 1 } } b.value = result default: result, remainder, exact := divideByScaleInt64(a.value, b.scale-a.scale) if !exact { return a.AsDec().Cmp(b.AsDec()) } if result == b.value { switch { case remainder == 0: return 0 case remainder > 0: return 1 default: return -1 } } a.value = result } switch { case a.value == b.value: return 0 case a.value < b.value: return -1 default: return 1 } }
Cmp returns 0 if a and b are equal, 1 if a is greater than b, or -1 if a is less than b.
Cmp
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/resource/amount.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/amount.go
Apache-2.0
func (a *int64Amount) Add(b int64Amount) bool { switch { case b.value == 0: return true case a.value == 0: a.value = b.value a.scale = b.scale return true case a.scale == b.scale: c, ok := int64Add(a.value, b.value) if !ok { return false } a.value = c case a.scale > b.scale: c, ok := positiveScaleInt64(a.value, a.scale-b.scale) if !ok { return false } c, ok = int64Add(c, b.value) if !ok { return false } a.scale = b.scale a.value = c default: c, ok := positiveScaleInt64(b.value, b.scale-a.scale) if !ok { return false } c, ok = int64Add(a.value, c) if !ok { return false } a.value = c } return true }
Add adds two int64Amounts together, matching scales. It will return false and not mutate a if overflow or underflow would result.
Add
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/resource/amount.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/amount.go
Apache-2.0
func (a *int64Amount) Sub(b int64Amount) bool { return a.Add(int64Amount{value: -b.value, scale: b.scale}) }
Sub removes the value of b from the current amount, or returns false if underflow would result.
Sub
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/resource/amount.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/amount.go
Apache-2.0
func (a *int64Amount) Mul(b int64) bool { switch { case a.value == 0: return true case b == 0: a.value = 0 a.scale = 0 return true case a.scale == 0: c, ok := int64Multiply(a.value, b) if !ok { return false } a.value = c case a.scale > 0: c, ok := int64Multiply(a.value, b) if !ok { return false } if _, ok = positiveScaleInt64(c, a.scale); !ok { return false } a.value = c default: c, ok := int64Multiply(a.value, b) if !ok { return false } if _, ok = negativeScaleInt64(c, -a.scale); !ok { return false } a.value = c } return true }
Mul multiplies the provided b to the current amount, or returns false if overflow or underflow would result.
Mul
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/resource/amount.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/amount.go
Apache-2.0
func (a int64Amount) AsScale(scale Scale) (int64Amount, bool) { if a.scale >= scale { return a, true } result, exact := negativeScaleInt64(a.value, scale-a.scale) return int64Amount{value: result, scale: scale}, exact }
AsScale adjusts this amount to set a minimum scale, rounding up, and returns true iff no precision was lost. (1.1e5).AsScale(5) would return 1.1e5, but (1.1e5).AsScale(6) would return 1e6.
AsScale
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/resource/amount.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/amount.go
Apache-2.0
func (a int64Amount) AsCanonicalBytes(out []byte) (result []byte, exponent int32) { mantissa := a.value exponent = int32(a.scale) amount, times := removeInt64Factors(mantissa, 10) exponent += int32(times) // make sure exponent is a multiple of 3 var ok bool switch exponent % 3 { case 1, -2: amount, ok = int64MultiplyScale10(amount) if !ok { return infDecAmount{a.AsDec()}.AsCanonicalBytes(out) } exponent = exponent - 1 case 2, -1: amount, ok = int64MultiplyScale100(amount) if !ok { return infDecAmount{a.AsDec()}.AsCanonicalBytes(out) } exponent = exponent - 2 } return strconv.AppendInt(out, amount, 10), exponent }
AsCanonicalBytes accepts a buffer to write the base-10 string value of this field to, and returns either that buffer or a larger buffer and the current exponent of the value. The value is adjusted until the exponent is a multiple of 3 - i.e. 1.1e5 would return "110", 3.
AsCanonicalBytes
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/resource/amount.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/amount.go
Apache-2.0
func (a int64Amount) AsCanonicalBase1024Bytes(out []byte) (result []byte, exponent int32) { value, ok := a.AsScaledInt64(0) if !ok { return infDecAmount{a.AsDec()}.AsCanonicalBase1024Bytes(out) } amount, exponent := removeInt64Factors(value, 1024) return strconv.AppendInt(out, amount, 10), exponent }
AsCanonicalBase1024Bytes accepts a buffer to write the base-1024 string value of this field to, and returns either that buffer or a larger buffer and the current exponent of the value. 2048 is 2 * 1024 ^ 1 and would return []byte("2048"), 1.
AsCanonicalBase1024Bytes
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/resource/amount.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/amount.go
Apache-2.0
func (a infDecAmount) AsScale(scale Scale) (infDecAmount, bool) { tmp := &inf.Dec{} tmp.Round(a.Dec, scale.infScale(), inf.RoundUp) return infDecAmount{tmp}, tmp.Cmp(a.Dec) == 0 }
AsScale adjusts this amount to set a minimum scale, rounding up, and returns true iff no precision was lost. (1.1e5).AsScale(5) would return 1.1e5, but (1.1e5).AsScale(6) would return 1e6.
AsScale
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/resource/amount.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/amount.go
Apache-2.0
func (a infDecAmount) AsCanonicalBytes(out []byte) (result []byte, exponent int32) { mantissa := a.Dec.UnscaledBig() exponent = int32(-a.Dec.Scale()) amount := big.NewInt(0).Set(mantissa) // move all factors of 10 into the exponent for easy reasoning amount, times := removeBigIntFactors(amount, bigTen) exponent += times // make sure exponent is a multiple of 3 for exponent%3 != 0 { amount.Mul(amount, bigTen) exponent-- } return append(out, amount.String()...), exponent }
AsCanonicalBytes accepts a buffer to write the base-10 string value of this field to, and returns either that buffer or a larger buffer and the current exponent of the value. The value is adjusted until the exponent is a multiple of 3 - i.e. 1.1e5 would return "110", 3.
AsCanonicalBytes
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/resource/amount.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/amount.go
Apache-2.0
func (a infDecAmount) AsCanonicalBase1024Bytes(out []byte) (result []byte, exponent int32) { tmp := &inf.Dec{} tmp.Round(a.Dec, 0, inf.RoundUp) amount, exponent := removeBigIntFactors(tmp.UnscaledBig(), big1024) return append(out, amount.String()...), exponent }
AsCanonicalBase1024Bytes accepts a buffer to write the base-1024 string value of this field to, and returns either that buffer or a larger buffer and the current exponent of the value. 2048 is 2 * 1024 ^ 1 and would return []byte("2048"), 1.
AsCanonicalBase1024Bytes
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/resource/amount.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/resource/amount.go
Apache-2.0
func ValidateAnnotations(annotations map[string]string, fldPath *field.Path) field.ErrorList { allErrs := field.ErrorList{} for k := range annotations { // The rule is QualifiedName except that case doesn't matter, so convert to lowercase before checking. for _, msg := range validation.IsQualifiedName(strings.ToLower(k)) { allErrs = append(allErrs, field.Invalid(fldPath, k, msg)) } } if err := ValidateAnnotationsSize(annotations); err != nil { allErrs = append(allErrs, field.TooLong(fldPath, "", TotalAnnotationSizeLimitB)) } return allErrs }
ValidateAnnotations validates that a set of annotations are correctly defined.
ValidateAnnotations
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/validation/objectmeta.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/validation/objectmeta.go
Apache-2.0
func ValidateOwnerReferences(ownerReferences []metav1.OwnerReference, fldPath *field.Path) field.ErrorList { allErrs := field.ErrorList{} firstControllerName := "" for _, ref := range ownerReferences { allErrs = append(allErrs, validateOwnerReference(ref, fldPath)...) if ref.Controller != nil && *ref.Controller { curControllerName := ref.Kind + "/" + ref.Name if firstControllerName != "" { allErrs = append(allErrs, field.Invalid(fldPath, ownerReferences, fmt.Sprintf("Only one reference can have Controller set to true. Found \"true\" in references for %v and %v", firstControllerName, curControllerName))) } else { firstControllerName = curControllerName } } } return allErrs }
ValidateOwnerReferences validates that a set of owner references are correctly defined.
ValidateOwnerReferences
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/validation/objectmeta.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/validation/objectmeta.go
Apache-2.0
func ValidateFinalizerName(stringValue string, fldPath *field.Path) field.ErrorList { allErrs := field.ErrorList{} for _, msg := range validation.IsQualifiedName(stringValue) { allErrs = append(allErrs, field.Invalid(fldPath, stringValue, msg)) } return allErrs }
ValidateFinalizerName validates finalizer names.
ValidateFinalizerName
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/validation/objectmeta.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/validation/objectmeta.go
Apache-2.0
func ValidateNoNewFinalizers(newFinalizers []string, oldFinalizers []string, fldPath *field.Path) field.ErrorList { allErrs := field.ErrorList{} extra := sets.NewString(newFinalizers...).Difference(sets.NewString(oldFinalizers...)) if len(extra) != 0 { allErrs = append(allErrs, field.Forbidden(fldPath, fmt.Sprintf("no new finalizers can be added if the object is being deleted, found new finalizers %#v", extra.List()))) } return allErrs }
ValidateNoNewFinalizers validates the new finalizers has no new finalizers compare to old finalizers.
ValidateNoNewFinalizers
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/validation/objectmeta.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/validation/objectmeta.go
Apache-2.0
func ValidateImmutableField(newVal, oldVal interface{}, fldPath *field.Path) field.ErrorList { allErrs := field.ErrorList{} if !apiequality.Semantic.DeepEqual(oldVal, newVal) { allErrs = append(allErrs, field.Invalid(fldPath, newVal, FieldImmutableErrorMsg)) } return allErrs }
ValidateImmutableField validates the new value and the old value are deeply equal.
ValidateImmutableField
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/validation/objectmeta.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/validation/objectmeta.go
Apache-2.0
func ValidateObjectMeta(objMeta *metav1.ObjectMeta, requiresNamespace bool, nameFn ValidateNameFunc, fldPath *field.Path) field.ErrorList { metadata, err := meta.Accessor(objMeta) if err != nil { var allErrs field.ErrorList allErrs = append(allErrs, field.Invalid(fldPath, objMeta, err.Error())) return allErrs } return ValidateObjectMetaAccessor(metadata, requiresNamespace, nameFn, fldPath) }
ValidateObjectMeta validates an object's metadata on creation. It expects that name generation has already been performed. It doesn't return an error for rootscoped resources with namespace, because namespace should already be cleared before.
ValidateObjectMeta
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/validation/objectmeta.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/validation/objectmeta.go
Apache-2.0
func ValidateObjectMetaAccessor(meta metav1.Object, requiresNamespace bool, nameFn ValidateNameFunc, fldPath *field.Path) field.ErrorList { var allErrs field.ErrorList if len(meta.GetGenerateName()) != 0 { for _, msg := range nameFn(meta.GetGenerateName(), true) { allErrs = append(allErrs, field.Invalid(fldPath.Child("generateName"), meta.GetGenerateName(), msg)) } } // If the generated name validates, but the calculated value does not, it's a problem with generation, and we // report it here. This may confuse users, but indicates a programming bug and still must be validated. // If there are multiple fields out of which one is required then add an or as a separator if len(meta.GetName()) == 0 { allErrs = append(allErrs, field.Required(fldPath.Child("name"), "name or generateName is required")) } else { for _, msg := range nameFn(meta.GetName(), false) { allErrs = append(allErrs, field.Invalid(fldPath.Child("name"), meta.GetName(), msg)) } } if requiresNamespace { if len(meta.GetNamespace()) == 0 { allErrs = append(allErrs, field.Required(fldPath.Child("namespace"), "")) } else { for _, msg := range ValidateNamespaceName(meta.GetNamespace(), false) { allErrs = append(allErrs, field.Invalid(fldPath.Child("namespace"), meta.GetNamespace(), msg)) } } } else { if len(meta.GetNamespace()) != 0 { allErrs = append(allErrs, field.Forbidden(fldPath.Child("namespace"), "not allowed on this type")) } } allErrs = append(allErrs, ValidateNonnegativeField(meta.GetGeneration(), fldPath.Child("generation"))...) allErrs = append(allErrs, v1validation.ValidateLabels(meta.GetLabels(), fldPath.Child("labels"))...) allErrs = append(allErrs, ValidateAnnotations(meta.GetAnnotations(), fldPath.Child("annotations"))...) allErrs = append(allErrs, ValidateOwnerReferences(meta.GetOwnerReferences(), fldPath.Child("ownerReferences"))...) allErrs = append(allErrs, ValidateFinalizers(meta.GetFinalizers(), fldPath.Child("finalizers"))...) allErrs = append(allErrs, v1validation.ValidateManagedFields(meta.GetManagedFields(), fldPath.Child("managedFields"))...) return allErrs }
ValidateObjectMetaAccessor validates an object's metadata on creation. It expects that name generation has already been performed. It doesn't return an error for rootscoped resources with namespace, because namespace should already be cleared before.
ValidateObjectMetaAccessor
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/validation/objectmeta.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/validation/objectmeta.go
Apache-2.0
func ValidateFinalizers(finalizers []string, fldPath *field.Path) field.ErrorList { allErrs := field.ErrorList{} hasFinalizerOrphanDependents := false hasFinalizerDeleteDependents := false for _, finalizer := range finalizers { allErrs = append(allErrs, ValidateFinalizerName(finalizer, fldPath)...) if finalizer == metav1.FinalizerOrphanDependents { hasFinalizerOrphanDependents = true } if finalizer == metav1.FinalizerDeleteDependents { hasFinalizerDeleteDependents = true } } if hasFinalizerDeleteDependents && hasFinalizerOrphanDependents { allErrs = append(allErrs, field.Invalid(fldPath, finalizers, fmt.Sprintf("finalizer %s and %s cannot be both set", metav1.FinalizerOrphanDependents, metav1.FinalizerDeleteDependents))) } return allErrs }
ValidateFinalizers tests if the finalizers name are valid, and if there are conflicting finalizers.
ValidateFinalizers
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/validation/objectmeta.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/validation/objectmeta.go
Apache-2.0
func ValidateObjectMetaUpdate(newMeta, oldMeta *metav1.ObjectMeta, fldPath *field.Path) field.ErrorList { newMetadata, err := meta.Accessor(newMeta) if err != nil { allErrs := field.ErrorList{} allErrs = append(allErrs, field.Invalid(fldPath, newMeta, err.Error())) return allErrs } oldMetadata, err := meta.Accessor(oldMeta) if err != nil { allErrs := field.ErrorList{} allErrs = append(allErrs, field.Invalid(fldPath, oldMeta, err.Error())) return allErrs } return ValidateObjectMetaAccessorUpdate(newMetadata, oldMetadata, fldPath) }
ValidateObjectMetaUpdate validates an object's metadata when updated.
ValidateObjectMetaUpdate
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/validation/objectmeta.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/validation/objectmeta.go
Apache-2.0
func ValidateObjectMetaAccessorUpdate(newMeta, oldMeta metav1.Object, fldPath *field.Path) field.ErrorList { var allErrs field.ErrorList // Finalizers cannot be added if the object is already being deleted. if oldMeta.GetDeletionTimestamp() != nil { allErrs = append(allErrs, ValidateNoNewFinalizers(newMeta.GetFinalizers(), oldMeta.GetFinalizers(), fldPath.Child("finalizers"))...) } // Reject updates that don't specify a resource version if len(newMeta.GetResourceVersion()) == 0 { allErrs = append(allErrs, field.Invalid(fldPath.Child("resourceVersion"), newMeta.GetResourceVersion(), "must be specified for an update")) } // Generation shouldn't be decremented if newMeta.GetGeneration() < oldMeta.GetGeneration() { allErrs = append(allErrs, field.Invalid(fldPath.Child("generation"), newMeta.GetGeneration(), "must not be decremented")) } allErrs = append(allErrs, ValidateImmutableField(newMeta.GetName(), oldMeta.GetName(), fldPath.Child("name"))...) allErrs = append(allErrs, ValidateImmutableField(newMeta.GetNamespace(), oldMeta.GetNamespace(), fldPath.Child("namespace"))...) allErrs = append(allErrs, ValidateImmutableField(newMeta.GetUID(), oldMeta.GetUID(), fldPath.Child("uid"))...) allErrs = append(allErrs, ValidateImmutableField(newMeta.GetCreationTimestamp(), oldMeta.GetCreationTimestamp(), fldPath.Child("creationTimestamp"))...) allErrs = append(allErrs, ValidateImmutableField(newMeta.GetDeletionTimestamp(), oldMeta.GetDeletionTimestamp(), fldPath.Child("deletionTimestamp"))...) allErrs = append(allErrs, ValidateImmutableField(newMeta.GetDeletionGracePeriodSeconds(), oldMeta.GetDeletionGracePeriodSeconds(), fldPath.Child("deletionGracePeriodSeconds"))...) allErrs = append(allErrs, v1validation.ValidateLabels(newMeta.GetLabels(), fldPath.Child("labels"))...) allErrs = append(allErrs, ValidateAnnotations(newMeta.GetAnnotations(), fldPath.Child("annotations"))...) allErrs = append(allErrs, ValidateOwnerReferences(newMeta.GetOwnerReferences(), fldPath.Child("ownerReferences"))...) allErrs = append(allErrs, v1validation.ValidateManagedFields(newMeta.GetManagedFields(), fldPath.Child("managedFields"))...) return allErrs }
ValidateObjectMetaAccessorUpdate validates an object's metadata when updated.
ValidateObjectMetaAccessorUpdate
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/validation/objectmeta.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/validation/objectmeta.go
Apache-2.0
func NameIsDNSSubdomain(name string, prefix bool) []string { if prefix { name = maskTrailingDash(name) } return validation.IsDNS1123Subdomain(name) }
NameIsDNSSubdomain is a ValidateNameFunc for names that must be a DNS subdomain.
NameIsDNSSubdomain
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/validation/generic.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/validation/generic.go
Apache-2.0
func NameIsDNSLabel(name string, prefix bool) []string { if prefix { name = maskTrailingDash(name) } return validation.IsDNS1123Label(name) }
NameIsDNSLabel is a ValidateNameFunc for names that must be a DNS 1123 label.
NameIsDNSLabel
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/validation/generic.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/validation/generic.go
Apache-2.0
func NameIsDNS1035Label(name string, prefix bool) []string { if prefix { name = maskTrailingDash(name) } return validation.IsDNS1035Label(name) }
NameIsDNS1035Label is a ValidateNameFunc for names that must be a DNS 952 label.
NameIsDNS1035Label
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/validation/generic.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/validation/generic.go
Apache-2.0
func maskTrailingDash(name string) string { if len(name) > 1 && strings.HasSuffix(name, "-") { return name[:len(name)-2] + "a" } return name }
maskTrailingDash replaces the final character of a string with a subdomain safe value if it is a dash and if the length of this string is greater than 1. Note that this is used when a value could be appended to the string, see ValidateNameFunc for more info.
maskTrailingDash
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/validation/generic.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/validation/generic.go
Apache-2.0
func ValidateNonnegativeField(value int64, fldPath *field.Path) field.ErrorList { allErrs := field.ErrorList{} if value < 0 { allErrs = append(allErrs, field.Invalid(fldPath, value, IsNegativeErrorMsg)) } return allErrs }
ValidateNonnegativeField validates that given value is not negative.
ValidateNonnegativeField
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/api/validation/generic.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/api/validation/generic.go
Apache-2.0
func NewConverter(NameFunc) *Converter { c := &Converter{ conversionFuncs: NewConversionFuncs(), generatedConversionFuncs: NewConversionFuncs(), ignoredUntypedConversions: make(map[typePair]struct{}), } c.RegisterUntypedConversionFunc( (*[]byte)(nil), (*[]byte)(nil), func(a, b interface{}, s Scope) error { return Convert_Slice_byte_To_Slice_byte(a.(*[]byte), b.(*[]byte), s) }, ) return c }
NewConverter creates a new Converter object. Arg NameFunc is just for backward compatibility.
NewConverter
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/conversion/converter.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/conversion/converter.go
Apache-2.0
func Convert_Slice_byte_To_Slice_byte(in *[]byte, out *[]byte, s Scope) error { if *in == nil { *out = nil return nil } *out = make([]byte, len(*in)) copy(*out, *in) return nil }
Convert_Slice_byte_To_Slice_byte prevents recursing into every byte
Convert_Slice_byte_To_Slice_byte
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/conversion/converter.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/conversion/converter.go
Apache-2.0
func EqualitiesOrDie(funcs ...interface{}) Equalities { e := Equalities{reflect.Equalities{}} if err := e.AddFuncs(funcs...); err != nil { panic(err) } return e }
For convenience, panics on errors
EqualitiesOrDie
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/conversion/deep_equal.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/conversion/deep_equal.go
Apache-2.0
func (e Equalities) Copy() Equalities { result := Equalities{reflect.Equalities{}} for key, value := range e.Equalities { result.Equalities[key] = value } return result }
Performs a shallow copy of the equalities map
Copy
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/conversion/deep_equal.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/conversion/deep_equal.go
Apache-2.0
func EnforcePtr(obj interface{}) (reflect.Value, error) { v := reflect.ValueOf(obj) if v.Kind() != reflect.Pointer { if v.Kind() == reflect.Invalid { return reflect.Value{}, fmt.Errorf("expected pointer, but got invalid kind") } return reflect.Value{}, fmt.Errorf("expected pointer, but got %v type", v.Type()) } if v.IsNil() { return reflect.Value{}, fmt.Errorf("expected pointer, but got nil") } return v.Elem(), nil }
EnforcePtr ensures that obj is a pointer of some sort. Returns a reflect.Value of the dereferenced pointer, ensuring that it is settable/addressable. Returns an error if this is not possible.
EnforcePtr
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/conversion/helper.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/conversion/helper.go
Apache-2.0
func Convert(obj interface{}) (url.Values, error) { result := url.Values{} if obj == nil { return result, nil } var sv reflect.Value switch reflect.TypeOf(obj).Kind() { case reflect.Pointer, reflect.Interface: sv = reflect.ValueOf(obj).Elem() default: return nil, fmt.Errorf("expecting a pointer or interface") } st := sv.Type() if !isStructKind(st.Kind()) { return nil, fmt.Errorf("expecting a pointer to a struct") } // Check all object fields convertStruct(result, st, sv) return result, nil }
Convert takes an object and converts it to a url.Values object using JSON tags as parameter names. Only top-level simple values, arrays, and slices are serialized. Embedded structs, maps, etc. will not be serialized.
Convert
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/conversion/queryparams/convert.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/conversion/queryparams/convert.go
Apache-2.0
func NewCodec(e Encoder, d Decoder) Codec { return codec{e, d} }
NewCodec creates a Codec from an Encoder and Decoder.
NewCodec
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/runtime/codec.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/codec.go
Apache-2.0
func Encode(e Encoder, obj Object) ([]byte, error) { buf := &bytes.Buffer{} if err := e.Encode(obj, buf); err != nil { return nil, err } return buf.Bytes(), nil }
Encode is a convenience wrapper for encoding to a []byte from an Encoder
Encode
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/runtime/codec.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/codec.go
Apache-2.0
func Decode(d Decoder, data []byte) (Object, error) { obj, _, err := d.Decode(data, nil, nil) return obj, err }
Decode is a convenience wrapper for decoding data into an Object.
Decode
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/runtime/codec.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/codec.go
Apache-2.0
func DecodeInto(d Decoder, data []byte, into Object) error { out, gvk, err := d.Decode(data, nil, into) if err != nil { return err } if out != into { return fmt.Errorf("unable to decode %s into %v", gvk, reflect.TypeOf(into)) } return nil }
DecodeInto performs a Decode into the provided object.
DecodeInto
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/runtime/codec.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/codec.go
Apache-2.0
func EncodeOrDie(e Encoder, obj Object) string { bytes, err := Encode(e, obj) if err != nil { panic(err) } return string(bytes) }
EncodeOrDie is a version of Encode which will panic instead of returning an error. For tests.
EncodeOrDie
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/runtime/codec.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/codec.go
Apache-2.0
func UseOrCreateObject(t ObjectTyper, c ObjectCreater, gvk schema.GroupVersionKind, obj Object) (Object, error) { if obj != nil { kinds, _, err := t.ObjectKinds(obj) if err != nil { return nil, err } for _, kind := range kinds { if gvk == kind { return obj, nil } } } return c.New(gvk) }
UseOrCreateObject returns obj if the canonical ObjectKind returned by the provided typer matches gvk, or invokes the ObjectCreator to instantiate a new gvk. Returns an error if the typer cannot find the object.
UseOrCreateObject
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/runtime/codec.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/codec.go
Apache-2.0
func (n NoopEncoder) Identifier() Identifier { return noopEncoderIdentifier }
Identifier implements runtime.Encoder interface.
Identifier
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/runtime/codec.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/codec.go
Apache-2.0
func NewParameterCodec(scheme *Scheme) ParameterCodec { return &parameterCodec{ typer: scheme, convertor: scheme, creator: scheme, defaulter: scheme, } }
NewParameterCodec creates a ParameterCodec capable of transforming url values into versioned objects and back.
NewParameterCodec
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/runtime/codec.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/codec.go
Apache-2.0
func (c *parameterCodec) DecodeParameters(parameters url.Values, from schema.GroupVersion, into Object) error { if len(parameters) == 0 { return nil } targetGVKs, _, err := c.typer.ObjectKinds(into) if err != nil { return err } for i := range targetGVKs { if targetGVKs[i].GroupVersion() == from { if err := c.convertor.Convert(&parameters, into, nil); err != nil { return err } // in the case where we going into the same object we're receiving, default on the outbound object if c.defaulter != nil { c.defaulter.Default(into) } return nil } } input, err := c.creator.New(from.WithKind(targetGVKs[0].Kind)) if err != nil { return err } if err := c.convertor.Convert(&parameters, input, nil); err != nil { return err } // if we have defaulter, default the input before converting to output if c.defaulter != nil { c.defaulter.Default(input) } return c.convertor.Convert(input, into, nil) }
DecodeParameters converts the provided url.Values into an object of type From with the kind of into, and then converts that object to into (if necessary). Returns an error if the operation cannot be completed.
DecodeParameters
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/runtime/codec.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/codec.go
Apache-2.0
func (c *parameterCodec) EncodeParameters(obj Object, to schema.GroupVersion) (url.Values, error) { gvks, _, err := c.typer.ObjectKinds(obj) if err != nil { return nil, err } gvk := gvks[0] if to != gvk.GroupVersion() { out, err := c.convertor.ConvertToVersion(obj, to) if err != nil { return nil, err } obj = out } return queryparams.Convert(obj) }
EncodeParameters converts the provided object into the to version, then converts that object to url.Values. Returns an error if conversion is not possible.
EncodeParameters
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/runtime/codec.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/codec.go
Apache-2.0
func (s base64Serializer) Identifier() Identifier { return s.identifier }
Identifier implements runtime.Encoder interface.
Identifier
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/runtime/codec.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/codec.go
Apache-2.0
func SerializerInfoForMediaType(types []SerializerInfo, mediaType string) (SerializerInfo, bool) { for _, info := range types { if info.MediaType == mediaType { return info, true } } for _, info := range types { if len(info.MediaType) == 0 { return info, true } } return SerializerInfo{}, false }
SerializerInfoForMediaType returns the first info in types that has a matching media type (which cannot include media-type parameters), or the first info with an empty media type, or false if no type matches.
SerializerInfoForMediaType
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/runtime/codec.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/codec.go
Apache-2.0
func (internalGroupVersioner) KindForGroupVersionKinds(kinds []schema.GroupVersionKind) (schema.GroupVersionKind, bool) { for _, kind := range kinds { if kind.Version == APIVersionInternal { return kind, true } } for _, kind := range kinds { return schema.GroupVersionKind{Group: kind.Group, Version: APIVersionInternal, Kind: kind.Kind}, true } return schema.GroupVersionKind{}, false }
KindForGroupVersionKinds returns an internal Kind if one is found, or converts the first provided kind to the internal version.
KindForGroupVersionKinds
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/runtime/codec.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/codec.go
Apache-2.0
func (internalGroupVersioner) Identifier() string { return internalGroupVersionerIdentifier }
Identifier implements GroupVersioner interface.
Identifier
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/runtime/codec.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/codec.go
Apache-2.0
func (disabledGroupVersioner) KindForGroupVersionKinds(kinds []schema.GroupVersionKind) (schema.GroupVersionKind, bool) { return schema.GroupVersionKind{}, false }
KindForGroupVersionKinds returns false for any input.
KindForGroupVersionKinds
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/runtime/codec.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/codec.go
Apache-2.0
func (disabledGroupVersioner) Identifier() string { return disabledGroupVersionerIdentifier }
Identifier implements GroupVersioner interface.
Identifier
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/runtime/codec.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/codec.go
Apache-2.0
func NewMultiGroupVersioner(gv schema.GroupVersion, groupKinds ...schema.GroupKind) GroupVersioner { if len(groupKinds) == 0 || (len(groupKinds) == 1 && groupKinds[0].Group == gv.Group) { return gv } return multiGroupVersioner{target: gv, acceptedGroupKinds: groupKinds} }
NewMultiGroupVersioner returns the provided group version for any kind that matches one of the provided group kinds. Kind may be empty in the provided group kind, in which case any kind will match.
NewMultiGroupVersioner
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/runtime/codec.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/codec.go
Apache-2.0
func NewCoercingMultiGroupVersioner(gv schema.GroupVersion, groupKinds ...schema.GroupKind) GroupVersioner { return multiGroupVersioner{target: gv, acceptedGroupKinds: groupKinds, coerce: true} }
NewCoercingMultiGroupVersioner returns the provided group version for any incoming kind. Incoming kinds that match the provided groupKinds are preferred. Kind may be empty in the provided group kind, in which case any kind will match. Examples: gv=mygroup/__internal, groupKinds=mygroup/Foo, anothergroup/Bar KindForGroupVersionKinds(yetanother/v1/Baz, anothergroup/v1/Bar) -> mygroup/__internal/Bar (matched preferred group/kind) gv=mygroup/__internal, groupKinds=mygroup, anothergroup KindForGroupVersionKinds(yetanother/v1/Baz, anothergroup/v1/Bar) -> mygroup/__internal/Bar (matched preferred group) gv=mygroup/__internal, groupKinds=mygroup, anothergroup KindForGroupVersionKinds(yetanother/v1/Baz, yetanother/v1/Bar) -> mygroup/__internal/Baz (no preferred group/kind match, uses first kind in list)
NewCoercingMultiGroupVersioner
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/runtime/codec.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/codec.go
Apache-2.0
func (v multiGroupVersioner) KindForGroupVersionKinds(kinds []schema.GroupVersionKind) (schema.GroupVersionKind, bool) { for _, src := range kinds { for _, kind := range v.acceptedGroupKinds { if kind.Group != src.Group { continue } if len(kind.Kind) > 0 && kind.Kind != src.Kind { continue } return v.target.WithKind(src.Kind), true } } if v.coerce && len(kinds) > 0 { return v.target.WithKind(kinds[0].Kind), true } return schema.GroupVersionKind{}, false }
KindForGroupVersionKinds returns the target group version if any kind matches any of the original group kinds. It will use the originating kind where possible.
KindForGroupVersionKinds
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/runtime/codec.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/codec.go
Apache-2.0
func (v multiGroupVersioner) Identifier() string { groupKinds := make([]string, 0, len(v.acceptedGroupKinds)) for _, gk := range v.acceptedGroupKinds { groupKinds = append(groupKinds, gk.String()) } result := map[string]string{ "name": "multi", "target": v.target.String(), "accepted": strings.Join(groupKinds, ","), "coerce": strconv.FormatBool(v.coerce), } identifier, err := json.Marshal(result) if err != nil { klog.Fatalf("Failed marshaling Identifier for %#v: %v", v, err) } return string(identifier) }
Identifier implements GroupVersioner interface.
Identifier
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/runtime/codec.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/codec.go
Apache-2.0
func NewEquivalentResourceRegistry() EquivalentResourceRegistry { return &equivalentResourceRegistry{} }
NewEquivalentResourceRegistry creates a resource registry that considers all versions of a GroupResource to be equivalent.
NewEquivalentResourceRegistry
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/runtime/mapper.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/mapper.go
Apache-2.0
func NewEquivalentResourceRegistryWithIdentity(keyFunc func(schema.GroupResource) string) EquivalentResourceRegistry { return &equivalentResourceRegistry{keyFunc: keyFunc} }
NewEquivalentResourceRegistryWithIdentity creates a resource mapper with a custom identity function. If "" is returned by the function, GroupResource#String is used as the identity. GroupResources with the same identity string are considered equivalent.
NewEquivalentResourceRegistryWithIdentity
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/runtime/mapper.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/mapper.go
Apache-2.0
func NewEncodable(e Encoder, obj Object, versions ...schema.GroupVersion) Object { if _, ok := obj.(*Unknown); ok { return obj } return encodable{e, obj, versions} }
NewEncodable creates an object that will be encoded with the provided codec on demand. Provided as a convenience for test cases dealing with internal objects.
NewEncodable
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/runtime/embedded.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/embedded.go
Apache-2.0
func (e encodable) MarshalJSON() ([]byte, error) { return Encode(e.E, e.obj) }
Marshal may get called on pointers or values, so implement MarshalJSON on value. http://stackoverflow.com/questions/21390979/custom-marshaljson-never-gets-called-in-go
MarshalJSON
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/runtime/embedded.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/embedded.go
Apache-2.0
func NewEncodableList(e Encoder, objects []Object, versions ...schema.GroupVersion) []Object { out := make([]Object, len(objects)) for i := range objects { if _, ok := objects[i].(*Unknown); ok { out[i] = objects[i] continue } out[i] = NewEncodable(e, objects[i], versions...) } return out }
NewEncodableList creates an object that will be encoded with the provided codec on demand. Provided as a convenience for test cases dealing with internal objects.
NewEncodableList
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/runtime/embedded.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/embedded.go
Apache-2.0
func (e Unknown) MarshalJSON() ([]byte, error) { // If ContentType is unset, we assume this is JSON. if e.ContentType != "" && e.ContentType != ContentTypeJSON { return nil, errors.New("runtime.Unknown: MarshalJSON on non-json data") } if e.Raw == nil { return []byte("null"), nil } return e.Raw, nil }
Marshal may get called on pointers or values, so implement MarshalJSON on value. http://stackoverflow.com/questions/21390979/custom-marshaljson-never-gets-called-in-go
MarshalJSON
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/runtime/embedded.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/embedded.go
Apache-2.0