fix: some failed version check when create cluster (#2877)

* fix: runc version check failed

Signed-off-by: William Wang <williamw0825@gmail.com>

* fix: kubectl version check failed

Signed-off-by: William Wang <williamw0825@gmail.com>

* fix: helm version check failed

Signed-off-by: William Wang <williamw0825@gmail.com>

* fix: use .kube_version in capkk task

Signed-off-by: William Wang <williamw0825@gmail.com>

* fix: helm version check in capkk

Signed-off-by: William Wang <williamw0825@gmail.com>

---------

Signed-off-by: William Wang <williamw0825@gmail.com>
This commit is contained in:
William Wang 2025-12-01 19:04:46 +08:00 committed by GitHub
parent 86dbf89026
commit 67fd6098c1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 25 additions and 7 deletions

View File

@ -1,7 +1,7 @@
---
- name: Check if helm is installed
ignore_errors: true
command: helm version --template "{{ .Version }}"
command: helm version --template "{{ "{{" }} .Version {{ "}}" }}"
register: helm_install_version
- name: Install helm
when: or (.helm_install_version.error | empty | not) (.helm_install_version.stdout | ne .helm_version)
@ -30,12 +30,17 @@
- name: Check if kubectl is installed
ignore_errors: true
command: kubectl version --short
command: |
{{- if .kube_version | semverCompare ">=v1.28.0" -}}
kubectl version --client
{{- else -}}
kubectl version --client --short
{{- end -}}
register: kubectl_install_version
register_type: yaml
- name: Sync kubectl to remote
when: |
or (.kubectl_install_version.error | empty | not) ((get .kubectl_install_version.stdout "Server Version") | ne .kube_version)
or (.kubectl_install_version.error | empty | not) ((get .kubectl_install_version.stdout "Client Version") | ne .kube_version)
copy:
src: >-
{{ .binary_dir }}/kube/{{ .kube_version }}/{{ .binary_type }}/kubectl

View File

@ -5,7 +5,7 @@
register: runc_install_version
- name: Containerd | Ensure the runc binary is present on the remote node
when: or (.runc_install_version.error | empty | not) (.runc_install_version.stdout | contains (printf "runc version %s\n" (.cri.runc_version | default "" | trimPrefix "v" )) | not)
when: or (.runc_install_version.error | empty | not) (.runc_install_version.stdout | regexMatch (printf "runc version %s\\s+" (.cri.runc_version | default "" | trimPrefix "v" )) | not)
copy:
src: >-
{{ .binary_dir }}/runc/{{ .cri.runc_version }}/{{ .binary_type }}/runc.{{ .binary_type }}

View File

@ -1,7 +1,7 @@
---
- name: Binary | Verify if Helm is already installed
ignore_errors: true
command: helm version --template "{{ .Version }}"
command: helm version --template "{{ "{{" }} .Version {{ "}}" }}"
register: helm_install_version
- name: Binary | Install Helm if not present or version mismatch
@ -32,13 +32,18 @@
- name: Binary | Check if kubectl is installed
ignore_errors: true
command: kubectl version --short
command: |
{{- if .kubernetes.kube_version | semverCompare ">=v1.28.0" -}}
kubectl version --client
{{- else -}}
kubectl version --client --short
{{- end -}}
register: kubectl_install_version
register_type: yaml
- name: Binary | Install kubectl if not present or version mismatch
when: |
or (.kubectl_install_version.error | empty | not) ((get .kubectl_install_version.stdout "Server Version") | ne .kubernetes.kube_version)
or (.kubectl_install_version.error | empty | not) ((get .kubectl_install_version.stdout "Client Version") | ne .kubernetes.kube_version)
copy:
src: >-
{{ .binary_dir }}/kube/{{ .kubernetes.kube_version }}/{{ .binary_type }}/kubectl

View File

@ -294,6 +294,14 @@ func TestParseValue(t *testing.T) {
},
excepted: []byte("bar"),
},
{
name: "{{ & }} character translation",
input: "helm version --template \"{{ \"{{\" }} .Version {{ \"}}\" }}\"",
variable: map[string]any{
"foo": "bar",
},
excepted: []byte("helm version --template \"{{ .Version }}\""),
},
}
for _, tc := range testcases {