use of io.fabric8.kubernetes.api.model.HasMetadata 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.model.HasMetadata 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.model.HasMetadata in project fabric8-maven-plugin by fabric8io.
the class ResourceMojo method moveTemplatesToTopLevel.
private void moveTemplatesToTopLevel(KubernetesListBuilder builder, List<HasMetadata> objects) {
Template template = extractAndRemoveTemplates(objects);
if (template != null) {
openshiftDependencyResources.addMissingParameters(template);
builder.addToItems(template);
} else {
for (HasMetadata object : objects) {
builder.addToItems(object);
}
}
}
use of io.fabric8.kubernetes.api.model.HasMetadata in project fabric8-maven-plugin by fabric8io.
the class DebugMojo method enableDebugging.
private boolean enableDebugging(HasMetadata entity, PodTemplateSpec template) {
if (template != null) {
PodSpec podSpec = template.getSpec();
if (podSpec != null) {
List<Container> containers = podSpec.getContainers();
boolean enabled = false;
for (int i = 0; i < containers.size(); i++) {
Container container = containers.get(i);
List<EnvVar> env = container.getEnv();
if (env == null) {
env = new ArrayList<>();
}
remoteDebugPort = KubernetesResourceUtil.getEnvVar(env, DebugConstants.ENV_VAR_JAVA_DEBUG_PORT, DebugConstants.ENV_VAR_JAVA_DEBUG_PORT_DEFAULT);
if (KubernetesResourceUtil.setEnvVar(env, DebugConstants.ENV_VAR_JAVA_DEBUG, "true")) {
container.setEnv(env);
enabled = true;
}
if (KubernetesResourceUtil.setEnvVar(env, DebugConstants.ENV_VAR_JAVA_DEBUG_SUSPEND, String.valueOf(debugSuspend))) {
container.setEnv(env);
enabled = true;
}
List<ContainerPort> ports = container.getPorts();
if (ports == null) {
ports = new ArrayList<>();
}
if (KubernetesResourceUtil.addPort(ports, remoteDebugPort, "debug", log)) {
container.setPorts(ports);
enabled = true;
}
if (debugSuspend) {
// Setting a random session value to force pod restart
this.debugSuspendValue = String.valueOf(new Random().nextLong());
KubernetesResourceUtil.setEnvVar(env, DebugConstants.ENV_VAR_JAVA_DEBUG_SESSION, this.debugSuspendValue);
container.setEnv(env);
if (container.getReadinessProbe() != null) {
log.info("Readiness probe will be disabled on " + getKind(entity) + " " + getName(entity) + " to allow attaching a remote debugger during suspension");
container.setReadinessProbe(null);
}
enabled = true;
} else {
if (KubernetesResourceUtil.removeEnvVar(env, DebugConstants.ENV_VAR_JAVA_DEBUG_SESSION)) {
container.setEnv(env);
enabled = true;
}
}
}
if (enabled) {
log.info("Enabling debug on " + getKind(entity) + " " + getName(entity));
return true;
}
}
}
return false;
}
use of io.fabric8.kubernetes.api.model.HasMetadata in project fabric8-maven-plugin by fabric8io.
the class AppCatalogMojo method populateLabelsFromResources.
private void populateLabelsFromResources(KubernetesResource resource, Map<String, String> labels) {
if (resource instanceof KubernetesList) {
KubernetesList list = (KubernetesList) resource;
List<HasMetadata> items = list.getItems();
if (items != null) {
for (HasMetadata item : items) {
populateLabelsFromEntity(item, labels);
}
}
} else if (resource instanceof HasMetadata) {
HasMetadata entity = (HasMetadata) resource;
populateLabelsFromEntity(entity, labels);
}
}
Aggregations