Skip to content

Commit d91be25

Browse files
authored
Merge pull request #1209 from simingweng/generate-prometheus-operator-model-classes
generate model classes for Prometheus Operator v0.38.1
2 parents d44ceb8 + c163549 commit d91be25

File tree

190 files changed

+38733
-4
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

190 files changed

+38733
-4
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,15 @@ public class WatchExample {
167167
}
168168
```
169169

170-
More examples can be found in [examples](examples/) folder. To run examples, run this command:
170+
More examples can be found in [examples](examples) folder. To run examples, run this command:
171171

172172
```shell
173173
mvn exec:java -Dexec.mainClass="io.kubernetes.client.examples.Example"
174174
```
175+
## Model Classes from Popular CRDs
176+
The project also provides model classes generated from some frequently used open source projects as separate maven dependencies. Please refer to the following to see their respective documentation.
177+
* [cert-manager](client-java-contrib/cert-manager)
178+
* [prometheus operator](client-java-contrib/prometheus-operator)
175179

176180
## Documentation
177181

client-java-contrib/generate.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# This script orchestrates the code generation procedure. It is executed inside a crdgen
1818
# container in order to minimize the environment dependencies on the host, being Docker only.
1919

20-
CRD_URL=${CRD_URL:-}
20+
CRD_URLS=${CRD_URLS:-}
2121
OUTPUT_DIR=${OUTPUT_DIR:-}
2222
KUBERNETES_CRD_GROUP_PREFIX=${KUBERNETES_CRD_GROUP_PREFIX:-}
2323
PACKAGE_NAME=${PACKAGE_NAME:-}
@@ -32,7 +32,7 @@ print_usage() {
3232

3333
while getopts 'u:n:p:o:' flag; do
3434
case "${flag}" in
35-
u) CRD_URL="${OPTARG}" ;;
35+
u) CRD_URLS+=("${OPTARG}") ;;
3636
n) KUBERNETES_CRD_GROUP_PREFIX="${OPTARG}" ;;
3737
p) PACKAGE_NAME="${OPTARG}" ;;
3838
o) OUTPUT_DIR="${OPTARG}" ;;
@@ -45,7 +45,10 @@ done
4545
kind create cluster
4646

4747
# install CRDs to the KinD cluster and dump the swagger spec
48-
kubectl apply -f "${CRD_URL}"
48+
for url in "${CRD_URLS[@]}"; do
49+
kubectl apply -f "$url"
50+
done
51+
4952
sleep 5
5053
kubectl get --raw="/openapi/v2" > /tmp/swagger
5154

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Prometheus Operator Model Classes
2+
This module contains the Java model classes generated from the release version of [prometheus operator](https://github.com/prometheus-operator/prometheus-operator) CRDs.
3+
4+
It makes it possible to CRUD custom resources defined by `prometheus operator` in a strong-typed manner in your Java application, such as create a prometheus instance, write a prometheus rule, etc.
5+
## Usage
6+
To use this library, include the following maven dependency
7+
```xml
8+
<dependency>
9+
<groupId>io.kubernetes</groupId>
10+
<artifactId>client-java-prometheus-operator-models</artifactId>
11+
<version>0.38.1-SNAPSHOT</version>
12+
</dependency>
13+
```
14+
Please refer to the [PromOpExample](../../examples/src/main/java/io/kubernetes/client/examples/PromOpExample.java), which demonstrates how to create a minimal prometheus instance with the model class and Kubernetes Java client generic API.
15+
## Compatibility
16+
Artifact Version|Prometheus Operator Release Version|CRD Source
17+
----------------|----------------------------|----------
18+
0.38.1-SNAPSHOT|0.38.1|[Here](https://github.com/prometheus-operator/prometheus-operator/tree/master/example/prometheus-operator-crd)
19+
## Code Generation
20+
There is a utility script [update.sh](update.sh) to help with the code generation.
21+
22+
* The only prerequisites required is Docker installed on the host
23+
24+
Under the `prometheus-operator` directory, execute:
25+
```shell script
26+
./update.sh
27+
```
28+
It will generate the model classes from the CRDs hosted at the URL specified via the `-u` options in the [update.sh](update.sh) script. If newer version of CRDs becomes available, just update the `-u` options accordingly.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>client-java-parent</artifactId>
7+
<groupId>io.kubernetes</groupId>
8+
<version>10.0.0-SNAPSHOT</version>
9+
<relativePath>../../pom.xml</relativePath>
10+
</parent>
11+
<modelVersion>4.0.0</modelVersion>
12+
13+
<artifactId>client-java-prometheus-operator-models</artifactId>
14+
<version>0.38.1-SNAPSHOT</version>
15+
<dependencies>
16+
<dependency>
17+
<groupId>io.kubernetes</groupId>
18+
<artifactId>client-java</artifactId>
19+
<version>${project.parent.version}</version>
20+
<scope>provided</scope>
21+
</dependency>
22+
</dependencies>
23+
</project>
Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
/*
2+
Copyright 2020 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 com.coreos.monitoring.models;
14+
15+
import com.google.gson.annotations.SerializedName;
16+
import io.kubernetes.client.openapi.models.V1ObjectMeta;
17+
import io.swagger.annotations.ApiModel;
18+
import io.swagger.annotations.ApiModelProperty;
19+
import java.util.Objects;
20+
21+
/** Alertmanager describes an Alertmanager cluster. */
22+
@ApiModel(description = "Alertmanager describes an Alertmanager cluster.")
23+
@javax.annotation.Generated(
24+
value = "org.openapitools.codegen.languages.JavaClientCodegen",
25+
date = "2020-08-31T19:41:55.826Z[Etc/UTC]")
26+
public class V1Alertmanager implements io.kubernetes.client.common.KubernetesObject {
27+
public static final String SERIALIZED_NAME_API_VERSION = "apiVersion";
28+
29+
@SerializedName(SERIALIZED_NAME_API_VERSION)
30+
private String apiVersion;
31+
32+
public static final String SERIALIZED_NAME_KIND = "kind";
33+
34+
@SerializedName(SERIALIZED_NAME_KIND)
35+
private String kind;
36+
37+
public static final String SERIALIZED_NAME_METADATA = "metadata";
38+
39+
@SerializedName(SERIALIZED_NAME_METADATA)
40+
private V1ObjectMeta metadata = null;
41+
42+
public static final String SERIALIZED_NAME_SPEC = "spec";
43+
44+
@SerializedName(SERIALIZED_NAME_SPEC)
45+
private V1AlertmanagerSpec spec;
46+
47+
public static final String SERIALIZED_NAME_STATUS = "status";
48+
49+
@SerializedName(SERIALIZED_NAME_STATUS)
50+
private V1AlertmanagerStatus status;
51+
52+
public V1Alertmanager apiVersion(String apiVersion) {
53+
54+
this.apiVersion = apiVersion;
55+
return this;
56+
}
57+
58+
/**
59+
* APIVersion defines the versioned schema of this representation of an object. Servers should
60+
* convert recognized schemas to the latest internal value, and may reject unrecognized values.
61+
* More info:
62+
* https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
63+
*
64+
* @return apiVersion
65+
*/
66+
@javax.annotation.Nullable
67+
@ApiModelProperty(
68+
value =
69+
"APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources")
70+
public String getApiVersion() {
71+
return apiVersion;
72+
}
73+
74+
public void setApiVersion(String apiVersion) {
75+
this.apiVersion = apiVersion;
76+
}
77+
78+
public V1Alertmanager kind(String kind) {
79+
80+
this.kind = kind;
81+
return this;
82+
}
83+
84+
/**
85+
* Kind is a string value representing the REST resource this object represents. Servers may infer
86+
* this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More
87+
* info:
88+
* https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
89+
*
90+
* @return kind
91+
*/
92+
@javax.annotation.Nullable
93+
@ApiModelProperty(
94+
value =
95+
"Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds")
96+
public String getKind() {
97+
return kind;
98+
}
99+
100+
public void setKind(String kind) {
101+
this.kind = kind;
102+
}
103+
104+
public V1Alertmanager metadata(V1ObjectMeta metadata) {
105+
106+
this.metadata = metadata;
107+
return this;
108+
}
109+
110+
/**
111+
* Get metadata
112+
*
113+
* @return metadata
114+
*/
115+
@javax.annotation.Nullable
116+
@ApiModelProperty(value = "")
117+
public V1ObjectMeta getMetadata() {
118+
return metadata;
119+
}
120+
121+
public void setMetadata(V1ObjectMeta metadata) {
122+
this.metadata = metadata;
123+
}
124+
125+
public V1Alertmanager spec(V1AlertmanagerSpec spec) {
126+
127+
this.spec = spec;
128+
return this;
129+
}
130+
131+
/**
132+
* Get spec
133+
*
134+
* @return spec
135+
*/
136+
@ApiModelProperty(required = true, value = "")
137+
public V1AlertmanagerSpec getSpec() {
138+
return spec;
139+
}
140+
141+
public void setSpec(V1AlertmanagerSpec spec) {
142+
this.spec = spec;
143+
}
144+
145+
public V1Alertmanager status(V1AlertmanagerStatus status) {
146+
147+
this.status = status;
148+
return this;
149+
}
150+
151+
/**
152+
* Get status
153+
*
154+
* @return status
155+
*/
156+
@javax.annotation.Nullable
157+
@ApiModelProperty(value = "")
158+
public V1AlertmanagerStatus getStatus() {
159+
return status;
160+
}
161+
162+
public void setStatus(V1AlertmanagerStatus status) {
163+
this.status = status;
164+
}
165+
166+
@Override
167+
public boolean equals(java.lang.Object o) {
168+
if (this == o) {
169+
return true;
170+
}
171+
if (o == null || getClass() != o.getClass()) {
172+
return false;
173+
}
174+
V1Alertmanager v1Alertmanager = (V1Alertmanager) o;
175+
return Objects.equals(this.apiVersion, v1Alertmanager.apiVersion)
176+
&& Objects.equals(this.kind, v1Alertmanager.kind)
177+
&& Objects.equals(this.metadata, v1Alertmanager.metadata)
178+
&& Objects.equals(this.spec, v1Alertmanager.spec)
179+
&& Objects.equals(this.status, v1Alertmanager.status);
180+
}
181+
182+
@Override
183+
public int hashCode() {
184+
return Objects.hash(apiVersion, kind, metadata, spec, status);
185+
}
186+
187+
@Override
188+
public String toString() {
189+
StringBuilder sb = new StringBuilder();
190+
sb.append("class V1Alertmanager {\n");
191+
sb.append(" apiVersion: ").append(toIndentedString(apiVersion)).append("\n");
192+
sb.append(" kind: ").append(toIndentedString(kind)).append("\n");
193+
sb.append(" metadata: ").append(toIndentedString(metadata)).append("\n");
194+
sb.append(" spec: ").append(toIndentedString(spec)).append("\n");
195+
sb.append(" status: ").append(toIndentedString(status)).append("\n");
196+
sb.append("}");
197+
return sb.toString();
198+
}
199+
200+
/**
201+
* Convert the given object to string with each line indented by 4 spaces (except the first line).
202+
*/
203+
private String toIndentedString(java.lang.Object o) {
204+
if (o == null) {
205+
return "null";
206+
}
207+
return o.toString().replace("\n", "\n ");
208+
}
209+
}

0 commit comments

Comments
 (0)