diff --git a/spring-cloud-deployer-kubernetes/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/DeploymentPropertiesResolver.java b/spring-cloud-deployer-kubernetes/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/DeploymentPropertiesResolver.java index bb55fca9..5aea716c 100644 --- a/spring-cloud-deployer-kubernetes/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/DeploymentPropertiesResolver.java +++ b/spring-cloud-deployer-kubernetes/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/DeploymentPropertiesResolver.java @@ -164,46 +164,38 @@ List getVolumes(Map kubernetesDeployerProperties) { * @return the resource limits to use */ Map deduceResourceLimits(Map kubernetesDeployerProperties) { - String memory = PropertyParserUtils.getDeploymentPropertyValue(kubernetesDeployerProperties, - this.propertyPrefix + ".limits.memory"); + String memory = PropertyParserUtils.getDeploymentPropertyValue(kubernetesDeployerProperties, this.propertyPrefix + ".limits.memory", properties.getLimits().getMemory()); + String cpu = PropertyParserUtils.getDeploymentPropertyValue(kubernetesDeployerProperties, this.propertyPrefix + ".limits.cpu", properties.getLimits().getCpu()); + String ephemeralStorage = PropertyParserUtils.getDeploymentPropertyValue(kubernetesDeployerProperties, ".limits.ephemeral-storage", properties.getLimits().getEphemeralStorage()); + String hugePages2Mi = PropertyParserUtils.getDeploymentPropertyValue(kubernetesDeployerProperties, ".limits.hugepages-2Mi", properties.getLimits().getHugepages2Mi()); + String hugePages1Gi = PropertyParserUtils.getDeploymentPropertyValue(kubernetesDeployerProperties, ".limits.hugepages-1Gi", properties.getLimits().getHugepages1Gi()); + String gpuVendor = PropertyParserUtils.getDeploymentPropertyValue(kubernetesDeployerProperties, this.propertyPrefix + ".limits.gpuVendor", properties.getLimits().getGpuVendor()); + String gpuCount = PropertyParserUtils.getDeploymentPropertyValue(kubernetesDeployerProperties, this.propertyPrefix + ".limits.gpuCount", properties.getLimits().getGpuCount()); - if (!StringUtils.hasText(memory)) { - memory = properties.getLimits().getMemory(); - } - - String cpu = PropertyParserUtils.getDeploymentPropertyValue(kubernetesDeployerProperties, - this.propertyPrefix + ".limits.cpu"); + Map limits = new HashMap(); - if (!StringUtils.hasText(cpu)) { - cpu = properties.getLimits().getCpu(); + if (StringUtils.hasText(memory)) { + limits.put("memory", new Quantity(memory)); } - String gpuVendor = PropertyParserUtils.getDeploymentPropertyValue(kubernetesDeployerProperties, - this.propertyPrefix + ".limits.gpuVendor"); - - if (!StringUtils.hasText(gpuVendor)) { - gpuVendor = properties.getLimits().getGpuVendor(); + if (StringUtils.hasText(cpu)) { + limits.put("cpu", new Quantity(cpu)); } - String gpuCount = PropertyParserUtils.getDeploymentPropertyValue(kubernetesDeployerProperties, - this.propertyPrefix + ".limits.gpuCount"); - - if (!StringUtils.hasText(gpuCount)) { - gpuCount = properties.getLimits().getGpuCount(); + if (StringUtils.hasText(ephemeralStorage)) { + limits.put("ephemeral-storage", new Quantity(ephemeralStorage)); } - Map limits = new HashMap(); - - if (StringUtils.hasText(memory)) { - limits.put("memory", new Quantity(memory)); + if (StringUtils.hasText(hugePages2Mi)) { + limits.put("hugepages-2Mi", new Quantity(hugePages2Mi)); } - if (StringUtils.hasText(cpu)) { - limits.put("cpu", new Quantity(cpu)); + if (StringUtils.hasText(hugePages1Gi)) { + limits.put("hugepages-1Gi", new Quantity(hugePages1Gi)); } if (StringUtils.hasText(gpuVendor) && StringUtils.hasText(gpuCount)) { - limits.put(gpuVendor + "/gpu", new Quantity(gpuCount)); + limits.put(gpuVendor, new Quantity(gpuCount)); } return limits; @@ -245,32 +237,36 @@ ImagePullPolicy deduceImagePullPolicy(Map kubernetesDeployerProp * @return the resource requests to use */ Map deduceResourceRequests(Map kubernetesDeployerProperties) { - String memOverride = PropertyParserUtils.getDeploymentPropertyValue(kubernetesDeployerProperties, - this.propertyPrefix + ".requests.memory"); - - if (memOverride == null) { - memOverride = properties.getRequests().getMemory(); - } - - - String cpuOverride = PropertyParserUtils.getDeploymentPropertyValue(kubernetesDeployerProperties, - this.propertyPrefix + ".requests.cpu"); - - if (cpuOverride == null) { - cpuOverride = properties.getRequests().getCpu(); - } + String memOverride = PropertyParserUtils.getDeploymentPropertyValue(kubernetesDeployerProperties, this.propertyPrefix + ".requests.memory", properties.getRequests().getMemory()); + String cpuOverride = PropertyParserUtils.getDeploymentPropertyValue(kubernetesDeployerProperties, this.propertyPrefix + ".requests.cpu", properties.getRequests().getCpu()); logger.debug("Using requests - cpu: " + cpuOverride + " mem: " + memOverride); + String ephemeralStorage = PropertyParserUtils.getDeploymentPropertyValue(kubernetesDeployerProperties, ".requests.ephemeral-storage", properties.getRequests().getEphemeralStorage()); + String hugePages2Mi = PropertyParserUtils.getDeploymentPropertyValue(kubernetesDeployerProperties, ".requests.hugepages-2Mi", properties.getRequests().getHugepages2Mi()); + String hugePages1Gi = PropertyParserUtils.getDeploymentPropertyValue(kubernetesDeployerProperties, ".requests.hugepages-1Gi", properties.getRequests().getHugepages1Gi()); + Map requests = new HashMap(); - if (memOverride != null) { + if (StringUtils.hasText(memOverride)) { requests.put("memory", new Quantity(memOverride)); } - if (cpuOverride != null) { + if (StringUtils.hasText(cpuOverride)) { requests.put("cpu", new Quantity(cpuOverride)); } + if(StringUtils.hasText(ephemeralStorage)) { + requests.put("ephemeral-storage", new Quantity(ephemeralStorage)); + } + + if(StringUtils.hasText(hugePages2Mi)) { + requests.put("hugepages-2Mi", new Quantity(hugePages2Mi)); + } + + if(StringUtils.hasText(hugePages1Gi)) { + requests.put("hugepages-1Gi", new Quantity(hugePages1Gi)); + } + return requests; } diff --git a/spring-cloud-deployer-kubernetes/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/KubernetesDeployerProperties.java b/spring-cloud-deployer-kubernetes/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/KubernetesDeployerProperties.java index 8f332468..089adcf4 100755 --- a/spring-cloud-deployer-kubernetes/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/KubernetesDeployerProperties.java +++ b/spring-cloud-deployer-kubernetes/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/KubernetesDeployerProperties.java @@ -89,9 +89,28 @@ public static class LimitsResources { * Container resource memory limit. */ private String memory; + /** + * Container resource ephemeral-storage limit. + */ + private String ephemeralStorage; + + /** + * Container resource hugepages-2Mi limit. + */ + private String hugepages2Mi; + + /** + * Container resource hugepages-1Gi limit. + */ + private String hugepages1Gi; /** * Container GPU vendor name for limit + * If gpuVendor=nvidia.com/gpu and gpuCount=2 then the following will be used + * {@code + * limits: + * nvidia.com/gpu: 2 + * } */ private String gpuVendor; @@ -102,20 +121,24 @@ public static class LimitsResources { public LimitsResources() { } - /** - * 'All' args constructor - * - * @param cpu Container resource cpu limit - * @param memory Container resource memory limit - * @deprecated This method should no longer be used to set all fields at construct time. - *

- * Use the default constructor and set() methods instead. + * New all args constructor + * @param cpu Container limit for cpu resource + * @param memory Container limit for memory resource + * @param ephemeralStorage Container limit for ephemetal storage + * @param hugepages2Mi Container limit for 2M huge pages + * @param hugepages1Gi Container limit for 1G huge pages + * @param gpuVendor The complete limit entry name for gpu vendor. + * @param gpuCount */ - @Deprecated - public LimitsResources(String cpu, String memory) { + public LimitsResources(String cpu, String memory, String ephemeralStorage, String hugepages2Mi, String hugepages1Gi, String gpuVendor, String gpuCount) { this.cpu = cpu; this.memory = memory; + this.ephemeralStorage = ephemeralStorage; + this.hugepages2Mi = hugepages2Mi; + this.hugepages1Gi = hugepages1Gi; + this.gpuVendor = gpuVendor; + this.gpuCount = gpuCount; } public String getCpu() { @@ -134,6 +157,30 @@ public void setMemory(String memory) { this.memory = memory; } + public String getEphemeralStorage() { + return ephemeralStorage; + } + + public void setEphemeralStorage(String ephemeralStorage) { + this.ephemeralStorage = ephemeralStorage; + } + + public String getHugepages2Mi() { + return hugepages2Mi; + } + + public void setHugepages2Mi(String hugepages2Mi) { + this.hugepages2Mi = hugepages2Mi; + } + + public String getHugepages1Gi() { + return hugepages1Gi; + } + + public void setHugepages1Gi(String hugepages1Gi) { + this.hugepages1Gi = hugepages1Gi; + } + public String getGpuVendor() { return gpuVendor; } @@ -166,13 +213,47 @@ public static class RequestsResources { */ private String memory; + /** + * Container resource ephemeral-storage request. + */ + private String ephemeralStorage; + + /** + * Container resource hugepages-2Mi request. + */ + private String hugepages2Mi; + + /** + * Container resource hugepages-1Gi request. + */ + private String hugepages1Gi; + + public RequestsResources() { } + /** + * 'All' args constructor + * + * @param cpu Container resource requested cpu + * @param memory Container resource requested memory + * @deprecated This method should no longer be used to set all fields at construct time. + *

+ * Use the default constructor and set() methods instead. + */ + @Deprecated public RequestsResources(String cpu, String memory) { this.cpu = cpu; this.memory = memory; } + @Deprecated + public RequestsResources(String cpu, String memory, String ephemeralStorage, String hugepages2Mi, String hugepages1Gi) { + this.cpu = cpu; + this.memory = memory; + this.ephemeralStorage = ephemeralStorage; + this.hugepages2Mi = hugepages2Mi; + this.hugepages1Gi = hugepages1Gi; + } public String getCpu() { return cpu; @@ -189,6 +270,30 @@ public String getMemory() { public void setMemory(String memory) { this.memory = memory; } + + public String getEphemeralStorage() { + return ephemeralStorage; + } + + public void setEphemeralStorage(String ephemeralStorage) { + this.ephemeralStorage = ephemeralStorage; + } + + public String getHugepages2Mi() { + return hugepages2Mi; + } + + public void setHugepages2Mi(String hugepages2Mi) { + this.hugepages2Mi = hugepages2Mi; + } + + public String getHugepages1Gi() { + return hugepages1Gi; + } + + public void setHugepages1Gi(String hugepages1Gi) { + this.hugepages1Gi = hugepages1Gi; + } } public static class StatefulSet { diff --git a/spring-cloud-deployer-kubernetes/src/test/java/org/springframework/cloud/deployer/spi/kubernetes/RunAbstractKubernetesDeployerTests.java b/spring-cloud-deployer-kubernetes/src/test/java/org/springframework/cloud/deployer/spi/kubernetes/RunAbstractKubernetesDeployerTests.java index 8406b7c5..53cb45b2 100755 --- a/spring-cloud-deployer-kubernetes/src/test/java/org/springframework/cloud/deployer/spi/kubernetes/RunAbstractKubernetesDeployerTests.java +++ b/spring-cloud-deployer-kubernetes/src/test/java/org/springframework/cloud/deployer/spi/kubernetes/RunAbstractKubernetesDeployerTests.java @@ -77,7 +77,7 @@ public void limitGpu_noDeploymentProperty_incompleteServerProperty2_noGpu() { @Test public void limitGpu_noDeploymentProperty_serverProperty_usesServerProperty() { - kubernetesDeployerProperties.getLimits().setGpuVendor("nvidia.com"); + kubernetesDeployerProperties.getLimits().setGpuVendor("nvidia.com/gpu"); kubernetesDeployerProperties.getLimits().setGpuCount("2"); Map limits = this.deploymentPropertiesResolver.deduceResourceLimits(deploymentRequest.getDeploymentProperties()); assertThat(limits.get("nvidia.com/gpu")).isEqualTo(new Quantity("2")); @@ -85,16 +85,16 @@ public void limitGpu_noDeploymentProperty_serverProperty_usesServerProperty() { @Test public void limitGpu_deploymentPropertyVendor_usesDeploymentProperty() { - kubernetesDeployerProperties.getLimits().setGpuVendor("nvidia.com"); + kubernetesDeployerProperties.getLimits().setGpuVendor("nvidia.com/gpu"); kubernetesDeployerProperties.getLimits().setGpuCount("2"); - deploymentProperties.put("spring.cloud.deployer.kubernetes.limits.gpu_vendor", "ati.com"); + deploymentProperties.put("spring.cloud.deployer.kubernetes.limits.gpu_vendor", "ati.com/gpu"); Map limits = this.deploymentPropertiesResolver.deduceResourceLimits(deploymentRequest.getDeploymentProperties()); assertThat(limits.get("ati.com/gpu")).isEqualTo(new Quantity("2")); } @Test public void limitGpu_deploymentPropertyCount_usesDeploymentProperty() { - kubernetesDeployerProperties.getLimits().setGpuVendor("nvidia.com"); + kubernetesDeployerProperties.getLimits().setGpuVendor("nvidia.com/gpu"); kubernetesDeployerProperties.getLimits().setGpuCount("2"); deploymentProperties.put("spring.cloud.deployer.kubernetes.limits.gpu_count", "1"); Map limits = this.deploymentPropertiesResolver.deduceResourceLimits(deploymentRequest.getDeploymentProperties()); @@ -103,9 +103,9 @@ public void limitGpu_deploymentPropertyCount_usesDeploymentProperty() { @Test public void limitGpu_deploymentPropertyBoth_usesDeploymentProperty() { - kubernetesDeployerProperties.getLimits().setGpuVendor("nvidia.com"); + kubernetesDeployerProperties.getLimits().setGpuVendor("nvidia.com/gpu"); kubernetesDeployerProperties.getLimits().setGpuCount("2"); - deploymentProperties.put("spring.cloud.deployer.kubernetes.limits.gpu_vendor", "ati.com"); + deploymentProperties.put("spring.cloud.deployer.kubernetes.limits.gpu_vendor", "ati.com/gpu"); deploymentProperties.put("spring.cloud.deployer.kubernetes.limits.gpu_count", "1"); Map limits = this.deploymentPropertiesResolver.deduceResourceLimits(deploymentRequest.getDeploymentProperties()); assertThat(limits.get("ati.com/gpu")).isEqualTo(new Quantity("1")); @@ -170,4 +170,51 @@ public void requestMemory_deploymentProperty_usesDeploymentProperty() { Map requests = this.deploymentPropertiesResolver.deduceResourceRequests(deploymentRequest.getDeploymentProperties()); assertThat(requests.get("memory")).isEqualTo(new Quantity("256Mi")); } + @Test + public void requestEphemeralStorage_deploymentProperty_usesDeploymentProperty() { + kubernetesDeployerProperties.getRequests().setEphemeralStorage("2Gi"); + deploymentProperties.put("spring.cloud.deployer.kubernetes.requests.ephemeral-storage", "2Gi"); + Map requests = this.deploymentPropertiesResolver.deduceResourceRequests(deploymentRequest.getDeploymentProperties()); + assertThat(requests.get("ephemeral-storage")).isEqualTo(new Quantity("2Gi")); + } + + @Test + public void limitEphemeralStorage_deploymentProperty_usesDeploymentProperty() { + kubernetesDeployerProperties.getLimits().setEphemeralStorage("2Gi"); + deploymentProperties.put("spring.cloud.deployer.kubernetes.limits.ephemeral-storage", "2Gi"); + Map limits = this.deploymentPropertiesResolver.deduceResourceLimits(deploymentRequest.getDeploymentProperties()); + assertThat(limits.get("ephemeral-storage")).isEqualTo(new Quantity("2Gi")); + } + + @Test + public void requestHugepages1Gi_deploymentProperty_usesDeploymentProperty() { + kubernetesDeployerProperties.getRequests().setHugepages1Gi("4"); + deploymentProperties.put("spring.cloud.deployer.kubernetes.requests.hugepages-1Gi", "4"); + Map requests = this.deploymentPropertiesResolver.deduceResourceRequests(deploymentRequest.getDeploymentProperties()); + assertThat(requests.get("hugepages-1Gi")).isEqualTo(new Quantity("4")); + } + + @Test + public void limitHugepages1Gi_deploymentProperty_usesDeploymentProperty() { + kubernetesDeployerProperties.getLimits().setHugepages1Gi("4"); + deploymentProperties.put("spring.cloud.deployer.kubernetes.limits.hugepages-1Gi", "4"); + Map limits = this.deploymentPropertiesResolver.deduceResourceLimits(deploymentRequest.getDeploymentProperties()); + assertThat(limits.get("hugepages-1Gi")).isEqualTo(new Quantity("4")); + } + + @Test + public void requestHugepages2Mi_deploymentProperty_usesDeploymentProperty() { + kubernetesDeployerProperties.getRequests().setHugepages2Mi("40"); + deploymentProperties.put("spring.cloud.deployer.kubernetes.requests.hugepages-2Mi", "40"); + Map requests = this.deploymentPropertiesResolver.deduceResourceRequests(deploymentRequest.getDeploymentProperties()); + assertThat(requests.get("hugepages-2Mi")).isEqualTo(new Quantity("40")); + } + + @Test + public void limitHugepages2Mi_deploymentProperty_usesDeploymentProperty() { + kubernetesDeployerProperties.getLimits().setHugepages2Mi("40"); + deploymentProperties.put("spring.cloud.deployer.kubernetes.limits.hugepages-2Mi", "40"); + Map limits = this.deploymentPropertiesResolver.deduceResourceLimits(deploymentRequest.getDeploymentProperties()); + assertThat(limits.get("hugepages-2Mi")).isEqualTo(new Quantity("40")); + } } diff --git a/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/KubernetesDeployerProperties.java b/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/KubernetesDeployerProperties.java index b20fbfda..03fe1c74 100755 --- a/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/KubernetesDeployerProperties.java +++ b/src/main/java/org/springframework/cloud/deployer/spi/kubernetes/KubernetesDeployerProperties.java @@ -84,9 +84,28 @@ public static class LimitsResources { * Container resource memory limit. */ private String memory; + /** + * Container resource ephemeral storage size limit. + */ + private String ephemeralStorage; + + /** + * Container resource hugepages-2Mi limit. + */ + private String hugepages2Mi; + + /** + * Container resource hugepages-1Gi limit. + */ + private String hugepages1Gi; /** * Container GPU vendor name for limit + * If gpuVendor=nvidia.com/gpu and gpuCount=2 then the following will be used + * {@code + * limits: + * nvidia.com/gpu: 2 + * } */ private String gpuVendor; @@ -113,6 +132,17 @@ public LimitsResources(String cpu, String memory) { this.memory = memory; } + @Deprecated + public LimitsResources(String cpu, String memory, String ephemeralStorage, String hugepages2Mi, String hugepages1Gi, String gpuVendor, String gpuCount) { + this.cpu = cpu; + this.memory = memory; + this.ephemeralStorage = ephemeralStorage; + this.hugepages2Mi = hugepages2Mi; + this.hugepages1Gi = hugepages1Gi; + this.gpuVendor = gpuVendor; + this.gpuCount = gpuCount; + } + public String getCpu() { return cpu; } @@ -129,6 +159,30 @@ public void setMemory(String memory) { this.memory = memory; } + public String getEphemeralStorage() { + return ephemeralStorage; + } + + public void setEphemeralStorage(String ephemeralStorage) { + this.ephemeralStorage = ephemeralStorage; + } + + public String getHugepages2Mi() { + return hugepages2Mi; + } + + public void setHugepages2Mi(String hugepages2Mi) { + this.hugepages2Mi = hugepages2Mi; + } + + public String getHugepages1Gi() { + return hugepages1Gi; + } + + public void setHugepages1Gi(String hugepages1Gi) { + this.hugepages1Gi = hugepages1Gi; + } + public String getGpuVendor() { return gpuVendor; } @@ -161,6 +215,21 @@ public static class RequestsResources { */ private String memory; + /** + * Container resource ephemeral storage size request. + */ + private String ephemeralStorage; + + /** + * Container resource hugepages-2Mi request. + */ + private String hugepages2Mi; + + /** + * Container resource hugepages-1Gi request. + */ + private String hugepages1Gi; + public RequestsResources() { } @@ -169,6 +238,14 @@ public RequestsResources(String cpu, String memory) { this.memory = memory; } + public RequestsResources(String cpu, String memory, String ephemeralStorage, String hugepages2Mi, String hugepages1Gi) { + this.cpu = cpu; + this.memory = memory; + this.ephemeralStorage = ephemeralStorage; + this.hugepages2Mi = hugepages2Mi; + this.hugepages1Gi = hugepages1Gi; + } + public String getCpu() { return cpu; } @@ -184,6 +261,30 @@ public String getMemory() { public void setMemory(String memory) { this.memory = memory; } + + public String getEphemeralStorage() { + return ephemeralStorage; + } + + public void setEphemeralStorage(String ephemeralStorage) { + this.ephemeralStorage = ephemeralStorage; + } + + public String getHugepages2Mi() { + return hugepages2Mi; + } + + public void setHugepages2Mi(String hugepages2Mi) { + this.hugepages2Mi = hugepages2Mi; + } + + public String getHugepages1Gi() { + return hugepages1Gi; + } + + public void setHugepages1Gi(String hugepages1Gi) { + this.hugepages1Gi = hugepages1Gi; + } } public static class StatefulSet {