Skip to content

Commit

Permalink
actually validate semver in node controller rather than prefix checking
Browse files Browse the repository at this point in the history
  • Loading branch information
mikedanese committed Dec 3, 2015
1 parent 2c49893 commit f784be3
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pkg/controller/node/nodecontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"errors"
"fmt"
"net"
"strings"
"sync"
"time"

Expand All @@ -38,6 +37,7 @@ import (
"k8s.io/kubernetes/pkg/types"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/sets"
"k8s.io/kubernetes/pkg/version"
"k8s.io/kubernetes/pkg/watch"
)

Expand Down Expand Up @@ -287,6 +287,8 @@ func (nc *NodeController) getCondition(status *api.NodeStatus, conditionType api
return nil
}

var gracefulDeletionVersion = version.MustParse("v1.1.0")

// maybeDeleteTerminatingPod non-gracefully deletes pods that are terminating
// that should not be gracefully terminated.
func (nc *NodeController) maybeDeleteTerminatingPod(obj interface{}) {
Expand Down Expand Up @@ -328,7 +330,13 @@ func (nc *NodeController) maybeDeleteTerminatingPod(obj interface{}) {
// guarantee backwards compatibility of master API to kubelets with
// versions less than 1.1.0
node := nodeObj.(*api.Node)
if strings.HasPrefix(node.Status.NodeInfo.KubeletVersion, "v1.0") {
v, err := version.Parse(node.Status.NodeInfo.KubeletVersion)
if err != nil {
glog.Infof("couldn't parse verions %q of minion: %v", node.Status.NodeInfo.KubeletVersion, err)
nc.forcefullyDeletePod(pod)
return
}
if gracefulDeletionVersion.GT(v) {
nc.forcefullyDeletePod(pod)
return
}
Expand Down
34 changes: 34 additions & 0 deletions pkg/controller/node/nodecontroller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,20 @@ func TestCheckPod(t *testing.T) {
},
prune: true,
},
{
pod: api.Pod{
ObjectMeta: api.ObjectMeta{DeletionTimestamp: &unversioned.Time{}},
Spec: api.PodSpec{NodeName: "older"},
},
prune: true,
},
{
pod: api.Pod{
ObjectMeta: api.ObjectMeta{DeletionTimestamp: &unversioned.Time{}},
Spec: api.PodSpec{NodeName: "oldest"},
},
prune: true,
},
{
pod: api.Pod{
ObjectMeta: api.ObjectMeta{DeletionTimestamp: &unversioned.Time{}},
Expand Down Expand Up @@ -763,6 +777,26 @@ func TestCheckPod(t *testing.T) {
},
},
})
nc.nodeStore.Store.Add(&api.Node{
ObjectMeta: api.ObjectMeta{
Name: "older",
},
Status: api.NodeStatus{
NodeInfo: api.NodeSystemInfo{
KubeletVersion: "v0.21.4",
},
},
})
nc.nodeStore.Store.Add(&api.Node{
ObjectMeta: api.ObjectMeta{
Name: "oldest",
},
Status: api.NodeStatus{
NodeInfo: api.NodeSystemInfo{
KubeletVersion: "v0.19.3",
},
},
})

for i, tc := range tcs {
var deleteCalls int
Expand Down

0 comments on commit f784be3

Please sign in to comment.