Skip to content

Commit

Permalink
Fix quarkus.knative.image-pull-policy property
Browse files Browse the repository at this point in the history
Plus, this pull request also verifies that #23832 is fixed.
Fix #23832
  • Loading branch information
Sgitario committed Dec 12, 2022
1 parent 6ab313d commit 3b8f8c9
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import io.dekorate.kubernetes.decorator.AddLabelDecorator;
import io.dekorate.kubernetes.decorator.AddServiceAccountResourceDecorator;
import io.dekorate.kubernetes.decorator.ApplicationContainerDecorator;
import io.dekorate.kubernetes.decorator.ApplyImagePullPolicyDecorator;
import io.dekorate.project.Project;
import io.quarkus.container.spi.BaseImageInfoBuildItem;
import io.quarkus.container.spi.ContainerImageInfoBuildItem;
Expand Down Expand Up @@ -156,6 +157,7 @@ public List<DecoratorBuildItem> createDecorators(ApplicationInfoBuildItem applic
image.ifPresent(i -> {
result.add(new DecoratorBuildItem(KNATIVE, new ApplyContainerImageDecorator(name, i.getImage())));
});
result.add(new DecoratorBuildItem(KNATIVE, new ApplyImagePullPolicyDecorator(name, config.getImagePullPolicy())));

config.getContainerName().ifPresent(containerName -> result
.add(new DecoratorBuildItem(KNATIVE, new ChangeContainerNameDecorator(containerName))));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package io.quarkus.it.kubernetes;

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

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

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.quarkus.bootstrap.model.AppArtifact;
import io.quarkus.builder.Version;
import io.quarkus.test.ProdBuildResults;
import io.quarkus.test.ProdModeTestResults;
import io.quarkus.test.QuarkusProdModeTest;

public class KnativeWithExtendedPropertiesTest {

private static final String APP_NAME = "knative-with-extended-properties";

@RegisterExtension
static final QuarkusProdModeTest config = new QuarkusProdModeTest()
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class).addClasses(GreetingResource.class))
.setApplicationName(APP_NAME)
.setApplicationVersion("0.1-SNAPSHOT")
.overrideConfigKey("quarkus.kubernetes.deployment-target", "knative")
.overrideConfigKey("quarkus.knative.revision-auto-scaling.container-concurrency", "5")
.overrideConfigKey("quarkus.knative.min-scale", "5")
.overrideConfigKey("quarkus.knative.max-scale", "10")
.overrideConfigKey("quarkus.knative.image-pull-policy", "Never")
.setLogFileName("k8s.log")
.setForcedDependencies(
Collections.singletonList(new AppArtifact("io.quarkus", "quarkus-kubernetes", Version.getVersion())));

@ProdBuildResults
private ProdModeTestResults prodModeTestResults;

@Test
public void assertGeneratedResources() throws IOException {
final Path kubernetesDir = prodModeTestResults.getBuildDir().resolve("kubernetes");
assertThat(kubernetesDir)
.isDirectoryContaining(p -> p.getFileName().endsWith("knative.json"))
.isDirectoryContaining(p -> p.getFileName().endsWith("knative.yml"));
List<HasMetadata> kubernetesList = DeserializationUtil
.deserializeAsList(kubernetesDir.resolve("knative.yml"));
assertThat(kubernetesList.get(0)).isInstanceOfSatisfying(Service.class, s -> {
assertThat(s.getMetadata()).satisfies(m -> {
assertThat(m.getName()).isEqualTo(APP_NAME);
});

assertThat(s.getSpec()).satisfies(serviceSpec -> {
assertThat(serviceSpec.getTemplate()).satisfies(template -> {
assertThat(template.getMetadata()).satisfies(m -> {
assertThat(m.getAnnotations()).contains(entry("autoscaling.knative.dev/minScale", "5"));
assertThat(m.getAnnotations()).contains(entry("autoscaling.knative.dev/maxScale", "10"));
});
assertThat(template.getSpec()).satisfies(revisionSpec -> {
assertThat(revisionSpec.getContainerConcurrency()).isEqualTo(5);

assertThat(revisionSpec.getContainers().get(0)).satisfies(c -> {
assertThat(c.getImagePullPolicy()).isEqualTo("Never");
});
});
});
});
});
}
}

0 comments on commit 3b8f8c9

Please sign in to comment.