Skip to content

Controller name as finalizer by default #223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

s-soroosh
Copy link
Contributor

@s-soroosh s-soroosh commented Nov 16, 2020

closes #57
closes #218

@@ -28,4 +28,10 @@
*/
UpdateControl<R> createOrUpdateResource(R resource, Context<R> context);

// What about we let developer to set the finalizer Name through overriding
// this method rather than setting it as attribute in annotation?
default String getDefaultFinalizerName() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Several places in the code finalizer references are named defaultFinalzer. Any objection to renaming them all to finalizer? I suppose they are indeed referring to the finalizer and not the default one.
e.g.
Several spots in this file:
https://github.com/java-operator-sdk/java-operator-sdk/blob/master/operator-framework/src/main/java/io/javaoperatorsdk/operator/processing/EventDispatcher.java#L24

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree.. sounds like we're calling everything defaultFinalizer even though we just mean the finalizer. This is actually confusing as there a thing called the default finalizer name. @csviri can you confirm we're seeing this right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I renamed the default finalizer to finalizer or similar everywhere in docs, logs and code for now.
LMK if you have any objection/thoughts about it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@psycho-ir looks good, yep it jus tfinalizer in most of the cases not default finalizer.
I don't think we should use default method in the interface however. Would stick to the annotation to override the finalizer name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I have removed this method already.

@s-soroosh
Copy link
Contributor Author

s-soroosh commented Nov 16, 2020

Some of Integration tests are failing due to the long finalized name. i.e ->

name part must be no more than 63 characters.

We can either truncate the package name or add validation on the finalizerName length and ask the developer to override the name a pick a shorter value.

@adam-sandor
Copy link
Collaborator

How about not putting the package name in the finalizer at all?

@s-soroosh
Copy link
Contributor Author

How about not putting the package name in the finalizer at all?

It may result in conflict. What I also found risky about using the class name is that refactoring the code may cause unintended different finalizer name.

What about using the crdName which is less likely to be changed and if it changes then I think it's OK to have another finalizer name by default. i.e crdName.finalizer

@adam-sandor
Copy link
Collaborator

Good thinking, CRD name is better. If that changes than you really need to think about migration strategy anyway. Do we need to add .finalizer to the end?

@s-soroosh
Copy link
Contributor Author

Good thinking, CRD name is better. If that changes than you really need to think about migration strategy anyway. Do we need to add .finalizer to the end?

I had a look into a few finalizers and didn't any de facto in naming conventions.
e.g. service.kubernetes.io/load-balancer-cleanup or even foregroundDeletion.
These options looks good to m e:

  • crdName
  • crdName/finalizer
  • finalizer.crdName

@s-soroosh
Copy link
Contributor Author

Good thinking, CRD name is better. If that changes than you really need to think about migration strategy anyway. Do we need to add .finalizer to the end?

I had a look into a few finalizers and didn't any de facto in naming conventions.
e.g. service.kubernetes.io/load-balancer-cleanup or even foregroundDeletion.
These options looks good to m e:

  • crdName
  • crdName/finalizer
  • finalizer.crdName

I picked crdName option, easy to change though in case you prefer any other convention.

@adam-sandor
Copy link
Collaborator

I'll give this a test today and merge if it's alright

@metacosm
Copy link
Collaborator

metacosm commented Nov 18, 2020

Good thinking, CRD name is better. If that changes than you really need to think about migration strategy anyway. Do we need to add .finalizer to the end?

I had a look into a few finalizers and didn't any de facto in naming conventions.
e.g. service.kubernetes.io/load-balancer-cleanup or even foregroundDeletion.
These options looks good to m e:

  • crdName
  • crdName/finalizer
  • finalizer.crdName

I picked crdName option, easy to change though in case you prefer any other convention.

This is actually incorrect according to the spec: https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#finalizers where a custom finalizer is supposed to be <domain name>/<finalizer name>

Note also that #229 uses the addFinalizer method added on HasMetadata in 5.0 which validates that part (and is why the tests are currently failing on that PR).

@s-soroosh
Copy link
Contributor Author

Good thinking, CRD name is better. If that changes than you really need to think about migration strategy anyway. Do we need to add .finalizer to the end?

I had a look into a few finalizers and didn't any de facto in naming conventions.
e.g. service.kubernetes.io/load-balancer-cleanup or even foregroundDeletion.
These options looks good to m e:

  • crdName
  • crdName/finalizer
  • finalizer.crdName

I picked crdName option, easy to change though in case you prefer any other convention.

This is actually incorrect according to the spec: https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#finalizers where a custom finalizer is supposed to be <domain name>/<finalizer name>

Note also that #229 uses the addFinalizer method added on HasMetadata in 5.0 which validates that part (and is why the tests are currently failing on that PR).

Good catch! so I'll go with crdName/finalizer option as the default name.

@s-soroosh s-soroosh closed this Nov 18, 2020
@s-soroosh s-soroosh reopened this Nov 18, 2020
@s-soroosh
Copy link
Contributor Author

Added the /finalizer suffix to be compliant with the specification.

@kirek007
Copy link
Contributor

LGTM!

@kirek007 kirek007 merged commit bc65b1c into operator-framework:master Nov 19, 2020
@metacosm
Copy link
Collaborator

metacosm commented Nov 21, 2020

@psycho-ir do you recall which test failed if the name was too long? The problem with using the CRD name is that, while the group should usually be a valid domain name, it doesn't appear to be mandatory. This is causing issues still with the k8s client 5.0 upgrade. I've opened an issue for this: #233

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use Controller name as finalizer
5 participants