Skip to content

Commit

Permalink
address getBackgroundDeletionPolicy() to all controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
freeznet committed Oct 24, 2023
1 parent 5f67573 commit dd128d6
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
8 changes: 8 additions & 0 deletions controllers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,3 +336,11 @@ func ConvertHPAV2ToV2beta2(hpa *autov2.HorizontalPodAutoscaler) *autoscalingv2be

return result
}

func getBackgroundDeletionPolicy() client.DeleteOption {
backgroundDeletion := metav1.DeletePropagationBackground
var deleteOptions client.DeleteOption = &client.DeleteOptions{
PropagationPolicy: &backgroundDeletion,
}
return deleteOptions
}
12 changes: 3 additions & 9 deletions controllers/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ package controllers
import (
"context"

"sigs.k8s.io/controller-runtime/pkg/client"

autoscalingv2beta2 "k8s.io/api/autoscaling/v2beta2"

"github.com/streamnative/function-mesh/api/compute/v1alpha1"
Expand Down Expand Up @@ -336,13 +334,9 @@ func (r *FunctionReconciler) ApplyFunctionVPA(ctx context.Context, function *v1a
}

func (r *FunctionReconciler) ApplyFunctionCleanUpJob(ctx context.Context, function *v1alpha1.Function) error {
backgroundDeletion := metav1.DeletePropagationBackground
var deleteOptions client.DeleteOption = &client.DeleteOptions{
PropagationPolicy: &backgroundDeletion,
}
if !spec.NeedCleanup(function) {
desiredJob := spec.MakeFunctionCleanUpJob(function)
if err := r.Delete(ctx, desiredJob); err != nil {
if err := r.Delete(ctx, desiredJob, getBackgroundDeletionPolicy()); err != nil {
if errors.IsNotFound(err) {
return nil
}
Expand Down Expand Up @@ -386,7 +380,7 @@ func (r *FunctionReconciler) ApplyFunctionCleanUpJob(ctx context.Context, functi
}
} else {
// delete the cleanup job
if err := r.Delete(ctx, desiredJob, deleteOptions); err != nil {
if err := r.Delete(ctx, desiredJob, getBackgroundDeletionPolicy()); err != nil {
return err
}
}
Expand All @@ -401,7 +395,7 @@ func (r *FunctionReconciler) ApplyFunctionCleanUpJob(ctx context.Context, functi

desiredJob := spec.MakeFunctionCleanUpJob(function)
// delete the cleanup job
if err := r.Delete(ctx, desiredJob, deleteOptions); err != nil {
if err := r.Delete(ctx, desiredJob, getBackgroundDeletionPolicy()); err != nil {
return err
}
}
Expand Down
6 changes: 3 additions & 3 deletions controllers/sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ func (r *SinkReconciler) ApplySinkVPA(ctx context.Context, sink *v1alpha1.Sink)
func (r *SinkReconciler) ApplySinkCleanUpJob(ctx context.Context, sink *v1alpha1.Sink) error {
if !spec.NeedCleanup(sink) {
desiredJob := spec.MakeSinkCleanUpJob(sink)
if err := r.Delete(ctx, desiredJob); err != nil {
if err := r.Delete(ctx, desiredJob, getBackgroundDeletionPolicy()); err != nil {
if errors.IsNotFound(err) {
return nil
}
Expand Down Expand Up @@ -376,7 +376,7 @@ func (r *SinkReconciler) ApplySinkCleanUpJob(ctx context.Context, sink *v1alpha1
}
} else {
// delete the cleanup job
if err := r.Delete(ctx, desiredJob); err != nil {
if err := r.Delete(ctx, desiredJob, getBackgroundDeletionPolicy()); err != nil {
return err
}
}
Expand All @@ -391,7 +391,7 @@ func (r *SinkReconciler) ApplySinkCleanUpJob(ctx context.Context, sink *v1alpha1

desiredJob := spec.MakeSinkCleanUpJob(sink)
// delete the cleanup job
if err := r.Delete(ctx, desiredJob); err != nil {
if err := r.Delete(ctx, desiredJob, getBackgroundDeletionPolicy()); err != nil {
return err
}

Expand Down
6 changes: 3 additions & 3 deletions controllers/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ func (r *SourceReconciler) ApplySourceVPA(ctx context.Context, source *v1alpha1.
func (r *SourceReconciler) ApplySourceCleanUpJob(ctx context.Context, source *v1alpha1.Source) error {
if !spec.NeedCleanup(source) {
desiredJob := spec.MakeSourceCleanUpJob(source)
if err := r.Delete(ctx, desiredJob); err != nil {
if err := r.Delete(ctx, desiredJob, getBackgroundDeletionPolicy()); err != nil {
if errors.IsNotFound(err) {
return nil
}
Expand Down Expand Up @@ -378,7 +378,7 @@ func (r *SourceReconciler) ApplySourceCleanUpJob(ctx context.Context, source *v1
}
} else {
// delete the cleanup job
if err := r.Delete(ctx, desiredJob); err != nil {
if err := r.Delete(ctx, desiredJob, getBackgroundDeletionPolicy()); err != nil {
return err
}
}
Expand All @@ -393,7 +393,7 @@ func (r *SourceReconciler) ApplySourceCleanUpJob(ctx context.Context, source *v1

desiredJob := spec.MakeSourceCleanUpJob(source)
// delete the cleanup job
if err := r.Delete(ctx, desiredJob); err != nil {
if err := r.Delete(ctx, desiredJob, getBackgroundDeletionPolicy()); err != nil {
return err
}

Expand Down

0 comments on commit dd128d6

Please sign in to comment.