@Override public String getFailureMessage() { PersistentVolume pv = client.persistentVolumes().withName(persistentVolume).get(); return "PersistentVolume for " + persistentVolume + " " + (pv == null ? "absent" : "pv=" + pv); } };
private String getOrCreateBrokerReplicationControllerId() { if (replicationControllerId == null) { try { ReplicationController running = kubernetes.replicationControllers().inNamespace(namespace).withName(getOrCreateBrokerReplicationControllerId()).get(); if (running == null) { ReplicationController replicationController = OBJECT_MAPPER.readerFor(ReplicationController.class).readValue(url); replicationControllerId = getName(replicationController); running = kubernetes.replicationControllers().inNamespace(namespace).withName(replicationControllerId).get(); if (running == null) { kubernetes.replicationControllers().inNamespace(namespace).create(replicationController); LOG.info("Created ReplicationController " + replicationControllerId); } else {
@Override public void delete(String kubeName, String namespace, ReplicationController replController) throws RepositoryException { String replControllerName = replController.getMetadata().getName(); if (LOGGER.isLoggable(Level.CONFIG) ) { LOGGER.config("Deleting Replication Controller and associated Pods: " + replControllerName); } final KubernetesClient client = kubeRepository.getClient(kubeName); client.replicationControllers().inNamespace(namespace).withName(replControllerName).scale(0, true); client.replicationControllers().inNamespace(namespace).delete(replController); } }
RouteList routes = openShiftClient.routes().inNamespace(namespace).list(); for (Route route : routes.getItems()) { RouteSpec spec = route.getSpec(); Service service = openShiftClient.services().inNamespace(namespace).withName(serviceName).get(); if (service != null) { ServiceSpec spec = service.getSpec();
DefaultKubernetesClient kube = new DefaultKubernetesClient(); ClientRollableScallableResource<ReplicationController, DoneableReplicationController> resource = kube.replicationControllers().inNamespace("default").withName(replicationControllerName); if (resource != null) { ReplicationController rc = resource.get(); Integer replicas = status.getReplicas(); } else { kube.replicationControllers().inNamespace(namespace).createNew() .withNewMetadata().withName(replicationControllerName).addToLabels("app", "drools").endMetadata() .withNewSpec().withReplicas(1) ClientResource<Service, DoneableService> serviceResource = kube.services().inNamespace(namespace).withName(serviceName); if (serviceResource != null) { Service service = serviceResource.get(); ServiceStatus status = service.getStatus(); } else { kube.services().inNamespace(namespace).createNew() .withNewMetadata().withName(serviceName).endMetadata() .withNewSpec()
@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); }
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();
private io.fabric8.kubernetes.api.model.extensions.Deployment getKubernetesDeployment(Service service, Optional<String> groupName) { return kubernetesClient .extensions() .deployments() .inNamespace(environment.getKubernetesNamespace()) .withLabel(ApolloToKubernetes.getApolloDeploymentUniqueIdentifierKey(), ApolloToKubernetes.getApolloDeploymentUniqueIdentifierValue(environment, service, groupName)) .list() .getItems() .stream() .findFirst() .orElse(null); }
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); } }
@Override public List<Pod> getRunningPods(String kubeName, String namespace) throws RepositoryException { final KubernetesClient client = kubeRepository.getClient(kubeName); final PodList list = client.pods().inNamespace(namespace).withField("status.phase","Running").list(); return list.getItems(); }
@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); }
/** * Discovers the nodes. It queries all endpoints (services) with a label `label` set to `labelValue`. By default, * it's `vertx-cluster=true`. * * @return the list of discovery nodes */ @Override public Iterable<DiscoveryNode> discoverNodes() { PodList list = client.pods().inNamespace(namespace).withLabel(label, labelValue).list(); if (list == null || list.getItems() == null || list.getItems().isEmpty()) { getLogger().info("No pods for service " + " in namespace " + namespace + " with label: `vertx-cluster=true`"); return Collections.emptyList(); } List<DiscoveryNode> nodes = new ArrayList<>(); List<Pod> podList = list.getItems(); for (Pod pod : podList) { final SimpleDiscoveryNode node = getSimpleDiscoveryNode(pod); if (node != null) { nodes.add(node); } } getLogger().info("Resolved nodes: " + nodes.stream().map(DiscoveryNode::getPublicAddress).collect(Collectors.toList())); return nodes; }
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();
@Override public Boolean call() { return client.projects().withName(name).get() == null; }
protected synchronized Namespace createOrGetNamespace(final String name, Boolean create) { Namespace namespace = client.namespaces().withName(name).get(); ExitCondition namespaceReady = new ExitCondition() { @Override public Boolean call() { Namespace actualNamespace = client.namespaces().withName(name).get(); return actualNamespace != null && actualNamespace.getStatus().getPhase().equals(PHASE_ACTIVE); } @Override public String getFailureMessage() { Namespace actualNamespace = client.namespaces().withName(name).get(); return "Namespace for " + name + " " + (actualNamespace == null ? "absent" : " status " + actualNamespace.getStatus()); } }; if (namespace != null) { LOG.debug("Found namespace {}, returning it.", namespace); } else if (create) { namespace = client.namespaces().create(new NamespaceBuilder().withNewMetadata().withName(name).endMetadata().build()); LOG.debug("Created namespace {}.", namespace); } else { throw new IllegalStateException("Namespace " + name + " does not exist and namespace.create is not set"); } waitForExitCondition(namespaceReady); return client.namespaces().withName(name).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); }
public Optional<String> getServiceLatestCreatedPodName(Service service, Optional<String> groupName) { PodList podList = kubernetesClient .pods() .inNamespace(environment.getKubernetesNamespace()) .withLabel(ApolloToKubernetes.getApolloDeploymentUniqueIdentifierKey(), ApolloToKubernetes.getApolloPodUniqueIdentifier(environment, service, groupName)) .list(); if (podList == null) { return Optional.empty(); } Optional<Pod> newestPod = podList.getItems() .stream() .sorted((o1, o2) -> { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'"); LocalDateTime pod1 = LocalDateTime.parse(o1.getStatus().getStartTime(), formatter); LocalDateTime pod2 = LocalDateTime.parse(o2.getStatus().getStartTime(), formatter); return pod1.compareTo(pod2); }).findFirst(); return newestPod.map(pod -> pod .getMetadata() .getName()); }
@Override public Boolean call() { return client.namespaces().withName(name).get() == null; }