Skip to content

Commit

Permalink
Merge pull request quarkusio#43862 from radcortez/fix-35874
Browse files Browse the repository at this point in the history
Move Kubernetes to @ConfigMapping
  • Loading branch information
iocanel authored Oct 24, 2024
2 parents c825cfb + a9f2355 commit 8f7119e
Show file tree
Hide file tree
Showing 92 changed files with 2,378 additions and 3,410 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void checkKind(ApplicationInfoBuildItem applicationInfo, KubernetesConfig
BuildProducer<KubernetesResourceMetadataBuildItem> resourceMeta) {
deploymentTargets.produce(
new KubernetesDeploymentTargetBuildItem(KIND, DEPLOYMENT, DEPLOYMENT_GROUP, DEPLOYMENT_VERSION,
KIND_PRIORITY, true, config.getDeployStrategy()));
KIND_PRIORITY, true, config.deployStrategy()));

String name = ResourceNameUtil.getResourceName(config, applicationInfo);
resourceMeta.produce(
Expand All @@ -75,13 +75,13 @@ public void checkKind(ApplicationInfoBuildItem applicationInfo, KubernetesConfig

@BuildStep
public void createAnnotations(KubernetesConfig config, BuildProducer<KubernetesAnnotationBuildItem> annotations) {
config.getAnnotations().forEach((k, v) -> annotations.produce(new KubernetesAnnotationBuildItem(k, v, KIND)));
config.annotations().forEach((k, v) -> annotations.produce(new KubernetesAnnotationBuildItem(k, v, KIND)));
}

@BuildStep
public void createLabels(KubernetesConfig config, BuildProducer<KubernetesLabelBuildItem> labels,
BuildProducer<ContainerImageLabelBuildItem> imageLabels) {
config.getLabels().forEach((k, v) -> {
config.labels().forEach((k, v) -> {
labels.produce(new KubernetesLabelBuildItem(k, v, KIND));
imageLabels.produce(new ContainerImageLabelBuildItem(k, v));
});
Expand Down Expand Up @@ -169,8 +169,8 @@ void externalizeInitTasks(

BuildProducer<DecoratorBuildItem> decorators) {
final String name = ResourceNameUtil.getResourceName(config, applicationInfo);
if (config.isExternalizeInit()) {
InitTaskProcessor.process(KIND, name, image, initTasks, config.getInitTaskDefaults(), config.getInitTasks(),
if (config.externalizeInit()) {
InitTaskProcessor.process(KIND, name, image, initTasks, config.initTaskDefaults(), config.initTasks(),
jobs, initContainers, env, roles, roleBindings, serviceAccount, decorators);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void checkMinikube(ApplicationInfoBuildItem applicationInfo, KubernetesCo
BuildProducer<KubernetesResourceMetadataBuildItem> resourceMeta) {
deploymentTargets.produce(
new KubernetesDeploymentTargetBuildItem(MINIKUBE, DEPLOYMENT, DEPLOYMENT_GROUP, DEPLOYMENT_VERSION,
MINIKUBE_PRIORITY, true, config.getDeployStrategy()));
MINIKUBE_PRIORITY, true, config.deployStrategy()));

String name = ResourceNameUtil.getResourceName(config, applicationInfo);
resourceMeta.produce(
Expand All @@ -71,13 +71,13 @@ public void checkMinikube(ApplicationInfoBuildItem applicationInfo, KubernetesCo

@BuildStep
public void createAnnotations(KubernetesConfig config, BuildProducer<KubernetesAnnotationBuildItem> annotations) {
config.getAnnotations().forEach((k, v) -> annotations.produce(new KubernetesAnnotationBuildItem(k, v, MINIKUBE)));
config.annotations().forEach((k, v) -> annotations.produce(new KubernetesAnnotationBuildItem(k, v, MINIKUBE)));
}

@BuildStep
public void createLabels(KubernetesConfig config, BuildProducer<KubernetesLabelBuildItem> labels,
BuildProducer<ContainerImageLabelBuildItem> imageLabels) {
config.getLabels().forEach((k, v) -> {
config.labels().forEach((k, v) -> {
labels.produce(new KubernetesLabelBuildItem(k, v, MINIKUBE));
imageLabels.produce(new ContainerImageLabelBuildItem(k, v));
});
Expand Down Expand Up @@ -154,8 +154,8 @@ void externalizeInitTasks(

BuildProducer<DecoratorBuildItem> decorators) {
final String name = ResourceNameUtil.getResourceName(config, applicationInfo);
if (config.isExternalizeInit()) {
InitTaskProcessor.process(MINIKUBE, name, image, initTasks, config.getInitTaskDefaults(), config.getInitTasks(),
if (config.externalizeInit()) {
InitTaskProcessor.process(MINIKUBE, name, image, initTasks, config.initTaskDefaults(), config.initTasks(),
jobs, initContainers, env, roles, roleBindings, serviceAccount, decorators);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.ApplicationInfoBuildItem;
import io.quarkus.kubernetes.deployment.DeploymentResourceKind;
import io.quarkus.kubernetes.deployment.OpenshiftConfig;
import io.quarkus.kubernetes.deployment.OpenShiftConfig;
import io.quarkus.kubernetes.deployment.ResourceNameUtil;
import io.quarkus.kubernetes.spi.KubernetesDeploymentTargetBuildItem;
import io.quarkus.kubernetes.spi.KubernetesResourceMetadataBuildItem;

public class OpenshiftProcessor {

@BuildStep
public void checkOpenshift(ApplicationInfoBuildItem applicationInfo, Capabilities capabilities, OpenshiftConfig config,
public void checkOpenshift(ApplicationInfoBuildItem applicationInfo, Capabilities capabilities, OpenShiftConfig config,
BuildProducer<KubernetesDeploymentTargetBuildItem> deploymentTargets,
BuildProducer<KubernetesResourceMetadataBuildItem> resourceMeta) {

Expand All @@ -25,7 +25,7 @@ public void checkOpenshift(ApplicationInfoBuildItem applicationInfo, Capabilitie
new KubernetesDeploymentTargetBuildItem(OPENSHIFT, deploymentResourceKind.getKind(),
deploymentResourceKind.getGroup(),
deploymentResourceKind.getVersion(), true,
config.getDeployStrategy()));
config.deployStrategy()));

String name = ResourceNameUtil.getResourceName(config, applicationInfo);
resourceMeta.produce(new KubernetesResourceMetadataBuildItem(OPENSHIFT, deploymentResourceKind.getGroup(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import io.quarkus.test.QuarkusProdModeTest;
import io.smallrye.config.source.yaml.YamlConfigSource;

public class OpenshiftConfigFallbackTest {
public class OpenShiftConfigFallbackTest {
@RegisterExtension
static final QuarkusProdModeTest TEST = new QuarkusProdModeTest()
.setApplicationName("config")
Expand Down Expand Up @@ -51,9 +51,9 @@ void configFallback() throws Exception {
YamlConfigSource kubernetes = new YamlConfigSource(kubernetesDir.resolve("kubernetes.yml").toUri().toURL());
YamlConfigSource openshift = new YamlConfigSource(kubernetesDir.resolve("openshift.yml").toUri().toURL());

// Only in Kubernetes, must fallback to Openshift
// spec.replicas is only for Kubernetes and Openshift, no fallback
assertEquals("10", kubernetes.getValue("spec.replicas"));
assertEquals("10", openshift.getValue("spec.replicas"));
assertEquals("1", openshift.getValue("spec.replicas"));

// In both, each should retain the value
assertEquals("0.1-SNAPSHOT", kubernetes.getValue("spec.template.metadata.labels.\"app.kubernetes.io/version\""));
Expand Down
3 changes: 0 additions & 3 deletions extensions/kubernetes/vanilla/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,6 @@
<version>${project.version}</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<arg>-AlegacyConfigRoot=true</arg>
</compilerArgs>
</configuration>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,20 @@ private void initCronJobResourceWithDefaults(CronJobBuilder builder) {
jobTemplateSpec.editTemplate().editSpec().addNewContainer().withName(name).endContainer().endSpec().endTemplate();
}

spec.withSuspend(config.suspend);
spec.withConcurrencyPolicy(config.concurrencyPolicy.name());
config.schedule.ifPresent(spec::withSchedule);
config.successfulJobsHistoryLimit.ifPresent(spec::withSuccessfulJobsHistoryLimit);
config.failedJobsHistoryLimit.ifPresent(spec::withFailedJobsHistoryLimit);
config.startingDeadlineSeconds.ifPresent(spec::withStartingDeadlineSeconds);

jobTemplateSpec.withCompletionMode(config.completionMode.name());
jobTemplateSpec.editTemplate().editSpec().withRestartPolicy(config.restartPolicy.name()).endSpec().endTemplate();
config.parallelism.ifPresent(jobTemplateSpec::withParallelism);
config.completions.ifPresent(jobTemplateSpec::withCompletions);
config.backoffLimit.ifPresent(jobTemplateSpec::withBackoffLimit);
config.activeDeadlineSeconds.ifPresent(jobTemplateSpec::withActiveDeadlineSeconds);
config.ttlSecondsAfterFinished.ifPresent(jobTemplateSpec::withTtlSecondsAfterFinished);
spec.withSuspend(config.suspend());
spec.withConcurrencyPolicy(config.concurrencyPolicy().name());
config.schedule().ifPresent(spec::withSchedule);
config.successfulJobsHistoryLimit().ifPresent(spec::withSuccessfulJobsHistoryLimit);
config.failedJobsHistoryLimit().ifPresent(spec::withFailedJobsHistoryLimit);
config.startingDeadlineSeconds().ifPresent(spec::withStartingDeadlineSeconds);

jobTemplateSpec.withCompletionMode(config.completionMode().name());
jobTemplateSpec.editTemplate().editSpec().withRestartPolicy(config.restartPolicy().name()).endSpec().endTemplate();
config.parallelism().ifPresent(jobTemplateSpec::withParallelism);
config.completions().ifPresent(jobTemplateSpec::withCompletions);
config.backoffLimit().ifPresent(jobTemplateSpec::withBackoffLimit);
config.activeDeadlineSeconds().ifPresent(jobTemplateSpec::withActiveDeadlineSeconds);
config.ttlSecondsAfterFinished().ifPresent(jobTemplateSpec::withTtlSecondsAfterFinished);

jobTemplateSpec.endSpec().endJobTemplate();
spec.endSpec();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

package io.quarkus.kubernetes.deployment;

import static io.quarkus.kubernetes.deployment.Constants.JOB;
Expand Down Expand Up @@ -65,14 +64,14 @@ private void initJobResourceWithDefaults(JobBuilder builder) {
spec.editTemplate().editSpec().addNewContainer().withName(name).endContainer().endSpec().endTemplate();
}

spec.withSuspend(config.suspend);
spec.withCompletionMode(config.completionMode.name());
spec.editTemplate().editSpec().withRestartPolicy(config.restartPolicy.name()).endSpec().endTemplate();
config.parallelism.ifPresent(spec::withParallelism);
config.completions.ifPresent(spec::withCompletions);
config.backoffLimit.ifPresent(spec::withBackoffLimit);
config.activeDeadlineSeconds.ifPresent(spec::withActiveDeadlineSeconds);
config.ttlSecondsAfterFinished.ifPresent(spec::withTtlSecondsAfterFinished);
spec.withSuspend(config.suspend());
spec.withCompletionMode(config.completionMode().name());
spec.editTemplate().editSpec().withRestartPolicy(config.restartPolicy().name()).endSpec().endTemplate();
config.parallelism().ifPresent(spec::withParallelism);
config.completions().ifPresent(spec::withCompletions);
config.backoffLimit().ifPresent(spec::withBackoffLimit);
config.activeDeadlineSeconds().ifPresent(spec::withActiveDeadlineSeconds);
config.ttlSecondsAfterFinished().ifPresent(spec::withTtlSecondsAfterFinished);

spec.endSpec();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void visit(OpenshiftConfigFluent<?> config) {
}

/**
* Check if the {@link OpenshiftConfig} already has port.
* Check if the {@link OpenShiftConfig} already has port.
*
* @param config The port.
* @return True if port with same container port exists.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ public ApplyKubernetesIngressConfigurator(IngressConfig ingressConfig) {

@Override
public void visit(KubernetesConfigFluent config) {
if (ingressConfig.expose) {
if (ingressConfig.expose()) {
KubernetesConfigFluent.IngressNested ingressConfigBuilder = config.withNewIngress();
ingressConfigBuilder.withExpose(true);
ingressConfig.host.ifPresent(ingressConfigBuilder::withHost);
ingressConfigBuilder.withTargetPort(ingressConfig.targetPort);
ingressConfig.ingressClassName.ifPresent(ingressConfigBuilder::withIngressClassName);
ingressConfig.host().ifPresent(ingressConfigBuilder::withHost);
ingressConfigBuilder.withTargetPort(ingressConfig.targetPort());
ingressConfig.ingressClassName().ifPresent(ingressConfigBuilder::withIngressClassName);

ingressConfigBuilder.endIngress();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ public void visit(OpenshiftConfigFluent config) {
// The route needs to be configured wether it's exposed or not.
// This is needed to support user provided routes.
var routeBuilder = config.editOrNewRoute();
routeBuilder.withExpose(routeConfig.expose);
if (routeConfig.host.isPresent()) {
routeBuilder.withHost(routeConfig.host.get());
routeBuilder.withExpose(routeConfig.expose());
if (routeConfig.host().isPresent()) {
routeBuilder.withHost(routeConfig.host().get());
}

routeBuilder.withTargetPort(routeConfig.targetPort);
if (routeConfig.tls != null) {
routeBuilder.withTargetPort(routeConfig.targetPort());
if (routeConfig.tls() != null) {
TLSConfig tls = new TLSConfig();
routeConfig.tls.caCertificate.ifPresent(tls::setCaCertificate);
routeConfig.tls.certificate.ifPresent(tls::setCertificate);
routeConfig.tls.destinationCACertificate.ifPresent(tls::setDestinationCACertificate);
routeConfig.tls.key.ifPresent(tls::setKey);
routeConfig.tls.termination.ifPresent(tls::setTermination);
routeConfig.tls.insecureEdgeTerminationPolicy.ifPresent(tls::setInsecureEdgeTerminationPolicy);
routeConfig.tls().caCertificate().ifPresent(tls::setCaCertificate);
routeConfig.tls().certificate().ifPresent(tls::setCertificate);
routeConfig.tls().destinationCACertificate().ifPresent(tls::setDestinationCACertificate);
routeConfig.tls().key().ifPresent(tls::setKey);
routeConfig.tls().termination().ifPresent(tls::setTermination);
routeConfig.tls().insecureEdgeTerminationPolicy().ifPresent(tls::setInsecureEdgeTerminationPolicy);
routeBuilder.withTls(tls);
}
routeBuilder.endRoute();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ public ApplySecuritySettingsDecorator(String resourceName, SecurityContextConfig
public void andThenVisit(PodSpecFluent podSpec, ObjectMeta resourceMeta) {
PodSecurityContextBuilder securityContextBuilder = new PodSecurityContextBuilder();

securityContext.runAsUser.ifPresent(securityContextBuilder::withRunAsUser);
securityContext.runAsGroup.ifPresent(securityContextBuilder::withRunAsGroup);
securityContext.runAsNonRoot.ifPresent(securityContextBuilder::withRunAsNonRoot);
securityContext.supplementalGroups.ifPresent(securityContextBuilder::addAllToSupplementalGroups);
securityContext.fsGroup.ifPresent(securityContextBuilder::withFsGroup);
securityContext.sysctls.ifPresent(map -> map.entrySet().stream()
securityContext.runAsUser().ifPresent(securityContextBuilder::withRunAsUser);
securityContext.runAsGroup().ifPresent(securityContextBuilder::withRunAsGroup);
securityContext.runAsNonRoot().ifPresent(securityContextBuilder::withRunAsNonRoot);
securityContext.supplementalGroups().ifPresent(securityContextBuilder::addAllToSupplementalGroups);
securityContext.fsGroup().ifPresent(securityContextBuilder::withFsGroup);
securityContext.sysctls().entrySet().stream()
.map(entry -> new SysctlBuilder().withName(entry.getKey()).withValue(entry.getValue()).build())
.forEach(securityContextBuilder::addToSysctls));
securityContext.fsGroupChangePolicy.map(e -> e.name()).ifPresent(securityContextBuilder::withFsGroupChangePolicy);
.forEach(securityContextBuilder::addToSysctls);
securityContext.fsGroupChangePolicy().map(e -> e.name()).ifPresent(securityContextBuilder::withFsGroupChangePolicy);
buildSeLinuxOptions().ifPresent(securityContextBuilder::withSeLinuxOptions);
buildWindowsOptions().ifPresent(securityContextBuilder::withWindowsOptions);

Expand All @@ -49,12 +49,12 @@ public Class<? extends Decorator>[] after() {

private Optional<WindowsSecurityContextOptions> buildWindowsOptions() {
WindowsSecurityContextOptions item = null;
if (securityContext.windowsOptions.isAnyPropertySet()) {
if (securityContext.windowsOptions().isAnyPropertySet()) {
WindowsSecurityContextOptionsBuilder builder = new WindowsSecurityContextOptionsBuilder();
securityContext.windowsOptions.gmsaCredentialSpec.ifPresent(builder::withGmsaCredentialSpec);
securityContext.windowsOptions.gmsaCredentialSpecName.ifPresent(builder::withGmsaCredentialSpecName);
securityContext.windowsOptions.hostProcess.ifPresent(builder::withHostProcess);
securityContext.windowsOptions.runAsUserName.ifPresent(builder::withRunAsUserName);
securityContext.windowsOptions().gmsaCredentialSpec().ifPresent(builder::withGmsaCredentialSpec);
securityContext.windowsOptions().gmsaCredentialSpecName().ifPresent(builder::withGmsaCredentialSpecName);
securityContext.windowsOptions().hostProcess().ifPresent(builder::withHostProcess);
securityContext.windowsOptions().runAsUserName().ifPresent(builder::withRunAsUserName);
item = builder.build();
}

Expand All @@ -63,12 +63,12 @@ private Optional<WindowsSecurityContextOptions> buildWindowsOptions() {

private Optional<SELinuxOptions> buildSeLinuxOptions() {
SELinuxOptions item = null;
if (securityContext.seLinuxOptions.isAnyPropertySet()) {
if (securityContext.seLinuxOptions().isAnyPropertySet()) {
SELinuxOptionsBuilder builder = new SELinuxOptionsBuilder();
securityContext.seLinuxOptions.user.ifPresent(builder::withUser);
securityContext.seLinuxOptions.role.ifPresent(builder::withRole);
securityContext.seLinuxOptions.level.ifPresent(builder::withLevel);
securityContext.seLinuxOptions.type.ifPresent(builder::withType);
securityContext.seLinuxOptions().user().ifPresent(builder::withUser);
securityContext.seLinuxOptions().role().ifPresent(builder::withRole);
securityContext.seLinuxOptions().level().ifPresent(builder::withLevel);
securityContext.seLinuxOptions().type().ifPresent(builder::withType);
item = builder.build();
}

Expand Down
Loading

0 comments on commit 8f7119e

Please sign in to comment.