use of it.fvaleri.integ.model.v1alpha1.CakeList in project integ-examples by fvaleri.
the class CakeOperator method main.
public static void main(String[] args) {
try (KubernetesClient client = new DefaultKubernetesClient()) {
String namespace = client.getNamespace();
if (namespace == null) {
LOG.warn("No namespace found via config, assuming default");
namespace = "default";
}
LOG.info("Using namespace {}", namespace);
OperationContext namespaced = new OperationContext().withNamespace(namespace);
// an infomer creates a watcher for a specific resource type and caches related events
// you can subscribe to these events by registering a resource event handler
SharedInformerFactory informerFactory = client.informers();
SharedIndexInformer<Pod> podSharedIndexInformer = informerFactory.sharedIndexInformerFor(Pod.class, namespaced, RESYNC_PERIOD_MS);
SharedIndexInformer<Cake> cakeSharedIndexInformer = informerFactory.sharedIndexInformerForCustomResource(Cake.class, namespaced, RESYNC_PERIOD_MS);
LOG.debug("Informer factories initialized");
MixedOperation<Cake, CakeList, Resource<Cake>> cakeClient = client.customResources(Cake.class, CakeList.class);
CakeController cakeController = new CakeController(client, cakeClient, podSharedIndexInformer, cakeSharedIndexInformer, namespace);
LOG.debug("Controller initialized");
cakeController.create();
informerFactory.startAllRegisteredInformers();
informerFactory.addSharedInformerEventListener(e -> LOG.error("Exception occurred", e));
cakeController.run();
} catch (KubernetesClientException e) {
LOG.error("Kubernetes client exception: {}", e.getMessage());
}
}
use of it.fvaleri.integ.model.v1alpha1.CakeList in project integ-examples by fvaleri.
the class CakeControllerTest method testReconcile.
@Test
@DisplayName("Should create requested number of pods")
void testReconcile() throws InterruptedException {
String namespace = "test";
Cake testCake = buildTestCake("apple-pie", namespace, "0800cff3-9d80-11ea-8973-0e13a02d8ebd");
server.expect().post().withPath(String.format("/api/v1/namespaces/%s/pods", namespace)).andReturn(HttpURLConnection.HTTP_CREATED, new PodBuilder().withNewMetadata().withName("foo").endMetadata().build()).times(testCake.getSpec().getReplicas());
SharedInformerFactory informerFactory = client.informers();
MixedOperation<Cake, CakeList, Resource<Cake>> cakeClient = client.customResources(Cake.class, CakeList.class);
SharedIndexInformer<Pod> podSharedIndexInformer = informerFactory.sharedIndexInformerFor(Pod.class, RESYNC_PERIOD_MILLIS);
SharedIndexInformer<Cake> cakeSharedIndexInformer = informerFactory.sharedIndexInformerForCustomResource(Cake.class, RESYNC_PERIOD_MILLIS);
CakeController cakeController = new CakeController(client, cakeClient, podSharedIndexInformer, cakeSharedIndexInformer, namespace);
cakeController.reconcile(testCake);
RecordedRequest recordedRequest = server.takeRequest();
assertEquals("POST", recordedRequest.getMethod());
assertTrue(recordedRequest.getBody().readUtf8().contains(testCake.getMetadata().getName()));
}
Aggregations