@Override protected boolean isNamespaceEmpty(String namespace) { return client.deploymentConfigs().inNamespace(namespace).list().getItems().isEmpty() && client.services().inNamespace(namespace).list().getItems().isEmpty() && client.secrets().inNamespace(namespace).list().getItems().isEmpty(); }
@Override public ServiceInstance getLocalServiceInstance() { String podName = System.getenv(HOSTNAME); return client.endpoints().withName(localServiceId).get().getSubsets() .stream() .filter(s -> s.getAddresses().iterator().next().getIp().equals(podName)) .map(s -> new KubernetesServiceInstance(localServiceId, s.getPorts().iterator().next().getName(), s, false)) .findFirst().get(); }
@Override public Collection<Instance> getInstanceList() throws Exception { LOGGER.info("Starting Kubernetes instance discovery using master URL: {}", client.getMasterUrl()); return client.pods().inAnyNamespace() .list() .getItems().stream() .filter(pod -> pod.getMetadata().getAnnotations() != null) // Ignore pods without annotations .filter(pod -> pod.getMetadata().getAnnotations().containsKey(PORT_ANNOTATION_KEY)) .map(pod -> { String portString = pod.getMetadata().getAnnotations().get(PORT_ANNOTATION_KEY); if (!Pattern.compile("^[0-9]{2,5}$").matcher(portString).matches()) { LOGGER.warn("Invalid port annotation for pod '{}': {}", pod.getMetadata().getName(), portString); return null; } else { String host = String.format("%s:%s", pod.getStatus().getPodIP(), portString); boolean running = pod.getStatus().getPhase().equals("Running"); LOGGER.info("Found Kubernetes Pod {} at address {}", pod.getMetadata().getName(), host); return new Instance(host, extractClusterNameFor(pod), running); } }) .filter(Objects::nonNull) .collect(Collectors.toList()); }
public void start() { final BuildList builds; if (namespace != null && !namespace.isEmpty()) { builds = getOpenShiftClient().builds().inNamespace(namespace).withField("status", BuildPhases.RUNNING).list(); buildsWatch = getOpenShiftClient().builds().inNamespace(namespace).withResourceVersion(builds.getMetadata().getResourceVersion()).watch(this); } else { builds = getOpenShiftClient().builds().withField("status", BuildPhases.RUNNING).list(); buildsWatch = getOpenShiftClient().builds().withResourceVersion(builds.getMetadata().getResourceVersion()).watch(this); } }
public void start() { final BuildConfigList buildConfigs; if (namespace != null && !namespace.isEmpty()) { buildConfigs = getOpenShiftClient().buildConfigs().inNamespace(namespace).list(); buildConfigWatch = getOpenShiftClient().buildConfigs().inNamespace(namespace).withResourceVersion(buildConfigs.getMetadata().getResourceVersion()).watch(this); } else { buildConfigs = getOpenShiftClient().buildConfigs().inAnyNamespace().list(); buildConfigWatch = getOpenShiftClient().buildConfigs().withResourceVersion(buildConfigs.getMetadata().getResourceVersion()).watch(this);
BuildConfig buildConfig = osClient.buildConfigs().withName(projectId).get(); if (buildConfig == null) { throw new NotFoundException("No BuildConfig for " + remoteRepository); if (sourceSecretName != null) { try { Secret secret = kubernetes.secrets().inNamespace(secretNamespace).withName(sourceSecretName).get(); if (secret != null) { Map<String, String> data = secret.getData();
@Override public List<String> getServices() { return client.services().list() .getItems() .stream().map(s -> s.getMetadata().getName()) .collect(Collectors.toList()); } }
public void start() { final BuildList builds; if (namespace != null && !namespace.isEmpty()) { builds = getOpenShiftClient().builds().inNamespace(namespace).withField("status", BuildPhases.NEW).list(); buildsWatch = getOpenShiftClient().builds().inNamespace(namespace).withResourceVersion(builds.getMetadata().getResourceVersion()).watch(this); } else { builds = getOpenShiftClient().builds().withField("status", BuildPhases.NEW).list(); buildsWatch = getOpenShiftClient().builds().withResourceVersion(builds.getMetadata().getResourceVersion()).watch(this);
public void run() { PodList pods = kube.pods().list(); List<Pod> items = pods.getItems(); for (Pod pod : items)
@Override public void delete(String kubeName, String namespace, String podName) throws RepositoryException { if (LOGGER.isLoggable(Level.CONFIG) ) { LOGGER.config("Deleting Pod: " + podName ); } kubeRepository.getClient(kubeName).pods().inNamespace(namespace).withName(podName).delete(); }
@Override public List<ServiceInstance> getInstances(String serviceId) { return client.endpoints().withName(serviceId).get() .getSubsets() .stream().map(s -> new KubernetesServiceInstance(serviceId, s.getPorts().iterator().next().getName(), s, false)) .collect(Collectors.toList()); }
protected boolean isNamespaceEmpty(String name) { return client.extensions().deployments().inNamespace(name).list().getItems().isEmpty() && client.services().inNamespace(name).list().getItems().isEmpty() && client.secrets().inNamespace(name).list().getItems().isEmpty(); }
private synchronized Pod internalGetPod() { if (isServiceAccountFound() && isHostNameEnvVarPresent()) { return client.pods().withName(hostName).get(); } else { return null; } }
public List<String> getPodContainerNames(String podName) { return kubernetesClient .pods() .inNamespace(environment.getKubernetesNamespace()) .withName(podName) .get() .getSpec() .getContainers() .stream() .map(Container::getName) .collect(Collectors.toList()); }
@Override public void create(String kubeName, String namespace, ReplicationController replController) throws RepositoryException { if (LOGGER.isLoggable(Level.CONFIG) ) { LOGGER.config("Creating Replication Controller: " + replController.getMetadata().getName() ); } kubeRepository.getClient(kubeName).replicationControllers().inNamespace(namespace).create(replController); }
private ReplicationController getBrokerReplicationController() throws InterruptedException { ReplicationController running; do { running = kubernetes.replicationControllers().inNamespace(namespace).withName(getReplicationControllerId()).get(); if (running == null) { LOG.info("Waiting for ReplicationController " + getReplicationControllerId() + " to start"); Thread.sleep(5000); } } while (running == null); return running; }
@Override public String getFailureMessage() { Endpoints endpoints = client.endpoints().inNamespace(namespace).withName(serviceName).get(); return "Service endpoints in " + namespace + " for serviceName= " + serviceName + " not ready: " + endpoints; } };
@Override public void create(String kubeName, String namespace, Pod pod) throws RepositoryException { if (LOGGER.isLoggable(Level.CONFIG) ) { LOGGER.config("Creating Pod: " + pod.getMetadata().getName() ); } kubeRepository.getClient(kubeName).pods().inNamespace(namespace).create(pod); }
@Override public Endpoints endpoints() { logger.debug("get endpoints for service {}, namespace {}", serviceName, namespace); return client().endpoints().inNamespace(namespace).withName(serviceName).get(); }
@Override public void create(String kubeName, String namespace, Service service) throws RepositoryException { if (LOGGER.isLoggable(Level.CONFIG) ) { LOGGER.config("Creating Service: " + service.getMetadata().getName() ); } kubeRepository.getClient(kubeName).services().inNamespace(namespace).create(service); }