Skip to content

Commit

Permalink
Merge pull request #6 from viktorpergjoka/5-bug-all-informer-should-b…
Browse files Browse the repository at this point in the history
…e-started-after-all-are-constructed

informers are started after all are created first
  • Loading branch information
viktorpergjoka authored Oct 18, 2024
2 parents 5c9c4d1 + d8616cb commit da78ae8
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 14 deletions.
4 changes: 1 addition & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
id 'java-library'
id 'org.springframework.boot' version '3.3.0' apply false
id 'io.spring.dependency-management' version '1.1.5'
id 'com.diffplug.spotless' version '7.0.0.BETA2'
id 'com.diffplug.spotless' version '6.25.0'
id 'maven-publish'
id 'signing'
id 'net.thebugmc.gradle.sonatype-central-portal-publisher' version '1.2.4'
Expand Down Expand Up @@ -61,8 +61,6 @@ tasks.withType(JavaCompile).configureEach {
apply plugin: "com.diffplug.spotless"

spotless {
ratchetFrom 'origin/main'

format 'misc', {
target '*.gradle', '.gitattributes', '.gitignore'

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
1 change: 0 additions & 1 deletion src/main/java/io/k8swatcher/annotation/EventType.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.k8swatcher.annotation;

public enum EventType {

ADD,
UPDATE,
DELETE
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/io/k8swatcher/annotation/Watch.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package io.k8swatcher.annotation;


import io.fabric8.kubernetes.api.model.KubernetesResource;

import java.lang.annotation.*;

@Target(ElementType.METHOD)
Expand All @@ -11,5 +9,6 @@
public @interface Watch {

EventType event();

Class<? extends KubernetesResource> resource();
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
@AllArgsConstructor
public class InformerContext {


@Setter(AccessLevel.NONE)
private Class<?> beanClass;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ List<SharedIndexInformer> createInformers() {
List<SharedIndexInformer> informers = namespaces.stream()
.map(nsName -> (NonNamespaceOperation)
client.resources(resource).inNamespace(nsName))
.map(nsOperation -> createSharedIndexInformer(nsOperation, resLabels))
.map(nsOperation -> createSharedIndexInformer(
nsOperation, resLabels, informerConfiguration.getResyncPeriod()))
.map(sharedIndexInformer -> sharedIndexInformer.addEventHandlerWithResyncPeriod(
new IndexInformerResHandler(ctx, watchMethod, beanClass),
informerConfiguration.getResyncPeriod()))
Expand Down Expand Up @@ -89,13 +90,13 @@ private List<String> getNamespaces(KubernetesClient client, InformerConfiguratio
}

private SharedIndexInformer createSharedIndexInformer(
NonNamespaceOperation nsOperation, Map<String, String> resLabels) {
NonNamespaceOperation nsOperation, Map<String, String> resLabels, long resyncPeriod) {
log.debug("resLabels={}", resLabels);
if (resLabels.isEmpty()) {
return nsOperation.inform();
return nsOperation.runnableInformer(resyncPeriod);
}

return ((FilterWatchListDeletable) nsOperation.withLabels(resLabels)).inform();
return ((FilterWatchListDeletable) nsOperation.withLabels(resLabels)).runnableInformer(resyncPeriod);
}

private List<InformerContext> getInformerContextList() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
@SuppressWarnings("rawtypes")
public class K8InformerEntrypoint {

private AnnotationValidator validator;
private InformerCreator informerCreator;
private final AnnotationValidator validator;
private final InformerCreator informerCreator;
private List<SharedIndexInformer> informerList;

public K8InformerEntrypoint(AnnotationValidator validator, InformerCreator informerCreator) {
Expand All @@ -29,6 +29,7 @@ public K8InformerEntrypoint(AnnotationValidator validator, InformerCreator infor
public void onStartUp(ApplicationReadyEvent event) {
validateAnnotations();
this.informerList = informerCreator.createInformers();
informerList.forEach(SharedIndexInformer::start);
}

private void validateAnnotations() {
Expand Down

0 comments on commit da78ae8

Please sign in to comment.