Skip to content

Commit

Permalink
fix(operator): make sure there is exactly one job per task execution (#…
Browse files Browse the repository at this point in the history
…1672)

Signed-off-by: Florian Bacher <florian.bacher@dynatrace.com>
  • Loading branch information
bacherfl committed Jul 5, 2023
1 parent adba1ec commit b68ba87
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 4 deletions.
2 changes: 0 additions & 2 deletions operator/controllers/lifecycle/keptntask/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/trace"
batchv1 "k8s.io/api/batch/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/tools/record"
Expand Down Expand Up @@ -136,7 +135,6 @@ func (r *KeptnTaskReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
// predicate disabling the auto reconciliation after updating the object status
For(&klcv1alpha3.KeptnTask{}, builder.WithPredicates(predicate.GenerationChangedPredicate{})).
Owns(&batchv1.Job{}).
Complete(r)
}

Expand Down
4 changes: 2 additions & 2 deletions operator/test/component/task/task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ var _ = Describe("Task", Ordered, func() {
}, task)
g.Expect(err).To(BeNil())
g.Expect(task.Status.Status).To(Equal(apicommon.StateFailed))
}, "10s").Should(Succeed())
}, "20s").Should(Succeed())
})
It("succeed task if taskDefiniton for Deno is present in default KLT namespace", func() {
It("succeed task if taskDefinition for Deno is present in default KLT namespace", func() {
By("create default KLT namespace")

ns := &v1.Namespace{
Expand Down
29 changes: 29 additions & 0 deletions test/integration/simple-task/00-install.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apiVersion: lifecycle.keptn.sh/v1alpha3
kind: KeptnTaskDefinition
metadata:
name: pre-deployment-hello
spec:
function:
inline:
code: |
console.log("Pre-Deployment Task has been executed");
---
apiVersion: lifecycle.keptn.sh/v1alpha3
kind: KeptnTask
metadata:
name: pre-deployment-hello-1234
spec:
app: podtato-head
appVersion: 0.1.2
checkType: pre
taskDefinition: pre-deployment-hello
timeout: 5m0s
workload: ""
workloadVersion: ""
context:
appName: ""
appVersion: ""
objectType: ""
taskType: ""
workloadName: ""
workloadVersion: ""
4 changes: 4 additions & 0 deletions test/integration/simple-task/01-teststep.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: kuttl.dev/v1
kind: TestStep
commands:
- script: ./verify-tasks.sh
23 changes: 23 additions & 0 deletions test/integration/simple-task/verify-tasks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

RETRY_COUNT=3
SLEEP_TIME=5

for i in $(seq 1 $RETRY_COUNT); do
NR_JOBS=$(kubectl get jobs -n ${NAMESPACE} --no-headers | wc -l)

if [[ ${NR_JOBS} -eq 1 ]]; then
echo "Found exactly 1 job"
exit 0
else
echo "Number of jobs is not equal to 1"
fi

if [ "$i" -lt "$RETRY_COUNT" ]; then
echo "Sleeping for ${SLEEP_TIME} seconds before retrying..."
sleep ${SLEEP_TIME}
fi
done

echo "Retried ${RETRY_COUNT} times, but expected number of resources could not be verified. Exiting..."
exit 1

0 comments on commit b68ba87

Please sign in to comment.