Skip to content

Commit

Permalink
support k8s 31 conditions
Browse files Browse the repository at this point in the history
Signed-off-by: odubajDT <[email protected]>
  • Loading branch information
odubajDT committed Oct 29, 2024
1 parent 5b5392e commit 2fb3fed
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .github/actions/deploy-keptn-on-cluster/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ func TestKeptnTaskReconciler_updateTaskStatus(t *testing.T) {

jobStatus := batchv1.JobStatus{
Conditions: []batchv1.JobCondition{
//todo
{
Type: batchv1.JobFailed,
},
Expand Down Expand Up @@ -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,
},
Expand All @@ -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"
Expand Down

0 comments on commit 2fb3fed

Please sign in to comment.