Skip to content
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

Add decorator to remove namespace from ClusterRole and ClusterRoleBin… #43579

Merged
merged 1 commit into from
Nov 6, 2024

Conversation

mcruzdev
Copy link
Contributor

@mcruzdev mcruzdev commented Sep 29, 2024

Copy link

quarkus-bot bot commented Sep 29, 2024

Thanks for your pull request!

Your pull request does not follow our editorial rules. Could you have a look?

  • title should not end up with ellipsis (make sure the title is complete)

This message is automatically generated by a bot.

@metacosm
Copy link
Contributor

While this solution probably works, I would rather we don't add the namespace to clustered resources in the first place instead of adding it and then removing it.

@mcruzdev
Copy link
Contributor Author

mcruzdev commented Sep 29, 2024

I think adding the AddClusterRole... after AddNamespaceDecorator, works well.

Thank you for this comment @metacosm, I solved it with before method!

@metacosm
Copy link
Contributor

Sorry to be a pain but I think the AddNamespaceDecorator should actually be rewritten completely to deal with this instead of trying to order things in such a way that things work. Maybe the decorator should only target resources that implement Namespaced so that we know for sure that processed resources need a namespace?

@mcruzdev
Copy link
Contributor Author

No worry, I was trying to solve it without big changes, but I agree with you, to deal with order is a problem. I will try to solve in a better way, thank you for the help @metacosm!

@geoand geoand requested a review from iocanel September 30, 2024 11:16
@mcruzdev
Copy link
Contributor Author

mcruzdev commented Oct 4, 2024

Hi @metacosm, I tried a lot to solve this one without to use after() method... I think that the previous way of configuring order is still better. Do you know another way to do the samething?

}
}).collect(Collectors.toList());

list.removeAllFromItems(copy);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @metacosm, I didn't want to have to remove and then add. Do you know, another way?

Copy link
Contributor

Choose a reason for hiding this comment

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

I would do something like:

final var updated = list.buildItems().stream()
                .filter(Namespaced.class::isInstance)
                .peek(o -> o.getMetadata().edit().withNamespace(namespace).build())
                .toList();
list.withItems(updated);

but I haven't checked if this actually works. This has the advantage to not require maintaining a list of clustered resources. Ideally, we wouldn't need to build the items in the first place but I'm not sure this is avoidable. withItems resets the list completely so it should be faster than first removing then adding the items again. Maybe @iocanel has a better solution?

Copy link
Contributor Author

@mcruzdev mcruzdev Oct 5, 2024

Choose a reason for hiding this comment

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

With this aproach:

                .filter(Namespaced.class::isInstance)

does not work 😢

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 don't like using .set. I prefer the object to manage its own state, but it's not working 😞

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm surprised that it doesn't work. I'll check tomorrow.

@mcruzdev mcruzdev force-pushed the issue-43464 branch 2 times, most recently from c0d3327 to 0503e89 Compare October 5, 2024 16:34
@mcruzdev mcruzdev force-pushed the issue-43464 branch 2 times, most recently from 92bdaf1 to 6600120 Compare October 5, 2024 23:10
public void visit(KubernetesListBuilder list) {
List<HasMetadata> buildItems = list.buildItems()
.stream()
.filter(obj -> obj instanceof HasMetadata)
Copy link
Contributor

Choose a reason for hiding this comment

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

At the very least, you don't need this: all the items in the list should be HasMetadata instances.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah!

@metacosm
Copy link
Contributor

metacosm commented Oct 8, 2024

This should work:

public void visit(KubernetesListBuilder list) {
        final var updated = list.buildItems().stream()
                .peek(o -> {
                    if (o instanceof Namespaced) {
                        final ObjectMeta metadata = o.getMetadata();
                        // only set the namespace if it hasn't already been otherwise explicitly set
                        if (metadata.getNamespace() == null) {
                            metadata.setNamespace(namespace);
                            o.setMetadata(metadata);
                        }
                    }
                })
                .toList();
        list.withItems(updated);
    }

The previous version was filtering so the updated list didn't contain any of the cluster-scoped resources.

@mcruzdev mcruzdev force-pushed the issue-43464 branch 3 times, most recently from 9a62805 to 70f1bf8 Compare October 15, 2024 16:54
@metacosm
Copy link
Contributor

The PR should be renamed more appropriately as well, since the PR is not adding a new decorator, simply fixing the existing one.

Copy link
Contributor

@iocanel iocanel left a comment

Choose a reason for hiding this comment

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

I really don't like it when a visitor operates on levels lower than its target, as it makes it really hard to order things.

I am wondering if it would be possible to crete a new kind of decroator based on sundrio's PathAwareTypedVisitor that allow devs to look up the parent node and / or the parent type.

If this is not possible, then we shall proceed with this approach.

@metacosm
Copy link
Contributor

I really don't like it when a visitor operates on levels lower than its target, as it makes it really hard to order things.

I'm not sure I understand what you mean here.

I am wondering if it would be possible to crete a new kind of decroator based on sundrio's PathAwareTypedVisitor that allow devs to look up the parent node and / or the parent type.

That would require a new Dekorate release, though. And I'm not sure what benefits that would bring. How looking up the parent would help in this case? Do you mean to look up the resource object from its ObjectMeta?
The current approach seems simpler with the downside of requiring building the objects instead of working directly on builders.

This comment has been minimized.

@mcruzdev
Copy link
Contributor Author

I tried to do this one and it requires a new implementation/release at Dekorate side.

@mcruzdev
Copy link
Contributor Author

Hi @iocanel, @metacosm what is the decision?

@iocanel iocanel self-requested a review October 24, 2024 09:56
Copy link
Contributor

@iocanel iocanel left a comment

Choose a reason for hiding this comment

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

The suggested change not only requires a decorate release, but it requires a major release that is also not trivial.

So, given that it will require time, I am going to accept this.

This comment has been minimized.

@mcruzdev
Copy link
Contributor Author

mcruzdev commented Nov 6, 2024

Hi @iocanel @metacosm, sorry for disturb you, but this one can be merged?

@metacosm
Copy link
Contributor

metacosm commented Nov 6, 2024

@mcruzdev I agree but this isn't my call to make 🙍🏼

@cescoffier cescoffier added the triage/waiting-for-ci Ready to merge when CI successfully finishes label Nov 6, 2024
Copy link

quarkus-bot bot commented Nov 6, 2024

Status for workflow Quarkus CI

This is the status report for running Quarkus CI on commit 34bb99d.

✅ The latest workflow run for the pull request has completed successfully.

It should be safe to merge provided you have a look at the other checks in the summary.

You can consult the Develocity build scans.

@cescoffier cescoffier merged commit 13eb3c4 into quarkusio:main Nov 6, 2024
22 checks passed
@quarkus-bot quarkus-bot bot added kind/bugfix and removed triage/waiting-for-ci Ready to merge when CI successfully finishes labels Nov 6, 2024
@quarkus-bot quarkus-bot bot added this to the 3.17 - main milestone Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

quarkus.kubernetes.namespace should not be applied to clustered resources
4 participants