-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
kubernetes/openshift/knative specified container name support;fix#108…
…75 returned;
- Loading branch information
1 parent
e30c14f
commit ad4d825
Showing
13 changed files
with
277 additions
and
10 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
...ployment/src/main/java/io/quarkus/kubernetes/deployment/ChangeContainerNameDecorator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package io.quarkus.kubernetes.deployment; | ||
|
||
import io.dekorate.kubernetes.decorator.AddInitContainerDecorator; | ||
import io.dekorate.kubernetes.decorator.AddSidecarDecorator; | ||
import io.dekorate.kubernetes.decorator.ApplicationContainerDecorator; | ||
import io.dekorate.kubernetes.decorator.ApplyImageDecorator; | ||
import io.dekorate.kubernetes.decorator.Decorator; | ||
import io.dekorate.kubernetes.decorator.ResourceProvidingDecorator; | ||
import io.fabric8.kubernetes.api.model.ContainerFluent; | ||
|
||
public class ChangeContainerNameDecorator extends ApplicationContainerDecorator<ContainerFluent<?>> { | ||
|
||
private final String name; | ||
|
||
public ChangeContainerNameDecorator(String name) { | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public void andThenVisit(ContainerFluent<?> containerFluent) { | ||
containerFluent.withName(name); | ||
} | ||
|
||
@Override | ||
public Class<? extends Decorator>[] after() { | ||
return new Class[] { ResourceProvidingDecorator.class, AddSidecarDecorator.class, AddInitContainerDecorator.class, | ||
ApplyImageDecorator.class }; | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
...ava/io/quarkus/kubernetes/deployment/ChangeContainerNameInDeploymentTriggerDecorator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package io.quarkus.kubernetes.deployment; | ||
|
||
import io.dekorate.kubernetes.decorator.*; | ||
import io.dekorate.kubernetes.decorator.AddSidecarDecorator; | ||
import io.dekorate.openshift.decorator.ApplyDeploymentTriggerDecorator; | ||
import io.fabric8.kubernetes.api.model.ObjectMeta; | ||
import io.fabric8.openshift.api.model.DeploymentConfigSpecFluent; | ||
|
||
public class ChangeContainerNameInDeploymentTriggerDecorator extends NamedResourceDecorator<DeploymentConfigSpecFluent<?>> { | ||
|
||
private final String containerName; | ||
|
||
public ChangeContainerNameInDeploymentTriggerDecorator(String containerName) { | ||
this.containerName = containerName; | ||
} | ||
|
||
@Override | ||
public void andThenVisit(DeploymentConfigSpecFluent<?> deploymentConfigSpecFluent, ObjectMeta objectMeta) { | ||
if (deploymentConfigSpecFluent.hasTriggers()) { | ||
deploymentConfigSpecFluent | ||
.editFirstTrigger() | ||
.editImageChangeParams() | ||
.withContainerNames(containerName) | ||
.endImageChangeParams() | ||
.endTrigger() | ||
.buildTriggers(); | ||
} | ||
} | ||
|
||
@Override | ||
public Class<? extends Decorator>[] after() { | ||
return new Class[] { ApplyDeploymentTriggerDecorator.class, AddEnvVarDecorator.class, AddPortDecorator.class, | ||
AddMountDecorator.class, AddPvcVolumeDecorator.class, AddAwsElasticBlockStoreVolumeDecorator.class, | ||
AddAzureDiskVolumeDecorator.class, AddAwsElasticBlockStoreVolumeDecorator.class, ApplyImageDecorator.class, | ||
ApplyImagePullPolicyDecorator.class, ApplyWorkingDirDecorator.class, ApplyCommandDecorator.class, | ||
ApplyArgsDecorator.class, ApplyServiceAccountNamedDecorator.class, AddReadinessProbeDecorator.class, | ||
AddLivenessProbeDecorator.class, ApplyApplicationContainerDecorator.class, AddSidecarDecorator.class, | ||
AddInitContainerDecorator.class }; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...ard-way/src/test/java/io/quarkus/it/kubernetes/KnativeWithSpecifiedContainerNameTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
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.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.test.ProdBuildResults; | ||
import io.quarkus.test.ProdModeTestResults; | ||
import io.quarkus.test.QuarkusProdModeTest; | ||
|
||
public class KnativeWithSpecifiedContainerNameTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusProdModeTest config = new QuarkusProdModeTest() | ||
.withApplicationRoot((jar) -> jar.addClasses(GreetingResource.class)) | ||
.setApplicationName("knative-with-specified-container-name") | ||
.setApplicationVersion("0.1-SNAPSHOT") | ||
.withConfigurationResource("knative-with-specified-container-name.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(s.getMetadata()).satisfies(m -> { | ||
assertThat(m.getName()).isEqualTo("kfoo"); | ||
}); | ||
|
||
assertThat(spec.getTemplate().getSpec().getContainers()).singleElement().satisfies(container -> { | ||
assertThat(container.getName()).isEqualTo("kbar"); | ||
}); | ||
}); | ||
}); | ||
}); | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
...-way/src/test/java/io/quarkus/it/kubernetes/KubernetesWithSpecifiedContainerNameTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
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.Arrays; | ||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
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.*; | ||
import io.fabric8.kubernetes.api.model.apps.Deployment; | ||
import io.fabric8.openshift.api.model.DeploymentTriggerPolicy; | ||
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 KubernetesWithSpecifiedContainerNameTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusProdModeTest config = new QuarkusProdModeTest() | ||
.withApplicationRoot((jar) -> jar.addClasses(GreetingResource.class)) | ||
.setApplicationName("kubernetes-with-specified-container-name") | ||
.setApplicationVersion("0.1-SNAPSHOT") | ||
.withConfigurationResource("kubernetes-with-specified-container-name.properties") | ||
.setForcedDependencies( | ||
Arrays.asList( | ||
new AppArtifact("io.quarkus", "quarkus-kubernetes", Version.getVersion()), | ||
new AppArtifact("io.quarkus", "quarkus-container-image-s2i", Version.getVersion()))); | ||
|
||
@ProdBuildResults | ||
private ProdModeTestResults prodModeTestResults; | ||
|
||
@Test | ||
public void assertGeneratedResources() throws IOException { | ||
Path kubernetesDir = prodModeTestResults.getBuildDir().resolve("kubernetes"); | ||
assertThat(kubernetesDir) | ||
.isDirectoryContaining(p -> p.getFileName().endsWith("kubernetes.json")) | ||
.isDirectoryContaining(p -> p.getFileName().endsWith("kubernetes.yml")); | ||
|
||
List<HasMetadata> kubernetesList = DeserializationUtil | ||
.deserializeAsList(kubernetesDir.resolve("kubernetes.yml")); | ||
assertThat(kubernetesList.get(0)).isInstanceOfSatisfying(Deployment.class, d -> { | ||
assertThat(d.getMetadata()).satisfies(m -> { | ||
assertThat(m.getName()).isEqualTo("foo"); | ||
assertThat(m.getLabels()).contains(entry("app.kubernetes.io/name", "foo")); | ||
}); | ||
|
||
assertThat(d.getSpec().getTemplate().getSpec().getContainers().get(0)) | ||
.satisfies(c -> assertThat(c.getName()).isEqualTo("bar")); | ||
}); | ||
|
||
List<HasMetadata> openshiftList = DeserializationUtil | ||
.deserializeAsList(kubernetesDir.resolve("openshift.yml")); | ||
assertThat(openshiftList).filteredOn(h -> "DeploymentConfig".equals(h.getKind())).singleElement().satisfies(h -> { | ||
AbstractObjectAssert<?, ?> specAssert = assertThat(h).extracting("spec"); | ||
specAssert.extracting("template").extracting("spec").isInstanceOfSatisfying(PodSpec.class, | ||
podSpec -> { | ||
assertThat(podSpec.getContainers()).singleElement().satisfies(container -> { | ||
assertThat(container) | ||
.satisfies(c -> assertThat(c.getName()).isEqualTo("obar")); | ||
}); | ||
}); | ||
|
||
specAssert.extracting("triggers").isInstanceOfSatisfying(Collection.class, c -> { | ||
assertThat(c).singleElement().satisfies(trigger -> { | ||
assertThat(((DeploymentTriggerPolicy) trigger).getImageChangeParams().getContainerNames()) | ||
.contains("obar"); | ||
}); | ||
}); | ||
|
||
assertThat(h.getMetadata().getName()).isIn("ofoo", "foo", "openjdk-11"); | ||
assertThat(h.getMetadata().getLabels()).contains(entry("app.kubernetes.io/name", "ofoo")); | ||
}); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
.../quarkus-standard-way/src/test/resources/knative-with-specified-container-name.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Configuration file | ||
quarkus.kubernetes.deployment-target=knative | ||
quarkus.knative.name=kfoo | ||
quarkus.knative.container-name=kbar |
10 changes: 10 additions & 0 deletions
10
...arkus-standard-way/src/test/resources/kubernetes-with-specified-container-name.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
quarkus.kubernetes.deployment-target=kubernetes,openshift | ||
|
||
quarkus.application.name=test | ||
quarkus.kubernetes.name=foo | ||
quarkus.kubernetes.container-name=bar | ||
|
||
quarkus.openshift.name=ofoo | ||
quarkus.openshift.container-name=obar | ||
|
||
quarkus.s2i.name=s2ifoo |