You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
And also the code generation requires accessing docker service on the host:
21
+
22
+
```
23
+
docker ps
24
+
```
11
25
12
26
##### Fetch openapi spec from the cluster
13
27
@@ -23,26 +37,31 @@ don't forget to deploy your CRDs into the local-run kubernetes cluster.
23
37
24
38
##### Generate Java model from the downloaded openapi spec
25
39
26
-
Run the following command and there will be a java sources generated under `/tmp/java`.
40
+
Run the following commands and there will be a java sources generated under `/tmp/java`.
27
41
28
42
```
29
-
docker run -i --rm yue9944882/java-model-gen < /tmp/swagger | tar -xzf - -C /tmp/
43
+
bash java-crd-cmd.sh -o /tmp/java < /tmp/swagger
30
44
```
31
45
32
-
By default, the package-name of generated codes will be `io.kubernetes.client`. If you want to override the package-name, consider
46
+
By default, the packagename of generated java classes will be `io.kubernetes.client`. If you want to override the packagename, consider
33
47
use `-p <package_name>` flag. Additionally, you can use `-l <length>` option to make the generator to trim the length of generated
34
48
class name, the lower number generates shorter names. e.g. for a CRD named `crontabs.v1.example.io`, with `-l 1` the generated
35
-
name will be `CronTab`, otherwise with `-l3` it will be `ExampleV1Crontab`.
49
+
name will be `CronTab`, otherwise with `-l3` it will be `ExampleV1Crontab`. And also if you feel like only generating classes for a few CRDs
50
+
instead of the whole lump of downloaded openapi specs, please use `-n` to filter out your target CRDs. For all supported flags, use `-h`
51
+
for help info as is shown in the following:
36
52
37
53
```
38
-
docker run -i --rm yue9944882/java-model-gen -p com.example < /tmp/swagger | tar -xzf - -C /tmp/
54
+
Usage: generate a java project using input openapi spec from stdin
55
+
-n: the prefix of the target CRD's api group to generate.
56
+
-p: the base package name of the generated java project.
57
+
-o: output directory of the generated java project.
58
+
-l: keep the n last segments for the generated class name.
39
59
```
40
60
41
-
42
61
##### Best practice to manipulate Java models?
43
62
44
63
It's recommended to use [CustomObjectApi](https://github.com/kubernetes-client/java/blob/master/kubernetes/src/main/java/io/kubernetes/client/apis/CustomObjectsApi.java)
45
-
to read/write the extended resources from/to the cluster.
64
+
or [GenericKubernetesApi](https://github.com/kubernetes-client/java/blob/master/extended/src/main/java/io/kubernetes/client/extended/generic/GenericKubernetesApi.java)to read/write the extended resources from/to the cluster.
46
65
47
66
### Hand-on exercise
48
67
@@ -106,23 +125,23 @@ kubectl get --raw="/openapi/v2" > /tmp/swagger
106
125
3. Generate models under `/tmp/java` directory
107
126
108
127
```bash
109
-
docker run -i --rm yue9944882/java-model-gen -p com.example </tmp/swagger | tar -xzf - -C /tmp/
0 commit comments