@Override public void close() throws IOException { this.client.close(); }
private ConfigMap getConfigMap() { return kubernetesClient.configMaps() .inNamespace(leaderProperties.getNamespace(kubernetesClient.getNamespace())) .withName(leaderProperties.getConfigMapName()) .get(); }
public void start() { if (watch == null) { synchronized (lock) { if (watch == null) { LOGGER.debug("Starting pod readiness watcher for '{}'", podName); PodResource<Pod, DoneablePod> podResource = kubernetesClient .pods() .withName(podName); previousState = podResource.isReady(); watch = podResource.watch(this); } } } }
@Bean @ConditionalOnMissingBean public KubernetesClient kubernetesClient(Config config) { return new DefaultKubernetesClient(config); }
private void deleteSeleniumPods() { logger.info("About to clean up any left over docker-selenium pods created by Zalenium"); client.pods().withLabels(createdByZaleniumMap).delete(); }
public static <C extends AbstractConfigProperties> String getApplicationNamespace( KubernetesClient client, String configNamespace, String configurationTarget) { String namespace = configNamespace; if (StringUtils.isEmpty(namespace)) { if (LOG.isDebugEnabled()) { LOG.debug(configurationTarget + " namespace has not been set, taking it from client (ns=" + client.getNamespace() + ")"); } namespace = client.getNamespace(); } return namespace; }
@Bean public KubernetesClientServicesFunction servicesFunction(KubernetesDiscoveryProperties properties) { if (properties.getServiceLabels().isEmpty()) { return KubernetesClient::services; } return (client) -> client.services().withLabels(properties.getServiceLabels()); }
@Override public String getHost() { return client.getMasterUrl().getHost(); }
public void stop() { if (watch != null) { synchronized (lock) { if (watch != null) { LOGGER.debug("Stopping leader record watcher"); watch.close(); watch = null; } } } }
private void revoke(ConfigMap configMap) { LOGGER.debug("Trying to revoke leadership for '{}'", candidate); try { String leaderKey = getLeaderKey(); removeConfigMapEntry(configMap, leaderKey); handleLeaderChange(null); } catch (KubernetesClientException e) { LOGGER.warn("Failure when revoking leadership for '{}': {}", candidate, e.getMessage()); } }
@Override public void eventReceived(Action action, ConfigMap configMap) { LOGGER.debug("'{}' event received, triggering leadership update", action); if (!Action.ERROR.equals(action)) { leadershipController.update(); } }
public KubernetesApplicationContextInitializer() { this(LazilyInstantiate.using(() -> // If we are inside Kubernetes this should be perfectly valid. // If not then we won't add the Kubernetes profile anyway. new KubernetesProfileApplicationListener( new StandardPodUtils(new DefaultKubernetesClient())))); }
private static String getName(KubernetesClient client, String name, String namespace) { return new StringBuilder().append(PREFIX) .append(Constants.PROPERTY_SOURCE_NAME_SEPARATOR).append(name) .append(Constants.PROPERTY_SOURCE_NAME_SEPARATOR) .append(namespace == null || namespace.isEmpty() ? client.getNamespace() : namespace) .toString(); }
@Override public URI getUri() { try { return client.getMasterUrl().toURI(); } catch (URISyntaxException e) { e.printStackTrace(); } return null; }
public void stop() { if (watch != null) { synchronized (lock) { if (watch != null) { LOGGER.debug("Stopping pod readiness watcher for '{}'", podName); watch.close(); watch = null; } } } }
@PreDestroy public void shutdown() { // Ensure the kubernetes client is cleaned up from spare threads when shutting // down kubernetesClient.close(); }
private static KubernetesContainerClient createKubernetesContainerClient() { // We only want one kubernetes client because it creates lots of thread pools and such things // so lets cache a copy of it in this factory. if (kubernetesContainerClient == null) { synchronized (ContainerFactory.class) { if (kubernetesContainerClient == null) { kubernetesContainerClient = new KubernetesContainerClient(new Environment(), KubernetesContainerClient::createDoneablePodDefaultImpl, new DefaultKubernetesClient()); kubernetesContainerClient.initialiseContainerEnvironment(); } } } return kubernetesContainerClient; }
public void initWithNiwsConfig(IClientConfig clientConfig) { this.serviceId = clientConfig.getClientName(); this.namespace = clientConfig.getPropertyAsString(KubernetesConfigKey.Namespace, client.getNamespace()); this.portName = clientConfig.getPropertyAsString(KubernetesConfigKey.PortName, null); }