mirror of
https://github.com/kubesphere/kubekey.git
synced 2025-12-25 17:12:50 +00:00
feat: add register_type (#2532)
Signed-off-by: joyceliu <joyceliu@yunify.com>
This commit is contained in:
parent
def153b0bc
commit
ea4a19ec9f
|
|
@ -53,8 +53,9 @@ type TaskSpec struct {
|
|||
FailedWhen []string `json:"failedWhen,omitempty"`
|
||||
Loop runtime.RawExtension `json:"loop,omitempty"`
|
||||
|
||||
Module Module `json:"module,omitempty"`
|
||||
Register string `json:"register,omitempty"`
|
||||
Module Module `json:"module,omitempty"`
|
||||
Register string `json:"register,omitempty"`
|
||||
RegisterType string `json:"register_type,omitempty"`
|
||||
}
|
||||
|
||||
// Module of Task
|
||||
|
|
|
|||
|
|
@ -62,8 +62,10 @@ type Task struct {
|
|||
LoopControl LoopControl `yaml:"loop_control,omitempty"`
|
||||
Poll int `yaml:"poll,omitempty"`
|
||||
Register string `yaml:"register,omitempty"`
|
||||
Retries int `yaml:"retries,omitempty"`
|
||||
Until When `yaml:"until,omitempty"`
|
||||
// RegisterType how to register value to variable. support: string(default), json, yaml.
|
||||
RegisterType string `yaml:"register_type,omitempty"`
|
||||
Retries int `yaml:"retries,omitempty"`
|
||||
Until When `yaml:"until,omitempty"`
|
||||
|
||||
// deprecated, used to be loop and loop_args but loop has been repurposed
|
||||
//LoopWith string `yaml:"loop_with"`
|
||||
|
|
|
|||
|
|
@ -21,9 +21,10 @@
|
|||
command: |
|
||||
cat {{ .cloud_config_dir }}/cloud-config/value
|
||||
register: cloud_config_out
|
||||
register_type: yaml
|
||||
- name: set_fact of cloud-config value
|
||||
set_fact:
|
||||
cloud_config: "{{ .cloud_config_out.stdout | fromYaml | toJson }}"
|
||||
cloud_config: "{{ .cloud_config_out.stdout | toJson }}"
|
||||
roles:
|
||||
- role: init/init-artifacts
|
||||
when: .kubernetes_installed | default false | eq false
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
ignore_errors: true
|
||||
command: calicoctl version
|
||||
register: calicoctl_install_version
|
||||
register_type: yaml
|
||||
- name: Install calicoctl
|
||||
when: .calicoctl_install_version.stderr | ne ""
|
||||
block:
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
- name: check cni by helm
|
||||
command: helm list -a -A -q -o json 2>/dev/null
|
||||
register: installed_helm_packages
|
||||
register_type: json
|
||||
|
||||
- include_tasks: calico.yaml
|
||||
when:
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@
|
|||
ignore_errors: true
|
||||
command: kubectl version --short
|
||||
register: kubectl_install_version
|
||||
register_type: yaml
|
||||
- name: Sync kubectl to remote
|
||||
when: |
|
||||
or (.kubectl_install_version.stderr | ne "") ((get .kubectl_install_version.stdout "Server Version") | ne .kube_version)
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
ignore_errors: true
|
||||
command: calicoctl version
|
||||
register: calicoctl_install_version
|
||||
register_type: yaml
|
||||
- name: Install calicoctl
|
||||
when: .calicoctl_install_version.stderr | ne ""
|
||||
block:
|
||||
|
|
|
|||
|
|
@ -57,9 +57,11 @@
|
|||
ignore_errors: true
|
||||
command: etcd --version
|
||||
register: etcd_install_version
|
||||
register_type: yaml
|
||||
- name: Check if etcd has match the version
|
||||
when: .etcd_install_service.stdout | eq "active"
|
||||
assert:
|
||||
that: eq (get .etcd_install_version.stdout "etcd Version") (.etcd_version | default "" | trimPrefix "v")
|
||||
that: |
|
||||
eq (get .etcd_install_version.stdout "etcd Version") (.etcd_version | default "" | trimPrefix "v")
|
||||
fail_msg: |
|
||||
etcd has installed with version:v{{ get .etcd_install_version.stdout "etcd Version" }}. but not match etcd_version: {{ .etcd_version }}
|
||||
excepted install etcd with version: {{ .etcd_version }} but has installed with: {{ get .etcd_install_version.stdout "etcd Version" }}.
|
||||
|
|
|
|||
|
|
@ -46,13 +46,14 @@ func MarshalBlock(hosts []string, when []string, block kkprojectv1.Block) *kkcor
|
|||
CreationTimestamp: metav1.Now(),
|
||||
},
|
||||
Spec: kkcorev1alpha1.TaskSpec{
|
||||
Name: block.Name,
|
||||
Hosts: hosts,
|
||||
IgnoreError: block.IgnoreErrors,
|
||||
Retries: block.Retries,
|
||||
When: when,
|
||||
FailedWhen: block.FailedWhen.Data,
|
||||
Register: block.Register,
|
||||
Name: block.Name,
|
||||
Hosts: hosts,
|
||||
IgnoreError: block.IgnoreErrors,
|
||||
Retries: block.Retries,
|
||||
When: when,
|
||||
FailedWhen: block.FailedWhen.Data,
|
||||
Register: block.Register,
|
||||
RegisterType: block.RegisterType,
|
||||
},
|
||||
}
|
||||
if annotation, ok := block.UnknownField["annotations"].(map[string]string); ok {
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import (
|
|||
kkcorev1 "github.com/kubesphere/kubekey/api/core/v1"
|
||||
kkcorev1alpha1 "github.com/kubesphere/kubekey/api/core/v1alpha1"
|
||||
"github.com/schollz/progressbar/v3"
|
||||
"gopkg.in/yaml.v3"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
"k8s.io/klog/v2"
|
||||
ctrl "sigs.k8s.io/controller-runtime"
|
||||
|
|
@ -377,10 +378,13 @@ func (e *taskExecutor) dealRegister(stdout, stderr, host string) error {
|
|||
if e.task.Spec.Register != "" {
|
||||
var stdoutResult any = stdout
|
||||
var stderrResult any = stderr
|
||||
// try to convert by json
|
||||
if json.Valid([]byte(stdout)) {
|
||||
switch e.task.Spec.RegisterType {
|
||||
case "json":
|
||||
_ = json.Unmarshal([]byte(stdout), &stdoutResult)
|
||||
_ = json.Unmarshal([]byte(stderr), &stderrResult)
|
||||
case "yaml", "yml":
|
||||
_ = yaml.Unmarshal([]byte(stdout), &stdoutResult)
|
||||
default:
|
||||
// store by string
|
||||
}
|
||||
// set variable to parent location
|
||||
if err := e.variable.Merge(variable.MergeRuntimeVariable(map[string]any{
|
||||
|
|
|
|||
Loading…
Reference in New Issue