Skip to content

Commit 5faf0f2

Browse files
committed
Modified the instance creation for CoreV1Api.
Modified the instance creation for CoreV1Api by using ApiClient client = Config.defaultClient();
1 parent 3ec85ea commit 5faf0f2

File tree

1 file changed

+10
-24
lines changed

1 file changed

+10
-24
lines changed

examples/src/main/java/io/kubernetes/client/examples/ExpandedExample.java

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2017 The Kubernetes Authors.
2+
Copyright 2018 The Kubernetes Authors.
33
Licensed under the Apache License, Version 2.0 (the "License");
44
you may not use this file except in compliance with the License.
55
You may obtain a copy of the License at
@@ -24,6 +24,7 @@
2424
import io.kubernetes.client.models.V1PodList;
2525
import io.kubernetes.client.models.V1ServiceList;
2626
import io.kubernetes.client.util.Config;
27+
import java.io.IOException;
2728
import java.util.List;
2829
import java.util.Optional;
2930
import java.util.stream.Collectors;
@@ -40,39 +41,24 @@
4041
*/
4142
public class ExpandedExample {
4243

43-
private static final CoreV1Api COREV1_API;
44+
private static CoreV1Api COREV1_API;
4445
private static final String DEFAULT_NAME_SPACE = "default";
4546
private static final Integer TIME_OUT_VALUE = 180;
46-
/*
47-
For API_SERVER_NAME, you can get the server name as follows.
48-
$ kubectl cluster-info|grep master
49-
Kubernetes master is running at https://*****************.hcp.japaneast.azmk8s.io:443
50-
*/
51-
private static final String API_SERVER_NAME = "https://*****************.hcp.japaneast.azmk8s.io";
52-
/*
53-
For ACCESS_TOKEN , you can get the token as follows
54-
$ kubectl describe secret $(kubectl get secrets | grep default | cut -f1 -d ' ') | grep -E '^token' | cut -f2 -d':' | tr -d '\t'
55-
*/
56-
private static final String ACCESS_TOKEN = "********************************";
57-
5847
private static final Logger LOGGER = LoggerFactory.getLogger(ExpandedExample.class);
5948

60-
/** Static Initializer */
61-
static {
62-
// ApiClient client = Config.defaultClient();
63-
// If you want to use specific k8s cluster and access token, please use following?
64-
ApiClient client = Config.fromToken(API_SERVER_NAME, ACCESS_TOKEN, false);
65-
Configuration.setDefaultApiClient(client);
66-
COREV1_API = new CoreV1Api(client);
67-
}
68-
6949
/**
7050
* Main method
7151
*
7252
* @param args
7353
*/
7454
public static void main(String[] args) {
7555
try {
56+
ApiClient client = Config.defaultClient();
57+
// To change the context of k8s cluster, you can use
58+
// io.kubernetes.client.util.KubeConfig
59+
Configuration.setDefaultApiClient(client);
60+
COREV1_API = new CoreV1Api(client);
61+
7662
// ScaleUp/ScaleDown the Deployment pod
7763
// Please change the name of Deployment?
7864
System.out.println("----- Scale Deployment Start -----");
@@ -103,7 +89,7 @@ public static void main(String[] args) {
10389
String firstPodName = getPods().get(0);
10490
printLog(DEFAULT_NAME_SPACE, firstPodName);
10591
System.out.println("----- Print Log of Specific Pod End -----");
106-
} catch (ApiException ex) {
92+
} catch (ApiException | IOException ex) {
10793
LOGGER.warn("Exception had occured ", ex);
10894
}
10995
}

0 commit comments

Comments
 (0)