From 6e63015ee5d32eefbd5f18828f7fdb6710014300 Mon Sep 17 00:00:00 2001 From: Jose Date: Thu, 11 Aug 2022 11:45:41 +0200 Subject: [PATCH] Support emptydir volumes We support many volume types, but we're missing the emptydir volume. This volume is a request from the user community: https://github.com/quarkusio/quarkus/issues/27222 --- .../annotation/KnativeApplication.java | 6 ++ .../annotation/KubernetesApplication.java | 5 ++ .../annotation/OpenshiftApplication.java | 6 ++ assets/config.md | 10 +++ .../AbstractKubernetesManifestGenerator.java | 14 ++++ .../dekorate/kubernetes/annotation/Base.java | 2 + .../kubernetes/annotation/CronJob.java | 5 ++ .../kubernetes/annotation/EmptyDirVolume.java | 27 +++++++ .../dekorate/kubernetes/annotation/Job.java | 5 ++ .../decorator/AddEmptyDirVolumeDecorator.java | 71 +++++++++++++++++++ docs/configuration-guide.md | 19 +++-- .../src/main/resources/application.properties | 1 + .../java/io/dekorate/example/Feat855Test.java | 1 + .../src/main/resources/application.properties | 1 + .../java/io/dekorate/example/Feat856Test.java | 1 + .../feat-kubernetes-emptydir-volumes/pom.xml | 68 ++++++++++++++++++ .../annotationless/DemoApplication.java | 28 ++++++++ .../src/main/resources/application.properties | 4 ++ .../FeatEmptyDirVolumesTest.java | 51 +++++++++++++ tests/pom.xml | 1 + 20 files changed, 322 insertions(+), 4 deletions(-) create mode 100644 core/src/main/java/io/dekorate/kubernetes/annotation/EmptyDirVolume.java create mode 100644 core/src/main/java/io/dekorate/kubernetes/decorator/AddEmptyDirVolumeDecorator.java create mode 100644 tests/feat-kubernetes-emptydir-volumes/pom.xml create mode 100644 tests/feat-kubernetes-emptydir-volumes/src/main/java/io/dekorate/annotationless/DemoApplication.java create mode 100644 tests/feat-kubernetes-emptydir-volumes/src/main/resources/application.properties create mode 100644 tests/feat-kubernetes-emptydir-volumes/src/test/java/io/dekorate/annotationless/FeatEmptyDirVolumesTest.java diff --git a/annotations/knative-annotations/src/main/java/io/dekorate/knative/annotation/KnativeApplication.java b/annotations/knative-annotations/src/main/java/io/dekorate/knative/annotation/KnativeApplication.java index fcc3871df..a70e1934a 100644 --- a/annotations/knative-annotations/src/main/java/io/dekorate/knative/annotation/KnativeApplication.java +++ b/annotations/knative-annotations/src/main/java/io/dekorate/knative/annotation/KnativeApplication.java @@ -30,6 +30,7 @@ import io.dekorate.kubernetes.annotation.ConfigMapVolume; import io.dekorate.kubernetes.annotation.Container; import io.dekorate.kubernetes.annotation.CronJob; +import io.dekorate.kubernetes.annotation.EmptyDirVolume; import io.dekorate.kubernetes.annotation.Env; import io.dekorate.kubernetes.annotation.GitRepoVolume; import io.dekorate.kubernetes.annotation.ImagePullPolicy; @@ -183,6 +184,11 @@ */ ConfigMapVolume[] configMapVolumes() default {}; + /** + * The EmptyDir volumes to add to all containers. + */ + EmptyDirVolume[] emptyDirVolumes() default {}; + /** * Git repo volumues to add to all containers. */ diff --git a/annotations/kubernetes-annotations/src/main/java/io/dekorate/kubernetes/annotation/KubernetesApplication.java b/annotations/kubernetes-annotations/src/main/java/io/dekorate/kubernetes/annotation/KubernetesApplication.java index b260c56d9..45c89faa8 100644 --- a/annotations/kubernetes-annotations/src/main/java/io/dekorate/kubernetes/annotation/KubernetesApplication.java +++ b/annotations/kubernetes-annotations/src/main/java/io/dekorate/kubernetes/annotation/KubernetesApplication.java @@ -173,6 +173,11 @@ */ ConfigMapVolume[] configMapVolumes() default {}; + /** + * The EmptyDir volumes to add to all containers. + */ + EmptyDirVolume[] emptyDirVolumes() default {}; + /** * Git repo volumes to add to all containers. */ diff --git a/annotations/openshift-annotations/src/main/java/io/dekorate/openshift/annotation/OpenshiftApplication.java b/annotations/openshift-annotations/src/main/java/io/dekorate/openshift/annotation/OpenshiftApplication.java index 22c2d1f88..1326162f9 100644 --- a/annotations/openshift-annotations/src/main/java/io/dekorate/openshift/annotation/OpenshiftApplication.java +++ b/annotations/openshift-annotations/src/main/java/io/dekorate/openshift/annotation/OpenshiftApplication.java @@ -27,6 +27,7 @@ import io.dekorate.kubernetes.annotation.ConfigMapVolume; import io.dekorate.kubernetes.annotation.Container; import io.dekorate.kubernetes.annotation.CronJob; +import io.dekorate.kubernetes.annotation.EmptyDirVolume; import io.dekorate.kubernetes.annotation.Env; import io.dekorate.kubernetes.annotation.GitRepoVolume; import io.dekorate.kubernetes.annotation.ImagePullPolicy; @@ -189,6 +190,11 @@ */ ConfigMapVolume[] configMapVolumes() default {}; + /** + * The EmptyDir volumes to add to all containers. + */ + EmptyDirVolume[] emptyDirVolumes() default {}; + /** * Git repo volumues to add to all containers. */ diff --git a/assets/config.md b/assets/config.md index 4bec1bbc4..45b9d6a7b 100644 --- a/assets/config.md +++ b/assets/config.md @@ -78,6 +78,7 @@ The document is structured as follows. | dekorate.kubernetes.pvc-volumes | PersistentVolumeClaimVolume[] | PersistentVolumeClaim volumes to add to all containers. | | | dekorate.kubernetes.secret-volumes | SecretVolume[] | Secret volumes to add to all containers. | | | dekorate.kubernetes.config-map-volumes | ConfigMapVolume[] | ConfigMap volumes to add to all containers. | | +| dekorate.kubernetes.empty-dir-volumes | EmptyDirVolume[] | EmptyDir volumes to add to all containers. | | | dekorate.kubernetes.git-repo-volumes | GitRepoVolume[] | Git repo volumes to add to all containers. | | | dekorate.kubernetes.aws-elastic-block-store-volumes | AwsElasticBlockStoreVolume[] | Aws elastic block store volumes to add to all containers | | | dekorate.kubernetes.azure-disk-volumes | AzureDiskVolume[] | Azure disk volumes to add | | @@ -173,6 +174,7 @@ The section below describes all the available subtypes. | pvc-volumes | PersistentVolumeClaimVolume[] | PersistentVolumeClaim volumes to add to all containers. | | | secret-volumes | SecretVolume[] | Secret volumes to add to all containers. | | | config-map-volumes | ConfigMapVolume[] | ConfigMap volumes to add to all containers. | | +| empty-dir-volumes | EmptyDirVolume[] | EmptyDir volumes to add to all containers. | | | aws-elastic-block-store-volumes | AwsElasticBlockStoreVolume[] | Aws elastic block store volumes to add to all containers. | | | azure-disk-volumes | AzureDiskVolume[] | Azure disk volumes to add. | | | azure-file-volumes | AzureFileVolume[] | Azure file volumes to add. | | @@ -199,6 +201,7 @@ The section below describes all the available subtypes. | pvc-volumes | PersistentVolumeClaimVolume[] | PersistentVolumeClaim volumes to add to all containers. | | | secret-volumes | SecretVolume[] | Secret volumes to add to all containers. | | | config-map-volumes | ConfigMapVolume[] | ConfigMap volumes to add to all containers. | | +| empty-dir-volumes | EmptyDirVolume[] | EmptyDir volumes to add to all containers. | | | aws-elastic-block-store-volumes | AwsElasticBlockStoreVolume[] | Aws elastic block store volumes to add to all containers. | | | azure-disk-volumes | AzureDiskVolume[] | Azure disk volumes to add. | | | azure-file-volumes | AzureFileVolume[] | Azure file volumes to add. | | @@ -230,6 +233,11 @@ The section below describes all the available subtypes. | optional | boolean | Optional | false | | items | Item[] | List of files to be mounted. Optional. | | +#### EmptyDirVolume +| Property | Type | Description | Default Value | +|-----------------|---------|----------------------------------------|---------------| +| volume-name | String | The volumeName name. | | + #### PersistentVolumeClaimVolume | Property | Type | Description | Default Value | |-------------|---------|--------------------------------------------|---------------| @@ -354,6 +362,7 @@ The section below describes all the available subtypes. | dekorate.openshift.pvc-volumes | PersistentVolumeClaimVolume[] | PersistentVolumeClaim volumes to add to all containers. | | | dekorate.openshift.secret-volumes | SecretVolume[] | Secret volumes to add to all containers. | | | dekorate.openshift.config-map-volumes | ConfigMapVolume[] | ConfigMap volumes to add to all containers. | | +| dekorate.openshift.empty-dir-volumes | EmptyDirVolume[] | EmptyDir volumes to add to all containers. | | | dekorate.openshift.git-repo-volumes | GitRepoVolume[] | Git repo volumes to add to all containers. | | | dekorate.openshift.aws-elastic-block-store-volumes | AwsElasticBlockStoreVolume[] | Aws elastic block store volumes to add to all containers | | | dekorate.openshift.azure-disk-volumes | AzureDiskVolume[] | Azure disk volumes to add | | @@ -409,6 +418,7 @@ The section below describes all the available subtypes. | dekorate.knative.pvc-volumes | PersistentVolumeClaimVolume[] | PersistentVolumeClaim volumes to add to all containers. | | | dekorate.knative.secret-volumes | SecretVolume[] | Secret volumes to add to all containers. | | | dekorate.knative.config-map-volumes | ConfigMapVolume[] | ConfigMap volumes to add to all containers. | | +| dekorate.knative.empty-dir-volumes | EmptyDirVolume[] | EmptyDir volumes to add to all containers. | | | dekorate.knative.git-repo-volumes | GitRepoVolume[] | Git repo volumes to add to all containers. | | | dekorate.knative.aws-elastic-block-store-volumes | AwsElasticBlockStoreVolume[] | Aws elastic block store volumes to add to all containers | | | dekorate.knative.azure-disk-volumes | AzureDiskVolume[] | Azure disk volumes to add | | diff --git a/core/src/main/java/io/dekorate/AbstractKubernetesManifestGenerator.java b/core/src/main/java/io/dekorate/AbstractKubernetesManifestGenerator.java index 8ffc73acd..8559cd327 100644 --- a/core/src/main/java/io/dekorate/AbstractKubernetesManifestGenerator.java +++ b/core/src/main/java/io/dekorate/AbstractKubernetesManifestGenerator.java @@ -29,6 +29,7 @@ import io.dekorate.kubernetes.config.ConfigMapVolume; import io.dekorate.kubernetes.config.Container; import io.dekorate.kubernetes.config.CronJob; +import io.dekorate.kubernetes.config.EmptyDirVolume; import io.dekorate.kubernetes.config.Env; import io.dekorate.kubernetes.config.HostAlias; import io.dekorate.kubernetes.config.ImageConfiguration; @@ -44,6 +45,7 @@ import io.dekorate.kubernetes.decorator.AddAzureFileVolumeDecorator; import io.dekorate.kubernetes.decorator.AddConfigMapVolumeDecorator; import io.dekorate.kubernetes.decorator.AddCronJobDecorator; +import io.dekorate.kubernetes.decorator.AddEmptyDirVolumeDecorator; import io.dekorate.kubernetes.decorator.AddEnvVarDecorator; import io.dekorate.kubernetes.decorator.AddHostAliasesDecorator; import io.dekorate.kubernetes.decorator.AddImagePullSecretDecorator; @@ -164,6 +166,10 @@ protected void addDecorators(String group, C config) { resourceRegistry.decorate(group, new AddConfigMapVolumeDecorator(config.getName(), volume)); } + for (EmptyDirVolume volume : config.getEmptyDirVolumes()) { + resourceRegistry.decorate(group, new AddEmptyDirVolumeDecorator(config.getName(), volume)); + } + for (PersistentVolumeClaimVolume volume : config.getPvcVolumes()) { resourceRegistry.decorate(group, new AddPvcVolumeDecorator(config.getName(), volume)); } @@ -247,6 +253,10 @@ protected void addDecorators(String group, C config) { resourceRegistry.decorate(group, new AddConfigMapVolumeDecorator(jobName, volume)); } + for (EmptyDirVolume volume : job.getEmptyDirVolumes()) { + resourceRegistry.decorate(group, new AddEmptyDirVolumeDecorator(jobName, volume)); + } + for (AwsElasticBlockStoreVolume volume : job.getAwsElasticBlockStoreVolumes()) { resourceRegistry.decorate(group, new AddAwsElasticBlockStoreVolumeDecorator(jobName, volume)); } @@ -279,6 +289,10 @@ protected void addDecorators(String group, C config) { resourceRegistry.decorate(group, new AddConfigMapVolumeDecorator(jobName, volume)); } + for (EmptyDirVolume volume : job.getEmptyDirVolumes()) { + resourceRegistry.decorate(group, new AddEmptyDirVolumeDecorator(jobName, volume)); + } + for (AwsElasticBlockStoreVolume volume : job.getAwsElasticBlockStoreVolumes()) { resourceRegistry.decorate(group, new AddAwsElasticBlockStoreVolumeDecorator(jobName, volume)); } diff --git a/core/src/main/java/io/dekorate/kubernetes/annotation/Base.java b/core/src/main/java/io/dekorate/kubernetes/annotation/Base.java index 2b5b45a12..01a1bf4f3 100644 --- a/core/src/main/java/io/dekorate/kubernetes/annotation/Base.java +++ b/core/src/main/java/io/dekorate/kubernetes/annotation/Base.java @@ -140,6 +140,8 @@ ConfigMapVolume[] configMapVolumes() default {}; + EmptyDirVolume[] emptyDirVolumes() default {}; + GitRepoVolume[] gitRepoVolumes() default {}; AwsElasticBlockStoreVolume[] awsElasticBlockStoreVolumes() default {}; diff --git a/core/src/main/java/io/dekorate/kubernetes/annotation/CronJob.java b/core/src/main/java/io/dekorate/kubernetes/annotation/CronJob.java index 87ea1fa43..9e45a41ad 100644 --- a/core/src/main/java/io/dekorate/kubernetes/annotation/CronJob.java +++ b/core/src/main/java/io/dekorate/kubernetes/annotation/CronJob.java @@ -133,6 +133,11 @@ */ ConfigMapVolume[] configMapVolumes() default {}; + /** + * The EmptyDir volumes to add to all containers. + */ + EmptyDirVolume[] emptyDirVolumes() default {}; + /** * Aws elastic block store volumes to add to all containers */ diff --git a/core/src/main/java/io/dekorate/kubernetes/annotation/EmptyDirVolume.java b/core/src/main/java/io/dekorate/kubernetes/annotation/EmptyDirVolume.java new file mode 100644 index 000000000..ffe18ebb9 --- /dev/null +++ b/core/src/main/java/io/dekorate/kubernetes/annotation/EmptyDirVolume.java @@ -0,0 +1,27 @@ +/** + * Copyright 2018 The original authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.dekorate.kubernetes.annotation; + +public @interface EmptyDirVolume { + + /** + * The volumeName name. + * + * @return The volumeName name. + */ + String volumeName(); + +} diff --git a/core/src/main/java/io/dekorate/kubernetes/annotation/Job.java b/core/src/main/java/io/dekorate/kubernetes/annotation/Job.java index bdb2d036f..2dfa1e4c3 100644 --- a/core/src/main/java/io/dekorate/kubernetes/annotation/Job.java +++ b/core/src/main/java/io/dekorate/kubernetes/annotation/Job.java @@ -97,6 +97,11 @@ */ ConfigMapVolume[] configMapVolumes() default {}; + /** + * The EmptyDir volumes to add to all containers. + */ + EmptyDirVolume[] emptyDirVolumes() default {}; + /** * Aws elastic block store volumes to add to all containers */ diff --git a/core/src/main/java/io/dekorate/kubernetes/decorator/AddEmptyDirVolumeDecorator.java b/core/src/main/java/io/dekorate/kubernetes/decorator/AddEmptyDirVolumeDecorator.java new file mode 100644 index 000000000..a1470fecc --- /dev/null +++ b/core/src/main/java/io/dekorate/kubernetes/decorator/AddEmptyDirVolumeDecorator.java @@ -0,0 +1,71 @@ +/** + * Copyright 2018 The original authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.dekorate.kubernetes.decorator; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import io.dekorate.doc.Description; +import io.dekorate.kubernetes.config.EmptyDirVolume; +import io.dekorate.kubernetes.config.Item; +import io.fabric8.kubernetes.api.model.KeyToPath; +import io.fabric8.kubernetes.api.model.KeyToPathBuilder; +import io.fabric8.kubernetes.api.model.ObjectMeta; +import io.fabric8.kubernetes.api.model.PodSpecFluent; + +@Description("Add a emptyDir volume to all pod specs.") +public class AddEmptyDirVolumeDecorator extends NamedResourceDecorator> { + + private final EmptyDirVolume volume; + + public AddEmptyDirVolumeDecorator(EmptyDirVolume volume) { + this(ANY, volume); + } + + public AddEmptyDirVolumeDecorator(String name, EmptyDirVolume volume) { + super(name); + this.volume = volume; + } + + @Override + public void andThenVisit(PodSpecFluent podSpec, ObjectMeta resourceMeta) { + podSpec.addNewVolume() + .withName(volume.getVolumeName()) + .withNewEmptyDir().endEmptyDir() + .endVolume(); + } + + private List toKeyToPathList(Item[] items) { + if (items == null || items.length == 0) { + return Collections.emptyList(); + } + + List keyToPathList = new ArrayList<>(items.length); + for (Item item : items) { + KeyToPathBuilder builder = new KeyToPathBuilder() + .withKey(item.getKey()) + .withPath(item.getPath()); + if (item.getMode() > 0) { + builder.withMode(item.getMode()); + } + + keyToPathList.add(builder.build()); + } + + return keyToPathList; + } +} diff --git a/docs/configuration-guide.md b/docs/configuration-guide.md index af19c8375..f63d5fe03 100644 --- a/docs/configuration-guide.md +++ b/docs/configuration-guide.md @@ -97,10 +97,11 @@ The document is structured as follows. | dekorate.kubernetes.ingress.host | String | The host under which the application is going to be exposed. | | | dekorate.kubernetes.ports | Port[] | The application ports. | | | dekorate.kubernetes.service-type | ServiceType | The type of service that will be generated for the application. | ClusterIP | -| dekorate.kubernetes.pvc-volumes | PersistentVolumeClaimVolume[] | PersistentVolumeClaim volumues to add to all containers. | | -| dekorate.kubernetes.secret-volumes | SecretVolume[] | Secret volumues to add to all containers. | | -| dekorate.kubernetes.config-map-volumes | ConfigMapVolume[] | ConfigMap volumues to add to all containers. | | -| dekorate.kubernetes.git-repo-volumes | GitRepoVolume[] | Git repo volumues to add to all containers. | | +| dekorate.kubernetes.pvc-volumes | PersistentVolumeClaimVolume[] | PersistentVolumeClaim volumes to add to all containers. | | +| dekorate.kubernetes.secret-volumes | SecretVolume[] | Secret volumes to add to all containers. | | +| dekorate.kubernetes.config-map-volumes | ConfigMapVolume[] | ConfigMap volumes to add to all containers. | | +| dekorate.kubernetes.empty-dir-volumes | EmptyDirVolume[] | EmptyDir volumes to add to all containers. | | +| dekorate.kubernetes.git-repo-volumes | GitRepoVolume[] | Git repo volumes to add to all containers. | | | dekorate.kubernetes.aws-elastic-block-store-volumes | AwsElasticBlockStoreVolume[] | Aws elastic block store volumes to add to all containers | | | dekorate.kubernetes.azure-disk-volumes | AzureDiskVolume[] | Azure disk volumes to add | | | dekorate.kubernetes.azure-file-volumes | AzureFileVolume[] | Azure file volumes to add | | @@ -218,6 +219,7 @@ The section below describes all the available subtypes. | pvc-volumes | PersistentVolumeClaimVolume[] | PersistentVolumeClaim volumes to add to all containers. | | | secret-volumes | SecretVolume[] | Secret volumes to add to all containers. | | | config-map-volumes | ConfigMapVolume[] | ConfigMap volumes to add to all containers. | | +| empty-dir-volumes | EmptyDirVolume[] | EmptyDir volumes to add to all containers. | | | aws-elastic-block-store-volumes | AwsElasticBlockStoreVolume[] | Aws elastic block store volumes to add to all containers. | | | azure-disk-volumes | AzureDiskVolume[] | Azure disk volumes to add. | | | azure-file-volumes | AzureFileVolume[] | Azure file volumes to add. | | @@ -244,6 +246,7 @@ The section below describes all the available subtypes. | pvc-volumes | PersistentVolumeClaimVolume[] | PersistentVolumeClaim volumes to add to all containers. | | | secret-volumes | SecretVolume[] | Secret volumes to add to all containers. | | | config-map-volumes | ConfigMapVolume[] | ConfigMap volumes to add to all containers. | | +| empty-dir-volumes | EmptyDirVolume[] | EmptyDir volumes to add to all containers. | | | aws-elastic-block-store-volumes | AwsElasticBlockStoreVolume[] | Aws elastic block store volumes to add to all containers. | | | azure-disk-volumes | AzureDiskVolume[] | Azure disk volumes to add. | | | azure-file-volumes | AzureFileVolume[] | Azure file volumes to add. | | @@ -278,6 +281,12 @@ The section below describes all the available subtypes. | optional | boolean | Optional | false | | items | Item[] | List of files to be mounted. Optional. | | +#### EmptyDirVolume + +| Property | Type | Description | Default Value | +|-----------------|---------|----------------------------------------|---------------| +| volume-name | String | The volumeName name. | | + #### PersistentVolumeClaimVolume | Property | Type | Description | Default Value | @@ -411,6 +420,7 @@ The section below describes all the available subtypes. | dekorate.openshift.pvc-volumes | PersistentVolumeClaimVolume[] | PersistentVolumeClaim volumues to add to all containers. | | | dekorate.openshift.secret-volumes | SecretVolume[] | Secret volumues to add to all containers. | | | dekorate.openshift.config-map-volumes | ConfigMapVolume[] | ConfigMap volumues to add to all containers. | | +| dekorate.openshift.empty-dir-volumes | EmptyDirVolume[] | EmptyDir volumes to add to all containers. | | | dekorate.openshift.git-repo-volumes | GitRepoVolume[] | Git repo volumues to add to all containers. | | | dekorate.openshift.aws-elastic-block-store-volumes | AwsElasticBlockStoreVolume[] | Aws elastic block store volumes to add to all containers | | | dekorate.openshift.azure-disk-volumes | AzureDiskVolume[] | Azure disk volumes to add | | @@ -468,6 +478,7 @@ The section below describes all the available subtypes. | dekorate.knative.pvc-volumes | PersistentVolumeClaimVolume[] | PersistentVolumeClaim volumues to add to all containers. | | | dekorate.knative.secret-volumes | SecretVolume[] | Secret volumues to add to all containers. | | | dekorate.knative.config-map-volumes | ConfigMapVolume[] | ConfigMap volumues to add to all containers. | | +| dekorate.knative.empty-dir-volumes | EmptyDirVolume[] | EmptyDir volumes to add to all containers. | | | dekorate.knative.git-repo-volumes | GitRepoVolume[] | Git repo volumues to add to all containers. | | | dekorate.knative.aws-elastic-block-store-volumes | AwsElasticBlockStoreVolume[] | Aws elastic block store volumes to add to all containers | | | dekorate.knative.azure-disk-volumes | AzureDiskVolume[] | Azure disk volumes to add | | diff --git a/tests/feat-855-kubernetes-cronjobs/src/main/resources/application.properties b/tests/feat-855-kubernetes-cronjobs/src/main/resources/application.properties index 7fba6e7fe..f3e5f5b81 100644 --- a/tests/feat-855-kubernetes-cronjobs/src/main/resources/application.properties +++ b/tests/feat-855-kubernetes-cronjobs/src/main/resources/application.properties @@ -16,3 +16,4 @@ dekorate.kubernetes.cron-jobs[0].azure-disk-volumes[0].disk-URI=diskURI dekorate.kubernetes.cron-jobs[0].azure-file-volumes[0].volume-name=azureFile dekorate.kubernetes.cron-jobs[0].azure-file-volumes[0].share-name=shareName dekorate.kubernetes.cron-jobs[0].azure-file-volumes[0].secret-name=secretName +dekorate.kubernetes.cron-jobs[0].empty-dir-volumes[0].volume-name=myEmptyDir diff --git a/tests/feat-855-kubernetes-cronjobs/src/test/java/io/dekorate/example/Feat855Test.java b/tests/feat-855-kubernetes-cronjobs/src/test/java/io/dekorate/example/Feat855Test.java index a01bf7c25..4d4ab0cbe 100644 --- a/tests/feat-855-kubernetes-cronjobs/src/test/java/io/dekorate/example/Feat855Test.java +++ b/tests/feat-855-kubernetes-cronjobs/src/test/java/io/dekorate/example/Feat855Test.java @@ -65,6 +65,7 @@ public void shouldGenerateCronJobResource() { && v.getAzureDisk().getDiskURI().equals("diskURI")); assertVolume(job, "azureFile", v -> v.getAzureFile().getShareName().equals("shareName") && v.getAzureFile().getSecretName().equals("secretName")); + assertVolume(job, "myEmptyDir", v -> v.getEmptyDir() != null); } private void assertVolume(CronJob job, String name, Predicate assertion) { diff --git a/tests/feat-856-kubernetes-jobs/src/main/resources/application.properties b/tests/feat-856-kubernetes-jobs/src/main/resources/application.properties index 156e5fe16..5e42f5fe6 100644 --- a/tests/feat-856-kubernetes-jobs/src/main/resources/application.properties +++ b/tests/feat-856-kubernetes-jobs/src/main/resources/application.properties @@ -15,3 +15,4 @@ dekorate.kubernetes.jobs[0].azure-disk-volumes[0].disk-URI=diskURI dekorate.kubernetes.jobs[0].azure-file-volumes[0].volume-name=azureFile dekorate.kubernetes.jobs[0].azure-file-volumes[0].share-name=shareName dekorate.kubernetes.jobs[0].azure-file-volumes[0].secret-name=secretName +dekorate.kubernetes.jobs[0].empty-dir-volumes[0].volume-name=myEmptyDir diff --git a/tests/feat-856-kubernetes-jobs/src/test/java/io/dekorate/example/Feat856Test.java b/tests/feat-856-kubernetes-jobs/src/test/java/io/dekorate/example/Feat856Test.java index b6486d4f0..3b381566f 100644 --- a/tests/feat-856-kubernetes-jobs/src/test/java/io/dekorate/example/Feat856Test.java +++ b/tests/feat-856-kubernetes-jobs/src/test/java/io/dekorate/example/Feat856Test.java @@ -61,6 +61,7 @@ public void shouldGenerateJobResource() { && v.getAzureDisk().getDiskURI().equals("diskURI")); assertVolume(job, "azureFile", v -> v.getAzureFile().getShareName().equals("shareName") && v.getAzureFile().getSecretName().equals("secretName")); + assertVolume(job, "myEmptyDir", v -> v.getEmptyDir() != null); } private void assertVolume(Job job, String name, Predicate assertion) { diff --git a/tests/feat-kubernetes-emptydir-volumes/pom.xml b/tests/feat-kubernetes-emptydir-volumes/pom.xml new file mode 100644 index 000000000..df3a24a14 --- /dev/null +++ b/tests/feat-kubernetes-emptydir-volumes/pom.xml @@ -0,0 +1,68 @@ + + + 4.0.0 + + + dekorate-tests + io.dekorate + 2.9-SNAPSHOT + ../ + + + io.dekorate + feat-kubernetes-emptydir-volumes + Dekorate :: Tests :: Annotations :: Kubernetes :: Integration test for emptydir volumes via application.properties + Integration test for emptydir volumes via application properties + + + + io.dekorate + kubernetes-annotations + ${project.version} + + + io.dekorate + dekorate-spring-boot + ${project.version} + + + + org.springframework.boot + spring-boot-starter-web + ${version.spring-boot} + + + + + org.junit.jupiter + junit-jupiter-api + ${version.junit-jupiter} + test + + + org.junit.jupiter + junit-jupiter-engine + ${version.junit-jupiter} + test + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + true + + false + + + + org.springframework.boot + spring-boot-maven-plugin + ${version.spring-boot} + + + + diff --git a/tests/feat-kubernetes-emptydir-volumes/src/main/java/io/dekorate/annotationless/DemoApplication.java b/tests/feat-kubernetes-emptydir-volumes/src/main/java/io/dekorate/annotationless/DemoApplication.java new file mode 100644 index 000000000..8bd220c62 --- /dev/null +++ b/tests/feat-kubernetes-emptydir-volumes/src/main/java/io/dekorate/annotationless/DemoApplication.java @@ -0,0 +1,28 @@ +/** + * Copyright 2018 The original authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.dekorate.annotationless; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class DemoApplication { + + public static void main(String[] args) { + SpringApplication.run(DemoApplication.class, args); + } + +} diff --git a/tests/feat-kubernetes-emptydir-volumes/src/main/resources/application.properties b/tests/feat-kubernetes-emptydir-volumes/src/main/resources/application.properties new file mode 100644 index 000000000..a7633bd76 --- /dev/null +++ b/tests/feat-kubernetes-emptydir-volumes/src/main/resources/application.properties @@ -0,0 +1,4 @@ +dekorate.kubernetes.mounts[0].name=test +dekorate.kubernetes.mounts[0].path=/deployment/github + +dekorate.kubernetes.emptyDirVolumes[0].volume-name=test diff --git a/tests/feat-kubernetes-emptydir-volumes/src/test/java/io/dekorate/annotationless/FeatEmptyDirVolumesTest.java b/tests/feat-kubernetes-emptydir-volumes/src/test/java/io/dekorate/annotationless/FeatEmptyDirVolumesTest.java new file mode 100644 index 000000000..32528b8a9 --- /dev/null +++ b/tests/feat-kubernetes-emptydir-volumes/src/test/java/io/dekorate/annotationless/FeatEmptyDirVolumesTest.java @@ -0,0 +1,51 @@ +/** + * Copyright 2018 The original authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.dekorate.annotationless; + +import static org.junit.jupiter.api.Assertions.*; + +import java.util.Optional; + +import org.junit.jupiter.api.Test; + +import io.dekorate.utils.Serialization; +import io.fabric8.kubernetes.api.model.*; +import io.fabric8.kubernetes.api.model.apps.Deployment; + +public class FeatEmptyDirVolumesTest { + + @Test + public void shouldContainComponent() { + KubernetesList list = Serialization + .unmarshalAsList( + FeatEmptyDirVolumesTest.class.getClassLoader().getResourceAsStream("META-INF/dekorate/kubernetes.yml")); + assertNotNull(list); + Deployment d = findFirst(list, Deployment.class).orElseThrow(() -> new IllegalStateException()); + assertNotNull(d); + PodSpec p = d.getSpec().getTemplate().getSpec(); + assertNotNull(p); + Volume firstVolume = p.getVolumes().get(0); + assertEquals("test", firstVolume.getName()); + assertNotNull(firstVolume.getEmptyDir()); + } + + Optional findFirst(KubernetesList list, Class t) { + return (Optional) list.getItems().stream() + .filter(i -> t.isInstance(i)) + .findFirst(); + } +} diff --git a/tests/pom.xml b/tests/pom.xml index db79ab856..d34212042 100644 --- a/tests/pom.xml +++ b/tests/pom.xml @@ -82,6 +82,7 @@ issue-987-role-binding-name issue-1006-defaults-handling issue-1009-probe-tcp-socket + feat-kubernetes-emptydir-volumes