Skip to content

Commit

Permalink
deps : Update Fabric8 Kubernetes Client to v6.10.0
Browse files Browse the repository at this point in the history
Signed-off-by: Rohan Kumar <rohaan@redhat.com>
  • Loading branch information
rohanKanojia committed Jan 15, 2024
1 parent dff3ac5 commit 52407ff
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 14 deletions.
2 changes: 1 addition & 1 deletion kubernetes-client-demo-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<maven-surefire-plugin.version>3.0.0-M7</maven-surefire-plugin.version>
<maven-failsafe-plugin.version>3.0.0-M7</maven-failsafe-plugin.version>
<junit.version>5.9.1</junit.version>
<fabric8.version>6.9.2</fabric8.version>
<fabric8.version>6.10.0</fabric8.version>
</properties>

<modules>
Expand Down
20 changes: 10 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-client</artifactId>
<exclusions>
<exclusion>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-httpclient-okhttp</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-httpclient-vertx</artifactId>
<!-- <exclusions>-->
<!-- <exclusion>-->
<!-- <groupId>io.fabric8</groupId>-->
<!-- <artifactId>kubernetes-httpclient-okhttp</artifactId>-->
<!-- </exclusion>-->
<!-- </exclusions>-->
</dependency>
<!-- <dependency>-->
<!-- <groupId>io.fabric8</groupId>-->
<!-- <artifactId>kubernetes-httpclient-vertx</artifactId>-->
<!-- </dependency>-->
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>openshift-client</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package io.fabric8;

import io.fabric8.kubernetes.api.model.apps.DeploymentBuilder;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
import io.fabric8.kubernetes.client.dsl.base.PatchContext;
import io.fabric8.kubernetes.client.dsl.base.PatchType;

public class DeploymentAddEnvironmentVariablePodTemplateDemo {
public static void main(String[] args) {
try (KubernetesClient client = new KubernetesClientBuilder().build()) {
client.apps()
.deployments()
.inNamespace("default")
.withName("jkube-spring-boot3-native-image-demo")
.edit(d -> new DeploymentBuilder(d)
.editSpec()
.editTemplate()
.editSpec()
.editContainer(0)
.addNewEnv()
.withName("TEST_ENV_KEY")
.withValue("TEST_ENV_VAL_UPDATED")
.endEnv()
.endContainer()
.endSpec()
.endTemplate()
.endSpec()
.build());
client.apps()
.deployments()
.inNamespace("default")
.withName("jkube-spring-boot3-native-image-demo")
.patch(PatchContext.of(PatchType.STRATEGIC_MERGE),
"{\"spec\":{\"template\":{\"spec\":{\"containers\":[{\"name\":\"spring-boot\",\"env\":[{\"name\":\"PATCHED_ENV\", \"value\":\"PATCH_ENV_VAL_UPDATED\"}]}]}}}}");
}
}
}
25 changes: 25 additions & 0 deletions src/main/java/io/fabric8/ExecWithPipesDemo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.fabric8;

import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
import io.fabric8.kubernetes.client.dsl.ExecWatch;
import io.fabric8.kubernetes.client.dsl.PodResource;

import java.io.ByteArrayOutputStream;

public class ExecWithPipesDemo {
public static void main(String[] args) {
try (KubernetesClient client = new KubernetesClientBuilder().build()) {
PodResource podResource = client.pods()
.inNamespace("default")
.withName("exrf9fr");
ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
try (ExecWatch execWatch = podResource.writingOutput(baos).terminateOnError()
.exec("sh", "-c", "ls -lrt /proc | wc -l")) {
execWatch.exitCode().join();
}

System.out.println("Result : " + baos);
}
}
}
22 changes: 22 additions & 0 deletions src/main/java/io/fabric8/RunDemo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.fabric8;

import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClientBuilder;

public class RunDemo {
public static void main(String[] args) {
try (KubernetesClient client = new KubernetesClientBuilder().build()) {
String namespace = "default";
String name = "run-config-example";
String image = "alpine:3.19.0";

client.run().inNamespace(namespace).withNewRunConfig()
.withRestartPolicy("Never")
.withName(name)
.withImage(image)
.withArgs("sh", "-c", "trap : TERM INT; sleep infinity & wait")
.done();
System.out.println("Done");
}
}
}
7 changes: 4 additions & 3 deletions src/main/java/io/fabric8/StatefulSetDelete.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import io.fabric8.kubernetes.api.model.QuantityBuilder;
import io.fabric8.kubernetes.api.model.ResourceRequirements;
import io.fabric8.kubernetes.api.model.ResourceRequirementsBuilder;
import io.fabric8.kubernetes.api.model.VolumeResourceRequirements;
import io.fabric8.kubernetes.api.model.VolumeResourceRequirementsBuilder;
import io.fabric8.kubernetes.api.model.apps.StatefulSet;
import io.fabric8.kubernetes.api.model.apps.StatefulSetBuilder;
import io.fabric8.kubernetes.api.model.apps.StatefulSetSpecBuilder;
Expand Down Expand Up @@ -57,7 +59,7 @@ private static StatefulSet createStatefulSet(final String statefulSetName) {
.endSpec()
.build();

final ResourceRequirements build = new ResourceRequirementsBuilder().withRequests(Collections.singletonMap(
final VolumeResourceRequirements build = new VolumeResourceRequirementsBuilder().withRequests(Collections.singletonMap(
"storage",
new QuantityBuilder().withAmount("1Mi").build())).build();

Expand All @@ -72,8 +74,7 @@ private static StatefulSet createStatefulSet(final String statefulSetName) {
.endMetadata()
.withNewSpec()
.withAccessModes("ReadWriteOnce")
.withResources(
build)
.withResources(build)
.endSpec()
.build())
.withSelector(new LabelSelectorBuilder().withMatchLabels(Collections.singletonMap(
Expand Down

0 comments on commit 52407ff

Please sign in to comment.