private void deleteBuilds() { if (getName() == null) { return; } String buildConfigLabelValue = getName().substring(0, Math.min(getName().length(), 63)); BuildList matchingBuilds = new BuildOperationsImpl(client, (OpenShiftConfig) config, namespace).inNamespace(namespace).withLabel(BUILD_CONFIG_LABEL, buildConfigLabelValue).list(); if (matchingBuilds.getItems() != null) { for (Build matchingBuild : matchingBuilds.getItems()) { if (matchingBuild.getMetadata() != null && matchingBuild.getMetadata().getAnnotations() != null && getName().equals(matchingBuild.getMetadata().getAnnotations().get(BUILD_CONFIG_ANNOTATION))) { new BuildOperationsImpl(client, (OpenShiftConfig) config, namespace).inNamespace(matchingBuild.getMetadata().getNamespace()).withName(matchingBuild.getMetadata().getName()).delete(); } } } }
protected void doListNodesByLabels(Exchange exchange, String operation) throws Exception { NodeList nodeList = null; Map<String, String> labels = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NODES_LABELS, Map.class); NonNamespaceOperation<Node, NodeList, DoneableNode, Resource<Node, DoneableNode>> nodes = getEndpoint().getKubernetesClient().nodes(); for (Map.Entry<String, String> entry : labels.entrySet()) { nodes.withLabel(entry.getKey(), entry.getValue()); } nodeList = nodes.list(); MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); exchange.getOut().setBody(nodeList.getItems()); }
protected void doListDeploymentsByLabels(Exchange exchange, String operation) throws Exception { DeploymentList deploymentList = null; Map<String, String> labels = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_DEPLOYMENTS_LABELS, Map.class); NonNamespaceOperation<Deployment, DeploymentList, DoneableDeployment, ScalableResource<Deployment, DoneableDeployment>> deployments = getEndpoint().getKubernetesClient() .apps().deployments(); for (Map.Entry<String, String> entry : labels.entrySet()) { deployments.withLabel(entry.getKey(), entry.getValue()); } deploymentList = deployments.list(); MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); exchange.getOut().setBody(deploymentList.getItems()); }
protected void doListPersistentVolumesByLabels(Exchange exchange, String operation) throws Exception { PersistentVolumeList pvList = null; Map<String, String> labels = exchange.getIn().getHeader( KubernetesConstants.KUBERNETES_PERSISTENT_VOLUMES_LABELS, Map.class); NonNamespaceOperation<PersistentVolume, PersistentVolumeList, DoneablePersistentVolume, Resource<PersistentVolume, DoneablePersistentVolume>> pvs; pvs = getEndpoint().getKubernetesClient().persistentVolumes(); for (Map.Entry<String, String> entry : labels.entrySet()) { pvs.withLabel(entry.getKey(), entry.getValue()); } pvList = pvs.list(); MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); exchange.getOut().setBody(pvList.getItems()); }
try (Watch watch = client.pods().inNamespace(namespace).withLabel("job-name").watch(new Watcher<Pod>() { @Override public void eventReceived(Action action, Pod aPod) {
protected void doListNamespaceByLabel(Exchange exchange, String operation) { Map<String, String> labels = exchange.getIn().getHeader( KubernetesConstants.KUBERNETES_NAMESPACE_LABELS, Map.class); if (ObjectHelper.isEmpty(labels)) { LOG.error("Get a specific namespace by labels require specify a labels set"); throw new IllegalArgumentException( "Get a specific namespace by labels require specify a labels set"); } NonNamespaceOperation<Namespace, NamespaceList, DoneableNamespace, Resource<Namespace, DoneableNamespace>> namespaces = getEndpoint().getKubernetesClient().namespaces(); for (Map.Entry<String, String> entry : labels.entrySet()) { namespaces.withLabel(entry.getKey(), entry.getValue()); } NamespaceList namespace = namespaces.list(); MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); exchange.getOut().setBody(namespace.getItems()); }
@Override public Set<Deployment> getReadyDeployments(AddressSpace addressSpace) { String infraUuid = addressSpace.getAnnotation(AnnotationKeys.INFRA_UUID); return client.apps().deployments().inNamespace(namespace).withLabel(LabelKeys.INFRA_UUID, infraUuid).list().getItems().stream() .filter(KubernetesHelper::isReady) .collect(Collectors.toSet()); }
@Override public Set<StatefulSet> getReadyStatefulSets(AddressSpace addressSpace) { String infraUuid = addressSpace.getAnnotation(AnnotationKeys.INFRA_UUID); return client.apps().statefulSets().inNamespace(namespace).withLabel(LabelKeys.INFRA_UUID, infraUuid).list().getItems().stream() .filter(KubernetesHelper::isReady) .collect(Collectors.toSet()); }
public List<Pod> listPods(String uuid) { return new ArrayList<>(client.pods().inNamespace(globalNamespace).withLabel("enmasse.io/uuid", uuid).list().getItems()); }
@Override public Collection<CertComponent> listComponents(String uuid) { List<HasMetadata> components = new ArrayList<>(); components.addAll(client.apps().deployments().inNamespace(namespace).withLabel(LabelKeys.INFRA_UUID, uuid).list().getItems()); components.addAll(client.apps().statefulSets().inNamespace(namespace).withLabel(LabelKeys.INFRA_UUID, uuid).list().getItems()); return components.stream() .filter(object -> object.getMetadata().getAnnotations() != null && object.getMetadata().getAnnotations().containsKey(AnnotationKeys.CERT_SECRET_NAME)) .map(object -> { Map<String, String> annotations = object.getMetadata().getAnnotations(); String cn = annotations.getOrDefault(AnnotationKeys.CERT_CN, object.getMetadata().getName()); return new CertComponent(cn, uuid, annotations.get(AnnotationKeys.CERT_SECRET_NAME)); }) .collect(Collectors.toList()); }
@Override public ConfigMapList list(ListOptions listOptions) { return client.configMaps() .inNamespace(client.getNamespace()) .withLabel(LabelKeys.TYPE, "address-space") .list(); }
/** * @see ContainerBasedGatewayGenerator#removeContainerBasedGateway(String, API) (String) */ @Override public void removeContainerBasedGateway(String label, API api) throws ContainerBasedGatewayException { try { client.services().inNamespace(namespace).withLabel(ContainerBasedGatewayConstants.GATEWAY, label).delete(); client.extensions().deployments().inNamespace(namespace).withLabel(ContainerBasedGatewayConstants.GATEWAY, label).delete(); client.extensions().ingresses().inNamespace(namespace).withLabel(ContainerBasedGatewayConstants.GATEWAY, label).delete(); log.info(String.format("Completed deleting the container gateway related %s deployment, service and " + "ingress resources.", cmsType)); } catch (KubernetesClientException e) { throw new ContainerBasedGatewayException("Error while removing container based gateway", e, ExceptionCodes.CONTAINER_GATEWAY_REMOVAL_FAILED); } }
private void updateEndpoints(AddressSpace addressSpace) { Map<String, String> annotations = new HashMap<>(); annotations.put(AnnotationKeys.ADDRESS_SPACE, addressSpace.getMetadata().getName()); String infraUuid = addressSpace.getAnnotation(AnnotationKeys.INFRA_UUID); List<Service> services = client.services().inNamespace(namespace).withLabel(LabelKeys.INFRA_UUID, infraUuid).list().getItems(); List<EndpointInfo> endpoints = collectEndpoints(addressSpace, services); /* Watch for routes and lb services */ final List<EndpointStatus> statuses; if (exposeServicesByDefault) { statuses = exposeEndpoints(addressSpace, endpoints); } else { statuses = endpoints.stream().map(e -> e.endpointStatus).collect(Collectors.toList()); } log.debug("Updating endpoints for " + addressSpace.getMetadata().getName() + " to " + statuses); addressSpace.getStatus().setEndpointStatuses(statuses); }
@SuppressWarnings("unused") private ConfigMapList list(String namespace) { return client.configMaps() .inNamespace(client.getNamespace()) .withLabel(LabelKeys.TYPE, "address-space") .withLabel(LabelKeys.NAMESPACE, namespace) .list(); }
/** * Returns all existing routes. * * @throws InfrastructureException when any exception occurs */ public List<Route> get() throws InfrastructureException { try { return clientFactory .createOC(workspaceId) .routes() .inNamespace(namespace) .withLabel(CHE_WORKSPACE_ID_LABEL, workspaceId) .list() .getItems(); } catch (KubernetesClientException e) { throw new KubernetesInfrastructureException(e); } }
@Override public io.fabric8.kubernetes.client.Watch watch(io.fabric8.kubernetes.client.Watcher<ConfigMap> watcher, ListOptions listOptions) { RequestConfig requestConfig = new RequestConfigBuilder() .withRequestTimeout(listOptions.getTimeoutSeconds()) .build(); return client.withRequestConfig(requestConfig).call(c -> c.configMaps() .inNamespace(client.getNamespace()) .withLabel(LabelKeys.TYPE, "address-space") .withResourceVersion(listOptions.getResourceVersion()) .watch(watcher)); } }