1
0
Fork 0

chore: update docker and k8s

This commit is contained in:
Ludovic Fernandez 2019-08-05 18:24:03 +02:00 committed by Traefiker Bot
parent 2b5c7f9e91
commit c2d440a914
1283 changed files with 67741 additions and 27918 deletions

View file

@ -26,6 +26,7 @@ import (
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
)
func NewRootGetAction(resource schema.GroupVersionResource, name string) GetActionImpl {
@ -152,45 +153,49 @@ func NewUpdateAction(resource schema.GroupVersionResource, namespace string, obj
return action
}
func NewRootPatchAction(resource schema.GroupVersionResource, name string, patch []byte) PatchActionImpl {
func NewRootPatchAction(resource schema.GroupVersionResource, name string, pt types.PatchType, patch []byte) PatchActionImpl {
action := PatchActionImpl{}
action.Verb = "patch"
action.Resource = resource
action.Name = name
action.PatchType = pt
action.Patch = patch
return action
}
func NewPatchAction(resource schema.GroupVersionResource, namespace string, name string, patch []byte) PatchActionImpl {
func NewPatchAction(resource schema.GroupVersionResource, namespace string, name string, pt types.PatchType, patch []byte) PatchActionImpl {
action := PatchActionImpl{}
action.Verb = "patch"
action.Resource = resource
action.Namespace = namespace
action.Name = name
action.PatchType = pt
action.Patch = patch
return action
}
func NewRootPatchSubresourceAction(resource schema.GroupVersionResource, name string, patch []byte, subresources ...string) PatchActionImpl {
func NewRootPatchSubresourceAction(resource schema.GroupVersionResource, name string, pt types.PatchType, patch []byte, subresources ...string) PatchActionImpl {
action := PatchActionImpl{}
action.Verb = "patch"
action.Resource = resource
action.Subresource = path.Join(subresources...)
action.Name = name
action.PatchType = pt
action.Patch = patch
return action
}
func NewPatchSubresourceAction(resource schema.GroupVersionResource, namespace, name string, patch []byte, subresources ...string) PatchActionImpl {
func NewPatchSubresourceAction(resource schema.GroupVersionResource, namespace, name string, pt types.PatchType, patch []byte, subresources ...string) PatchActionImpl {
action := PatchActionImpl{}
action.Verb = "patch"
action.Resource = resource
action.Subresource = path.Join(subresources...)
action.Namespace = namespace
action.Name = name
action.PatchType = pt
action.Patch = patch
return action
@ -396,6 +401,7 @@ type DeleteCollectionAction interface {
type PatchAction interface {
Action
GetName() string
GetPatchType() types.PatchType
GetPatch() []byte
}
@ -537,8 +543,9 @@ func (a UpdateActionImpl) DeepCopy() Action {
type PatchActionImpl struct {
ActionImpl
Name string
Patch []byte
Name string
PatchType types.PatchType
Patch []byte
}
func (a PatchActionImpl) GetName() string {
@ -549,12 +556,17 @@ func (a PatchActionImpl) GetPatch() []byte {
return a.Patch
}
func (a PatchActionImpl) GetPatchType() types.PatchType {
return a.PatchType
}
func (a PatchActionImpl) DeepCopy() Action {
patch := make([]byte, len(a.Patch))
copy(patch, a.Patch)
return PatchActionImpl{
ActionImpl: a.ActionImpl.DeepCopy().(ActionImpl),
Name: a.Name,
PatchType: a.PatchType,
Patch: patch,
}
}

View file

@ -131,13 +131,14 @@ func (c *Fake) Invokes(action Action, defaultReturnObj runtime.Object) (runtime.
c.Lock()
defer c.Unlock()
actionCopy := action.DeepCopy()
c.actions = append(c.actions, action.DeepCopy())
for _, reactor := range c.ReactionChain {
if !reactor.Handles(action) {
if !reactor.Handles(actionCopy) {
continue
}
handled, ret, err := reactor.React(action.DeepCopy())
handled, ret, err := reactor.React(actionCopy)
if !handled {
continue
}
@ -154,13 +155,14 @@ func (c *Fake) InvokesWatch(action Action) (watch.Interface, error) {
c.Lock()
defer c.Unlock()
actionCopy := action.DeepCopy()
c.actions = append(c.actions, action.DeepCopy())
for _, reactor := range c.WatchReactionChain {
if !reactor.Handles(action) {
if !reactor.Handles(actionCopy) {
continue
}
handled, ret, err := reactor.React(action.DeepCopy())
handled, ret, err := reactor.React(actionCopy)
if !handled {
continue
}
@ -177,13 +179,14 @@ func (c *Fake) InvokesProxy(action Action) restclient.ResponseWrapper {
c.Lock()
defer c.Unlock()
actionCopy := action.DeepCopy()
c.actions = append(c.actions, action.DeepCopy())
for _, reactor := range c.ProxyReactionChain {
if !reactor.Handles(action) {
if !reactor.Handles(actionCopy) {
continue
}
handled, ret, err := reactor.React(action.DeepCopy())
handled, ret, err := reactor.React(actionCopy)
if !handled || err != nil {
continue
}

View file

@ -20,11 +20,13 @@ import (
"fmt"
"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"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/json"
"k8s.io/apimachinery/pkg/util/strategicpatch"
"k8s.io/apimachinery/pkg/watch"
@ -129,23 +131,46 @@ func ObjectReaction(tracker ObjectTracker) ReactionFunc {
case PatchActionImpl:
obj, err := tracker.Get(gvr, ns, action.GetName())
if err != nil {
// object is not registered
return false, nil, err
return true, nil, err
}
old, err := json.Marshal(obj)
if err != nil {
return true, nil, err
}
// Only supports strategic merge patch
// TODO: Add support for other Patch types
mergedByte, err := strategicpatch.StrategicMergePatch(old, action.GetPatch(), obj)
if err != nil {
return true, nil, err
}
if err = json.Unmarshal(mergedByte, obj); err != nil {
return true, nil, err
switch action.GetPatchType() {
case types.JSONPatchType:
patch, err := jsonpatch.DecodePatch(action.GetPatch())
if err != nil {
return true, nil, err
}
modified, err := patch.Apply(old)
if err != nil {
return true, nil, err
}
if err = json.Unmarshal(modified, obj); err != nil {
return true, nil, err
}
case types.MergePatchType:
modified, err := jsonpatch.MergePatch(old, action.GetPatch())
if err != nil {
return true, nil, err
}
if err := json.Unmarshal(modified, obj); err != nil {
return true, nil, err
}
case types.StrategicMergePatchType:
mergedByte, err := strategicpatch.StrategicMergePatch(old, action.GetPatch(), obj)
if err != nil {
return true, nil, err
}
if err = json.Unmarshal(mergedByte, obj); err != nil {
return true, nil, err
}
default:
return true, nil, fmt.Errorf("PatchType is not supported")
}
if err = tracker.Update(gvr, obj, ns); err != nil {
@ -322,8 +347,10 @@ func (t *tracker) getWatches(gvr schema.GroupVersionResource, ns string) []*watc
if w := t.watchers[gvr][ns]; w != nil {
watches = append(watches, w...)
}
if w := t.watchers[gvr][""]; w != nil {
watches = append(watches, w...)
if ns != metav1.NamespaceAll {
if w := t.watchers[gvr][metav1.NamespaceAll]; w != nil {
watches = append(watches, w...)
}
}
}
return watches