diff --git a/kubernetes-client-demo-parent/pom.xml b/kubernetes-client-demo-parent/pom.xml index 987c82f..65fa8db 100644 --- a/kubernetes-client-demo-parent/pom.xml +++ b/kubernetes-client-demo-parent/pom.xml @@ -17,7 +17,7 @@ 3.0.0-M7 3.0.0-M7 5.9.1 - 6.9.2 + 6.10.0 diff --git a/pom.xml b/pom.xml index 9d1efa1..7e9d85a 100644 --- a/pom.xml +++ b/pom.xml @@ -29,17 +29,17 @@ io.fabric8 kubernetes-client - - - io.fabric8 - kubernetes-httpclient-okhttp - - - - - io.fabric8 - kubernetes-httpclient-vertx + + + + + + + + + + io.fabric8 openshift-client diff --git a/src/main/java/io/fabric8/DeploymentAddEnvironmentVariablePodTemplateDemo.java b/src/main/java/io/fabric8/DeploymentAddEnvironmentVariablePodTemplateDemo.java new file mode 100644 index 0000000..9fa8779 --- /dev/null +++ b/src/main/java/io/fabric8/DeploymentAddEnvironmentVariablePodTemplateDemo.java @@ -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\"}]}]}}}}"); + } + } +} diff --git a/src/main/java/io/fabric8/ExecWithPipesDemo.java b/src/main/java/io/fabric8/ExecWithPipesDemo.java new file mode 100644 index 0000000..09e3d08 --- /dev/null +++ b/src/main/java/io/fabric8/ExecWithPipesDemo.java @@ -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); + } + } +} diff --git a/src/main/java/io/fabric8/RunDemo.java b/src/main/java/io/fabric8/RunDemo.java new file mode 100644 index 0000000..0a7a998 --- /dev/null +++ b/src/main/java/io/fabric8/RunDemo.java @@ -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"); + } + } +} diff --git a/src/main/java/io/fabric8/StatefulSetDelete.java b/src/main/java/io/fabric8/StatefulSetDelete.java index a35dc96..fb9989b 100644 --- a/src/main/java/io/fabric8/StatefulSetDelete.java +++ b/src/main/java/io/fabric8/StatefulSetDelete.java @@ -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; @@ -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(); @@ -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(