Skip to content

Commit

Permalink
fix (#12121) fix volume,sidecar and hostalias support for knative
Browse files Browse the repository at this point in the history
  • Loading branch information
iocanel committed Dec 17, 2020
1 parent 9cdae32 commit a086f7d
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
<aws-alexa-sdk.version>2.37.1</aws-alexa-sdk.version>
<azure-functions-java-library.version>1.3.0</azure-functions-java-library.version>
<kotlin.version>1.4.20</kotlin.version>
<dekorate.version>0.13.6</dekorate.version>
<dekorate.version>0.14.1</dekorate.version>
<maven-artifact-transfer.version>0.10.0</maven-artifact-transfer.version>
<jline.version>2.14.6</jline.version>
<maven-invoker.version>3.0.1</maven-invoker.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
import java.util.Optional;
import java.util.stream.Stream;

import io.dekorate.knative.decorator.AddAwsElasticBlockStoreVolumeToRevisionDecorator;
import io.dekorate.knative.decorator.AddAzureDiskVolumeToRevisionDecorator;
import io.dekorate.knative.decorator.AddAzureFileVolumeToRevisionDecorator;
import io.dekorate.knative.decorator.AddConfigMapVolumeToRevisionDecorator;
import io.dekorate.knative.decorator.AddHostAliasesToRevisionDecorator;
import io.dekorate.knative.decorator.AddPvcVolumeToRevisionDecorator;
import io.dekorate.knative.decorator.AddSecretVolumeToRevisionDecorator;
import io.dekorate.knative.decorator.AddSidecarToRevisionDecorator;
import io.dekorate.knative.decorator.ApplyGlobalAutoscalingClassDecorator;
import io.dekorate.knative.decorator.ApplyGlobalContainerConcurrencyDecorator;
import io.dekorate.knative.decorator.ApplyGlobalRequestsPerSecondTargetDecorator;
Expand Down Expand Up @@ -211,6 +219,52 @@ public List<DecoratorBuildItem> createDecorators(ApplicationInfoBuildItem applic
result.add(new DecoratorBuildItem(KNATIVE,
new ApplyTrafficDecorator(name, revisionName, latestRevision, percent, tag)));
});

//Add revision decorators
result.addAll(createVolumeDecorators(project, name, config));
config.getHostAliases().entrySet().forEach(e -> {
result.add(new DecoratorBuildItem(KNATIVE,
new AddHostAliasesToRevisionDecorator(name, HostAliasConverter.convert(e))));
});
config.getSidecars().entrySet().forEach(e -> {
result.add(new DecoratorBuildItem(KNATIVE, new AddSidecarToRevisionDecorator(name, ContainerConverter.convert(e))));
});

return result;
}

private static List<DecoratorBuildItem> createVolumeDecorators(Optional<Project> project, String name,
PlatformConfiguration config) {
List<DecoratorBuildItem> result = new ArrayList<>();

config.getSecretVolumes().entrySet().forEach(e -> {
result.add(
new DecoratorBuildItem(KNATIVE, new AddSecretVolumeToRevisionDecorator(SecretVolumeConverter.convert(e))));
});

config.getConfigMapVolumes().entrySet().forEach(e -> {
result.add(new DecoratorBuildItem(KNATIVE,
new AddConfigMapVolumeToRevisionDecorator(ConfigMapVolumeConverter.convert(e))));
});

config.getPvcVolumes().entrySet().forEach(e -> {
result.add(new DecoratorBuildItem(KNATIVE, new AddPvcVolumeToRevisionDecorator(PvcVolumeConverter.convert(e))));
});

config.getAwsElasticBlockStoreVolumes().entrySet().forEach(e -> {
result.add(new DecoratorBuildItem(KNATIVE,
new AddAwsElasticBlockStoreVolumeToRevisionDecorator(AwsElasticBlockStoreVolumeConverter.convert(e))));
});

config.getAzureFileVolumes().entrySet().forEach(e -> {
result.add(new DecoratorBuildItem(KNATIVE,
new AddAzureFileVolumeToRevisionDecorator(AzureFileVolumeConverter.convert(e))));
});

config.getAzureDiskVolumes().entrySet().forEach(e -> {
result.add(new DecoratorBuildItem(KNATIVE,
new AddAzureDiskVolumeToRevisionDecorator(AzureDiskVolumeConverter.convert(e))));
});
return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package io.quarkus.it.kubernetes;

import static org.assertj.core.api.Assertions.assertThat;

import java.io.IOException;
import java.nio.file.Path;
import java.util.List;

import org.assertj.core.api.Condition;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.fabric8.knative.serving.v1.Service;
import io.fabric8.kubernetes.api.model.HasMetadata;
import io.fabric8.kubernetes.api.model.Volume;
import io.fabric8.kubernetes.api.model.VolumeMount;
import io.quarkus.test.ProdBuildResults;
import io.quarkus.test.ProdModeTestResults;
import io.quarkus.test.QuarkusProdModeTest;

public class KnativeWithVolumesTest {

@RegisterExtension
static final QuarkusProdModeTest config = new QuarkusProdModeTest()
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class).addClasses(GreetingResource.class))
.setApplicationName("knative-with-volumes-properties")
.setApplicationVersion("0.1-SNAPSHOT")
.withConfigurationResource("knative-with-volumes.properties");

@ProdBuildResults
private ProdModeTestResults prodModeTestResults;

@Test
public void assertGeneratedResources() throws IOException {
Path kubernetesDir = prodModeTestResults.getBuildDir().resolve("kubernetes");
assertThat(kubernetesDir)
.isDirectoryContaining(p -> p.getFileName().endsWith("knative.json"))
.isDirectoryContaining(p -> p.getFileName().endsWith("knative.yml"))
.satisfies(p -> assertThat(p.toFile().listFiles()).hasSize(2));

List<HasMetadata> kubernetesList = DeserializationUtil
.deserializeAsList(kubernetesDir.resolve("knative.yml"));

assertThat(kubernetesList).filteredOn(i -> "Service".equals(i.getKind())).singleElement().satisfies(i -> {
assertThat(i).isInstanceOfSatisfying(Service.class, s -> {
assertThat(s.getSpec()).satisfies(spec -> {

assertThat(spec.getTemplate()).satisfies(template -> {
assertThat(template.getSpec()).satisfies(revisionSpec -> {
assertThat(revisionSpec.getVolumes()).haveAtLeastOne(new Condition<Volume>(
v -> v.getName().equals("client-crts")
&& v.getSecret().getSecretName().equals("clientcerts"),
"Has secret volume named client-crts referencing secert clientcerts"));
assertThat(revisionSpec.getVolumes()).haveAtLeastOne(new Condition<Volume>(
v -> v.getName().equals("client-cfg") && v.getConfigMap().getName().equals("clientconfig"),
"Has config-map named client-cfg referencing configmap clientconfig"));

assertThat(revisionSpec.getContainers()).hasSize(1).singleElement().satisfies(c -> {

assertThat(c.getVolumeMounts()).haveAtLeastOne(new Condition<VolumeMount>(
m -> m.getName().equals("client-crts"), "Has client-crts mount"));
assertThat(c.getVolumeMounts()).haveAtLeastOne(new Condition<VolumeMount>(
m -> m.getName().equals("client-cfg"), "Has client-cfg mount"));

assertThat(c.getPorts()).hasSize(1).singleElement().satisfies(p -> {
assertThat(p.getName()).isEqualTo("http1");
});
});
});
});
});
});
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Configuration file
quarkus.kubernetes.deployment-target=knative

quarkus.knative.mounts.client-crts.path=/mnt/clientcerts
quarkus.knative.secret-volumes.client-crts.secret-name=clientcerts

quarkus.knative.mounts.client-cfg.path=/mnt/clientconfig
quarkus.knative.config-map-volumes.client-cfg.config-map-name=clientconfig

0 comments on commit a086f7d

Please sign in to comment.