Skip to content

Commit

Permalink
chore: Get latest apimachinery files
Browse files Browse the repository at this point in the history
Made with ❤️️ by updatecli

Signed-off-by: José Guilherme Vanz <[email protected]>
  • Loading branch information
chimera-kube-bot authored and jvanz committed Sep 9, 2024
1 parent c778fd4 commit 9520ca1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
6 changes: 2 additions & 4 deletions third_party/k8s.io/apimachinery/pkg/api/resource/math.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@ var (
MaxMilliValue = int64(((1 << 63) - 1) / 1000)
)

const (
mostNegative = -(mostPositive + 1)
mostPositive = 1<<63 - 1
)
const mostNegative = -(mostPositive + 1)
const mostPositive = 1<<63 - 1

// int64Add returns a+b, or false if that would overflow int64.
func int64Add(a, b int64) (int64, bool) {
Expand Down
29 changes: 29 additions & 0 deletions third_party/k8s.io/apimachinery/pkg/api/resource/quantity.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"strconv"
"strings"

cbor "k8s.io/apimachinery/pkg/runtime/serializer/cbor/direct"

inf "gopkg.in/inf.v0"
)

Expand Down Expand Up @@ -683,6 +685,12 @@ func (q Quantity) MarshalJSON() ([]byte, error) {
return result, nil
}

func (q Quantity) MarshalCBOR() ([]byte, error) {
// The call to String() should never return the string "<nil>" because the receiver's
// address will never be nil.
return cbor.Marshal(q.String())
}

// ToUnstructured implements the value.UnstructuredConverter interface.
func (q Quantity) ToUnstructured() interface{} {
return q.String()
Expand Down Expand Up @@ -711,6 +719,27 @@ func (q *Quantity) UnmarshalJSON(value []byte) error {
return nil
}

func (q *Quantity) UnmarshalCBOR(value []byte) error {
var s *string
if err := cbor.Unmarshal(value, &s); err != nil {
return err
}

if s == nil {
q.d.Dec = nil
q.i = int64Amount{}
return nil
}

parsed, err := ParseQuantity(strings.TrimSpace(*s))
if err != nil {
return err
}

*q = parsed
return nil
}

// NewDecimalQuantity returns a new Quantity representing the given
// value in the given format.
func NewDecimalQuantity(b inf.Dec, format Format) *Quantity {
Expand Down

0 comments on commit 9520ca1

Please sign in to comment.