Skip to content

Commit

Permalink
feat: add support for Kubernetes v1.31 (#3785)
Browse files Browse the repository at this point in the history
Signed-off-by: odubajDT <[email protected]>
  • Loading branch information
odubajDT authored Oct 29, 2024
1 parent 9e742e8 commit 2c5ba22
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 18 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
16 changes: 14 additions & 2 deletions lifecycle-operator/controllers/lifecycle/keptntask/job_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,28 @@ 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 job.Status.Conditions[0].Type == batchv1.JobComplete {
if hasJobCondition(job.Status.Conditions, batchv1.JobComplete) ||
hasJobCondition(job.Status.Conditions, batchv1.JobSuccessCriteriaMet) {
task.Status.Status = apicommon.StateSucceeded
} else if job.Status.Conditions[0].Type == 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
}
}
}

func hasJobCondition(conditions []batchv1.JobCondition, searched batchv1.JobConditionType) bool {
for _, v := range conditions {
if v.Type == searched {
return true
}
}

return false
}

func (r *KeptnTaskReconciler) getJob(ctx context.Context, jobName string, namespace string) (*batchv1.Job, error) {
job := &batchv1.Job{}
err := r.Client.Get(ctx, types.NamespacedName{Name: jobName, Namespace: namespace}, job)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ func TestKeptnTaskReconciler_createJob_withTaskDefInDefaultNamespace(t *testing.
}, resultingJob.Annotations)
}

//nolint:dupl
func TestKeptnTaskReconciler_updateTaskStatus(t *testing.T) {
namespace := "default"
taskDefinitionName := "my-task-definition"
Expand Down Expand Up @@ -201,6 +202,56 @@ func TestKeptnTaskReconciler_updateTaskStatus(t *testing.T) {
require.Equal(t, apicommon.StateSucceeded, task.Status.Status)
}

//nolint:dupl
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,4 @@ metadata:
spec:
ttlSecondsAfterFinished: 100
status:
conditions:
- type: Complete
status: 'True'
succeeded: 1
3 changes: 0 additions & 3 deletions test/chainsaw/integration/container-runtime/00-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,4 @@ spec:
- '-c'
- 'sleep 30'
status:
conditions:
- type: Complete
status: 'True'
succeeded: 1
3 changes: 0 additions & 3 deletions test/chainsaw/integration/imagepullsecret/00-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,4 @@ spec:
imagePullSecrets:
- name: my-registry-secret
status:
conditions:
- type: Complete
status: 'True'
succeeded: 1
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,4 @@ metadata:
keptn.sh/version: '0.4'
keptn.sh/workload: waiter-waiter
status:
conditions:
- type: Complete
status: 'True'
succeeded: 1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ apiVersion: batch/v1
kind: Job
metadata:
annotations:
batch.kubernetes.io/job-tracking: ""
keptn.sh/app: waiter
keptn.sh/version: "0.4"
keptn.sh/workload: waiter-waiter
Expand Down Expand Up @@ -43,7 +42,6 @@ apiVersion: batch/v1
kind: Job
metadata:
annotations:
batch.kubernetes.io/job-tracking: ""
keptn.sh/app: waiter
keptn.sh/version: "0.4"
keptn.sh/workload: waiter-waiter
Expand Down

0 comments on commit 2c5ba22

Please sign in to comment.