Skip to content

Commit 2c5ba22

Browse files
authored
feat: add support for Kubernetes v1.31 (#3785)
Signed-off-by: odubajDT <[email protected]>
1 parent 9e742e8 commit 2c5ba22

File tree

8 files changed

+67
-18
lines changed

8 files changed

+67
-18
lines changed

.github/actions/deploy-keptn-on-cluster/action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ inputs:
55
required: false
66
description: "Version of kind that should be used"
77
# renovate: datasource=github-releases depName=kubernetes-sigs/kind
8-
default: "v0.18.0"
8+
default: "v0.24.0"
99
k8s-version:
1010
required: false
1111
description: "Kubernetes version that should be used"
1212
# renovate: datasource=github-releases depName=kubernetes/kubernetes
13-
default: "v1.27.3"
13+
default: "v1.31.0"
1414
runtime_tag:
1515
description: "Tag for the runner image"
1616
required: true

lifecycle-operator/controllers/lifecycle/keptntask/job_utils.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,28 @@ func (r *KeptnTaskReconciler) createFunctionJob(ctx context.Context, req ctrl.Re
7272

7373
func (r *KeptnTaskReconciler) updateTaskStatus(job *batchv1.Job, task *apilifecycle.KeptnTask) {
7474
if len(job.Status.Conditions) > 0 {
75-
if job.Status.Conditions[0].Type == batchv1.JobComplete {
75+
if hasJobCondition(job.Status.Conditions, batchv1.JobComplete) ||
76+
hasJobCondition(job.Status.Conditions, batchv1.JobSuccessCriteriaMet) {
7677
task.Status.Status = apicommon.StateSucceeded
77-
} else if job.Status.Conditions[0].Type == batchv1.JobFailed {
78+
} else if hasJobCondition(job.Status.Conditions, batchv1.JobFailed) ||
79+
hasJobCondition(job.Status.Conditions, batchv1.JobFailureTarget) {
7880
task.Status.Status = apicommon.StateFailed
7981
task.Status.Message = job.Status.Conditions[0].Message
8082
task.Status.Reason = job.Status.Conditions[0].Reason
8183
}
8284
}
8385
}
8486

87+
func hasJobCondition(conditions []batchv1.JobCondition, searched batchv1.JobConditionType) bool {
88+
for _, v := range conditions {
89+
if v.Type == searched {
90+
return true
91+
}
92+
}
93+
94+
return false
95+
}
96+
8597
func (r *KeptnTaskReconciler) getJob(ctx context.Context, jobName string, namespace string) (*batchv1.Job, error) {
8698
job := &batchv1.Job{}
8799
err := r.Client.Get(ctx, types.NamespacedName{Name: jobName, Namespace: namespace}, job)

lifecycle-operator/controllers/lifecycle/keptntask/job_utils_test.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ func TestKeptnTaskReconciler_createJob_withTaskDefInDefaultNamespace(t *testing.
152152
}, resultingJob.Annotations)
153153
}
154154

155+
//nolint:dupl
155156
func TestKeptnTaskReconciler_updateTaskStatus(t *testing.T) {
156157
namespace := "default"
157158
taskDefinitionName := "my-task-definition"
@@ -201,6 +202,56 @@ func TestKeptnTaskReconciler_updateTaskStatus(t *testing.T) {
201202
require.Equal(t, apicommon.StateSucceeded, task.Status.Status)
202203
}
203204

205+
//nolint:dupl
206+
func TestKeptnTaskReconciler_updateTaskStatusK8s31(t *testing.T) {
207+
namespace := "default"
208+
taskDefinitionName := "my-task-definition"
209+
210+
jobStatus := batchv1.JobStatus{
211+
Conditions: []batchv1.JobCondition{
212+
{
213+
Type: batchv1.JobFailureTarget,
214+
},
215+
},
216+
}
217+
218+
job := makeJob("my.job", namespace, jobStatus)
219+
220+
fakeClient := fake.NewClientBuilder().WithObjects(job).Build()
221+
222+
err := apilifecycle.AddToScheme(fakeClient.Scheme())
223+
require.Nil(t, err)
224+
225+
r := &KeptnTaskReconciler{
226+
Client: fakeClient,
227+
EventSender: eventsender.NewK8sSender(record.NewFakeRecorder(100)),
228+
Log: ctrl.Log.WithName("task-controller"),
229+
Scheme: fakeClient.Scheme(),
230+
}
231+
232+
task := makeTask("my-task", namespace, taskDefinitionName)
233+
234+
err = fakeClient.Create(context.TODO(), task)
235+
require.Nil(t, err)
236+
237+
task.Status.JobName = job.Name
238+
239+
r.updateTaskStatus(job, task)
240+
241+
require.Equal(t, apicommon.StateFailed, task.Status.Status)
242+
243+
// now, set the job to succeeded
244+
job.Status.Conditions = []batchv1.JobCondition{
245+
{
246+
Type: batchv1.JobSuccessCriteriaMet,
247+
},
248+
}
249+
250+
r.updateTaskStatus(job, task)
251+
252+
require.Equal(t, apicommon.StateSucceeded, task.Status.Status)
253+
}
254+
204255
func TestKeptnTaskReconciler_generateJob(t *testing.T) {
205256
namespace := "default"
206257
taskName := "my-task"

test/chainsaw/integration/TTLSecondsAfterFinished-in-jobs/00-assert.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,4 @@ metadata:
99
spec:
1010
ttlSecondsAfterFinished: 100
1111
status:
12-
conditions:
13-
- type: Complete
14-
status: 'True'
1512
succeeded: 1

test/chainsaw/integration/container-runtime/00-assert.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,4 @@ spec:
4444
- '-c'
4545
- 'sleep 30'
4646
status:
47-
conditions:
48-
- type: Complete
49-
status: 'True'
5047
succeeded: 1

test/chainsaw/integration/imagepullsecret/00-assert.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,4 @@ spec:
4646
imagePullSecrets:
4747
- name: my-registry-secret
4848
status:
49-
conditions:
50-
- type: Complete
51-
status: 'True'
5249
succeeded: 1

test/chainsaw/integration/simple-deployment-python-runtime/00-assert.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,4 @@ metadata:
3131
keptn.sh/version: '0.4'
3232
keptn.sh/workload: waiter-waiter
3333
status:
34-
conditions:
35-
- type: Complete
36-
status: 'True'
3734
succeeded: 1

test/chainsaw/integration/simple-deployment-recursive-task/00-assert.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ apiVersion: batch/v1
1111
kind: Job
1212
metadata:
1313
annotations:
14-
batch.kubernetes.io/job-tracking: ""
1514
keptn.sh/app: waiter
1615
keptn.sh/version: "0.4"
1716
keptn.sh/workload: waiter-waiter
@@ -43,7 +42,6 @@ apiVersion: batch/v1
4342
kind: Job
4443
metadata:
4544
annotations:
46-
batch.kubernetes.io/job-tracking: ""
4745
keptn.sh/app: waiter
4846
keptn.sh/version: "0.4"
4947
keptn.sh/workload: waiter-waiter

0 commit comments

Comments
 (0)