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; }
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(); }
public void initWithNiwsConfig(IClientConfig clientConfig) { this.serviceId = clientConfig.getClientName(); this.namespace = clientConfig.getPropertyAsString(KubernetesConfigKey.Namespace, client.getNamespace()); this.portName = clientConfig.getPropertyAsString(KubernetesConfigKey.PortName, null); }
public void start() { if (watch == null) { synchronized (lock) { if (watch == null) { LOGGER.debug("Starting leader record watcher"); watch = kubernetesClient .configMaps() .inNamespace(leaderProperties.getNamespace(kubernetesClient.getNamespace())) .withName(leaderProperties.getConfigMapName()) .watch(this); } } } }
private ConfigMap getConfigMap() { return kubernetesClient.configMaps() .inNamespace(leaderProperties.getNamespace(kubernetesClient.getNamespace())) .withName(leaderProperties.getConfigMapName()) .get(); }
private void updateConfigMap(ConfigMap oldConfigMap, ConfigMap newConfigMap) { kubernetesClient.configMaps() .inNamespace(leaderProperties.getNamespace(kubernetesClient.getNamespace())) .withName(leaderProperties.getConfigMapName()) .lockResourceVersion(oldConfigMap.getMetadata().getResourceVersion()) .replace(newConfigMap); } }
private void createConfigMap(Map<String, String> data) { LOGGER.debug("Creating new config map with data: {}", data); ConfigMap newConfigMap = new ConfigMapBuilder().withNewMetadata() .withName(leaderProperties.getConfigMapName()) .addToLabels(PROVIDER_KEY, PROVIDER) .addToLabels(KIND_KEY, KIND) .endMetadata() .addToData(data) .build(); kubernetesClient.configMaps() .inNamespace(leaderProperties.getNamespace(kubernetesClient.getNamespace())) .create(newConfigMap); }
@Override public String getNamespace() { return delegate.getNamespace(); }
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(); }
public static <C extends AbstractConfigProperties> String getApplicationNamespace(KubernetesClient client, Environment env, C config) { String namespace = config.getNamespace(); if (StringUtils.isEmpty(namespace)) { LOGGER.debug(config.getConfigurationTarget() + " namespace has not been set, taking it from client (ns={})", client.getNamespace()); namespace = client.getNamespace(); } return namespace; }
public void initWithNiwsConfig(IClientConfig clientConfig) { this.serviceId = clientConfig.getClientName(); this.namespace = clientConfig.getPropertyAsString(KubernetesConfigKey.Namespace, client.getNamespace()); this.portName = clientConfig.getPropertyAsString(KubernetesConfigKey.PortName, null); }
@Bean public ZipkinSpanReporter reporter(KubernetesClient client, KubernetesZipkinDiscoveryProperties discoveryProperties, SpanMetricReporter spanMetricReporter, ZipkinProperties zipkin) { String serviceName = discoveryProperties.getServiceName(); String serviceNamespace = Utils.isNotNullOrEmpty(discoveryProperties.getServiceNamespace()) ? discoveryProperties.getServiceNamespace() : client.getNamespace(); List<ServiceInstance> services = getInstances(client, serviceName, serviceNamespace); String serviceUrl = services.stream() .findFirst() .map(s -> s.getUri().toString()) .orElse(null); return serviceUrl == null || serviceUrl.isEmpty() ? new NullZipkinSpanReporter() : new HttpZipkinSpanReporter(serviceUrl, zipkin.getFlushInterval(), zipkin.getCompression().isEnabled(), spanMetricReporter); }
try (final KubernetesClient client = new DefaultKubernetesClient(config)) { if (namespace == null) { namespace = client.getNamespace();
public WildcardCertProvider(KubernetesClient client, String wildcardSecretName) { this.client = client; this.wildcardSecretName = wildcardSecretName; this.namespace = client.getNamespace(); }
if (resourceNamespaced) { if (namespace == null) { namespace = client.getNamespace();
public static void main(String[] args) throws InterruptedException { Config config = new ConfigBuilder().build(); KubernetesClient client = new DefaultKubernetesClient(config); String namespace = null; if (args.length > 0) { namespace = args[0]; } if (namespace == null) { namespace = client.getNamespace(); } if (namespace == null) { namespace = "default"; } String name = "cheese"; try { Resource<ConfigMap, DoneableConfigMap> configMapResource = client.configMaps().inNamespace(namespace).withName(name); ConfigMap configMap = configMapResource.createOrReplace(new ConfigMapBuilder(). withNewMetadata().withName(name).endMetadata(). addToData("foo", "" + new Date()). addToData("bar", "beer"). build()); log("Upserted ConfigMap at " + configMap.getMetadata().getSelfLink() + " data " + configMap.getData()); } finally { client.close(); } }
public static void createNamespace(KubernetesClient client, Controller controller, Session session) { String newNamespace = session.getNamespace(); Map<String, String> labels = new HashMap<>(); labels.put("project", client.getNamespace()); labels.put("provider", "fabric8"); labels.put("component", "integrationTest"); labels.put("framework", "arquillian"); controller.applyNamespace(newNamespace, labels); }
public static void main(String args[]) { try (final KubernetesClient client = new DefaultKubernetesClient()) { Service service = new ServiceBuilder() .withNewMetadata() .withName("my-service") .endMetadata() .withNewSpec() .withSelector(Collections.singletonMap("app", "MyApp")) .addNewPort() .withName("test-port") .withProtocol("TCP") .withPort(80) .withTargetPort(new IntOrString(9376)) .endPort() .withType("LoadBalancer") .endSpec() .withNewStatus() .withNewLoadBalancer() .addNewIngress() .withIp("146.148.47.155") .endIngress() .endLoadBalancer() .endStatus() .build(); service = client.services().inNamespace(client.getNamespace()).create(service); log("Created service with name ", service.getMetadata().getName()); String serviceURL = client.services().inNamespace(client.getNamespace()).withName(service.getMetadata().getName()).getURL("test-port"); log("Service URL", serviceURL); } }
Config config = new ConfigBuilder().withMasterUrl(master).build(); try(final KubernetesClient client = new DefaultKubernetesClient(config)) { final String namespace = client.getNamespace();
public Boolean deleteCustomResources(IstioResource resource) { if (resource != null) { final CustomResourceDefinition customResourceDefinition = getCustomResourceDefinition(resource); return client.customResources(customResourceDefinition, IstioResource.class, KubernetesResourceList.class, DoneableIstioResource.class) .inNamespace(client.getNamespace()) .delete(resource); } return false; }