Skip to content

Commit

Permalink
Fix sidecars resource requirements properties in Kubernetes
Browse files Browse the repository at this point in the history
Before these changes, the resource requirements limits/requests were ignored for the sidecars containers.

Note that these changes include a workaround for dekorateio/dekorate#1234.

Fix quarkusio#35006
  • Loading branch information
Sgitario committed Jul 26, 2023
1 parent 207fc2c commit 5312cd3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 56 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.quarkus.kubernetes.deployment;

import io.dekorate.kubernetes.adapter.ContainerAdapter;
import io.dekorate.kubernetes.config.Container;
import io.dekorate.kubernetes.decorator.Decorator;
import io.dekorate.kubernetes.decorator.NamedResourceDecorator;
Expand All @@ -8,7 +9,9 @@
import io.fabric8.kubernetes.api.model.PodSpecBuilder;

/**
* Copied from dekorate in order to fix some issues
* Copied from dekorate in order to fix some issues.
* TODO: This decorator should be removed and replaced by the Dekorate AddSidecarDecorator class after
* https://github.com/dekorateio/dekorate/pull/1234 is merged and Dekorate is bumped.
*/
class AddSidecarDecorator extends NamedResourceDecorator<PodSpecBuilder> {

Expand All @@ -26,7 +29,10 @@ public AddSidecarDecorator(String deployment, Container container) {
@Override
public void andThenVisit(PodSpecBuilder podSpec, ObjectMeta resourceMeta) {
// this was changed to use our patched adapter
podSpec.addToContainers(ContainerAdapter.adapt(container));
var sidecarContainer = ContainerAdapter.adapt(container);
// This is necessary because of the issue that this pull request fixes https://github.com/dekorateio/dekorate/pull/1234
sidecarContainer.setWorkingDir(container.getWorkingDir());
podSpec.addToContainers(sidecarContainer);
}

public Class<? extends Decorator>[] after() {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.junit.jupiter.api.extension.RegisterExtension;

import io.fabric8.kubernetes.api.model.HasMetadata;
import io.fabric8.kubernetes.api.model.Quantity;
import io.fabric8.kubernetes.api.model.apps.Deployment;
import io.quarkus.builder.Version;
import io.quarkus.maven.dependency.Dependency;
Expand Down Expand Up @@ -90,6 +91,12 @@ private void assertSidecar(io.fabric8.kubernetes.api.model.PodSpec podSpec) {
assertThat(e.getName()).isEqualTo("FOO");
assertThat(e.getValue()).isEqualTo("bar");
});
assertThat(c.getResources()).satisfies(r -> {
assertThat(r.getRequests().get("cpu")).isEqualTo(new Quantity("102m"));
assertThat(r.getRequests().get("memory")).isEqualTo(new Quantity("201Mi"));
assertThat(r.getLimits().get("cpu")).isEqualTo(new Quantity("100m"));
assertThat(r.getLimits().get("memory")).isEqualTo(new Quantity("200Mi"));
});
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ quarkus.kubernetes.sidecars.sc.arguments=-l
quarkus.kubernetes.sidecars.sc.mounts.app-config.path=/deployments/config
quarkus.kubernetes.sidecars.sc.ports.http.container-port=3000
quarkus.kubernetes.sidecars.sc.env-vars.foo.value=bar
quarkus.kubernetes.sidecars.sc.resources.requests.memory=201Mi
quarkus.kubernetes.sidecars.sc.resources.limits.memory=200Mi
quarkus.kubernetes.sidecars.sc.resources.requests.cpu=102m
quarkus.kubernetes.sidecars.sc.resources.limits.cpu=100m

0 comments on commit 5312cd3

Please sign in to comment.