Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

Hi there!

I face the case where I have to create an external Custom Resource as a dependent resource of my primary one. Typically, I have to reconcile a Strimzi.io Kafka and KafkaTopic from my primary resource. As those custom resources are particularly lightweight (and also because I do not control which version of Strimzi CRD are actually deployed on the cluster and I'll probably have to manage different versions), I was thinking reconciling those features using YAML resources only.

The approach I tried so far is to define a StrimziKafkaTopicDependentResource class that extends KubernetesDependentResource<HasMetadata, Primary> and implements GarbageCollected<Primary>. In this class, I implement HasMetadata desired(Primary primary, Context<Primary> context), load topic resource description as a YAML string and finally call getKubernetesClient().resource(strimziTopic).inNamespace(microcksMetadata.getNamespace()).createOrReplace();.

The problem I'm facing is when I build an EventSource for this dependent resource. I try to call KubernertesDependentResource.initEventSource(context) but ends with the following stack trace:

2023-04-24 11:32:28,882 ERROR [io.qua.run.Application] (Quarkus Main Thread) Failed to start application (with profile [dev]): java.lang.IllegalArgumentException: Should provide non-null group. Is io.fabric8.kubernetes.api.model.HasMetadata properly annotated with @Group and/or @Version?
	at io.fabric8.kubernetes.api.model.HasMetadata.getFullResourceName(HasMetadata.java:167)
	at io.javaoperatorsdk.operator.ReconcilerUtils.getResourceTypeName(ReconcilerUtils.java:41)
	at io.javaoperatorsdk.operator.api.config.DefaultResourceConfiguration.<init>(DefaultResourceConfiguration.java:27)
	at io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration$DefaultInformerConfiguration.<init>(InformerConfiguration.java:42)
	at io.javaoperatorsdk.operator.api.config.informer.InformerConfiguration$InformerConfigurationBuilder.build(InformerConfiguration.java:207)
	at io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResource.configureWith(KubernetesDependentResource.java:80)
	at io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResource.createEventSource(KubernetesDependentResource.java:198)
	at io.javaoperatorsdk.operator.processing.dependent.kubernetes.KubernetesDependentResource.createEventSource(KubernetesDependentResource.java:32)
	at io.javaoperatorsdk.operator.processing.dependent.AbstractEventSourceHolderDependentResource.eventSource(AbstractEventSourceHolderDependentResource.java:45)
	at io.javaoperatorsdk.operator.processing.dependent.AbstractEventSourceHolderDependentResource.initEventSource(AbstractEventSourceHolderDependentResource.java:67)

I think I understand the issue but I'm not sure about the best way to solve this.. Is there another correct way of initializing event source in that case? Should I extend HasMetadata with basic implementation that provides group and version in that case? What's the best way of solving this?

Thanks for help and advices!

You must be logged in to vote

Replies: 2 comments · 7 replies

Comment options

Hi @lbroudoux ,

the dependent resource is also responsible to provide the event source. You can provide one that you initialize instead with EventSourceInitializer in the reconciler, then in dependent resource just use the useEventSourceWithName=[name]. See:

https://github.com/java-operator-sdk/java-operator-sdk/blob/3daac13deeddeaa48c241656ed2c14aa36ebecf8/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/Dependent.java#L68-L68

However, the issue will be probably with the event source in this case, that is more bound to a static resource, but you can add I guess multiple classes of strimzi resources on the classpath and on runtime make sure which one to use based on the CRD present on the cluster.

You must be logged in to vote
4 replies
@lbroudoux
Comment options

Thanks for your response but sorry I'm stuck on this one. Forgot to say that I'm in the context of a un-managed/manually written workflow reconciliation and thus I'm not putting annotation on my classes. I'm looking for some equivalent on DependentResource but cannot found any at the moment.

@csviri
Comment options

@csviri
Comment options

Assuming you DR extends this class (probably is), you can just use this method directly and set the event source.

@lbroudoux
Comment options

Sorry but still stuck on this one... Could you add some more details please?
On other resources I just setup a resource discriminator and then call initEventSource(context). I've never changed anything else on event sources.

Thanks,

Comment options

That's an interesting use case that we indeed currently don't support well. Maybe we should look into making such a scenario simpler to deal with?

You must be logged in to vote
3 replies
@lbroudoux
Comment options

It would be awesome. Or at least having some guidelines on how to implement it could be great. 👍

@lbroudoux
Comment options

Hi there!

Still struggling with this after a break from other topics. I'm kind of stuck here 😢

Since previous comments, I had a look at GenericKubernetesResource from Fabric8 and it looks great even if it seems a bit tedious to use (all the spec details should be provided through the additionalProperties map and I'm loading a bunch of YAML)

What I'd like to have in an ideal world, is represented in the following pseudo-Java code:

public class StrimziKafkaTopicDependentResource extends KubernetesDependentResource<HasMetadata, Primary> {

  @Override
   protected HasMetadata desired(Primary primary, Context<Primary> context) {
      // Compute strimzi-Kafka with Qute template.
      String strimziKafka= Templates.kafka(primary.getMetadata().getName(), primary.getMetadata().getNamespace()).render();

      return ReconcilerUtils.buildGenericKubernetesResource(strimziKafka);
   }
}

What do you think? Could you please provide some guidance on how to cope with this?

Many thanks,

@metacosm
Comment options

I'll take a look tomorrow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.