diff --git a/operator/src/main/java/com/github/streamshub/console/api/v1alpha1/spec/containers/ContainerTemplate.java b/operator/src/main/java/com/github/streamshub/console/api/v1alpha1/spec/containers/ContainerSpec.java similarity index 97% rename from operator/src/main/java/com/github/streamshub/console/api/v1alpha1/spec/containers/ContainerTemplate.java rename to operator/src/main/java/com/github/streamshub/console/api/v1alpha1/spec/containers/ContainerSpec.java index 7a710109f..0797e2693 100644 --- a/operator/src/main/java/com/github/streamshub/console/api/v1alpha1/spec/containers/ContainerTemplate.java +++ b/operator/src/main/java/com/github/streamshub/console/api/v1alpha1/spec/containers/ContainerSpec.java @@ -11,7 +11,7 @@ @Buildable @JsonInclude(JsonInclude.Include.NON_NULL) -public class ContainerTemplate { +public class ContainerSpec { @JsonPropertyDescription("Container image to be used for the container") private String image; diff --git a/operator/src/main/java/com/github/streamshub/console/api/v1alpha1/spec/containers/ContainerTemplateSpec.java b/operator/src/main/java/com/github/streamshub/console/api/v1alpha1/spec/containers/ContainerTemplateSpec.java new file mode 100644 index 000000000..ccd7e4e4b --- /dev/null +++ b/operator/src/main/java/com/github/streamshub/console/api/v1alpha1/spec/containers/ContainerTemplateSpec.java @@ -0,0 +1,22 @@ +package com.github.streamshub.console.api.v1alpha1.spec.containers; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonPropertyDescription; + +import io.sundr.builder.annotations.Buildable; + +@Buildable +@JsonInclude(JsonInclude.Include.NON_NULL) +public class ContainerTemplateSpec { + + @JsonPropertyDescription("Specification to be applied to the resulting container.") + ContainerSpec spec; + + public ContainerSpec getSpec() { + return spec; + } + + public void setSpec(ContainerSpec spec) { + this.spec = spec; + } +} diff --git a/operator/src/main/java/com/github/streamshub/console/api/v1alpha1/spec/containers/Containers.java b/operator/src/main/java/com/github/streamshub/console/api/v1alpha1/spec/containers/Containers.java index c619e9b11..584c9bdfd 100644 --- a/operator/src/main/java/com/github/streamshub/console/api/v1alpha1/spec/containers/Containers.java +++ b/operator/src/main/java/com/github/streamshub/console/api/v1alpha1/spec/containers/Containers.java @@ -11,25 +11,25 @@ public class Containers { @JsonPropertyDescription("Template for the Console API server container. " + "The template allows users to specify how the Kubernetes resources are generated.") - ContainerTemplate api; + ContainerTemplateSpec api; @JsonPropertyDescription("Template for the Console UI server container. " + "The template allows users to specify how the Kubernetes resources are generated.") - ContainerTemplate ui; + ContainerTemplateSpec ui; - public ContainerTemplate getApi() { + public ContainerTemplateSpec getApi() { return api; } - public void setApi(ContainerTemplate api) { + public void setApi(ContainerTemplateSpec api) { this.api = api; } - public ContainerTemplate getUi() { + public ContainerTemplateSpec getUi() { return ui; } - public void setUi(ContainerTemplate ui) { + public void setUi(ContainerTemplateSpec ui) { this.ui = ui; } } diff --git a/operator/src/main/java/com/github/streamshub/console/dependents/ConsoleDeployment.java b/operator/src/main/java/com/github/streamshub/console/dependents/ConsoleDeployment.java index e45281650..8b332cdf3 100644 --- a/operator/src/main/java/com/github/streamshub/console/dependents/ConsoleDeployment.java +++ b/operator/src/main/java/com/github/streamshub/console/dependents/ConsoleDeployment.java @@ -1,7 +1,7 @@ package com.github.streamshub.console.dependents; -import java.util.Collections; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Optional; @@ -13,7 +13,8 @@ import com.github.streamshub.console.api.v1alpha1.Console; import com.github.streamshub.console.api.v1alpha1.spec.Images; -import com.github.streamshub.console.api.v1alpha1.spec.containers.ContainerTemplate; +import com.github.streamshub.console.api.v1alpha1.spec.containers.ContainerSpec; +import com.github.streamshub.console.api.v1alpha1.spec.containers.ContainerTemplateSpec; import com.github.streamshub.console.api.v1alpha1.spec.containers.Containers; import com.github.streamshub.console.dependents.discriminators.ConsoleLabelDiscriminator; @@ -64,27 +65,27 @@ protected Deployment desired(Console primary, Context context) { String configSecretName = secret.instanceName(primary); var containers = Optional.ofNullable(primary.getSpec().getContainers()); - var templateAPI = containers.map(Containers::getApi); - var templateUI = containers.map(Containers::getUi); + var templateAPI = containers.map(Containers::getApi).map(ContainerTemplateSpec::getSpec); + var templateUI = containers.map(Containers::getUi).map(ContainerTemplateSpec::getSpec); // deprecated var images = Optional.ofNullable(primary.getSpec().getImages()); - String imageAPI = templateAPI.map(ContainerTemplate::getImage) + String imageAPI = templateAPI.map(ContainerSpec::getImage) .or(() -> images.map(Images::getApi)) .orElse(defaultAPIImage); - String imageUI = templateUI.map(ContainerTemplate::getImage) + String imageUI = templateUI.map(ContainerSpec::getImage) .or(() -> images.map(Images::getUi)) .orElse(defaultUIImage); var trustResources = getTrustResources("TrustStoreResources", context); List envVars = new ArrayList<>(); envVars.addAll(coalesce(primary.getSpec().getEnv(), Collections::emptyList)); - envVars.addAll(templateAPI.map(ContainerTemplate::getEnv).orElseGet(Collections::emptyList)); + envVars.addAll(templateAPI.map(ContainerSpec::getEnv).orElseGet(Collections::emptyList)); envVars.addAll(getResourcesByType(trustResources, EnvVar.class)); var trustResourcesUI = getTrustResources("TrustStoreResourcesUI", context); List envVarsUI = new ArrayList<>(); - envVarsUI.addAll(templateUI.map(ContainerTemplate::getEnv).orElseGet(Collections::emptyList)); + envVarsUI.addAll(templateUI.map(ContainerSpec::getEnv).orElseGet(Collections::emptyList)); envVarsUI.addAll(getResourcesByType(trustResourcesUI, EnvVar.class)); return desired.edit() @@ -116,7 +117,7 @@ protected Deployment desired(Console primary, Context context) { .editMatchingContainer(c -> "console-api".equals(c.getName())) .withImage(imageAPI) .withImagePullPolicy(pullPolicy(imageAPI)) - .withResources(templateAPI.map(ContainerTemplate::getResources).orElse(null)) + .withResources(templateAPI.map(ContainerSpec::getResources).orElse(null)) .addAllToVolumeMounts(getResourcesByType(trustResources, VolumeMount.class)) .addAllToEnv(envVars) .endContainer() @@ -124,7 +125,7 @@ protected Deployment desired(Console primary, Context context) { .editMatchingContainer(c -> "console-ui".equals(c.getName())) .withImage(imageUI) .withImagePullPolicy(pullPolicy(imageUI)) - .withResources(templateUI.map(ContainerTemplate::getResources).orElse(null)) + .withResources(templateUI.map(ContainerSpec::getResources).orElse(null)) .editMatchingEnv(env -> "NEXTAUTH_URL".equals(env.getName())) .withValue(getAttribute(context, ConsoleIngress.NAME + ".url", String.class)) .endEnv() diff --git a/operator/src/test/java/com/github/streamshub/console/ConsoleReconcilerTest.java b/operator/src/test/java/com/github/streamshub/console/ConsoleReconcilerTest.java index e0e9da555..4949eb357 100644 --- a/operator/src/test/java/com/github/streamshub/console/ConsoleReconcilerTest.java +++ b/operator/src/test/java/com/github/streamshub/console/ConsoleReconcilerTest.java @@ -107,26 +107,30 @@ void testConsoleReconciliationWithContainerOverrides() { .build()) .withNewContainers() .withNewApi() - .withImage("custom-api-image") - .withResources(new ResourceRequirementsBuilder() - .withRequests(Map.of("cpu", Quantity.parse("250m"))) - .withLimits(Map.of("cpu", Quantity.parse("500m"))) - .build()) - .addToEnv(new EnvVarBuilder() - .withName("CUSTOM_API_VAR") - .withValue("value1") - .build()) + .withNewSpec() + .withImage("custom-api-image") + .withResources(new ResourceRequirementsBuilder() + .withRequests(Map.of("cpu", Quantity.parse("250m"))) + .withLimits(Map.of("cpu", Quantity.parse("500m"))) + .build()) + .addToEnv(new EnvVarBuilder() + .withName("CUSTOM_API_VAR") + .withValue("value1") + .build()) + .endSpec() .endApi() .withNewUi() - .withImage("custom-ui-image") - .withResources(new ResourceRequirementsBuilder() - .withRequests(Map.of("cpu", Quantity.parse("100m"))) - .withLimits(Map.of("cpu", Quantity.parse("200m"))) - .build()) - .addToEnv(new EnvVarBuilder() - .withName("CUSTOM_UI_VAR") - .withValue("value2") - .build()) + .withNewSpec() + .withImage("custom-ui-image") + .withResources(new ResourceRequirementsBuilder() + .withRequests(Map.of("cpu", Quantity.parse("100m"))) + .withLimits(Map.of("cpu", Quantity.parse("200m"))) + .build()) + .addToEnv(new EnvVarBuilder() + .withName("CUSTOM_UI_VAR") + .withValue("value2") + .build()) + .endSpec() .endUi() .endContainers() .addNewKafkaCluster()