Skip to content

Commit

Permalink
[release-1.8] 🐛 Delete successful job with background propagation pol…
Browse files Browse the repository at this point in the history
…icy (#245)

* Repro of #228

* Delete successful job with background propagation policy

Co-authored-by: Chris Suszyński <[email protected]>
  • Loading branch information
knative-prow-robot and cardil authored Oct 26, 2022
1 parent 5c8c69e commit 974a85e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/phayes/freeport v0.0.0-20220201140144-74d24b5ae9f5
github.com/pkg/errors v0.9.1
github.com/spf13/cobra v1.6.0
github.com/stretchr/testify v1.8.0
github.com/thediveo/enumflag v0.10.0
github.com/wavesoftware/go-commandline v1.0.0
github.com/wavesoftware/go-ensure v1.0.0
Expand Down Expand Up @@ -170,7 +171,6 @@ require (
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.13.0 // indirect
github.com/stretchr/testify v1.8.0 // indirect
github.com/subosito/gotenv v1.4.1 // indirect
github.com/theupdateframework/go-tuf v0.5.0 // indirect
github.com/titanous/rocacheck v0.0.0-20171023193734-afe73141d399 // indirect
Expand Down
5 changes: 4 additions & 1 deletion pkg/k8s/jobrunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ func waitAndClose(tsk task) {
func (j *jobRunner) deleteJob(job *batchv1.Job) error {
ctx := j.kube.Context()
jobs := j.kube.Typed().BatchV1().Jobs(job.GetNamespace())
err := jobs.Delete(ctx, job.GetName(), metav1.DeleteOptions{})
policy := metav1.DeletePropagationBackground
err := jobs.Delete(ctx, job.GetName(), metav1.DeleteOptions{
PropagationPolicy: &policy,
})
if err != nil {
return fmt.Errorf("%w: %v", ErrICSenderJobFailed, err)
}
Expand Down
13 changes: 10 additions & 3 deletions test/e2e/ics_send.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build e2e
// +build e2e

package e2e

Expand All @@ -10,18 +9,25 @@ import (

cloudevents "github.com/cloudevents/sdk-go/v2"
cetest "github.com/cloudevents/sdk-go/v2/test"
"github.com/stretchr/testify/assert"
"gotest.tools/v3/icmd"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"knative.dev/kn-plugin-event/test"
kubeclient "knative.dev/pkg/client/injection/kube/client"
"knative.dev/pkg/logging"
"knative.dev/reconciler-test/pkg/environment"
"knative.dev/reconciler-test/pkg/eventshub"
"knative.dev/reconciler-test/pkg/eventshub/assert"
eventshubassert "knative.dev/reconciler-test/pkg/eventshub/assert"
"knative.dev/reconciler-test/pkg/feature"
"sigs.k8s.io/yaml"
)

const (
issue228Warn = "child pods are preserved by default when jobs are deleted; " +
"set propagationPolicy=Background to remove them or set " +
"propagationPolicy=Orphan to suppress this warning"
)

// SendEventFeature will create a feature.Feature that will test sending an
// event using in cluster sender to SystemUnderTest.
func SendEventFeature(sut SystemUnderTest) *feature.Feature {
Expand Down Expand Up @@ -71,12 +77,13 @@ func sendEvent(ev cloudevents.Event, sink Sink) feature.StepFn {
}); err != nil {
handleSendErr(ctx, t, err, ev)
}
assert.NotContains(t, result.Stderr(), issue228Warn)
log.Info("Succeeded")
}
}

func receiveEvent(ev cloudevents.Event, sinkName string) feature.StepFn {
return assert.OnStore(sinkName).
return eventshubassert.OnStore(sinkName).
MatchEvent(cetest.HasId(ev.ID())).
Exact(1)
}
Expand Down

0 comments on commit 974a85e

Please sign in to comment.