Search in sources :

Example 1 with ResourceEventSource

use of org.bf2.operator.events.ResourceEventSource in project kas-fleetshard by bf2fc6cc711aee1a0c2a.

the class InformerManager method onStart.

@PostConstruct
protected void onStart() {
    deploymentInformer = resourceInformerFactory.create(Deployment.class, filter(kubernetesClient.apps().deployments()), eventSource);
    serviceInformer = resourceInformerFactory.create(Service.class, filterManagedByFleetshardOrStrimzi(kubernetesClient.services()), eventSource);
    configMapInformer = resourceInformerFactory.create(ConfigMap.class, filter(kubernetesClient.configMaps()), eventSource);
    secretInformer = resourceInformerFactory.create(Secret.class, filter(kubernetesClient.secrets()), eventSource);
    // pvcs have an owner reference set to the kafka, not managedkakfa, so we need some lookup logic in the handleEvent
    pvcInformer = resourceInformerFactory.create(PersistentVolumeClaim.class, kubernetesClient.persistentVolumeClaims().inAnyNamespace().withLabel("app.kubernetes.io/name", "kafka"), new ResourceEventSource() {

        @Override
        protected void handleEvent(HasMetadata resource, Action action) {
            if (kafkaInformer != null) {
                // TODO: could index by uid, or use namespace
                String name = OperandUtils.getOrDefault(resource.getMetadata().getLabels(), "strimzi.io/cluster", null);
                if (name != null) {
                    Kafka kafka = kafkaInformer.getByKey(Cache.namespaceKeyFunc(resource.getMetadata().getNamespace(), name));
                    if (kafka != null) {
                        handleEvent(kafka, Action.MODIFIED);
                    }
                }
            }
        }
    });
    if (isOpenShift()) {
        routeInformer = resourceInformerFactory.create(Route.class, filterManagedByFleetshardOrStrimzi(openShiftSupport.adapt(kubernetesClient).routes()), eventSource);
    }
}
Also used : Secret(io.fabric8.kubernetes.api.model.Secret) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Action(io.fabric8.kubernetes.client.Watcher.Action) ResourceEventSource(org.bf2.operator.events.ResourceEventSource) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Kafka(io.strimzi.api.kafka.model.Kafka) ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) Service(io.fabric8.kubernetes.api.model.Service) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) Route(io.fabric8.openshift.api.model.Route) PostConstruct(javax.annotation.PostConstruct)

Aggregations

ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)1 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)1 PersistentVolumeClaim (io.fabric8.kubernetes.api.model.PersistentVolumeClaim)1 Secret (io.fabric8.kubernetes.api.model.Secret)1 Service (io.fabric8.kubernetes.api.model.Service)1 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)1 Action (io.fabric8.kubernetes.client.Watcher.Action)1 Route (io.fabric8.openshift.api.model.Route)1 Kafka (io.strimzi.api.kafka.model.Kafka)1 PostConstruct (javax.annotation.PostConstruct)1 ResourceEventSource (org.bf2.operator.events.ResourceEventSource)1 ManagedKafka (org.bf2.operator.resources.v1alpha1.ManagedKafka)1