Skip to content

Commit

Permalink
Fix e2e test
Browse files Browse the repository at this point in the history
Signed-off-by: Pierangelo Di Pilato <[email protected]>
  • Loading branch information
pierDipi authored and knative-prow-robot committed Nov 19, 2024
1 parent 2a7de5d commit 1ffc381
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
24 changes: 19 additions & 5 deletions cmd/jobsink/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,6 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}

logger.Debug("Creating job for event", zap.String("URI", r.RequestURI), zap.String("jobName", jobName))

job := js.Spec.Job.DeepCopy()
job.Name = jobName
if job.Labels == nil {
Expand Down Expand Up @@ -314,6 +312,12 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
})
}

logger.Debug("Creating job for event",
zap.String("URI", r.RequestURI),
zap.String("jobName", jobName),
zap.Any("job", job),
)

createdJob, err := h.k8s.BatchV1().Jobs(ref.Namespace).Create(r.Context(), job, metav1.CreateOptions{})
if err != nil && !apierrors.IsAlreadyExists(err) {
logger.Warn("Failed to create job", zap.Error(err))
Expand All @@ -322,8 +326,9 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusInternalServerError)
return
}

logger.Debug("Creating secret for event", zap.String("URI", r.RequestURI), zap.String("jobName", jobName))
if apierrors.IsAlreadyExists(err) {
logger.Debug("Job already exists", zap.String("URI", r.RequestURI), zap.String("jobName", jobName))
}

secret := &corev1.Secret{
TypeMeta: metav1.TypeMeta{},
Expand All @@ -340,7 +345,7 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
Kind: "Job",
Name: createdJob.Name,
UID: createdJob.UID,
Controller: ptr.Bool(false),
Controller: ptr.Bool(true),
BlockOwnerDeletion: ptr.Bool(false),
},
},
Expand All @@ -350,6 +355,12 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
Type: corev1.SecretTypeOpaque,
}

logger.Debug("Creating secret for event",
zap.String("URI", r.RequestURI),
zap.String("jobName", jobName),
zap.Any("secret.metadata", secret.ObjectMeta),
)

_, err = h.k8s.CoreV1().Secrets(ref.Namespace).Create(r.Context(), secret, metav1.CreateOptions{})
if err != nil && !apierrors.IsAlreadyExists(err) {
logger.Warn("Failed to create secret", zap.Error(err))
Expand All @@ -358,6 +369,9 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusInternalServerError)
return
}
if apierrors.IsAlreadyExists(err) {
logger.Debug("Secret already exists", zap.String("URI", r.RequestURI), zap.String("jobName", jobName))
}

w.Header().Add("Location", locationHeader(ref, event.Source(), event.ID()))
w.WriteHeader(http.StatusAccepted)
Expand Down
2 changes: 1 addition & 1 deletion hack/e2e-debug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ wait_until_pods_running knative-eventing || fail_test "Pods in knative-eventing

header "Running tests"

go test -tags=e2e -v -timeout=30m -run="${test_name}" "${test_dir}" || fail_test "Test(s) failed"
go test -tags=e2e -v -timeout=30m -parallel=12 -run="${test_name}" "${test_dir}" || fail_test "Test(s) failed"
3 changes: 2 additions & 1 deletion test/rekt/features/jobsink/jobsink.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,10 @@ func DeleteJobsCascadeSecretsDeletion(jobSink string) *feature.Feature {
}))

f.Requirement("delete jobs for jobsink", func(ctx context.Context, t feature.T) {
policy := metav1.DeletePropagationBackground
err := kubeclient.Get(ctx).BatchV1().
Jobs(environment.FromContext(ctx).Namespace()).
DeleteCollection(ctx, metav1.DeleteOptions{}, metav1.ListOptions{
DeleteCollection(ctx, metav1.DeleteOptions{PropagationPolicy: &policy}, metav1.ListOptions{
LabelSelector: fmt.Sprintf("%s=%s", sinks.JobSinkNameLabel, jobSink),
})
if err != nil {
Expand Down

0 comments on commit 1ffc381

Please sign in to comment.