-
Notifications
You must be signed in to change notification settings - Fork 3k
Allow applying manifests on Kubernetes Dev Service startup #48536
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
Conversation
...nt/src/main/java/io/quarkus/kubernetes/client/deployment/DevServicesKubernetesProcessor.java
Outdated
Show resolved
Hide resolved
...nt/src/main/java/io/quarkus/kubernetes/client/deployment/DevServicesKubernetesProcessor.java
Outdated
Show resolved
Hide resolved
* | ||
* If not set, no manifests are applied. | ||
*/ | ||
Optional<List<String>> manifests(); |
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.
Would it also be possible to make this a non-optional parameter with a default value of []? Then I could replace
if (configuration.manifests.isPresent())
deployManifests(configuration.manifests.get(), devService.getConfig());
with
deployManifests(configuration.manifests.get(), devService.getConfig());
How would it look like to use an @WithDefault
for a list?
cc @metacosm |
badc735
to
70f991f
Compare
I rebased it against main since there were quite a few big changes in the dev service class in main that conflicted with this change. |
5065a69
to
e347c74
Compare
OK, so initial comments: I would separate the deploy phase into a separate build step. Look at Line 116 in 6316ec2
KubernetesClientBuildItem ). This way, you wouldn't have to deal with the client configuration and the deploy step would be done at an appropriate step (at least, I think, I haven't checked).
|
I've never written a Quarkus extension before so I've been reading through the extension documentation. I get the concept of BuildSteps and the dependencies between them, but I don't quite get how to get a BuildStep to run if no other BuildStep consumes it (since this BuildStep is more a followup of the Dev Service creation). Obviously this doesn't work:
But when I follow the error message
and do:
It no longer crashes but doesn't run. Also how do I add a depenendency on the previous |
Does
work? |
Since the dev service configuration step produces |
I am sorry for being such a nuisance and not understanding the build steps framework, but I added the following code to the project to the
This still doesn't do anything. It doesn't matter if I just take the BuildProducer as the only parameter, or if I take the direct example graciously provided by @geoand. I simply never see this log message appear even though I see the log message from the other build step within the same class appear. |
I've pushed the new build step to this MR if anyone would like to take a look? I can deal with all the code, tests and documentation surrounding this MR, I just need the new build step to actually run, which I am really struggling with because I am missing something about how this all works. I did check that none of the class level IfOnly/IfOnlyNots were blocking the new build step, but that doesn't seem to be the case. |
You're not being a nuisance. How build steps work is not always as easy or intuitive as we think they might be. Don't worry about it. I will take a look and see if we can make it work! 😅 |
Thank you, I appreciate the help :) |
I just tried this and the reason why @BuildStep
public void deployManifests(
KubernetesDevServiceInfoBuildItem kubernetesDevServiceInfoBuildItem,
BuildProducer<ArtifactResultBuildItem> fakeProducer) {
log.info("Deploying manifests...");
} doesn't work in |
Ah, this is what I was starting to wonder about because, while debugging, I didn't see anything producing |
@metacosm @geoand I switched the manifests deployment over to a separate build step. However, using the |
Things that I still need to do:
|
...nt/src/main/java/io/quarkus/kubernetes/client/deployment/DevServicesKubernetesProcessor.java
Outdated
Show resolved
Hide resolved
...nt/src/main/java/io/quarkus/kubernetes/client/deployment/DevServicesKubernetesProcessor.java
Outdated
Show resolved
Hide resolved
This is probably something that we should look into, the client build item should probably take the dev service into account. |
Created #48748 |
I manually tested this against the normal, test and dev profiles and it works as expected. Some automated tests seem to be all that's left. |
This comment has been minimized.
This comment has been minimized.
Will squash to a single commit once I'm fully happy with the PR 👍 |
This comment has been minimized.
This comment has been minimized.
@holly-cummins how am I supposed to run the Edit: I figured out I need to add the |
52e918f
to
17e8fab
Compare
I migrated the test over to an integration test and rebased the commits. I am happy with the PR in its current state. This is the only comment that I think may have a nicer solution still: #48536 (comment) |
This comment has been minimized.
This comment has been minimized.
17e8fab
to
0b64160
Compare
This comment has been minimized.
This comment has been minimized.
cfg = getConfiguration(kubernetesClientBuildTimeConfig); | ||
|
||
// Do not run the manifest deployment if no manifests are configured | ||
if (cfg.manifests.isEmpty()) |
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.
Nit picking but maybe this check could be done before so that the "internal" config is not re-created if there are no manifests present? (Sorry, should have noticed this before)
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.
No worries, that's indeed a good point. I moved this to the top.
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.
No wait that doesn't work, because the code is now:
if (cfg.manifests.isEmpty())
return;
if (cfg == null)
cfg = getConfiguration(kubernetesClientBuildTimeConfig);
Which throws an NPE if cfg == null
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 went back to the old approach
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.
Sorry wasn't clear enough, indeed doing it that way would cause an NPE. What I meant was to check fro the presence of the manifests directly in KubernetesDevServicesBuildTimeConfig
, which I thought was injected in the method already. That said, thinking about it some more, it should probably be injected instead of using cfg
because that internal object is only used to check for equality of a potentially already present one. In this step, we only need to get the manifests list from the configuration, and we do not care about the rest. Things definitely work the way they currently are, just doing extra unneeded work. Could definitely be addressed in a subsequent PR if you'd rather be done with this one, which I could understand… 😅
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.
No worries at all, I'm more than happy to improve this PR before merging it.
The manifests are already available from the KubernetesClientBuildConfig
through kubernetesClientBuildTimeConfig.devservices().manifests()
, so I used that rather than also injecting KubernetesDevServicesBuildTimeConfig
. I hope that's an okay solution? I pushed it.
2a0f323
to
c62c180
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
c62c180
to
de3954e
Compare
@metacosm it is ready for another round of review :) |
public void applyManifests( | ||
KubernetesDevServiceInfoBuildItem kubernetesDevServiceInfoBuildItem, | ||
KubernetesClientBuildConfig kubernetesClientBuildTimeConfig) { | ||
if (kubernetesDevServiceInfoBuildItem == null) { |
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 think this check is needed since this step won't be called if the build item is not produced.
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.
Quarkus acts really weird around starting up a Quarkus dev service when the containers from its previous run are still in the process of terminating. I've seen this happen a few times now.
If this happens, we already get other exceptions anyways, but I'd rather not forward a "KubernetesDevServiceInfoBuildIte is null" exception to the users if this happens, because it'll be confusing.
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.
Ah, ok. Wasn't aware of this. Thanks for the explanation, and, indeed, it makes more sense to have some information instead of a simple NPE.
integration-tests/kubernetes-client-devservices/src/main/resources/application.properties
Outdated
Show resolved
Hide resolved
99bde5e
to
44d1530
Compare
Status for workflow
|
Status for workflow
|
This contribution adds a new configuration parameter to the kubernetes-client extension that allows users to deploy manifests to their Kubernetes cluster Dev Service (https://quarkus.io/guides/kubernetes-dev-services).
This is useful because certain applications expect certain resources to be present in the cluster. For our specific use case for example, we expect a custom resource definition to be present such that our Quarkus application can deploy custom resources.
I have for now left out the tests and documentation. I plan to add them as soon as the implementation looks good, but I would first like to figure out if the Quarkus team likes the idea and likes the implementation of it.
You can only deploy manifests using this method and not helm charts. However helm charts are still supported with this feature, since one of the Kubernetes flavors is k3s, which has a helm chart controller built in. I will add this to the documentation with an example of how to deploy a helm chart once I write the documentation for this PR.