update kube dependencies to v1.24.0 release

Signed-off-by: Humble Chirammal <hchiramm@redhat.com>
This commit is contained in:
Humble Chirammal
2022-05-05 08:33:48 +05:30
parent 9ffdb95103
commit 4b1dd81de1
828 changed files with 68259 additions and 16176 deletions

View File

@@ -234,6 +234,7 @@ type decodeState struct {
savedStrictErrors []error
seenStrictErrors map[string]struct{}
strictFieldStack []string
caseSensitive bool
@@ -261,6 +262,8 @@ func (d *decodeState) init(data []byte) *decodeState {
// Reuse the allocated space for the FieldStack slice.
d.errorContext.FieldStack = d.errorContext.FieldStack[:0]
}
// Reuse the allocated space for the strict FieldStack slice.
d.strictFieldStack = d.strictFieldStack[:0]
return d
}
@@ -555,6 +558,12 @@ func (d *decodeState) array(v reflect.Value) error {
break
}
origStrictFieldStackLen := len(d.strictFieldStack)
defer func() {
// Reset to original length and reuse the allocated space for the strict FieldStack slice.
d.strictFieldStack = d.strictFieldStack[:origStrictFieldStackLen]
}()
i := 0
for {
// Look ahead for ] - can only happen on first iteration.
@@ -580,6 +589,7 @@ func (d *decodeState) array(v reflect.Value) error {
}
}
d.appendStrictFieldStackIndex(i)
if i < v.Len() {
// Decode into element.
if err := d.value(v.Index(i)); err != nil {
@@ -591,6 +601,8 @@ func (d *decodeState) array(v reflect.Value) error {
return err
}
}
// Reset to original length and reuse the allocated space for the strict FieldStack slice.
d.strictFieldStack = d.strictFieldStack[:origStrictFieldStackLen]
i++
// Next token must be , or ].
@@ -683,7 +695,7 @@ func (d *decodeState) object(v reflect.Value) error {
seenKeys = map[string]struct{}{}
}
if _, seen := seenKeys[fieldName]; seen {
d.saveStrictError(fmt.Errorf("duplicate field %q", fieldName))
d.saveStrictError(d.newFieldError("duplicate field", fieldName))
} else {
seenKeys[fieldName] = struct{}{}
}
@@ -699,7 +711,7 @@ func (d *decodeState) object(v reflect.Value) error {
var seenKeys uint64
checkDuplicateField = func(fieldNameIndex int, fieldName string) {
if seenKeys&(1<<fieldNameIndex) != 0 {
d.saveStrictError(fmt.Errorf("duplicate field %q", fieldName))
d.saveStrictError(d.newFieldError("duplicate field", fieldName))
} else {
seenKeys = seenKeys | (1 << fieldNameIndex)
}
@@ -712,7 +724,7 @@ func (d *decodeState) object(v reflect.Value) error {
seenIndexes = make([]bool, len(fields.list))
}
if seenIndexes[fieldNameIndex] {
d.saveStrictError(fmt.Errorf("duplicate field %q", fieldName))
d.saveStrictError(d.newFieldError("duplicate field", fieldName))
} else {
seenIndexes[fieldNameIndex] = true
}
@@ -732,6 +744,7 @@ func (d *decodeState) object(v reflect.Value) error {
if d.errorContext != nil {
origErrorContext = *d.errorContext
}
origStrictFieldStackLen := len(d.strictFieldStack)
for {
// Read opening " of string key or closing }.
@@ -768,6 +781,7 @@ func (d *decodeState) object(v reflect.Value) error {
if checkDuplicateField != nil {
checkDuplicateField(0, string(key))
}
d.appendStrictFieldStackKey(string(key))
} else {
var f *field
if i, ok := fields.nameIndex[string(key)]; ok {
@@ -820,8 +834,9 @@ func (d *decodeState) object(v reflect.Value) error {
}
d.errorContext.FieldStack = append(d.errorContext.FieldStack, f.name)
d.errorContext.Struct = t
d.appendStrictFieldStackKey(f.name)
} else if d.disallowUnknownFields {
d.saveStrictError(fmt.Errorf("unknown field %q", key))
d.saveStrictError(d.newFieldError("unknown field", string(key)))
}
}
@@ -905,6 +920,8 @@ func (d *decodeState) object(v reflect.Value) error {
d.errorContext.FieldStack = d.errorContext.FieldStack[:len(origErrorContext.FieldStack)]
d.errorContext.Struct = origErrorContext.Struct
}
// Reset to original length and reuse the allocated space for the strict FieldStack slice.
d.strictFieldStack = d.strictFieldStack[:origStrictFieldStackLen]
if d.opcode == scanEndObject {
break
}
@@ -1141,6 +1158,12 @@ func (d *decodeState) valueInterface() (val interface{}) {
// arrayInterface is like array but returns []interface{}.
func (d *decodeState) arrayInterface() []interface{} {
origStrictFieldStackLen := len(d.strictFieldStack)
defer func() {
// Reset to original length and reuse the allocated space for the strict FieldStack slice.
d.strictFieldStack = d.strictFieldStack[:origStrictFieldStackLen]
}()
var v = make([]interface{}, 0)
for {
// Look ahead for ] - can only happen on first iteration.
@@ -1149,7 +1172,10 @@ func (d *decodeState) arrayInterface() []interface{} {
break
}
d.appendStrictFieldStackIndex(len(v))
v = append(v, d.valueInterface())
// Reset to original length and reuse the allocated space for the strict FieldStack slice.
d.strictFieldStack = d.strictFieldStack[:origStrictFieldStackLen]
// Next token must be , or ].
if d.opcode == scanSkipSpace {
@@ -1167,6 +1193,12 @@ func (d *decodeState) arrayInterface() []interface{} {
// objectInterface is like object but returns map[string]interface{}.
func (d *decodeState) objectInterface() map[string]interface{} {
origStrictFieldStackLen := len(d.strictFieldStack)
defer func() {
// Reset to original length and reuse the allocated space for the strict FieldStack slice.
d.strictFieldStack = d.strictFieldStack[:origStrictFieldStackLen]
}()
m := make(map[string]interface{})
for {
// Read opening " of string key or closing }.
@@ -1199,12 +1231,15 @@ func (d *decodeState) objectInterface() map[string]interface{} {
if d.disallowDuplicateFields {
if _, exists := m[key]; exists {
d.saveStrictError(fmt.Errorf("duplicate field %q", key))
d.saveStrictError(d.newFieldError("duplicate field", key))
}
}
// Read value.
d.appendStrictFieldStackKey(key)
m[key] = d.valueInterface()
// Reset to original length and reuse the allocated space for the strict FieldStack slice.
d.strictFieldStack = d.strictFieldStack[:origStrictFieldStackLen]
// Next token must be , or }.
if d.opcode == scanSkipSpace {

View File

@@ -18,6 +18,8 @@ package json
import (
gojson "encoding/json"
"fmt"
"strconv"
"strings"
)
@@ -69,6 +71,14 @@ func (d *Decoder) DisallowDuplicateFields() {
d.d.disallowDuplicateFields = true
}
func (d *decodeState) newFieldError(msg, field string) error {
if len(d.strictFieldStack) > 0 {
return fmt.Errorf("%s %q", msg, strings.Join(d.strictFieldStack, "")+"."+field)
} else {
return fmt.Errorf("%s %q", msg, field)
}
}
// saveStrictError saves a strict decoding error,
// for reporting at the end of the unmarshal if no other errors occurred.
func (d *decodeState) saveStrictError(err error) {
@@ -90,6 +100,24 @@ func (d *decodeState) saveStrictError(err error) {
d.savedStrictErrors = append(d.savedStrictErrors, err)
}
func (d *decodeState) appendStrictFieldStackKey(key string) {
if !d.disallowDuplicateFields && !d.disallowUnknownFields {
return
}
if len(d.strictFieldStack) > 0 {
d.strictFieldStack = append(d.strictFieldStack, ".", key)
} else {
d.strictFieldStack = append(d.strictFieldStack, key)
}
}
func (d *decodeState) appendStrictFieldStackIndex(i int) {
if !d.disallowDuplicateFields && !d.disallowUnknownFields {
return
}
d.strictFieldStack = append(d.strictFieldStack, "[", strconv.Itoa(i), "]")
}
// UnmarshalStrictError holds errors resulting from use of strict disallow___ decoder directives.
// If this is returned from Unmarshal(), it means the decoding was successful in all other respects.
type UnmarshalStrictError struct {

View File

@@ -17,8 +17,6 @@ limitations under the License.
package typed
import (
"math"
"sigs.k8s.io/structured-merge-diff/v4/fieldpath"
"sigs.k8s.io/structured-merge-diff/v4/schema"
"sigs.k8s.io/structured-merge-diff/v4/value"
@@ -170,78 +168,94 @@ func (w *mergingWalker) visitListItems(t *schema.List, lhs, rhs value.List) (err
if lhs != nil {
lLen = lhs.Length()
}
out := make([]interface{}, 0, int(math.Max(float64(rLen), float64(lLen))))
outLen := lLen
if outLen < rLen {
outLen = rLen
}
out := make([]interface{}, 0, outLen)
// TODO: ordering is totally wrong.
// TODO: might as well make the map order work the same way.
rhsOrder, observedRHS, rhsErrs := w.indexListPathElements(t, rhs)
errs = append(errs, rhsErrs...)
lhsOrder, observedLHS, lhsErrs := w.indexListPathElements(t, lhs)
errs = append(errs, lhsErrs...)
// This is a cheap hack to at least make the output order stable.
rhsOrder := make([]fieldpath.PathElement, 0, rLen)
// First, collect all RHS children.
observedRHS := fieldpath.MakePathElementValueMap(rLen)
if rhs != nil {
for i := 0; i < rhs.Length(); i++ {
child := rhs.At(i)
pe, err := listItemToPathElement(w.allocator, w.schema, t, i, child)
if err != nil {
errs = append(errs, errorf("rhs: element %v: %v", i, err.Error())...)
// If we can't construct the path element, we can't
// even report errors deeper in the schema, so bail on
// this element.
continue
}
if _, ok := observedRHS.Get(pe); ok {
errs = append(errs, errorf("rhs: duplicate entries for key %v", pe.String())...)
}
observedRHS.Insert(pe, child)
rhsOrder = append(rhsOrder, pe)
sharedOrder := make([]*fieldpath.PathElement, 0, rLen)
for i := range rhsOrder {
pe := &rhsOrder[i]
if _, ok := observedLHS.Get(*pe); ok {
sharedOrder = append(sharedOrder, pe)
}
}
// Then merge with LHS children.
observedLHS := fieldpath.MakePathElementSet(lLen)
if lhs != nil {
for i := 0; i < lhs.Length(); i++ {
child := lhs.At(i)
pe, err := listItemToPathElement(w.allocator, w.schema, t, i, child)
if err != nil {
errs = append(errs, errorf("lhs: element %v: %v", i, err.Error())...)
// If we can't construct the path element, we can't
// even report errors deeper in the schema, so bail on
// this element.
continue
}
if observedLHS.Has(pe) {
errs = append(errs, errorf("lhs: duplicate entries for key %v", pe.String())...)
continue
}
observedLHS.Insert(pe)
w2 := w.prepareDescent(pe, t.ElementType)
w2.lhs = value.Value(child)
if rchild, ok := observedRHS.Get(pe); ok {
w2.rhs = rchild
}
errs = append(errs, w2.merge(pe.String)...)
if w2.out != nil {
out = append(out, *w2.out)
}
w.finishDescent(w2)
}
var nextShared *fieldpath.PathElement
if len(sharedOrder) > 0 {
nextShared = sharedOrder[0]
sharedOrder = sharedOrder[1:]
}
for _, pe := range rhsOrder {
if observedLHS.Has(pe) {
continue
lLen, rLen = len(lhsOrder), len(rhsOrder)
for lI, rI := 0, 0; lI < lLen || rI < rLen; {
if lI < lLen && rI < rLen {
pe := lhsOrder[lI]
if pe.Equals(rhsOrder[rI]) {
// merge LHS & RHS items
lChild, _ := observedLHS.Get(pe)
rChild, _ := observedRHS.Get(pe)
mergeOut, errs := w.mergeListItem(t, pe, lChild, rChild)
errs = append(errs, errs...)
if mergeOut != nil {
out = append(out, *mergeOut)
}
lI++
rI++
nextShared = nil
if len(sharedOrder) > 0 {
nextShared = sharedOrder[0]
sharedOrder = sharedOrder[1:]
}
continue
}
if _, ok := observedRHS.Get(pe); ok && nextShared != nil && !nextShared.Equals(lhsOrder[lI]) {
// shared item, but not the one we want in this round
lI++
continue
}
}
value, _ := observedRHS.Get(pe)
w2 := w.prepareDescent(pe, t.ElementType)
w2.rhs = value
errs = append(errs, w2.merge(pe.String)...)
if w2.out != nil {
out = append(out, *w2.out)
if lI < lLen {
pe := lhsOrder[lI]
if _, ok := observedRHS.Get(pe); !ok {
// take LHS item
lChild, _ := observedLHS.Get(pe)
mergeOut, errs := w.mergeListItem(t, pe, lChild, nil)
errs = append(errs, errs...)
if mergeOut != nil {
out = append(out, *mergeOut)
}
lI++
continue
}
}
if rI < rLen {
// Take the RHS item, merge with matching LHS item if possible
pe := rhsOrder[rI]
lChild, _ := observedLHS.Get(pe) // may be nil
rChild, _ := observedRHS.Get(pe)
mergeOut, errs := w.mergeListItem(t, pe, lChild, rChild)
errs = append(errs, errs...)
if mergeOut != nil {
out = append(out, *mergeOut)
}
rI++
// Advance nextShared, if we are merging nextShared.
if nextShared != nil && nextShared.Equals(pe) {
nextShared = nil
if len(sharedOrder) > 0 {
nextShared = sharedOrder[0]
sharedOrder = sharedOrder[1:]
}
}
}
w.finishDescent(w2)
}
if len(out) > 0 {
@@ -252,6 +266,46 @@ func (w *mergingWalker) visitListItems(t *schema.List, lhs, rhs value.List) (err
return errs
}
func (w *mergingWalker) indexListPathElements(t *schema.List, list value.List) ([]fieldpath.PathElement, fieldpath.PathElementValueMap, ValidationErrors) {
var errs ValidationErrors
length := 0
if list != nil {
length = list.Length()
}
observed := fieldpath.MakePathElementValueMap(length)
pes := make([]fieldpath.PathElement, 0, length)
for i := 0; i < length; i++ {
child := list.At(i)
pe, err := listItemToPathElement(w.allocator, w.schema, t, i, child)
if err != nil {
errs = append(errs, errorf("element %v: %v", i, err.Error())...)
// If we can't construct the path element, we can't
// even report errors deeper in the schema, so bail on
// this element.
continue
}
if _, found := observed.Get(pe); found {
errs = append(errs, errorf("duplicate entries for key %v", pe.String())...)
continue
}
observed.Insert(pe, child)
pes = append(pes, pe)
}
return pes, observed, errs
}
func (w *mergingWalker) mergeListItem(t *schema.List, pe fieldpath.PathElement, lChild, rChild value.Value) (out *interface{}, errs ValidationErrors) {
w2 := w.prepareDescent(pe, t.ElementType)
w2.lhs = lChild
w2.rhs = rChild
errs = append(errs, w2.merge(pe.String)...)
if w2.out != nil {
out = w2.out
}
w.finishDescent(w2)
return
}
func (w *mergingWalker) derefList(prefix string, v value.Value) (value.List, ValidationErrors) {
if v == nil {
return nil, nil