Skip to content

Commit ef299eb

Browse files
committed
feat: java from CRD showcase
Signed-off-by: Marc Nuri <[email protected]>
1 parent 2f7250c commit ef299eb

File tree

5 files changed

+230
-6
lines changed

5 files changed

+230
-6
lines changed

java-generator/pom.xml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<parent>
7+
<groupId>com.marcnuri.demo.kubernetes-client</groupId>
8+
<artifactId>kubernetes-client-parent</artifactId>
9+
<version>${revision}</version>
10+
<relativePath>../pom.xml</relativePath>
11+
</parent>
12+
13+
<artifactId>kubernetes-client-java-generator</artifactId>
14+
<name>${global.name} :: Java Generator Demo</name>
15+
16+
<dependencies>
17+
<dependency>
18+
<groupId>io.sundr</groupId>
19+
<artifactId>builder-annotations</artifactId>
20+
<scope>provided</scope>
21+
</dependency>
22+
<dependency>
23+
<groupId>org.projectlombok</groupId>
24+
<artifactId>lombok</artifactId>
25+
<scope>provided</scope>
26+
</dependency>
27+
<dependency>
28+
<groupId>io.fabric8</groupId>
29+
<artifactId>kubernetes-client</artifactId>
30+
</dependency>
31+
<dependency>
32+
<groupId>io.fabric8</groupId>
33+
<artifactId>generator-annotations</artifactId>
34+
</dependency>
35+
<dependency>
36+
<groupId>org.junit.jupiter</groupId>
37+
<artifactId>junit-jupiter</artifactId>
38+
</dependency>
39+
<dependency>
40+
<groupId>io.fabric8</groupId>
41+
<artifactId>kubernetes-junit-jupiter</artifactId>
42+
</dependency>
43+
<dependency>
44+
<groupId>org.assertj</groupId>
45+
<artifactId>assertj-core</artifactId>
46+
</dependency>
47+
</dependencies>
48+
49+
<build>
50+
<plugins>
51+
<plugin>
52+
<groupId>io.fabric8</groupId>
53+
<artifactId>java-generator-maven-plugin</artifactId>
54+
<executions>
55+
<execution>
56+
<goals>
57+
<goal>generate</goal>
58+
</goals>
59+
</execution>
60+
</executions>
61+
<configuration>
62+
<source>src/main/resources/</source>
63+
<extraAnnotations>true</extraAnnotations>
64+
</configuration>
65+
</plugin>
66+
</plugins>
67+
</build>
68+
69+
</project>
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
apiVersion: apiextensions.k8s.io/v1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
annotations:
5+
controller-gen.kubebuilder.io/version: v0.16.3
6+
name: vaultconnections.secrets.hashicorp.com
7+
spec:
8+
group: secrets.hashicorp.com
9+
names:
10+
kind: VaultConnection
11+
listKind: VaultConnectionList
12+
plural: vaultconnections
13+
singular: vaultconnection
14+
scope: Namespaced
15+
versions:
16+
- name: v1beta1
17+
schema:
18+
openAPIV3Schema:
19+
description: VaultConnection is the Schema for the vaultconnections API
20+
properties:
21+
apiVersion:
22+
description: |-
23+
APIVersion defines the versioned schema of this representation of an object.
24+
Servers should convert recognized schemas to the latest internal value, and
25+
may reject unrecognized values.
26+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
27+
type: string
28+
kind:
29+
description: |-
30+
Kind is a string value representing the REST resource this object represents.
31+
Servers may infer this from the endpoint the client submits requests to.
32+
Cannot be updated.
33+
In CamelCase.
34+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
35+
type: string
36+
metadata:
37+
type: object
38+
spec:
39+
description: VaultConnectionSpec defines the desired state of VaultConnection
40+
properties:
41+
address:
42+
description: Address of the Vault server
43+
type: string
44+
caCertSecretRef:
45+
description: CACertSecretRef is the name of a Kubernetes secret containing
46+
the trusted PEM encoded CA certificate chain as `ca.crt`.
47+
type: string
48+
headers:
49+
additionalProperties:
50+
type: string
51+
description: Headers to be included in all Vault requests.
52+
type: object
53+
skipTLSVerify:
54+
default: false
55+
description: SkipTLSVerify for TLS connections.
56+
type: boolean
57+
timeout:
58+
description: |-
59+
Timeout applied to all Vault requests for this connection. If not set, the
60+
default timeout from the Vault API client config is used.
61+
pattern: ^([0-9]+(\.[0-9]+)?(s|m|h))$
62+
type: string
63+
tlsServerName:
64+
description: TLSServerName to use as the SNI host for TLS connections.
65+
type: string
66+
required:
67+
- address
68+
- skipTLSVerify
69+
type: object
70+
status:
71+
description: VaultConnectionStatus defines the observed state of VaultConnection
72+
properties:
73+
valid:
74+
description: Valid auth mechanism.
75+
type: boolean
76+
required:
77+
- valid
78+
type: object
79+
type: object
80+
served: true
81+
storage: true
82+
subresources:
83+
status: {}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.hashicorp.secrets.v1beta1;
2+
3+
import io.fabric8.junit.jupiter.api.KubernetesTest;
4+
import io.fabric8.kubernetes.api.model.HasMetadata;
5+
import io.fabric8.kubernetes.client.KubernetesClient;
6+
import io.fabric8.kubernetes.client.dsl.NonDeletingOperation;
7+
import org.junit.jupiter.api.AfterEach;
8+
import org.junit.jupiter.api.BeforeEach;
9+
import org.junit.jupiter.api.Test;
10+
11+
import java.io.InputStream;
12+
13+
import static org.assertj.core.api.Assertions.assertThat;
14+
15+
@KubernetesTest
16+
class VaultConnectionTest {
17+
18+
KubernetesClient client;
19+
20+
@BeforeEach
21+
void setUp() throws Exception {
22+
try (InputStream is = VaultConnectionTest.class.getResourceAsStream("/vault-connection.yaml")) {
23+
client.resource(is).createOr(NonDeletingOperation::update);
24+
}
25+
// If necessary we can wait for the CRD to be ready:
26+
// client.apiextensions().v1().customResourceDefinitions().waitUntilCondition(c -> {
27+
// if (!Objects.equals(c.getMetadata().getName(), "vaultconnections.secrets.hashicorp.com")) {
28+
// return false;
29+
// }
30+
// return c.getStatus().getConditions().stream()
31+
// .anyMatch(cond -> Objects.equals(cond.getType(), "Established") && Objects.equals(cond.getStatus(), "True"));
32+
// }, 10, TimeUnit.SECONDS);
33+
}
34+
35+
@AfterEach
36+
void tearDown() throws Exception {
37+
try (InputStream is = VaultConnectionTest.class.getResourceAsStream("/vault-connection.yaml")) {
38+
client.resource(is).delete();
39+
}
40+
}
41+
42+
@Test
43+
void create() {
44+
final var result = client
45+
.resource(new VaultConnectionBuilder().withNewMetadata().withName("my-vault-connection").endMetadata().build())
46+
.createOr(NonDeletingOperation::update);
47+
assertThat(result)
48+
.extracting(HasMetadata::getMetadata)
49+
.extracting("creationTimestamp")
50+
.isNotNull();
51+
}
52+
}

karaf/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
<dependency>
3636
<groupId>org.apache.karaf.features</groupId>
3737
<artifactId>standard</artifactId>
38-
<version>${karaf.version}</version>
38+
<version>${apache.karaf.version}</version>
3939
<classifier>features</classifier>
4040
<type>xml</type>
4141
</dependency>
@@ -77,7 +77,7 @@
7777
<plugin>
7878
<groupId>org.apache.karaf.tooling</groupId>
7979
<artifactId>karaf-maven-plugin</artifactId>
80-
<version>${karaf.version}</version>
80+
<version>${apache.karaf.version}</version>
8181
<extensions>true</extensions>
8282
<executions>
8383
<execution>

pom.xml

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,23 @@
1313
<revision>0.0.1-SNAPSHOT</revision>
1414
<java.version>11</java.version>
1515
<global.name>blog.marcnuri.com :: Kubernetes Client</global.name>
16-
<apache.maven.maven-compiler-plugin.version>3.13.0</apache.maven.maven-compiler-plugin.version>
16+
<apache.karaf.version>4.4.6</apache.karaf.version>
1717
<apache.maven.maven-assembly-plugin.version>3.7.1</apache.maven.maven-assembly-plugin.version>
18+
<apache.maven.maven-compiler-plugin.version>3.13.0</apache.maven.maven-compiler-plugin.version>
1819
<apache.maven.maven-surefire-plugin.version>3.5.2</apache.maven.maven-surefire-plugin.version>
1920
<apache.commons.commons-compress.version>1.27.1</apache.commons.commons-compress.version>
21+
<assertj.version>3.26.3</assertj.version>
22+
<awaitility.version>4.2.2</awaitility.version>
2023
<jackson.bundle.version>2.17.1</jackson.bundle.version>
2124
<kubernetes-client.version>6.13.4</kubernetes-client.version>
2225
<kubernetes-client.bundle.version>${kubernetes-client.version}</kubernetes-client.bundle.version>
23-
<karaf.version>4.4.6</karaf.version>
26+
<lombok.version>1.18.34</lombok.version>
2427
<slf4j.version>1.7.36</slf4j.version>
2528
<snakeyaml.version>2.8</snakeyaml.version>
2629
<snakeyaml.bundle.version>2.2</snakeyaml.bundle.version>
30+
<sundrio.version>0.200.0</sundrio.version>
2731
<junit.version>5.11.3</junit.version>
2832
<hamcrest.version>2.0.0.0</hamcrest.version>
29-
<assertj.version>3.26.3</assertj.version>
30-
<awaitility.version>4.2.2</awaitility.version>
3133
</properties>
3234

3335
<modules>
@@ -37,6 +39,7 @@
3739
<module>other</module>
3840
<module>run</module>
3941
<module>upload</module>
42+
<module>java-generator</module>
4043
</modules>
4144

4245
<dependencyManagement>
@@ -53,11 +56,23 @@
5356
<artifactId>knative-client</artifactId>
5457
<version>${kubernetes-client.version}</version>
5558
</dependency>
59+
<dependency>
60+
<groupId>io.sundr</groupId>
61+
<artifactId>builder-annotations</artifactId>
62+
<version>${sundrio.version}</version>
63+
<scope>provided</scope>
64+
</dependency>
5665
<dependency>
5766
<groupId>org.apache.commons</groupId>
5867
<artifactId>commons-compress</artifactId>
5968
<version>${apache.commons.commons-compress.version}</version>
6069
</dependency>
70+
<dependency>
71+
<groupId>org.projectlombok</groupId>
72+
<artifactId>lombok</artifactId>
73+
<version>${lombok.version}</version>
74+
<scope>provided</scope>
75+
</dependency>
6176
<dependency>
6277
<groupId>org.slf4j</groupId>
6378
<artifactId>slf4j-simple</artifactId>
@@ -117,6 +132,11 @@
117132
<artifactId>maven-surefire-plugin</artifactId>
118133
<version>${apache.maven.maven-surefire-plugin.version}</version>
119134
</plugin>
135+
<plugin>
136+
<groupId>io.fabric8</groupId>
137+
<artifactId>java-generator-maven-plugin</artifactId>
138+
<version>${kubernetes-client.version}</version>
139+
</plugin>
120140
</plugins>
121141
</pluginManagement>
122142
</build>

0 commit comments

Comments
 (0)