Skip to content

Commit

Permalink
Allow client version to be 1 minor version greater than server version (
Browse files Browse the repository at this point in the history
#50)

* Allow client version to be 1 minor version greater than server version

Fixes #49

* Add additional test case
  • Loading branch information
Ayush Sobti committed Apr 29, 2021
1 parent f1e2904 commit 5e4f51c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
3 changes: 2 additions & 1 deletion kube/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"io/ioutil"
"log"
"math"
"os/exec"
"regexp"
"strconv"
Expand Down Expand Up @@ -122,7 +123,7 @@ func isCompatible(clientMajor, clientMinor, serverMajor, serverMinor string) err
}

minorDiff := serverMinorInt - clientMinorInt
if minorDiff != 0 && minorDiff != 1 {
if math.Abs(float64(minorDiff)) > 1 {
return incompatible
}
return nil
Expand Down
11 changes: 8 additions & 3 deletions kube/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package kube

import (
"fmt"
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

type testCase struct {
Expand Down Expand Up @@ -36,8 +37,12 @@ func TestClientIsCompatible(t *testing.T) {
tc = testCase{"1", "0", "1", "2", fmt.Errorf("Error: kubectl client and server versions are incompatible. Client is 1.0; server is 1.2. Client must be same minor release as server or one minor release behind server.")}
createAndAssert(t, tc)

// Client 1.2, Server 1.0
tc = testCase{"1", "2", "1", "0", fmt.Errorf("Error: kubectl client and server versions are incompatible. Client is 1.2; server is 1.0. Client must be same minor release as server or one minor release behind server.")}
createAndAssert(t, tc)

// Client 1.1, Server 1.0
tc = testCase{"1", "1", "1", "0", fmt.Errorf("Error: kubectl client and server versions are incompatible. Client is 1.1; server is 1.0. Client must be same minor release as server or one minor release behind server.")}
tc = testCase{"1", "1", "1", "0", nil}
createAndAssert(t, tc)

// Client 1.1, Server 1.1+
Expand All @@ -53,7 +58,7 @@ func TestClientIsCompatible(t *testing.T) {
createAndAssert(t, tc)

// Client 1.2, Server 1.1+
tc = testCase{"1", "2", "1", "1+", fmt.Errorf("Error: kubectl client and server versions are incompatible. Client is 1.2; server is 1.1+. Client must be same minor release as server or one minor release behind server.")}
tc = testCase{"1", "2", "1", "1+", nil}
createAndAssert(t, tc)
}

Expand Down

0 comments on commit 5e4f51c

Please sign in to comment.