Repository: kubean-io/kubean
Pull request #462 (2023-01-06 03:39:17)

Add spray job timeout
<!--  

Thanks for sending a pull request!  Here are some tips for you:

* make sure your commit is signed off

-->

**What type of PR is this?**
<!-- 
Uncomment only one ` /kind <>` line, hit enter to put that in a new line, and remove leading whitespaces from that line:

/kind api-change
/kind bug
/kind cleanup
/kind design
/kind documentation
/kind failing-test
/kind feature
/kind flake
-->

/kind feature

**What this PR does / why we need it**:

* add timeout control for spray-job pod

**Which issue(s) this PR fixes**:
<!--
*Automatically closes linked issue when PR is merged.
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
_If PR is about `failing-tests or flakes`, please post the related issues/tests in a comment and do not use `Fixes`_*
-->
Fixes #

**Special notes for your reviewer**:




Patch:
diff --git a/api/apis/clusteroperation/v1alpha1/types.go b/api/apis/clusteroperation/v1alpha1/types.go
index e298f811f..3058351f1 100644
--- a/api/apis/clusteroperation/v1alpha1/types.go
+++ b/api/apis/clusteroperation/v1alpha1/types.go
@@ -1,8 +1,8 @@
 package v1alpha1
 
 import (
-	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 	corev1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 	"kubean.io/api/apis"
 )
 
@@ -65,6 +65,8 @@ type Spec struct {
 	PostHook []HookAction `json:"postHook"`
 	// +optional
 	Resources corev1.ResourceRequirements `json:"resources"`
+	// +optional
+	ActiveDeadlineSeconds *int64 `json:"activeDeadlineSeconds"`
 }
 
 type HookAction struct {
diff --git a/api/apis/clusteroperation/v1alpha1/zz_generated.deepcopy.go b/api/apis/clusteroperation/v1alpha1/zz_generated.deepcopy.go
index bc08d7f11..0ca48a752 100644
--- a/api/apis/clusteroperation/v1alpha1/zz_generated.deepcopy.go
+++ b/api/apis/clusteroperation/v1alpha1/zz_generated.deepcopy.go
@@ -121,6 +121,11 @@ func (in *Spec) DeepCopyInto(out *Spec) {
 		copy(*out, *in)
 	}
 	in.Resources.DeepCopyInto(&out.Resources)
+	if in.ActiveDeadlineSeconds != nil {
+		in, out := &in.ActiveDeadlineSeconds, &out.ActiveDeadlineSeconds
+		*out = new(int64)
+		**out = **in
+	}
 	return
 }
 
diff --git a/api/charts/crds/kubean.io_clusteroperations.yaml b/api/charts/crds/kubean.io_clusteroperations.yaml
index 7d4f01153..41179ad92 100644
--- a/api/charts/crds/kubean.io_clusteroperations.yaml
+++ b/api/charts/crds/kubean.io_clusteroperations.yaml
@@ -45,6 +45,9 @@ spec:
                 type: string
               actionType:
                 type: string
+              activeDeadlineSeconds:
+                format: int64
+                type: integer
               backoffLimit:
                 type: integer
               cluster:
diff --git a/api/generated/cluster/cluster/clientset/versioned/fake/register.go b/api/generated/cluster/cluster/clientset/versioned/fake/register.go
index f3348645b..f33304d4f 100644
--- a/api/generated/cluster/cluster/clientset/versioned/fake/register.go
+++ b/api/generated/cluster/cluster/clientset/versioned/fake/register.go
@@ -21,14 +21,14 @@ var localSchemeBuilder = runtime.SchemeBuilder{
 // AddToScheme adds all types of this clientset into the given scheme. This allows composition
 // of clientsets, like in:
 //
-//	import (
-//	  "k8s.io/client-go/kubernetes"
-//	  clientsetscheme "k8s.io/client-go/kubernetes/scheme"
-//	  aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme"
-//	)
+//   import (
+//     "k8s.io/client-go/kubernetes"
+//     clientsetscheme "k8s.io/client-go/kubernetes/scheme"
+//     aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme"
+//   )
 //
-//	kclientset, _ := kubernetes.NewForConfig(c)
-//	_ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme)
+//   kclientset, _ := kubernetes.NewForConfig(c)
+//   _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme)
 //
 // After this, RawExtensions in Kubernetes types will serialize kube-aggregator types
 // correctly.
diff --git a/api/generated/cluster/cluster/clientset/versioned/scheme/register.go b/api/generated/cluster/cluster/clientset/versioned/scheme/register.go
index e108c8a43..0e45b5107 100644
--- a/api/generated/cluster/cluster/clientset/versioned/scheme/register.go
+++ b/api/generated/cluster/cluster/clientset/versioned/scheme/register.go
@@ -21,14 +21,14 @@ var localSchemeBuilder = runtime.SchemeBuilder{
 // AddToScheme adds all types of this clientset into the given scheme. This allows composition
 // of clientsets, like in:
 //
-//	import (
-//	  "k8s.io/client-go/kubernetes"
-//	  clientsetscheme "k8s.io/client-go/kubernetes/scheme"
-//	  aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme"
-//	)
+//   import (
+//     "k8s.io/client-go/kubernetes"
+//     clientsetscheme "k8s.io/client-go/kubernetes/scheme"
+//     aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme"
+//   )
 //
-//	kclientset, _ := kubernetes.NewForConfig(c)
-//	_ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme)
+//   kclientset, _ := kubernetes.NewForConfig(c)
+//   _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme)
 //
 // After this, RawExtensions in Kubernetes types will serialize kube-aggregator types
 // correctly.
diff --git a/api/generated/clusteroperation/clusteroperation/clientset/versioned/fake/register.go b/api/generated/clusteroperation/clusteroperation/clientset/versioned/fake/register.go
index 2bb23ea7a..d9fdd6f7e 100644
--- a/api/generated/clusteroperation/clusteroperation/clientset/versioned/fake/register.go
+++ b/api/generated/clusteroperation/clusteroperation/clientset/versioned/fake/register.go
@@ -21,14 +21,14 @@ var localSchemeBuilder = runtime.SchemeBuilder{
 // AddToScheme adds all types of this clientset into the given scheme. This allows composition
 // of clientsets, like in:
 //
-//	import (
-//	  "k8s.io/client-go/kubernetes"
-//	  clientsetscheme "k8s.io/client-go/kubernetes/scheme"
-//	  aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme"
-//	)
+//   import (
+//     "k8s.io/client-go/kubernetes"
+//     clientsetscheme "k8s.io/client-go/kubernetes/scheme"
+//     aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme"
+//   )
 //
-//	kclientset, _ := kubernetes.NewForConfig(c)
-//	_ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme)
+//   kclientset, _ := kubernetes.NewForConfig(c)
+//   _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme)
 //
 // After this, RawExtensions in Kubernetes types will serialize kube-aggregator types
 // correctly.
diff --git a/api/generated/clusteroperation/clusteroperation/clientset/versioned/scheme/register.go b/api/generated/clusteroperation/clusteroperation/clientset/versioned/scheme/register.go
index 7036bd3d3..bf7f894d3 100644
--- a/api/generated/clusteroperation/clusteroperation/clientset/versioned/scheme/register.go
+++ b/api/generated/clusteroperation/clusteroperation/clientset/versioned/scheme/register.go
@@ -21,14 +21,14 @@ var localSchemeBuilder = runtime.SchemeBuilder{
 // AddToScheme adds all types of this clientset into the given scheme. This allows composition
 // of clientsets, like in:
 //
-//	import (
-//	  "k8s.io/client-go/kubernetes"
-//	  clientsetscheme "k8s.io/client-go/kubernetes/scheme"
-//	  aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme"
-//	)
+//   import (
+//     "k8s.io/client-go/kubernetes"
+//     clientsetscheme "k8s.io/client-go/kubernetes/scheme"
+//     aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme"
+//   )
 //
-//	kclientset, _ := kubernetes.NewForConfig(c)
-//	_ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme)
+//   kclientset, _ := kubernetes.NewForConfig(c)
+//   _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme)
 //
 // After this, RawExtensions in Kubernetes types will serialize kube-aggregator types
 // correctly.
diff --git a/api/generated/localartifactset/localartifactset/clientset/versioned/fake/register.go b/api/generated/localartifactset/localartifactset/clientset/versioned/fake/register.go
index ed35531c7..3fa3fb9d0 100644
--- a/api/generated/localartifactset/localartifactset/clientset/versioned/fake/register.go
+++ b/api/generated/localartifactset/localartifactset/clientset/versioned/fake/register.go
@@ -21,14 +21,14 @@ var localSchemeBuilder = runtime.SchemeBuilder{
 // AddToScheme adds all types of this clientset into the given scheme. This allows composition
 // of clientsets, like in:
 //
-//	import (
-//	  "k8s.io/client-go/kubernetes"
-//	  clientsetscheme "k8s.io/client-go/kubernetes/scheme"
-//	  aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme"
-//	)
+//   import (
+//     "k8s.io/client-go/kubernetes"
+//     clientsetscheme "k8s.io/client-go/kubernetes/scheme"
+//     aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme"
+//   )
 //
-//	kclientset, _ := kubernetes.NewForConfig(c)
-//	_ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme)
+//   kclientset, _ := kubernetes.NewForConfig(c)
+//   _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme)
 //
 // After this, RawExtensions in Kubernetes types will serialize kube-aggregator types
 // correctly.
diff --git a/api/generated/localartifactset/localartifactset/clientset/versioned/scheme/register.go b/api/generated/localartifactset/localartifactset/clientset/versioned/scheme/register.go
index cb1f1c060..cf6116e4e 100644
--- a/api/generated/localartifactset/localartifactset/clientset/versioned/scheme/register.go
+++ b/api/generated/localartifactset/localartifactset/clientset/versioned/scheme/register.go
@@ -21,14 +21,14 @@ var localSchemeBuilder = runtime.SchemeBuilder{
 // AddToScheme adds all types of this clientset into the given scheme. This allows composition
 // of clientsets, like in:
 //
-//	import (
-//	  "k8s.io/client-go/kubernetes"
-//	  clientsetscheme "k8s.io/client-go/kubernetes/scheme"
-//	  aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme"
-//	)
+//   import (
+//     "k8s.io/client-go/kubernetes"
+//     clientsetscheme "k8s.io/client-go/kubernetes/scheme"
+//     aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme"
+//   )
 //
-//	kclientset, _ := kubernetes.NewForConfig(c)
-//	_ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme)
+//   kclientset, _ := kubernetes.NewForConfig(c)
+//   _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme)
 //
 // After this, RawExtensions in Kubernetes types will serialize kube-aggregator types
 // correctly.
diff --git a/api/generated/manifest/manifest/clientset/versioned/fake/register.go b/api/generated/manifest/manifest/clientset/versioned/fake/register.go
index a1a92cf1b..2c958a5e9 100644
--- a/api/generated/manifest/manifest/clientset/versioned/fake/register.go
+++ b/api/generated/manifest/manifest/clientset/versioned/fake/register.go
@@ -21,14 +21,14 @@ var localSchemeBuilder = runtime.SchemeBuilder{
 // AddToScheme adds all types of this clientset into the given scheme. This allows composition
 // of clientsets, like in:
 //
-//	import (
-//	  "k8s.io/client-go/kubernetes"
-//	  clientsetscheme "k8s.io/client-go/kubernetes/scheme"
-//	  aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme"
-//	)
+//   import (
+//     "k8s.io/client-go/kubernetes"
+//     clientsetscheme "k8s.io/client-go/kubernetes/scheme"
+//     aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme"
+//   )
 //
-//	kclientset, _ := kubernetes.NewForConfig(c)
-//	_ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme)
+//   kclientset, _ := kubernetes.NewForConfig(c)
+//   _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme)
 //
 // After this, RawExtensions in Kubernetes types will serialize kube-aggregator types
 // correctly.
diff --git a/api/generated/manifest/manifest/clientset/versioned/scheme/register.go b/api/generated/manifest/manifest/clientset/versioned/scheme/register.go
index 81ffe7d54..cc9c8aecf 100644
--- a/api/generated/manifest/manifest/clientset/versioned/scheme/register.go
+++ b/api/generated/manifest/manifest/clientset/versioned/scheme/register.go
@@ -21,14 +21,14 @@ var localSchemeBuilder = runtime.SchemeBuilder{
 // AddToScheme adds all types of this clientset into the given scheme. This allows composition
 // of clientsets, like in:
 //
-//	import (
-//	  "k8s.io/client-go/kubernetes"
-//	  clientsetscheme "k8s.io/client-go/kubernetes/scheme"
-//	  aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme"
-//	)
+//   import (
+//     "k8s.io/client-go/kubernetes"
+//     clientsetscheme "k8s.io/client-go/kubernetes/scheme"
+//     aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme"
+//   )
 //
-//	kclientset, _ := kubernetes.NewForConfig(c)
-//	_ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme)
+//   kclientset, _ := kubernetes.NewForConfig(c)
+//   _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme)
 //
 // After this, RawExtensions in Kubernetes types will serialize kube-aggregator types
 // correctly.
diff --git a/charts/kubean/Chart.yaml b/charts/kubean/Chart.yaml
index 505fb83e8..25f1cb862 100644
--- a/charts/kubean/Chart.yaml
+++ b/charts/kubean/Chart.yaml
@@ -1,6 +1,3 @@
-annotations:
-  addon.kpanda.io/namespace: kubean-system
-  addon.kpanda.io/release-name: kubean
 apiVersion: v2
 name: kubean
 description: A Helm chart for kubean
diff --git a/charts/kubean/crds/kubean.io_clusteroperations.yaml b/charts/kubean/crds/kubean.io_clusteroperations.yaml
index 7d4f01153..41179ad92 100644
--- a/charts/kubean/crds/kubean.io_clusteroperations.yaml
+++ b/charts/kubean/crds/kubean.io_clusteroperations.yaml
@@ -45,6 +45,9 @@ spec:
                 type: string
               actionType:
                 type: string
+              activeDeadlineSeconds:
+                format: int64
+                type: integer
               backoffLimit:
                 type: integer
               cluster:
diff --git a/pkg/controllers/clusterops/controller.go b/pkg/controllers/clusterops/controller.go
index 0080dd689..06e6f19f5 100644
--- a/pkg/controllers/clusterops/controller.go
+++ b/pkg/controllers/clusterops/controller.go
@@ -457,6 +457,9 @@ func (c *Controller) NewKubesprayJob(clusterOps *clusteroperationv1alpha1.Cluste
 				},
 			})
 	}
+	if clusterOps.Spec.ActiveDeadlineSeconds != nil && *clusterOps.Spec.ActiveDeadlineSeconds > 0 {
+		job.Spec.ActiveDeadlineSeconds = clusterOps.Spec.ActiveDeadlineSeconds
+	}
 	if !reflect.ValueOf(clusterOps.Spec.Resources).IsZero() {
 		if len(job.Spec.Template.Spec.Containers) > 0 && job.Spec.Template.Spec.Containers[0].Name == "kubespray" {
 			job.Spec.Template.Spec.Containers[0].Resources = clusterOps.Spec.Resources
diff --git a/vendor/kubean.io/api/apis/clusteroperation/v1alpha1/types.go b/vendor/kubean.io/api/apis/clusteroperation/v1alpha1/types.go
index e298f811f..3058351f1 100644
--- a/vendor/kubean.io/api/apis/clusteroperation/v1alpha1/types.go
+++ b/vendor/kubean.io/api/apis/clusteroperation/v1alpha1/types.go
@@ -1,8 +1,8 @@
 package v1alpha1
 
 import (
-	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 	corev1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 	"kubean.io/api/apis"
 )
 
@@ -65,6 +65,8 @@ type Spec struct {
 	PostHook []HookAction `json:"postHook"`
 	// +optional
 	Resources corev1.ResourceRequirements `json:"resources"`
+	// +optional
+	ActiveDeadlineSeconds *int64 `json:"activeDeadlineSeconds"`
 }
 
 type HookAction struct {
diff --git a/vendor/kubean.io/api/apis/clusteroperation/v1alpha1/zz_generated.deepcopy.go b/vendor/kubean.io/api/apis/clusteroperation/v1alpha1/zz_generated.deepcopy.go
index bc08d7f11..0ca48a752 100644
--- a/vendor/kubean.io/api/apis/clusteroperation/v1alpha1/zz_generated.deepcopy.go
+++ b/vendor/kubean.io/api/apis/clusteroperation/v1alpha1/zz_generated.deepcopy.go
@@ -121,6 +121,11 @@ func (in *Spec) DeepCopyInto(out *Spec) {
 		copy(*out, *in)
 	}
 	in.Resources.DeepCopyInto(&out.Resources)
+	if in.ActiveDeadlineSeconds != nil {
+		in, out := &in.ActiveDeadlineSeconds, &out.ActiveDeadlineSeconds
+		*out = new(int64)
+		**out = **in
+	}
 	return
 }
 


Test patch:
diff --git a/pkg/controllers/clusterops/controller_test.go b/pkg/controllers/clusterops/controller_test.go
index 975c87873..3f3b9f732 100644
--- a/pkg/controllers/clusterops/controller_test.go
+++ b/pkg/controllers/clusterops/controller_test.go
@@ -454,6 +454,25 @@ func TestNewKubesprayJob(t *testing.T) {
 			},
 			want: true,
 		},
+		{
+			name: "activeDeadlineSeconds args",
+			args: func() bool {
+				ActiveDeadlineSeconds := int64(10)
+				clusterOps.Spec.ActiveDeadlineSeconds = &ActiveDeadlineSeconds
+				job := controller.NewKubesprayJob(clusterOps)
+				return *job.Spec.ActiveDeadlineSeconds == 10
+			},
+			want: true,
+		},
+		{
+			name: "nil activeDeadlineSeconds args",
+			args: func() bool {
+				clusterOps.Spec.ActiveDeadlineSeconds = nil
+				job := controller.NewKubesprayJob(clusterOps)
+				return job.Spec.ActiveDeadlineSeconds == nil
+			},
+			want: true,
+		},
 	}
 	for _, test := range tests {
 		t.Run(test.name, func(t *testing.T) {