Repository: kubean-io/kubean
Pull request #832 (2023-06-19 08:24:08)

[docs] update custom_action
**What type of PR is this?**

/kind documentation

**What this PR does / why we need it**:

Mainly add en text to: `docs/en/concepts/custom_action.md`. The local preview is good.



Patch:
diff --git a/docs/en/concepts/custom_action.md b/docs/en/concepts/custom_action.md
index 9c8d99927..f184e7e0d 100644
--- a/docs/en/concepts/custom_action.md
+++ b/docs/en/concepts/custom_action.md
@@ -1,29 +1,39 @@
-# 自定义 Action
+# Custom Actions
 
-### 动机
-对于使用者来讲，Kubean 和 Kubesprary 的产物都是 OCI 镜像、 helm chart 及 K8s manifests。在已拿到这些产物的情况下要自定义一些操作，也能做到，但是会比较复杂，需要手动修改不少的配置。希望能够简化这一过程。
+## Motivation
 
-### 目标
-提供一种便捷的方式能够让使用者使用一些自定义的操作来查看、修改和控制集群节点的状态。
+For users, the products of Kubean and Kubespray are OCI images, Helm charts, and K8s manifests.
+If you want to customize some operations after obtaining these products, it is possible but can
+be complicated and requires a lot of manual configuration modifications. We hope to simplify this process.
 
-### CRD 设计
-1. 增加 ActionSource 字段以声明 Action 来源，其值目前支持：
-   - builtin（缺省值） 
+## Goal
 
-     表明使用 kubean 内建 ansible playbook 或在 manifest 内联的 shell 脚本
+Provide a convenient way for users to use customized actions to view, modify, and control the status of cluster nodes.
+
+## CRD Design
+
+1. Add the ActionSource field to declare the source of the action, whose value currently supports:
+
+   - builtin (default)
+
+        Indicates the use of Kubean's built-in Ansible playbook or shell script in the manifest.
 
    - configmap
 
-     表明需要的 ansible playbook 或 shell 脚本通过 引用 K8s configmap 来获取
+        Indicates that the required Ansible playbook or shell script is obtained by referencing a K8s ConfigMap.
+
+2. Add the ActionSourceRef field to declare the resource object referenced
+   when ActionSource is configmap. This field only takes effect when ActionSource is configmap,
+   and its format is:
 
-2. 增加 ActionSourceRef 字段以声明当 ActionSource 值为 configmap 时所引用的资源对象，且仅当 ActionSource 为 configmap 时此字段才生效，其格式为：
     ```yaml
     actionSourceRef:
       name: <configmap name>
       namespace: <namespace of configmap>
     ```
-   
-配置示例：
+
+Configuration example:
+
 ```yaml
 apiVersion: v1
 kind: ConfigMap
@@ -64,4 +74,4 @@ spec:
       actionSourceRef:
         name: cluster1-demo-myaction
         namespace: kubean-system
-```
\ No newline at end of file
+```
diff --git a/docs/en/usage/mirror-install.md b/docs/en/usage/mirror-install.md
index 40b2dd9dd..1139ec638 100644
--- a/docs/en/usage/mirror-install.md
+++ b/docs/en/usage/mirror-install.md
@@ -32,13 +32,13 @@ You only need to modify the host information and other relevant information in t
 ```
 </details>
 
-#### 1.Configure Host Parameters in HostsConfCM.yml
+#### 1. Configure Host Parameters in HostsConfCM.yml
 
 Navigate to the `kubean/examples/install/2.mirror/` path and edit the `HostsConfCM.yml`template for the node configuration information of the cluster to be built. Replace the following parameters with your actual parameters:
 
-  - `<IP1>`：Node IP.
-  - `<USERNAME>`： Username for logging in to the node. We recommend using root or a user with root privileges to log in.
-  - `<PASSWORD>`：Password for logging in to the node.
+- `<IP1>`：Node IP.
+- `<USERNAME>`： Username for logging in to the node. We recommend using root or a user with root privileges to log in.
+- `<PASSWORD>`：Password for logging in to the node.
 
 For example, the following is an example HostsConfCM.yml file:
 <details>
@@ -97,7 +97,7 @@ $ vi kubean/examples/install/2.mirror/HostsConfCM.yml
 
 Navigate to the `kubean/examples/install/2.mirror/` path and edit the `ClusterOperation.yml` template for the configuration information of the cluster to be built. Replace the following parameters with your actual parameters:
 
-  - `<TAG>`: kubean image version. We recommend using the latest version.[Refer to the kubean version list](https://github.com/kubean-io/kubean/tags)
+- `<TAG>`: kubean image version. We recommend using the latest version.[Refer to the kubean version list](https://github.com/kubean-io/kubean/tags)
 
 For example, the following is an example `ClusterOperation.yml` file:
 <details>
@@ -132,7 +132,7 @@ To edit the ClusterOperation.yml configuration template, run the following comma
 $ vi kubean/examples/install/2.mirror/ClusterOperation.yml
 ```
 
-#### 3.Apply all configurations under the 2.mirror directory
+#### 3. Apply all configurations under the `2.mirror` directory
 
 After completing the above steps and saving the HostsConfCM.yml and ClusterOperation.yml files, run the following command:
 
diff --git a/docs/zh/concepts/custom_action.md b/docs/zh/concepts/custom_action.md
index 9c8d99927..3784cf5ea 100644
--- a/docs/zh/concepts/custom_action.md
+++ b/docs/zh/concepts/custom_action.md
@@ -1,29 +1,36 @@
 # 自定义 Action
 
-### 动机
-对于使用者来讲，Kubean 和 Kubesprary 的产物都是 OCI 镜像、 helm chart 及 K8s manifests。在已拿到这些产物的情况下要自定义一些操作，也能做到，但是会比较复杂，需要手动修改不少的配置。希望能够简化这一过程。
+## 动机
+
+对于使用者来讲，Kubean 和 Kubesprary 的产物都是 OCI 镜像、Helm Chart 及 K8s manifest。
+在已拿到这些产物的情况下要自定义一些操作，也能做到，但是会比较复杂，需要手动修改不少的配置。希望能够简化这一过程。
+
+## 目标
 
-### 目标
 提供一种便捷的方式能够让使用者使用一些自定义的操作来查看、修改和控制集群节点的状态。
 
-### CRD 设计
+## CRD 设计
+
 1. 增加 ActionSource 字段以声明 Action 来源，其值目前支持：
-   - builtin（缺省值） 
 
-     表明使用 kubean 内建 ansible playbook 或在 manifest 内联的 shell 脚本
+    - builtin（缺省值）
+
+        表明使用 kubean 内建 ansible playbook 或在 manifest 内联的 shell 脚本
 
-   - configmap
+    - configmap
 
-     表明需要的 ansible playbook 或 shell 脚本通过 引用 K8s configmap 来获取
+        表明需要的 ansible playbook 或 shell 脚本通过 引用 K8s configmap 来获取
 
 2. 增加 ActionSourceRef 字段以声明当 ActionSource 值为 configmap 时所引用的资源对象，且仅当 ActionSource 为 configmap 时此字段才生效，其格式为：
+
     ```yaml
     actionSourceRef:
       name: <configmap name>
       namespace: <namespace of configmap>
     ```
-   
+
 配置示例：
+
 ```yaml
 apiVersion: v1
 kind: ConfigMap
@@ -64,4 +71,4 @@ spec:
       actionSourceRef:
         name: cluster1-demo-myaction
         namespace: kubean-system
-```
\ No newline at end of file
+```
diff --git a/pkg/controllers/clusterops/controller.go b/pkg/controllers/clusterops/controller.go
index d2c1783c4..656d97803 100644
--- a/pkg/controllers/clusterops/controller.go
+++ b/pkg/controllers/clusterops/controller.go
@@ -123,10 +123,10 @@ func (c *Controller) FetchGlobalInfoManifest() (*manifestv1alpha1.Manifest, erro
 	return global, nil
 }
 
-func (c *Controller) UpdateStatusLoop(clusterOps *clusteroperationv1alpha1.ClusterOperation, fetchJobStatus func(*clusteroperationv1alpha1.ClusterOperation) (clusteroperationv1alpha1.OpsStatus, *metav1.Time, error)) (bool, error) {
+func (c *Controller) UpdateStatusLoop(clusterOps *clusteroperationv1alpha1.ClusterOperation, fetchJobStatus func(*clusteroperationv1alpha1.ClusterOperation) (clusteroperationv1alpha1.OpsStatus, error)) (bool, error) {
 	if clusterOps.Status.Status == clusteroperationv1alpha1.RunningStatus || len(clusterOps.Status.Status) == 0 {
 		// need fetch jobStatus again when the last status of job is running
-		jobStatus, completionTime, err := fetchJobStatus(clusterOps)
+		jobStatus, err := fetchJobStatus(clusterOps)
 		if err != nil {
 			return false, err
 		}
@@ -137,9 +137,6 @@ func (c *Controller) UpdateStatusLoop(clusterOps *clusteroperationv1alpha1.Clust
 		// the status  succeed or failed
 		clusterOps.Status.Status = jobStatus
 		clusterOps.Status.EndTime = &metav1.Time{Time: time.Now()}
-		if completionTime != nil {
-			clusterOps.Status.EndTime = completionTime
-		}
 		if err := c.Client.Status().Update(context.Background(), clusterOps); err != nil {
 			return false, err
 		}
@@ -149,29 +146,29 @@ func (c *Controller) UpdateStatusLoop(clusterOps *clusteroperationv1alpha1.Clust
 	return false, nil
 }
 
-func (c *Controller) FetchJobConditionStatusAndCompletionTime(clusterOps *clusteroperationv1alpha1.ClusterOperation) (clusteroperationv1alpha1.OpsStatus, *metav1.Time, error) {
+func (c *Controller) FetchJobStatus(clusterOps *clusteroperationv1alpha1.ClusterOperation) (clusteroperationv1alpha1.OpsStatus, error) {
 	if clusterOps.Status.JobRef.IsEmpty() {
-		return "", nil, fmt.Errorf("clusterOps %s no job", clusterOps.Name)
+		return "", fmt.Errorf("clusterOps %s no job", clusterOps.Name)
 	}
 	targetJob, err := c.ClientSet.BatchV1().Jobs(clusterOps.Status.JobRef.NameSpace).Get(context.Background(), clusterOps.Status.JobRef.Name, metav1.GetOptions{})
 	if apierrors.IsNotFound(err) {
 		// maybe the job is removed.
 		klog.Errorf("clusterOps %s  job %s not found", clusterOps.Name, clusterOps.Status.JobRef.Name)
-		return clusteroperationv1alpha1.FailedStatus, nil, nil
+		return clusteroperationv1alpha1.FailedStatus, nil
 	}
 	if err != nil {
-		return "", nil, err
+		return "", err
 	}
 	// according to the job condtions, return success or failed
 	for _, contion := range targetJob.Status.Conditions {
 		if contion.Type == batchv1.JobComplete && contion.Status == corev1.ConditionTrue {
-			return clusteroperationv1alpha1.SucceededStatus, targetJob.Status.CompletionTime, nil
+			return clusteroperationv1alpha1.SucceededStatus, nil
 		} else if contion.Type == batchv1.JobFailed && contion.Status == corev1.ConditionTrue {
-			return clusteroperationv1alpha1.FailedStatus, targetJob.Status.CompletionTime, nil
+			return clusteroperationv1alpha1.FailedStatus, nil
 		}
 	}
 
-	return clusteroperationv1alpha1.RunningStatus, nil, nil
+	return clusteroperationv1alpha1.RunningStatus, nil
 }
 
 func (c *Controller) ListClusterOps(clusterName string) ([]clusteroperationv1alpha1.ClusterOperation, error) {
@@ -323,7 +320,7 @@ func (c *Controller) Reconcile(ctx context.Context, req controllerruntime.Reques
 		return controllerruntime.Result{RequeueAfter: RequeueAfter}, nil
 	}
 
-	needRequeue, err = c.UpdateStatusLoop(clusterOps, c.FetchJobConditionStatusAndCompletionTime)
+	needRequeue, err = c.UpdateStatusLoop(clusterOps, c.FetchJobStatus)
 	if err != nil {
 		klog.Error(err)
 		return controllerruntime.Result{RequeueAfter: RequeueAfter}, err
diff --git a/playbooks/precheck.yml b/playbooks/precheck.yml
index b8e197d88..2c23a98bb 100644
--- a/playbooks/precheck.yml
+++ b/playbooks/precheck.yml
@@ -93,7 +93,6 @@
         ( if [ ! -f /tmp/kubean_data_temp_cache ]; then touch /tmp/kubean_data_temp_cache ; fi )
         yq -i '.{{inventory_hostname}}.os_kernel_version_output="{{ ansible_kernel }}"' /tmp/kubean_data_temp_cache
         yq -i '.{{inventory_hostname}}.os_kernel_version="{{ ansible_kernel.split('-')[0] }}"' /tmp/kubean_data_temp_cache
-        yq -i '.{{inventory_hostname}}.pkg_mgr="{{ ansible_pkg_mgr }}"' /tmp/kubean_data_temp_cache
       ignore_errors: true
       delegate_to: localhost
       when:


Test patch:
diff --git a/pkg/controllers/clusterops/controller_test.go b/pkg/controllers/clusterops/controller_test.go
index 5dd87d77c..a1a539691 100644
--- a/pkg/controllers/clusterops/controller_test.go
+++ b/pkg/controllers/clusterops/controller_test.go
@@ -89,8 +89,8 @@ func TestUpdateStatusLoop(t *testing.T) {
 			name: "the status is Running and the result of fetchJobStatus is err",
 			args: func(ops *clusteroperationv1alpha1.ClusterOperation) bool {
 				ops.Status.Status = clusteroperationv1alpha1.RunningStatus
-				needRequeue, err := controller.UpdateStatusLoop(ops, func(ops *clusteroperationv1alpha1.ClusterOperation) (clusteroperationv1alpha1.OpsStatus, *metav1.Time, error) {
-					return "", nil, fmt.Errorf("one error")
+				needRequeue, err := controller.UpdateStatusLoop(ops, func(ops *clusteroperationv1alpha1.ClusterOperation) (clusteroperationv1alpha1.OpsStatus, error) {
+					return "", fmt.Errorf("one error")
 				})
 				return err != nil && err.Error() == "one error" && !needRequeue
 			},
@@ -100,8 +100,8 @@ func TestUpdateStatusLoop(t *testing.T) {
 			name: "the status is Running and the result of fetchJobStatus is still Running",
 			args: func(ops *clusteroperationv1alpha1.ClusterOperation) bool {
 				ops.Status.Status = clusteroperationv1alpha1.RunningStatus
-				needRequeue, err := controller.UpdateStatusLoop(ops, func(ops *clusteroperationv1alpha1.ClusterOperation) (clusteroperationv1alpha1.OpsStatus, *metav1.Time, error) {
-					return clusteroperationv1alpha1.RunningStatus, nil, nil
+				needRequeue, err := controller.UpdateStatusLoop(ops, func(ops *clusteroperationv1alpha1.ClusterOperation) (clusteroperationv1alpha1.OpsStatus, error) {
+					return clusteroperationv1alpha1.RunningStatus, nil
 				})
 				return err == nil && needRequeue
 			},
@@ -112,8 +112,8 @@ func TestUpdateStatusLoop(t *testing.T) {
 			args: func(ops *clusteroperationv1alpha1.ClusterOperation) bool {
 				ops.Status.Status = clusteroperationv1alpha1.RunningStatus
 				ops.Status.EndTime = nil
-				needRequeue, err := controller.UpdateStatusLoop(ops, func(ops *clusteroperationv1alpha1.ClusterOperation) (clusteroperationv1alpha1.OpsStatus, *metav1.Time, error) {
-					return clusteroperationv1alpha1.SucceededStatus, &metav1.Time{}, nil
+				needRequeue, err := controller.UpdateStatusLoop(ops, func(ops *clusteroperationv1alpha1.ClusterOperation) (clusteroperationv1alpha1.OpsStatus, error) {
+					return clusteroperationv1alpha1.SucceededStatus, nil
 				})
 				resultOps := &clusteroperationv1alpha1.ClusterOperation{}
 				controller.Client.Get(context.Background(), client.ObjectKey{Name: "clusteropsname"}, resultOps)
@@ -130,8 +130,8 @@ func TestUpdateStatusLoop(t *testing.T) {
 				controller.Client.Get(context.Background(), client.ObjectKey{Name: "clusteropsname"}, ops)
 				ops.Status.Status = clusteroperationv1alpha1.RunningStatus
 				ops.Status.EndTime = nil
-				needRequeue, err := controller.UpdateStatusLoop(ops, func(ops *clusteroperationv1alpha1.ClusterOperation) (clusteroperationv1alpha1.OpsStatus, *metav1.Time, error) {
-					return clusteroperationv1alpha1.FailedStatus, nil, nil
+				needRequeue, err := controller.UpdateStatusLoop(ops, func(ops *clusteroperationv1alpha1.ClusterOperation) (clusteroperationv1alpha1.OpsStatus, error) {
+					return clusteroperationv1alpha1.FailedStatus, nil
 				})
 				return err == nil && !needRequeue && ops.Status.EndTime != nil && ops.Status.Status == clusteroperationv1alpha1.FailedStatus
 			},
@@ -1745,7 +1745,7 @@ func Test_FetchJobStatus(t *testing.T) {
 			name: "jobRef is empty",
 			args: func() bool {
 				clusterOps := &clusteroperationv1alpha1.ClusterOperation{}
-				_, _, err := controller.FetchJobConditionStatusAndCompletionTime(clusterOps)
+				_, err := controller.FetchJobStatus(clusterOps)
 				return err != nil
 			},
 			want: true,
@@ -1755,7 +1755,7 @@ func Test_FetchJobStatus(t *testing.T) {
 			args: func() bool {
 				clusterOps := &clusteroperationv1alpha1.ClusterOperation{}
 				clusterOps.Status.JobRef = &apis.JobRef{NameSpace: "kubean-system", Name: "job123"}
-				status, _, err := controller.FetchJobConditionStatusAndCompletionTime(clusterOps)
+				status, err := controller.FetchJobStatus(clusterOps)
 				return err == nil && status == clusteroperationv1alpha1.FailedStatus
 			},
 			want: true,
@@ -1784,7 +1784,7 @@ func Test_FetchJobStatus(t *testing.T) {
 					},
 				}
 				controller.ClientSet.BatchV1().Jobs("kubean-system").Create(context.Background(), targetJob, metav1.CreateOptions{})
-				status, _, err := controller.FetchJobConditionStatusAndCompletionTime(clusterOps)
+				status, err := controller.FetchJobStatus(clusterOps)
 				return err == nil && status == clusteroperationv1alpha1.SucceededStatus
 			},
 			want: true,
@@ -1813,7 +1813,7 @@ func Test_FetchJobStatus(t *testing.T) {
 					},
 				}
 				controller.ClientSet.BatchV1().Jobs("kubean-system").Create(context.Background(), targetJob, metav1.CreateOptions{})
-				status, _, err := controller.FetchJobConditionStatusAndCompletionTime(clusterOps)
+				status, err := controller.FetchJobStatus(clusterOps)
 				return err == nil && status == clusteroperationv1alpha1.FailedStatus
 			},
 			want: true,
@@ -1834,8 +1834,8 @@ func Test_FetchJobStatus(t *testing.T) {
 					},
 				}
 				controller.ClientSet.BatchV1().Jobs("kubean-system").Create(context.Background(), targetJob, metav1.CreateOptions{})
-				status, completionTime, err := controller.FetchJobConditionStatusAndCompletionTime(clusterOps)
-				return err == nil && status == clusteroperationv1alpha1.RunningStatus && completionTime == nil
+				status, err := controller.FetchJobStatus(clusterOps)
+				return err == nil && status == clusteroperationv1alpha1.RunningStatus
 			},
 			want: true,
 		},