Skip to content

fix: generate proper resource name & finalizer for group-less resources #814

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
merged 3 commits into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@
public class ReconcilerUtils {

private static final String FINALIZER_NAME_SUFFIX = "/finalizer";
protected static final String MISSING_GROUP_SUFFIX = ".javaoperatorsdk.io";

public static String getDefaultFinalizerName(String crdName) {
return crdName + FINALIZER_NAME_SUFFIX;
public static String getDefaultFinalizerName(String resourceName) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Pls add unit test

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

// resource names for historic resources such as Pods are missing periods and therefore do not
// constitute valid domain names as mandated by Kubernetes so generate one that does
if (resourceName.indexOf('.') < 0) {
resourceName = resourceName + MISSING_GROUP_SUFFIX;
}
return resourceName + FINALIZER_NAME_SUFFIX;
}

public static String getNameFor(Class<? extends Reconciler> reconcilerClass) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@ default String getName() {
}

default String getResourceTypeName() {
return HasMetadata.getFullResourceName(getResourceClass());
return getResourceTypeName(getResourceClass());
}

static <T extends HasMetadata> String getResourceTypeName(Class<T> resourceClass) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here, pls add unit test.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is a workaround for a fix that will be in fabric8 5.12 where it's already pretty well tested.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, that is kinda questionable, still our code, maybe we can copy the unit test too?

Copy link
Collaborator

Choose a reason for hiding this comment

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

But if too much effort, I'm ok to skip it.

final var group = HasMetadata.getGroup(resourceClass);
final var plural = HasMetadata.getPlural(resourceClass);
return (group == null || group.isEmpty()) ? plural : plural + "." + group;
// use when fabric8 5.12 is released
// return HasMetadata.getFullResourceName(getResourceClass());
}

default String getFinalizer() {
Expand Down