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
Register ControllerFactory bean definition as opposite to bean instance #1516
Register ControllerFactory bean definition as opposite to bean instance #1516
Conversation
Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA. It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
Welcome @asavov! |
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.
/lgtm
@asavov can you remove @Autowired
from the commit message, otherwise it will lead to spammy github references on the page
Looks like you need to run |
6fb7950
to
aa27bb0
Compare
Done with updated commit. |
Done. And now seems ok. |
@dsyer @brendanburns https://github.com/kubernetes-client/java/pull/1516/checks has failed. Not sure it's related to this PR. How to Re-run it through UI? Or should I upload new "dummy" commit? |
aa27bb0
to
bf5e2f8
Compare
You just signed CNCF Individual Contributor License Agreement. Seems this one is also checked. |
Looking good. Sorry for the CLA hassle (at least you only have to do it once). I would make a couple of small (but could be important) changes. I don’t see a need to inject the |
No worries at all. It's done.
Do you refer this snippet? The whole idea is to be able to do exactly this logic: autowire other beans, benefiting from Spring container. I just used SharedInformer, cause it's natural fit, still it might be Env, or AppCtx or @value(${some.prop}). Would provided more details, cause maybe I miss something.
The way to go is to extend from |
|
You are absolutely right. Hmm. What's the Spring/right way for a |
One way would be to set a constructor arg ref (not value) if you can get the bean name by type for the @Bean
public static BeanDefinitionRegistryPostProcessor processor() {
return new BeanDefinitionRegistryPostProcessor() {
private ConfigurableListableBeanFactory beanFactory;
@Override
public void postProcessBeanFactory(
ConfigurableListableBeanFactory beanFactory) throws BeansException {
this.beanFactory = beanFactory;
}
@Override
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry)
throws BeansException {
BeanDefinitionBuilder definition = BeanDefinitionBuilder
.genericBeanDefinition(Bar.class,
() -> new Bar(beanFactory.getBean(Foo.class)));
registry.registerBeanDefinition("bar", definition.getBeanDefinition());
}
};
} |
Looking at the code of |
Those two post processors are unrelated to this change though, right? They need to be fixed in probably almost identical ways, if we decide we want to keep them, but I don't think we have to interrupt this PR process to deal with that. |
I miss that, cause the focus of the change is |
I'm sorry, you are right. You fixed one of them in this PR, though? So we can leave the other one for another effort? |
Should I go with current version (if approved) OR remove
(causing SharedInformerFactory to be pre-instantiated) and default to the SINGLETON
|
That would work. We'd have to be sure about the bean name. The lazy instantiation alternative with a |
@dsyer Does this version satisfy-them-all ? :)
|
That would work, but I don't see why we need to keep the old constructor, or the code path with |
If backward compatibility is not an issue - my pleasure to simplify it :) |
IMO no-one is using this class directly - it's all via autoconfiguration. Plus although it still says 11.0.1-SNAPSHOT in the top level POM, I know the next release will be 12.0.0 because of the Joda time changes. So I don't think we should care about backwards compatibility here. @yue9944882 would have to say for sure, but she also said that other day that this whole module is considered a prototype still, so breaking changes are expected. |
bf5e2f8
to
62aadea
Compare
PR update with new code as discussed. |
c48a82b
to
c7ab7d6
Compare
With this change KubernetesReconcilerProcessor conforms to BeanFactoryPostProcessor contract to register BeanDefinitions and not to manipulate bean instances. As a result Reconciler beans are: 1) not created at all by postProcessBeanFactory (which was the core issue) 2) participate in Spring container management hooks, and hence autowired
c7ab7d6
to
ad7f1b6
Compare
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) { | ||
for (String reconcilerName : beanFactory.getBeanNamesForType(Reconciler.class)) { | ||
|
||
Supplier<KubernetesControllerFactory> kubernetesControllerFactorySupplier = |
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 guess this can be inlined. It's a matter of taste though.
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.
Agree it's opinionated. I prefer readability vs. compact code.
By the way the PR is finally green... :)
LGTM |
Nice! and thank you. This is my first contribution, so the PR would be eventually merged by someone on kubernetes-client team with write access. No more actions on my site? |
Yes, we have to wait for @brendanburns and @yue9944882 . If they have no more changes to request they can merge it without you doing anything else. |
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.
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: asavov, yue9944882 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@asavov are you going to do the same thing for |
@dsyer I'd like to. Still at the moment not enough bandwidth. |
See #1532 for my solution |
With this change
KubernetesReconcilerProcessor
conforms toBeanFactoryPostProcessor
contract to register
BeanDefinitions
and not to manipulate bean instances.As a result Reconciler beans are:
postProcessBeanFactory
(which was the core issue)@Autowired