Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenShift: Fix image pull policy property #24068

Merged
merged 1 commit into from
Mar 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.dekorate.kubernetes.decorator.AddEnvVarDecorator;
import io.dekorate.kubernetes.decorator.AddLabelDecorator;
import io.dekorate.kubernetes.decorator.ApplicationContainerDecorator;
import io.dekorate.kubernetes.decorator.ApplyImagePullPolicyDecorator;
import io.dekorate.kubernetes.decorator.RemoveFromSelectorDecorator;
import io.dekorate.kubernetes.decorator.RemoveLabelDecorator;
import io.dekorate.openshift.decorator.ApplyReplicasDecorator;
Expand Down Expand Up @@ -220,6 +221,7 @@ public List<DecoratorBuildItem> createDecorators(ApplicationInfoBuildItem applic
image.ifPresent(i -> {
result.add(new DecoratorBuildItem(OPENSHIFT, new ApplyContainerImageDecorator(name, i.getImage())));
});
result.add(new DecoratorBuildItem(OPENSHIFT, new ApplyImagePullPolicyDecorator(name, config.getImagePullPolicy())));
result.add(new DecoratorBuildItem(OPENSHIFT, new AddLabelDecorator(name, OPENSHIFT_APP_RUNTIME, QUARKUS)));

Stream.concat(config.convertToBuildItems().stream(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,7 @@ public List<DecoratorBuildItem> createDecorators(ApplicationInfoBuildItem applic
result.add(new DecoratorBuildItem(KUBERNETES, new ApplyContainerImageDecorator(name, i.getImage())));
});

result
.add(new DecoratorBuildItem(KUBERNETES, new ApplyImagePullPolicyDecorator(name, config.getImagePullPolicy())));
result.add(new DecoratorBuildItem(KUBERNETES, new ApplyImagePullPolicyDecorator(name, config.getImagePullPolicy())));
result.add(new DecoratorBuildItem(KUBERNETES, new AddSelectorToDeploymentDecorator(name)));

Stream.concat(config.convertToBuildItems().stream(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
import java.util.Map;

import org.assertj.core.api.AbstractObjectAssert;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.fabric8.kubernetes.api.model.HasMetadata;
import io.fabric8.kubernetes.api.model.Service;
import io.fabric8.openshift.api.model.DeploymentConfig;
import io.quarkus.test.ProdBuildResults;
import io.quarkus.test.ProdModeTestResults;
import io.quarkus.test.QuarkusProdModeTest;
Expand Down Expand Up @@ -41,16 +40,21 @@ public void assertGeneratedResources() throws IOException {
.deserializeAsList(kubernetesDir.resolve("openshift.yml"));

assertThat(openshiftList).filteredOn(h -> "DeploymentConfig".equals(h.getKind())).singleElement().satisfies(h -> {
assertThat(h.getMetadata()).satisfies(m -> {
assertThat(m.getName()).isEqualTo("basic-openshift");
assertThat(m.getLabels().get("app.openshift.io/runtime")).isEqualTo("quarkus");
assertThat(m.getNamespace()).isNull();
});
AbstractObjectAssert<?, ?> specAssert = assertThat(h).extracting("spec");
specAssert.extracting("replicas").isEqualTo(1);
specAssert.extracting("selector").isInstanceOfSatisfying(Map.class, selectorsMap -> {
assertThat(selectorsMap).containsOnly(entry("app.kubernetes.io/name", "basic-openshift"),
entry("app.kubernetes.io/version", "0.1-SNAPSHOT"));
DeploymentConfig deployment = (DeploymentConfig) h;

// metadata assertions
assertThat(deployment.getMetadata().getName()).isEqualTo("basic-openshift");
assertThat(deployment.getMetadata().getLabels().get("app.openshift.io/runtime")).isEqualTo("quarkus");
assertThat(deployment.getMetadata().getNamespace()).isNull();

// spec assertions
assertThat(deployment.getSpec().getReplicas()).isEqualTo(1);
assertThat(deployment.getSpec().getSelector()).containsOnly(entry("app.kubernetes.io/name", "basic-openshift"),
entry("app.kubernetes.io/version", "0.1-SNAPSHOT"));

// containers assertions
assertThat(deployment.getSpec().getTemplate().getSpec().getContainers()).satisfiesExactly(container -> {
assertThat(container.getImagePullPolicy()).isEqualTo("Always"); // expect the default value
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public void assertGeneratedResources() throws IOException {
assertThat(podSpec.getContainers()).singleElement().satisfies(container -> {
assertThat(container.getEnv()).extracting("name", "value")
.contains(tuple("MY_ENV_VAR", "SOMEVALUE"));
assertThat(container.getImagePullPolicy()).isEqualTo("IfNotPresent");
});
});
specAssert.extracting("selector").isInstanceOfSatisfying(Map.class, selectorsMap -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ quarkus.openshift.env-vars.my-env-var.value=SOMEVALUE
quarkus.openshift.group=grp
quarkus.openshift.route.expose=true
quarkus.s2i.registry=quay.io
quarkus.openshift.image-pull-policy=IfNotPresent
quarkus.openshift.replicas=3
quarkus.openshift.add-version-to-label-selectors=false