use of io.kubernetes.client.openapi.ApiClient in project java by kubernetes-client.
the class ClientBuilderTest method testDefaultClientReadsKubeConfigMultiple.
@Test
public void testDefaultClientReadsKubeConfigMultiple() throws Exception {
final String kubeConfigEnv = KUBECONFIG_FILE_PATH + File.pathSeparator + "/non-existent";
String path = withEnvironmentVariable("KUBECONFIG", kubeConfigEnv).execute(() -> {
final ApiClient client = ClientBuilder.defaultClient();
return client.getBasePath();
});
assertEquals("http://kubeconfig.dir.com", path);
}
use of io.kubernetes.client.openapi.ApiClient in project java by kubernetes-client.
the class ClientCertificateAuthenticationTest method testValidOldECCertificates.
@Test
public void testValidOldECCertificates() throws Exception {
try {
final ApiClient client = new ApiClient();
final byte[] certificate = Files.readAllBytes(Paths.get(CLIENT_EC_CERT_PATH));
final byte[] key = Files.readAllBytes(Paths.get(CLIENT_EC_KEY_OLD_PATH));
new ClientCertificateAuthentication(certificate, key).provide(client);
} catch (Exception ex) {
ex.printStackTrace();
}
}
use of io.kubernetes.client.openapi.ApiClient in project java by kubernetes-client.
the class DynamicClientExample method main.
public static void main(String[] args) throws IOException, ApiException {
ApiClient apiClient = ClientBuilder.standard().build();
// retrieving the latest state of the default namespace
DynamicKubernetesApi dynamicApi = new DynamicKubernetesApi("", "v1", "namespaces", apiClient);
DynamicKubernetesObject defaultNamespace = dynamicApi.get("default").throwsApiException().getObject();
// attaching a "foo=bar" label to the default namespace
defaultNamespace.setMetadata(defaultNamespace.getMetadata().putLabelsItem("foo", "bar"));
DynamicKubernetesObject updatedDefaultNamespace = dynamicApi.update(defaultNamespace).throwsApiException().getObject();
System.out.println(updatedDefaultNamespace);
apiClient.getHttpClient().connectionPool().evictAll();
}
use of io.kubernetes.client.openapi.ApiClient in project java by kubernetes-client.
the class ExecExample method main.
public static void main(String[] args) throws IOException, ApiException, InterruptedException, ParseException {
final Options options = new Options();
options.addOption(new Option("p", "pod", true, "The name of the pod"));
options.addOption(new Option("n", "namespace", true, "The namespace of the pod"));
CommandLineParser parser = new DefaultParser();
CommandLine cmd = parser.parse(options, args);
String podName = cmd.getOptionValue("p", "nginx-dbddb74b8-s4cx5");
String namespace = cmd.getOptionValue("n", "default");
args = cmd.getArgs();
ApiClient client = Config.defaultClient();
Configuration.setDefaultApiClient(client);
Exec exec = new Exec();
boolean tty = System.console() != null;
// final Process proc = exec.exec("default", "nginx-4217019353-k5sn9", new String[]
// {"sh", "-c", "echo foo"}, true, tty);
final Process proc = exec.exec(namespace, podName, args.length == 0 ? new String[] { "sh" } : args, true, tty);
Thread in = new Thread(new Runnable() {
public void run() {
try {
Streams.copy(System.in, proc.getOutputStream());
} catch (IOException ex) {
ex.printStackTrace();
}
}
});
in.start();
Thread out = new Thread(new Runnable() {
public void run() {
try {
Streams.copy(proc.getInputStream(), System.out);
} catch (IOException ex) {
ex.printStackTrace();
}
}
});
out.start();
proc.waitFor();
// wait for any last output; no need to wait for input thread
out.join();
proc.destroy();
System.exit(proc.exitValue());
}
use of io.kubernetes.client.openapi.ApiClient in project java by kubernetes-client.
the class FluentExample method main.
public static void main(String[] args) throws IOException, ApiException {
ApiClient client = Config.defaultClient();
Configuration.setDefaultApiClient(client);
CoreV1Api api = new CoreV1Api();
V1Pod pod = new V1PodBuilder().withNewMetadata().withName("apod").endMetadata().withNewSpec().addNewContainer().withName("www").withImage("nginx").endContainer().endSpec().build();
api.createNamespacedPod("default", pod, null, null, null, null);
V1Pod pod2 = new V1Pod().metadata(new V1ObjectMeta().name("anotherpod")).spec(new V1PodSpec().containers(Arrays.asList(new V1Container().name("www").image("nginx"))));
api.createNamespacedPod("default", pod2, null, null, null, null);
V1PodList list = api.listNamespacedPod("default", null, null, null, null, null, null, null, null, null, null);
for (V1Pod item : list.getItems()) {
System.out.println(item.getMetadata().getName());
}
}
Aggregations