Skip to content

Trim controller example based on controller auto-configuration #1379

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

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,14 @@
import io.kubernetes.client.informer.SharedInformer;
import io.kubernetes.client.informer.SharedInformerFactory;
import io.kubernetes.client.informer.cache.Lister;
import io.kubernetes.client.openapi.ApiClient;
import io.kubernetes.client.openapi.models.V1Endpoints;
import io.kubernetes.client.openapi.models.V1EndpointsList;
import io.kubernetes.client.openapi.models.V1Node;
import io.kubernetes.client.openapi.models.V1NodeList;
import io.kubernetes.client.openapi.models.V1Pod;
import io.kubernetes.client.openapi.models.V1PodList;
import io.kubernetes.client.spring.extended.controller.KubernetesInformerConfigurer;
import io.kubernetes.client.spring.extended.controller.annotation.*;
import io.kubernetes.client.spring.extended.controller.factory.KubernetesControllerFactory;
import io.kubernetes.client.spring.extended.controller.metrics.PrometheusScrapeEndpoint;
import io.kubernetes.client.util.ClientBuilder;
import java.io.IOException;
import java.time.Duration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
Expand Down Expand Up @@ -66,14 +60,6 @@ public CommandLineRunner commandLineRunner(
};
}

// *REQUIRED*
// Configurer components that registers informers to the informer-factory in the context.
@Bean
public KubernetesInformerConfigurer kubernetesInformerConfigurer(
ApiClient apiClient, SharedInformerFactory sharedInformerFactory) {
return new KubernetesInformerConfigurer(apiClient, sharedInformerFactory);
}

// *REQUIRED*
// factorybean to crete controller
@Bean("node-printing-controller")
Expand All @@ -82,30 +68,12 @@ public KubernetesControllerFactory kubernetesReconcilerConfigurer(
return new KubernetesControllerFactory(sharedInformerFactory, reconciler);
}

// *OPTIONAL*
// Injecting and customize your ApiClient, if not specified, fallbacks to {@link
// io.kubernetes.client.util.ClientBuilder#standard}
@Bean
public ApiClient myApiClient() throws IOException {
ApiClient apiClient = ClientBuilder.standard().build();
return apiClient.setHttpClient(
apiClient.getHttpClient().newBuilder().readTimeout(Duration.ZERO).build());
}

// *REQUIRED*
// Injecting your SharedInformerFactory class annotated `@KubernetesInformers`
@Bean("sharedInformerFactory")
public SharedInformerFactory sharedInformerFactory() {
return new MySharedInformerFactory();
}

// *OPTIONAL*
// Enabling prometheus scraping endpoint at `/actuator/prometheus`
// SHOULD set `management.endpoints.web.exposure.include=prometheus` property.
@Bean
public PrometheusScrapeEndpoint prometheusScrapeEndpoint() {
return new PrometheusScrapeEndpoint();
}
}

@KubernetesInformers({ // Defining what resources is the informer-factory actually watching.
Expand Down