use of io.fabric8.kubernetes.client.dsl.ServiceResource in project strimzi-kafka-operator by strimzi.
the class ServiceMockBuilder method mockCreate.
/**
* Override Service creation to also create Endpoints
*/
@Override
protected void mockCreate(String resourceName, ServiceResource<Service> resource) {
when(resource.create(any(Service.class))).thenAnswer(i -> {
Service argument = i.getArgument(0);
db.put(resourceName, copyResource(argument));
LOGGER.debug("create {} (and endpoint) {} ", resourceType, resourceName);
endpointsDb.put(resourceName, new Endpoints());
return argument;
});
}
use of io.fabric8.kubernetes.client.dsl.ServiceResource 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.client.dsl.ServiceResource in project elastest-torm by elastest.
the class K8sService method getServiceIp.
public String getServiceIp(String serviceName, String port, String namespace) {
String serviceIP = "";
logger.debug("Nodes in the cluster: {}", client.nodes().list().getItems().size());
for (NodeAddress address : client.nodes().list().getItems().get(0).getStatus().getAddresses()) {
logger.debug("Check ip for the cluster 1. Ip type: {}", address.getType());
if (address.getType().equals("ExternalIP")) {
serviceIP = address.getAddress();
}
}
if (serviceIP.isEmpty()) {
ServiceResource<Service, DoneableService> service = client.services().inNamespace(namespace != null && !namespace.isEmpty() ? namespace : DEFAULT_NAMESPACE).withName(serviceName.replace("_", "-"));
serviceIP = service.getURL(service.get().getSpec().getPorts().get(0).getName()).split(":")[1].replace("//", "");
logger.debug("External service ip {}", serviceIP);
}
return serviceIP;
}
use of io.fabric8.kubernetes.client.dsl.ServiceResource in project fabric8-maven-plugin by fabric8io.
the class SpringBootWatcher method getServiceExposeUrl.
private String getServiceExposeUrl(KubernetesClient kubernetes, Set<HasMetadata> resources) throws InterruptedException {
long serviceUrlWaitTimeSeconds = Configs.asInt(getConfig(Config.serviceUrlWaitTimeSeconds));
for (HasMetadata entity : resources) {
if (entity instanceof Service) {
Service service = (Service) entity;
String name = KubernetesHelper.getName(service);
Resource<Service, DoneableService> serviceResource = kubernetes.services().inNamespace(getContext().getClusterConfiguration().getNamespace()).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 = KubernetesHelper.getOrCreateAnnotations(s).get(Fabric8Annotations.SERVICE_EXPOSE_URL);
if (StringUtils.isNotBlank(url)) {
break;
}
}
if (!isExposeService(service)) {
break;
}
}
// lets not wait for other services
serviceUrlWaitTimeSeconds = 1;
if (StringUtils.isNotBlank(url) && url.startsWith("http")) {
return url;
}
}
}
log.info("No exposed service found for connecting the dev tools");
return null;
}
use of io.fabric8.kubernetes.client.dsl.ServiceResource in project fabric8-maven-plugin by fabric8io.
the class ApplyMojo method applyEntities.
protected void applyEntities(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;
applyService.applyPod(pod, fileName);
} else if (entity instanceof Service) {
Service service = (Service) entity;
applyService.applyService(service, fileName);
} else if (entity instanceof ReplicationController) {
ReplicationController replicationController = (ReplicationController) entity;
applyService.applyReplicationController(replicationController, fileName);
} else if (entity != null) {
applyService.apply(entity, fileName);
}
}
Logger serviceLogger = createExternalProcessLogger("[[G]][SVC][[G]] ");
long serviceUrlWaitTimeSeconds = this.serviceUrlWaitTimeSeconds;
for (HasMetadata entity : entities) {
if (entity instanceof Service) {
Service service = (Service) entity;
String name = KubernetesHelper.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 (StringUtils.isNotBlank(url)) {
break;
}
}
if (!isExposeService(service)) {
break;
}
}
// lets not wait for other services
serviceUrlWaitTimeSeconds = 1;
if (StringUtils.isNotBlank(url) && url.startsWith("http")) {
serviceLogger.info("" + name + ": " + url);
}
}
}
processCustomEntities(kubernetes, namespace, resources != null ? resources.getCrdContexts() : null, false);
}
Aggregations