use of io.fabric8.kubernetes.api.Controller in project strimzi by strimzi.
the class ControllerTest method testOnTopicChanged.
/**
* 0. ZK notifies of a change in topic config
* 1. controller gets updated topic metadata
* 2. controller updates k8s and topic store.
*/
@Test
public void testOnTopicChanged(TestContext context) {
Topic kubeTopic = new Topic.Builder(topicName.toString(), 10, (short) 2, map("cleanup.policy", "bar")).build();
Topic kafkaTopic = new Topic.Builder(topicName.toString(), 10, (short) 2, map("cleanup.policy", "baz")).build();
Topic privateTopic = kubeTopic;
ConfigMap cm = TopicSerialization.toConfigMap(kubeTopic, cmPredicate);
mockKafka.setCreateTopicResponse(topicName.toString(), null).createTopic(kafkaTopic, ar -> {
});
mockKafka.setTopicMetadataResponse(topicName, Utils.getTopicMetadata(kafkaTopic), null);
// mockKafka.setUpdateTopicResponse(topicName -> Future.succeededFuture());
mockTopicStore.setCreateTopicResponse(topicName, null).create(privateTopic, ar -> {
});
mockTopicStore.setUpdateTopicResponse(topicName, null);
mockK8s.setCreateResponse(mapName, null).createConfigMap(cm, ar -> {
});
mockK8s.setModifyResponse(mapName, null);
Async async = context.async(3);
controller.onTopicConfigChanged(topicName, ar -> {
assertSucceeded(context, ar);
context.assertEquals("baz", mockKafka.getTopicState(topicName).getConfig().get("cleanup.policy"));
mockTopicStore.read(topicName, ar2 -> {
assertSucceeded(context, ar2);
context.assertEquals("baz", ar2.result().getConfig().get("cleanup.policy"));
async.countDown();
});
mockK8s.getFromName(mapName, ar2 -> {
assertSucceeded(context, ar2);
context.assertEquals("baz", TopicSerialization.fromConfigMap(ar2.result()).getConfig().get("cleanup.policy"));
async.countDown();
});
async.countDown();
});
}
use of io.fabric8.kubernetes.api.Controller in project fabric8-maven-plugin by fabric8io.
the class ApplyMojo method applyEntities.
protected void applyEntities(Controller controller, KubernetesClient kubernetes, String namespace, String fileName, Set<HasMetadata> entities) throws Exception {
// Apply all items
for (HasMetadata entity : entities) {
if (entity instanceof Pod) {
Pod pod = (Pod) entity;
controller.applyPod(pod, fileName);
} else if (entity instanceof Service) {
Service service = (Service) entity;
controller.applyService(service, fileName);
} else if (entity instanceof ReplicationController) {
ReplicationController replicationController = (ReplicationController) entity;
controller.applyReplicationController(replicationController, fileName);
} else if (entity != null) {
controller.apply(entity, fileName);
}
}
String command = clusterAccess.isOpenShiftImageStream(log) ? "oc" : "kubectl";
log.info("[[B]]HINT:[[B]] Use the command `%s get pods -w` to watch your pods start up", command);
Logger serviceLogger = createExternalProcessLogger("[[G]][SVC][[G]] ");
long serviceUrlWaitTimeSeconds = this.serviceUrlWaitTimeSeconds;
for (HasMetadata entity : entities) {
if (entity instanceof Service) {
Service service = (Service) entity;
String name = getName(service);
Resource<Service, DoneableService> serviceResource = kubernetes.services().inNamespace(namespace).withName(name);
String url = null;
// lets wait a little while until there is a service URL in case the exposecontroller is running slow
for (int i = 0; i < serviceUrlWaitTimeSeconds; i++) {
if (i > 0) {
Thread.sleep(1000);
}
Service s = serviceResource.get();
if (s != null) {
url = getExternalServiceURL(s);
if (Strings.isNotBlank(url)) {
break;
}
}
if (!isExposeService(service)) {
break;
}
}
// lets not wait for other services
serviceUrlWaitTimeSeconds = 1;
if (Strings.isNotBlank(url) && url.startsWith("http")) {
serviceLogger.info("" + name + ": " + url);
}
}
}
}
use of io.fabric8.kubernetes.api.Controller in project fabric8-maven-plugin by fabric8io.
the class ApplyMojo method createController.
protected Controller createController() {
Controller controller = new Controller(clusterAccess.createDefaultClient(log));
controller.setThrowExceptionOnError(failOnError);
controller.setRecreateMode(recreate);
getLog().debug("Using recreate mode: " + recreate);
return controller;
}
use of io.fabric8.kubernetes.api.Controller in project fabric8-maven-plugin by fabric8io.
the class ApplyMojo method createIngress.
protected void createIngress(Controller controller, KubernetesClient kubernetesClient, Collection<HasMetadata> collection) {
String routeDomainPostfix = this.routeDomain;
Log log = getLog();
String namespace = clusterAccess.getNamespace();
List<Ingress> ingressList = null;
// lets get the routes first to see if we should bother
try {
IngressList ingresses = kubernetesClient.extensions().ingresses().inNamespace(namespace).list();
if (ingresses != null) {
ingressList = ingresses.getItems();
}
} catch (Exception e) {
log.warn("Cannot load Ingress instances. Must be an older version of Kubernetes? Error: " + e, e);
return;
}
List<Ingress> ingresses = new ArrayList<>();
for (Object object : collection) {
if (object instanceof Service) {
Service service = (Service) object;
if (!serviceHasIngressRule(ingressList, service)) {
Ingress ingress = createIngressForService(routeDomainPostfix, namespace, service);
if (ingress != null) {
ingresses.add(ingress);
log.info("Created ingress for " + namespace + ":" + KubernetesHelper.getName(service));
} else {
log.debug("No ingress required for " + namespace + ":" + KubernetesHelper.getName(service));
}
} else {
log.info("Already has ingress for service " + namespace + ":" + KubernetesHelper.getName(service));
}
}
}
collection.addAll(ingresses);
}
use of io.fabric8.kubernetes.api.Controller in project fabric8-maven-plugin by fabric8io.
the class DebugMojo method portForward.
private void portForward(Controller controller, String podName) throws MojoExecutionException {
try {
getFabric8ServiceHub(controller).getPortForwardService().forwardPort(createExternalProcessLogger("[[B]]port-forward[[B]] "), podName, portToInt(remoteDebugPort, "remoteDebugPort"), portToInt(localDebugPort, "localDebugPort"));
log.info("");
log.info("Now you can start a Remote debug execution in your IDE by using localhost and the debug port " + localDebugPort);
log.info("");
} catch (Fabric8ServiceException e) {
throw new MojoExecutionException("Failed to start port forwarding" + e, e);
}
}
Aggregations