-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Conversation
Thanks for your pull request! Your pull request does not follow our editorial rules. Could you have a look?
This message is automatically generated by a bot. |
e3984af
to
dc093a8
Compare
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. |
I think adding the AddClusterRole... after AddNamespaceDecorator, works well. Thank you for this comment @metacosm, I solved it with |
43a68d3
to
424b3ce
Compare
Sorry to be a pain but I think the |
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! |
Hi @metacosm, I tried a lot to solve this one without to use |
} | ||
}).collect(Collectors.toList()); | ||
|
||
list.removeAllFromItems(copy); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 😢
There was a problem hiding this comment.
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 😞
There was a problem hiding this comment.
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.
c0d3327
to
0503e89
Compare
...vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/AddNamespaceDecorator.java
Outdated
Show resolved
Hide resolved
92bdaf1
to
6600120
Compare
public void visit(KubernetesListBuilder list) { | ||
List<HasMetadata> buildItems = list.buildItems() | ||
.stream() | ||
.filter(obj -> obj instanceof HasMetadata) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah!
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. |
...vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/AddNamespaceDecorator.java
Show resolved
Hide resolved
9a62805
to
70f1bf8
Compare
The PR should be renamed more appropriately as well, since the PR is not adding a new decorator, simply fixing the existing one. |
There was a problem hiding this 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.
I'm not sure I understand what you mean here.
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 |
This comment has been minimized.
This comment has been minimized.
I tried to do this one and it requires a new implementation/release at Dekorate side. |
There was a problem hiding this 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.
This comment has been minimized.
@mcruzdev I agree but this isn't my call to make 🙍🏼 |
Status for workflow
|
quarkus.kubernetes.namespace
should not be applied to clustered resources #43464