Skip to content

Commit

Permalink
Support emptydir volumes
Browse files Browse the repository at this point in the history
We support many volume types, but we're missing the emptydir volume. This volume is a request from the user community: quarkusio/quarkus#27222
  • Loading branch information
Sgitario committed Aug 11, 2022
1 parent b3cacfd commit 6e63015
Show file tree
Hide file tree
Showing 20 changed files with 322 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*/
Expand Down
10 changes: 10 additions & 0 deletions assets/config.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@

ConfigMapVolume[] configMapVolumes() default {};

EmptyDirVolume[] emptyDirVolumes() default {};

GitRepoVolume[] gitRepoVolumes() default {};

AwsElasticBlockStoreVolume[] awsElasticBlockStoreVolumes() default {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -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();

}
5 changes: 5 additions & 0 deletions core/src/main/java/io/dekorate/kubernetes/annotation/Job.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -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<PodSpecFluent<?>> {

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<KeyToPath> toKeyToPathList(Item[] items) {
if (items == null || items.length == 0) {
return Collections.emptyList();
}

List<KeyToPath> 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;
}
}
Loading

0 comments on commit 6e63015

Please sign in to comment.