Skip to content

Commit

Permalink
Merge pull request #1899 from fluxcd/kubernetes-constraints
Browse files Browse the repository at this point in the history
Update Kubernetes version minimum requirements
  • Loading branch information
stefanprodan authored Oct 6, 2021
2 parents 6033039 + 4c5a7d0 commit 9a8433d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
30 changes: 21 additions & 9 deletions cmd/flux/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/Masterminds/semver/v3"
"github.com/spf13/cobra"
v1 "k8s.io/api/apps/v1"
apimachineryversion "k8s.io/apimachinery/pkg/version"
"k8s.io/client-go/kubernetes"
"sigs.k8s.io/controller-runtime/pkg/client"

Expand Down Expand Up @@ -54,8 +53,11 @@ type checkFlags struct {
extraComponents []string
}

type kubectlVersion struct {
ClientVersion *apimachineryversion.Info `json:"clientVersion"`
var kubernetesConstraints = []string{
">=1.19.0-0",
">=1.16.11-0 <=1.16.15-0",
">=1.17.7-0 <=1.17.17-0",
">=1.18.4-0 <=1.18.20-0",
}

var checkArgs checkFlags
Expand All @@ -76,7 +78,7 @@ func runCheckCmd(cmd *cobra.Command, args []string) error {

fluxCheck()

if !kubernetesCheck(">=1.16.0-0") {
if !kubernetesCheck(kubernetesConstraints) {
checkFailed = true
}

Expand Down Expand Up @@ -121,7 +123,7 @@ func fluxCheck() {
}
}

func kubernetesCheck(constraint string) bool {
func kubernetesCheck(constraints []string) bool {
cfg, err := utils.KubeConfig(rootArgs.kubeconfig, rootArgs.kubecontext)
if err != nil {
logger.Failuref("Kubernetes client initialization failed: %s", err.Error())
Expand All @@ -146,13 +148,23 @@ func kubernetesCheck(constraint string) bool {
return false
}

c, _ := semver.NewConstraint(constraint)
if !c.Check(v) {
logger.Failuref("Kubernetes version %s < %s", v.Original(), constraint)
var valid bool
var vrange string
for _, constraint := range constraints {
c, _ := semver.NewConstraint(constraint)
if c.Check(v) {
valid = true
vrange = constraint
break
}
}

if !valid {
logger.Failuref("Kubernetes version %s does not match %s", v.Original(), constraints[0])
return false
}

logger.Successf("Kubernetes %s %s", v.String(), constraint)
logger.Successf("Kubernetes %s %s", v.String(), vrange)
return true
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/flux/testdata/check/check_pre.golden
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
► checking prerequisites
✔ Kubernetes {{ .serverVersion }} >=1.16.0-0
✔ Kubernetes {{ .serverVersion }} >=1.19.0-0
✔ prerequisites checks passed

0 comments on commit 9a8433d

Please sign in to comment.