Skip to content

Cronjob example - add fianlizer #4564

@matrus2

Description

@matrus2

What do you want to happen?

I wonder why in the cronjob example there is a condition to check if cronjob contains finalizer and if so add it. See:

		if !controllerutil.ContainsFinalizer(cronJob, myFinalizerName) {
			controllerutil.AddFinalizer(cronJob, myFinalizerName)

if !controllerutil.ContainsFinalizer(cronJob, myFinalizerName) {

However ContainsFinalizer seems to be overkill as AddFinalizer function do the same check inside and it will not add the finalizer once it is already there:

func AddFinalizer(o client.Object, finalizer string) (finalizersUpdated bool) {
	f := o.GetFinalizers()
	for _, e := range f {
		if e == finalizer {
			return false
		}
	}
	o.SetFinalizers(append(f, finalizer))
	return true
}

I would like to remove ContainsFinalizer as it is not needed and update documentation. Before doing so please comment if my reasoning is fine.

Extra Labels

No response

Metadata

Metadata

Assignees

Labels

kind/featureCategorizes issue or PR as related to a new feature.lifecycle/rottenDenotes an issue or PR that has aged beyond stale and will be auto-closed.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions