From 2fb3fed69ccd02a9c1fdb46d27be0d56655ae712 Mon Sep 17 00:00:00 2001 From: odubajDT Date: Tue, 29 Oct 2024 14:20:24 +0100 Subject: [PATCH] support k8s 31 conditions Signed-off-by: odubajDT --- .../deploy-keptn-on-cluster/action.yml | 4 +- .../lifecycle/keptntask/job_utils.go | 6 ++- .../lifecycle/keptntask/job_utils_test.go | 51 ++++++++++++++++++- 3 files changed, 55 insertions(+), 6 deletions(-) diff --git a/.github/actions/deploy-keptn-on-cluster/action.yml b/.github/actions/deploy-keptn-on-cluster/action.yml index 2be44c6781..36e7d31d21 100644 --- a/.github/actions/deploy-keptn-on-cluster/action.yml +++ b/.github/actions/deploy-keptn-on-cluster/action.yml @@ -5,12 +5,12 @@ inputs: required: false description: "Version of kind that should be used" # renovate: datasource=github-releases depName=kubernetes-sigs/kind - default: "v0.18.0" + default: "v0.24.0" k8s-version: required: false description: "Kubernetes version that should be used" # renovate: datasource=github-releases depName=kubernetes/kubernetes - default: "v1.27.3" + default: "v1.31.0" runtime_tag: description: "Tag for the runner image" required: true diff --git a/lifecycle-operator/controllers/lifecycle/keptntask/job_utils.go b/lifecycle-operator/controllers/lifecycle/keptntask/job_utils.go index 279369d866..baaa9c9cd5 100644 --- a/lifecycle-operator/controllers/lifecycle/keptntask/job_utils.go +++ b/lifecycle-operator/controllers/lifecycle/keptntask/job_utils.go @@ -72,9 +72,11 @@ func (r *KeptnTaskReconciler) createFunctionJob(ctx context.Context, req ctrl.Re func (r *KeptnTaskReconciler) updateTaskStatus(job *batchv1.Job, task *apilifecycle.KeptnTask) { if len(job.Status.Conditions) > 0 { - if hasJobCondition(job.Status.Conditions, batchv1.JobComplete) { + if hasJobCondition(job.Status.Conditions, batchv1.JobComplete) || + hasJobCondition(job.Status.Conditions, batchv1.JobSuccessCriteriaMet) { task.Status.Status = apicommon.StateSucceeded - } else if hasJobCondition(job.Status.Conditions, batchv1.JobFailed) { + } else if hasJobCondition(job.Status.Conditions, batchv1.JobFailed) || + hasJobCondition(job.Status.Conditions, batchv1.JobFailureTarget) { task.Status.Status = apicommon.StateFailed task.Status.Message = job.Status.Conditions[0].Message task.Status.Reason = job.Status.Conditions[0].Reason diff --git a/lifecycle-operator/controllers/lifecycle/keptntask/job_utils_test.go b/lifecycle-operator/controllers/lifecycle/keptntask/job_utils_test.go index c9f9d293bc..912d205fc2 100644 --- a/lifecycle-operator/controllers/lifecycle/keptntask/job_utils_test.go +++ b/lifecycle-operator/controllers/lifecycle/keptntask/job_utils_test.go @@ -158,7 +158,6 @@ func TestKeptnTaskReconciler_updateTaskStatus(t *testing.T) { jobStatus := batchv1.JobStatus{ Conditions: []batchv1.JobCondition{ - //todo { Type: batchv1.JobFailed, }, @@ -192,7 +191,6 @@ func TestKeptnTaskReconciler_updateTaskStatus(t *testing.T) { // now, set the job to succeeded job.Status.Conditions = []batchv1.JobCondition{ - //todo { Type: batchv1.JobComplete, }, @@ -203,6 +201,55 @@ func TestKeptnTaskReconciler_updateTaskStatus(t *testing.T) { require.Equal(t, apicommon.StateSucceeded, task.Status.Status) } +func TestKeptnTaskReconciler_updateTaskStatusK8s31(t *testing.T) { + namespace := "default" + taskDefinitionName := "my-task-definition" + + jobStatus := batchv1.JobStatus{ + Conditions: []batchv1.JobCondition{ + { + Type: batchv1.JobFailureTarget, + }, + }, + } + + job := makeJob("my.job", namespace, jobStatus) + + fakeClient := fake.NewClientBuilder().WithObjects(job).Build() + + err := apilifecycle.AddToScheme(fakeClient.Scheme()) + require.Nil(t, err) + + r := &KeptnTaskReconciler{ + Client: fakeClient, + EventSender: eventsender.NewK8sSender(record.NewFakeRecorder(100)), + Log: ctrl.Log.WithName("task-controller"), + Scheme: fakeClient.Scheme(), + } + + task := makeTask("my-task", namespace, taskDefinitionName) + + err = fakeClient.Create(context.TODO(), task) + require.Nil(t, err) + + task.Status.JobName = job.Name + + r.updateTaskStatus(job, task) + + require.Equal(t, apicommon.StateFailed, task.Status.Status) + + // now, set the job to succeeded + job.Status.Conditions = []batchv1.JobCondition{ + { + Type: batchv1.JobSuccessCriteriaMet, + }, + } + + r.updateTaskStatus(job, task) + + require.Equal(t, apicommon.StateSucceeded, task.Status.Status) +} + func TestKeptnTaskReconciler_generateJob(t *testing.T) { namespace := "default" taskName := "my-task"