go.mod: bump client-go and api machinerie
I had to run `make generate`. Some API functions got additional parameters `Options` and `Context`. I used empty options and `context.TODO()` for now. Signed-off-by: leonnicolas <leonloechner@gmx.de>
This commit is contained in:
14
vendor/k8s.io/client-go/testing/actions.go
generated
vendored
14
vendor/k8s.io/client-go/testing/actions.go
generated
vendored
@@ -439,8 +439,18 @@ func (a ActionImpl) GetSubresource() string {
|
||||
return a.Subresource
|
||||
}
|
||||
func (a ActionImpl) Matches(verb, resource string) bool {
|
||||
return strings.ToLower(verb) == strings.ToLower(a.Verb) &&
|
||||
strings.ToLower(resource) == strings.ToLower(a.Resource.Resource)
|
||||
// Stay backwards compatible.
|
||||
if !strings.Contains(resource, "/") {
|
||||
return strings.EqualFold(verb, a.Verb) &&
|
||||
strings.EqualFold(resource, a.Resource.Resource)
|
||||
}
|
||||
|
||||
parts := strings.SplitN(resource, "/", 2)
|
||||
topresource, subresource := parts[0], parts[1]
|
||||
|
||||
return strings.EqualFold(verb, a.Verb) &&
|
||||
strings.EqualFold(topresource, a.Resource.Resource) &&
|
||||
strings.EqualFold(subresource, a.Subresource)
|
||||
}
|
||||
func (a ActionImpl) DeepCopy() Action {
|
||||
ret := a
|
||||
|
109
vendor/k8s.io/client-go/testing/fixture.go
generated
vendored
109
vendor/k8s.io/client-go/testing/fixture.go
generated
vendored
@@ -18,9 +18,12 @@ package testing
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"sort"
|
||||
"sync"
|
||||
|
||||
jsonpatch "github.com/evanphx/json-patch"
|
||||
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
"k8s.io/apimachinery/pkg/api/meta"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
@@ -139,6 +142,11 @@ func ObjectReaction(tracker ObjectTracker) ReactionFunc {
|
||||
return true, nil, err
|
||||
}
|
||||
|
||||
// reset the object in preparation to unmarshal, since unmarshal does not guarantee that fields
|
||||
// in obj that are removed by patch are cleared
|
||||
value := reflect.ValueOf(obj)
|
||||
value.Elem().Set(reflect.New(value.Type().Elem()).Elem())
|
||||
|
||||
switch action.GetPatchType() {
|
||||
case types.JSONPatchType:
|
||||
patch, err := jsonpatch.DecodePatch(action.GetPatch())
|
||||
@@ -149,6 +157,7 @@ func ObjectReaction(tracker ObjectTracker) ReactionFunc {
|
||||
if err != nil {
|
||||
return true, nil, err
|
||||
}
|
||||
|
||||
if err = json.Unmarshal(modified, obj); err != nil {
|
||||
return true, nil, err
|
||||
}
|
||||
@@ -189,7 +198,7 @@ type tracker struct {
|
||||
scheme ObjectScheme
|
||||
decoder runtime.Decoder
|
||||
lock sync.RWMutex
|
||||
objects map[schema.GroupVersionResource][]runtime.Object
|
||||
objects map[schema.GroupVersionResource]map[types.NamespacedName]runtime.Object
|
||||
// The value type of watchers is a map of which the key is either a namespace or
|
||||
// all/non namespace aka "" and its value is list of fake watchers.
|
||||
// Manipulations on resources will broadcast the notification events into the
|
||||
@@ -206,7 +215,7 @@ func NewObjectTracker(scheme ObjectScheme, decoder runtime.Decoder) ObjectTracke
|
||||
return &tracker{
|
||||
scheme: scheme,
|
||||
decoder: decoder,
|
||||
objects: make(map[schema.GroupVersionResource][]runtime.Object),
|
||||
objects: make(map[schema.GroupVersionResource]map[types.NamespacedName]runtime.Object),
|
||||
watchers: make(map[schema.GroupVersionResource]map[string][]*watch.RaceFreeFakeWatcher),
|
||||
}
|
||||
}
|
||||
@@ -240,7 +249,7 @@ func (t *tracker) List(gvr schema.GroupVersionResource, gvk schema.GroupVersionK
|
||||
return list, nil
|
||||
}
|
||||
|
||||
matchingObjs, err := filterByNamespaceAndName(objs, ns, "")
|
||||
matchingObjs, err := filterByNamespace(objs, ns)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -274,21 +283,15 @@ func (t *tracker) Get(gvr schema.GroupVersionResource, ns, name string) (runtime
|
||||
return nil, errNotFound
|
||||
}
|
||||
|
||||
matchingObjs, err := filterByNamespaceAndName(objs, ns, name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(matchingObjs) == 0 {
|
||||
matchingObj, ok := objs[types.NamespacedName{Namespace: ns, Name: name}]
|
||||
if !ok {
|
||||
return nil, errNotFound
|
||||
}
|
||||
if len(matchingObjs) > 1 {
|
||||
return nil, fmt.Errorf("more than one object matched gvr %s, ns: %q name: %q", gvr, ns, name)
|
||||
}
|
||||
|
||||
// Only one object should match in the tracker if it works
|
||||
// correctly, as Add/Update methods enforce kind/namespace/name
|
||||
// uniqueness.
|
||||
obj := matchingObjs[0].DeepCopyObject()
|
||||
obj := matchingObj.DeepCopyObject()
|
||||
if status, ok := obj.(*metav1.Status); ok {
|
||||
if status.Status != metav1.StatusSuccess {
|
||||
return nil, &errors.StatusError{ErrStatus: *status}
|
||||
@@ -310,6 +313,11 @@ func (t *tracker) Add(obj runtime.Object) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if partial, ok := obj.(*metav1.PartialObjectMetadata); ok && len(partial.TypeMeta.APIVersion) > 0 {
|
||||
gvks = []schema.GroupVersionKind{partial.TypeMeta.GroupVersionKind()}
|
||||
}
|
||||
|
||||
if len(gvks) == 0 {
|
||||
return fmt.Errorf("no registered kinds for %v", obj)
|
||||
}
|
||||
@@ -382,21 +390,21 @@ func (t *tracker) add(gvr schema.GroupVersionResource, obj runtime.Object, ns st
|
||||
return errors.NewBadRequest(msg)
|
||||
}
|
||||
|
||||
for i, existingObj := range t.objects[gvr] {
|
||||
oldMeta, err := meta.Accessor(existingObj)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if oldMeta.GetNamespace() == newMeta.GetNamespace() && oldMeta.GetName() == newMeta.GetName() {
|
||||
if replaceExisting {
|
||||
for _, w := range t.getWatches(gvr, ns) {
|
||||
w.Modify(obj)
|
||||
}
|
||||
t.objects[gvr][i] = obj
|
||||
return nil
|
||||
_, ok := t.objects[gvr]
|
||||
if !ok {
|
||||
t.objects[gvr] = make(map[types.NamespacedName]runtime.Object)
|
||||
}
|
||||
|
||||
namespacedName := types.NamespacedName{Namespace: newMeta.GetNamespace(), Name: newMeta.GetName()}
|
||||
if _, ok = t.objects[gvr][namespacedName]; ok {
|
||||
if replaceExisting {
|
||||
for _, w := range t.getWatches(gvr, ns) {
|
||||
w.Modify(obj)
|
||||
}
|
||||
return errors.NewAlreadyExists(gr, newMeta.GetName())
|
||||
t.objects[gvr][namespacedName] = obj
|
||||
return nil
|
||||
}
|
||||
return errors.NewAlreadyExists(gr, newMeta.GetName())
|
||||
}
|
||||
|
||||
if replaceExisting {
|
||||
@@ -404,7 +412,7 @@ func (t *tracker) add(gvr schema.GroupVersionResource, obj runtime.Object, ns st
|
||||
return errors.NewNotFound(gr, newMeta.GetName())
|
||||
}
|
||||
|
||||
t.objects[gvr] = append(t.objects[gvr], obj)
|
||||
t.objects[gvr][namespacedName] = obj
|
||||
|
||||
for _, w := range t.getWatches(gvr, ns) {
|
||||
w.Add(obj)
|
||||
@@ -434,35 +442,28 @@ func (t *tracker) Delete(gvr schema.GroupVersionResource, ns, name string) error
|
||||
t.lock.Lock()
|
||||
defer t.lock.Unlock()
|
||||
|
||||
found := false
|
||||
|
||||
for i, existingObj := range t.objects[gvr] {
|
||||
objMeta, err := meta.Accessor(existingObj)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if objMeta.GetNamespace() == ns && objMeta.GetName() == name {
|
||||
obj := t.objects[gvr][i]
|
||||
t.objects[gvr] = append(t.objects[gvr][:i], t.objects[gvr][i+1:]...)
|
||||
for _, w := range t.getWatches(gvr, ns) {
|
||||
w.Delete(obj)
|
||||
}
|
||||
found = true
|
||||
break
|
||||
}
|
||||
objs, ok := t.objects[gvr]
|
||||
if !ok {
|
||||
return errors.NewNotFound(gvr.GroupResource(), name)
|
||||
}
|
||||
|
||||
if found {
|
||||
return nil
|
||||
namespacedName := types.NamespacedName{Namespace: ns, Name: name}
|
||||
obj, ok := objs[namespacedName]
|
||||
if !ok {
|
||||
return errors.NewNotFound(gvr.GroupResource(), name)
|
||||
}
|
||||
|
||||
return errors.NewNotFound(gvr.GroupResource(), name)
|
||||
delete(objs, namespacedName)
|
||||
for _, w := range t.getWatches(gvr, ns) {
|
||||
w.Delete(obj)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// filterByNamespaceAndName returns all objects in the collection that
|
||||
// match provided namespace and name. Empty namespace matches
|
||||
// filterByNamespace returns all objects in the collection that
|
||||
// match provided namespace. Empty namespace matches
|
||||
// non-namespaced objects.
|
||||
func filterByNamespaceAndName(objs []runtime.Object, ns, name string) ([]runtime.Object, error) {
|
||||
func filterByNamespace(objs map[types.NamespacedName]runtime.Object, ns string) ([]runtime.Object, error) {
|
||||
var res []runtime.Object
|
||||
|
||||
for _, obj := range objs {
|
||||
@@ -473,12 +474,18 @@ func filterByNamespaceAndName(objs []runtime.Object, ns, name string) ([]runtime
|
||||
if ns != "" && acc.GetNamespace() != ns {
|
||||
continue
|
||||
}
|
||||
if name != "" && acc.GetName() != name {
|
||||
continue
|
||||
}
|
||||
res = append(res, obj)
|
||||
}
|
||||
|
||||
// Sort res to get deterministic order.
|
||||
sort.Slice(res, func(i, j int) bool {
|
||||
acc1, _ := meta.Accessor(res[i])
|
||||
acc2, _ := meta.Accessor(res[j])
|
||||
if acc1.GetNamespace() != acc2.GetNamespace() {
|
||||
return acc1.GetNamespace() < acc2.GetNamespace()
|
||||
}
|
||||
return acc1.GetName() < acc2.GetName()
|
||||
})
|
||||
return res, nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user