Skip to content

Commit 4918869

Browse files
authored
Merge pull request #359 from brendandburns/fluent
Example of fluent builders.
2 parents bc9fb55 + b0dd787 commit 4918869

File tree

3 files changed

+78
-1
lines changed

3 files changed

+78
-1
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,6 @@ hs_err_pid*
2626
*.iml
2727

2828
.DS_Store
29+
30+
# generated stuff
31+
kubernetes/bin
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
Copyright 2018 The Kubernetes Authors.
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
package io.kubernetes.client.examples;
14+
15+
import io.kubernetes.client.ApiClient;
16+
import io.kubernetes.client.ApiException;
17+
import io.kubernetes.client.Configuration;
18+
import io.kubernetes.client.apis.CoreV1Api;
19+
import io.kubernetes.client.models.V1Container;
20+
import io.kubernetes.client.models.V1ObjectMeta;
21+
import io.kubernetes.client.models.V1Pod;
22+
import io.kubernetes.client.models.V1PodBuilder;
23+
import io.kubernetes.client.models.V1PodList;
24+
import io.kubernetes.client.models.V1PodSpec;
25+
import io.kubernetes.client.util.Config;
26+
import java.io.IOException;
27+
import java.util.Arrays;
28+
29+
/**
30+
* A simple example of how to use the Java API
31+
*
32+
* <p>Easiest way to run this: mvn exec:java
33+
* -Dexec.mainClass="io.kubernetes.client.examples.FluentExample"
34+
*
35+
* <p>From inside $REPO_DIR/examples
36+
*/
37+
public class FluentExample {
38+
public static void main(String[] args) throws IOException, ApiException {
39+
ApiClient client = Config.defaultClient();
40+
Configuration.setDefaultApiClient(client);
41+
42+
CoreV1Api api = new CoreV1Api();
43+
44+
V1Pod pod =
45+
new V1PodBuilder()
46+
.withNewMetadata()
47+
.withName("apod")
48+
.endMetadata()
49+
.withNewSpec()
50+
.addNewContainer()
51+
.withName("www")
52+
.withImage("nginx")
53+
.endContainer()
54+
.endSpec()
55+
.build();
56+
57+
api.createNamespacedPod("default", pod, null);
58+
59+
V1Pod pod2 =
60+
new V1Pod()
61+
.metadata(new V1ObjectMeta().name("anotherpod"))
62+
.spec(
63+
new V1PodSpec()
64+
.containers(Arrays.asList(new V1Container().name("www").image("nginx"))));
65+
66+
api.createNamespacedPod("default", pod2, null);
67+
68+
V1PodList list =
69+
api.listNamespacedPod("default", null, null, null, null, null, null, null, null, null);
70+
for (V1Pod item : list.getItems()) {
71+
System.out.println(item.getMetadata().getName());
72+
}
73+
}
74+
}

kubernetes/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@
200200
<maven.compiler.source>${java.version}</maven.compiler.source>
201201
<maven.compiler.target>${java.version}</maven.compiler.target>
202202
<swagger-core-version>1.5.12</swagger-core-version>
203-
<sundrio.version>0.8.0</sundrio.version>
203+
<sundrio.version>0.9.2</sundrio.version>
204204
<okhttp-version>2.7.5</okhttp-version>
205205
<gson-version>2.6.2</gson-version>
206206
<jodatime-version>2.9.3</jodatime-version>

0 commit comments

Comments
 (0)