Skip to content

Commit 82cc8d8

Browse files
CR-9041 cluster version check (#254)
* add cluster version check * bump * small fix * skip cluster requirements with --skip-cluster-checks * small fix * bump
1 parent c6d28fb commit 82cc8d8

File tree

7 files changed

+23
-7
lines changed

7 files changed

+23
-7
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION=v0.0.233
1+
VERSION=v0.0.234
22

33
OUT_DIR=dist
44
YEAR?=$(shell date +"%Y")

cmd/commands/runtime.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,9 @@ func preInstallationChecks(ctx context.Context, opts *RuntimeInstallOptions) err
857857
return fmt.Errorf(fmt.Sprintf("cluster network tests failed: %v ", err))
858858
}
859859

860-
err = kubeutil.EnsureClusterRequirements(ctx, opts.KubeFactory, opts.RuntimeName)
860+
if !opts.SkipClusterChecks {
861+
err = kubeutil.EnsureClusterRequirements(ctx, opts.KubeFactory, opts.RuntimeName)
862+
}
861863
handleCliStep(reporter.InstallStepRunPreCheckValidateClusterRequirements, "Ensuring cluster requirements", err, false)
862864
if err != nil {
863865
return fmt.Errorf(fmt.Sprintf("validation of minimum cluster requirements failed: %v ", err))

docs/releases/release_notes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ cf version
2323

2424
```bash
2525
# download and extract the binary
26-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.233/cf-linux-amd64.tar.gz | tar zx
26+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.234/cf-linux-amd64.tar.gz | tar zx
2727

2828
# move the binary to your $PATH
2929
mv ./cf-linux-amd64 /usr/local/bin/cf
@@ -36,7 +36,7 @@ cf version
3636

3737
```bash
3838
# download and extract the binary
39-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.233/cf-darwin-amd64.tar.gz | tar zx
39+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.234/cf-darwin-amd64.tar.gz | tar zx
4040

4141
# move the binary to your $PATH
4242
mv ./cf-darwin-amd64 /usr/local/bin/cf

manifests/runtime.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ metadata:
55
namespace: '{{ namespace }}'
66
spec:
77
defVersion: 1.0.0
8-
version: 0.0.233
8+
version: 0.0.234
99
bootstrapSpecifier: github.com/codefresh-io/cli-v2/manifests/argo-cd
1010
components:
1111
- name: events

pkg/reporter/reporter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ const (
6464
InstallStepPreCheckRuntimeNameValidation CliStep = "install.pre-check.step.runtime-name-validation"
6565
InstallStepPreCheckGetKubeContext CliStep = "install.pre-check.step.get-kube-context"
6666
InstallStepPreCheckEnsureIngressClass CliStep = "install.pre-check.step.ensure-ingress-class"
67+
InstallStepPreCheckEnsureIngressHost CliStep = "install.pre-check.step.ensure-ingress-host"
6768
InstallStepPreCheckEnsureRuntimeRepo CliStep = "install.pre-check.step.ensure-runtime-repo"
6869
InstallStepPreCheckEnsureGitToken CliStep = "install.pre-check.step.ensure-git-token"
6970
InstallStepPreCheckEnsureGitPAT CliStep = "install.pre-check.step.ensure-git-personal-access-token"
70-
InstallStepPreCheckEnsureIngressHost CliStep = "install.pre-check.step.ensure-ingress-host"
7171
InstallStepPreCheckShouldInstallDemoResources CliStep = "install.pre-check.step.should-install-demo-resources"
7272
InstallPhasePreCheckFinish CliStep = "install.pre-check.phase.finish"
7373
InstallPhaseRunPreCheckStart CliStep = "install.run.pre-check.phase.start"

pkg/store/store.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ type Store struct {
135135
NetworkTesterName string
136136
NetworkTesterGenerateName string
137137
NetworkTesterImage string
138+
MinKubeVersion string
138139
}
139140

140141
// Get returns the global store
@@ -226,6 +227,7 @@ func init() {
226227
s.NetworkTesterName = "cf-network-tester"
227228
s.NetworkTesterGenerateName = "cf-network-tester-"
228229
s.NetworkTesterImage = "quay.io/codefresh/cf-venona-network-tester:latest"
230+
s.MinKubeVersion = "v1.18.0"
229231

230232
initVersion()
231233
}

pkg/util/kube/kube.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
v1 "k8s.io/api/core/v1"
2727
"k8s.io/apimachinery/pkg/api/resource"
2828
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
29+
"k8s.io/apimachinery/pkg/version"
2930
"k8s.io/client-go/kubernetes"
3031
)
3132

@@ -60,7 +61,18 @@ func EnsureClusterRequirements(ctx context.Context, kubeFactory kube.Factory, na
6061

6162
client, err := kubeFactory.KubernetesClientSet()
6263
if err != nil {
63-
return fmt.Errorf("cannot create kubernetes clientset: %v ", err)
64+
return fmt.Errorf("cannot create kubernetes clientset: %w", err)
65+
}
66+
67+
kubeVersion, err := client.Discovery().ServerVersion()
68+
if err != nil {
69+
return fmt.Errorf("failed to check the cluster's version: %w", err)
70+
}
71+
72+
delta := version.CompareKubeAwareVersionStrings(store.Get().MinKubeVersion, kubeVersion.String())
73+
74+
if delta < 0 {
75+
return fmt.Errorf("%s: cluster's server version must be %s or higher", requirementsValidationErrorMessage, store.Get().MinKubeVersion)
6476
}
6577

6678
req := validationRequest{

0 commit comments

Comments
 (0)