Skip to content

Commit

Permalink
switch kube subnet manager to PATCH
Browse files Browse the repository at this point in the history
  • Loading branch information
mikedanese committed Apr 14, 2017
1 parent 444ef90 commit 0ef5b19
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion subnet/kube/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ import (
"github.com/golang/glog"
"golang.org/x/net/context"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/v1"
"k8s.io/kubernetes/pkg/client/cache"
clientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
"k8s.io/kubernetes/pkg/client/restclient"
"k8s.io/kubernetes/pkg/controller/framework"
"k8s.io/kubernetes/pkg/runtime"
utilruntime "k8s.io/kubernetes/pkg/util/runtime"
"k8s.io/kubernetes/pkg/util/strategicpatch"
"k8s.io/kubernetes/pkg/util/wait"
"k8s.io/kubernetes/pkg/watch"
)
Expand Down Expand Up @@ -231,7 +233,31 @@ func (ksm *kubeSubnetManager) AcquireLease(ctx context.Context, network string,
n.Annotations[backendDataAnnotation] = string(bd)
n.Annotations[backendPublicIPAnnotation] = attrs.PublicIP.String()
n.Annotations[subnetKubeManagedAnnotation] = "true"
n, err = ksm.client.Core().Nodes().Update(n)

var oldNode, newNode v1.Node
if err := api.Scheme.Convert(cacheNode, &oldNode, nil); err != nil {
return nil, err
}
if err := api.Scheme.Convert(n, &newNode, nil); err != nil {
return nil, err
}

oldData, err := json.Marshal(oldNode)
if err != nil {
return nil, err
}

newData, err := json.Marshal(newNode)
if err != nil {
return nil, err
}

patchBytes, err := strategicpatch.CreateTwoWayMergePatch(oldData, newData, v1.Node{})
if err != nil {
return nil, fmt.Errorf("failed to create patch for node %q: %v", ksm.nodeName, err)
}

_, err = ksm.client.Core().Nodes().Patch(ksm.nodeName, api.StrategicMergePatchType, patchBytes)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 0ef5b19

Please sign in to comment.