Skip to content

Commit b69ff9f

Browse files
committed
Use default Constructor
1 parent 8823622 commit b69ff9f

File tree

1 file changed

+11
-7
lines changed
  • examples/src/main/java/io/kubernetes/client/examples

1 file changed

+11
-7
lines changed

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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.logging.Level;
@@ -49,21 +50,24 @@ public class Example {
4950
For API_SERVER_NAME, you can get the server name as follows.
5051
$ kubectl cluster-info|grep master
5152
Kubernetes master is running at https://*****************.hcp.japaneast.azmk8s.io:443
52-
*/
53+
*/
5354
private final static String API_SERVER_NAME = "https://*****************.hcp.japaneast.azmk8s.io";
5455
/*
5556
For ACCESS_TOKEN , you can get the token as follows
5657
$ kubectl describe secret $(kubectl get secrets | grep default | cut -f1 -d ' ') | grep -E '^token' | cut -f2 -d':' | tr -d '\t'
57-
*/
58+
*/
5859
private static final String ACCESS_TOKEN = "********************************";
5960

6061
private final static Logger LOGGER = Logger.getLogger(Example.class.getName());
6162

6263
/**
6364
* Constructor
65+
* @throws java.io.IOException
6466
*/
65-
public Example() {
66-
ApiClient client = Config.fromToken(API_SERVER_NAME, ACCESS_TOKEN, false);
67+
public Example() throws IOException {
68+
ApiClient client = Config.defaultClient();
69+
//If you want to use specific k8s cluster and access token, please use following?
70+
//ApiClient client = Config.fromToken(API_SERVER_NAME, ACCESS_TOKEN, false);
6771
Configuration.setDefaultApiClient(client);
6872
corev1Api = new CoreV1Api(client);
6973
}
@@ -77,8 +81,8 @@ public static void main(String[] args) {
7781
try {
7882
Example operation = new Example();
7983
operation.executeCommand();
80-
} catch (ApiException ex) {
81-
LOGGER.log(Level.SEVERE, null, ex);
84+
} catch (ApiException | IOException ex) {
85+
Logger.getLogger(Example.class.getName()).log(Level.SEVERE, null, ex);
8286
}
8387
}
8488

@@ -201,7 +205,7 @@ public List<String> getServices() throws ApiException {
201205
public void scaleDeployment(String deploymentName, int numberOfReplicas) throws ApiException {
202206
ExtensionsV1beta1Api extensionV1Api = new ExtensionsV1beta1Api();
203207
extensionV1Api.setApiClient(corev1Api.getApiClient());
204-
ExtensionsV1beta1DeploymentList listNamespacedDeployment = extensionV1Api.listNamespacedDeployment(DEFAULT_NAME_SPACE,null,null,null,Boolean.FALSE,null,null,null,null,Boolean.FALSE);
208+
ExtensionsV1beta1DeploymentList listNamespacedDeployment = extensionV1Api.listNamespacedDeployment(DEFAULT_NAME_SPACE, null, null, null, Boolean.FALSE, null, null, null, null, Boolean.FALSE);
205209

206210
List<ExtensionsV1beta1Deployment> extensionsV1beta1DeploymentItems = listNamespacedDeployment.getItems();
207211
Optional<ExtensionsV1beta1Deployment> findedDeployment = extensionsV1beta1DeploymentItems.stream()

0 commit comments

Comments
 (0)