|
1 | 1 | /*
|
2 |
| -Copyright 2017 The Kubernetes Authors. |
| 2 | +Copyright 2018 The Kubernetes Authors. |
3 | 3 | Licensed under the Apache License, Version 2.0 (the "License");
|
4 | 4 | you may not use this file except in compliance with the License.
|
5 | 5 | You may obtain a copy of the License at
|
|
24 | 24 | import io.kubernetes.client.models.V1PodList;
|
25 | 25 | import io.kubernetes.client.models.V1ServiceList;
|
26 | 26 | import io.kubernetes.client.util.Config;
|
| 27 | +import java.io.IOException; |
27 | 28 | import java.util.List;
|
28 | 29 | import java.util.Optional;
|
29 | 30 | import java.util.stream.Collectors;
|
|
40 | 41 | */
|
41 | 42 | public class ExpandedExample {
|
42 | 43 |
|
43 |
| - private static final CoreV1Api COREV1_API; |
| 44 | + private static CoreV1Api COREV1_API; |
44 | 45 | private static final String DEFAULT_NAME_SPACE = "default";
|
45 | 46 | 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 |
| - |
58 | 47 | private static final Logger LOGGER = LoggerFactory.getLogger(ExpandedExample.class);
|
59 | 48 |
|
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 |
| - |
69 | 49 | /**
|
70 | 50 | * Main method
|
71 | 51 | *
|
72 | 52 | * @param args
|
73 | 53 | */
|
74 | 54 | public static void main(String[] args) {
|
75 | 55 | 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 | + |
76 | 62 | // ScaleUp/ScaleDown the Deployment pod
|
77 | 63 | // Please change the name of Deployment?
|
78 | 64 | System.out.println("----- Scale Deployment Start -----");
|
@@ -103,7 +89,7 @@ public static void main(String[] args) {
|
103 | 89 | String firstPodName = getPods().get(0);
|
104 | 90 | printLog(DEFAULT_NAME_SPACE, firstPodName);
|
105 | 91 | System.out.println("----- Print Log of Specific Pod End -----");
|
106 |
| - } catch (ApiException ex) { |
| 92 | + } catch (ApiException | IOException ex) { |
107 | 93 | LOGGER.warn("Exception had occured ", ex);
|
108 | 94 | }
|
109 | 95 | }
|
|
0 commit comments