DefaultTaskToPodConverter implements TaskToPodConverter { @VisibleForTesting V1ResourceRequirements buildV1ResourceRequirements(ContainerResources containerResources) { Map<String, Quantity> requests = new HashMap<>(); Map<String, Quantity> limits = new HashMap<>(); requests.put("cpu", new Quantity(String.valueOf(containerResources.getCpu()))); limits.put("cpu", new Quantity(String.valueOf(containerResources.getCpu()))); requests.put("nvidia.com/gpu", new Quantity(String.valueOf(containerResources.getGpu()))); limits.put("nvidia.com/gpu", new Quantity(String.valueOf(containerResources.getGpu()))); Quantity memory; Quantity disk; Quantity network; if (configuration.isBytePodResourceEnabled()) { memory = new Quantity(containerResources.getMemoryMB() + "Mi"); disk = new Quantity(containerResources.getDiskMB() + "Mi"); network = new Quantity(containerResources.getNetworkMbps() + "M"); } else { memory = new Quantity(String.valueOf(containerResources.getMemoryMB())); disk = new Quantity(String.valueOf(containerResources.getDiskMB())); network = new Quantity(String.valueOf(containerResources.getNetworkMbps())); } requests.put("memory", memory); limits.put("memory", memory); requests.put("ephemeral-storage", disk); limits.put("ephemeral-storage", disk); requests.put("titus/network", network); limits.put("titus/network", network); return new V1ResourceRequirements().requests(requests).limits(limits); } @Inject  DefaultTaskToPodConverter(DirectKubeConfiguration configuration,
                                     PodAffinityFactory podAffinityFactory,
                                     TaintTolerationFactory taintTolerationFactory,
                                     LogStorageInfo<Task> logStorageInfo); @Override V1Pod apply(Job<?> job, Task task);  }
@Test public void testByteResourceUnits() { ContainerResources containerResources = ContainerResources.newBuilder() .withMemoryMB(2) .withDiskMB(4) .withNetworkMbps(128) .build(); when(configuration.isBytePodResourceEnabled()).thenReturn(false); V1ResourceRequirements podResources = converter.buildV1ResourceRequirements(containerResources); assertThat(podResources.getLimits().get("memory").toSuffixedString()).isEqualTo("2"); assertThat(podResources.getLimits().get("ephemeral-storage").toSuffixedString()).isEqualTo("4"); assertThat(podResources.getLimits().get("titus/network").toSuffixedString()).isEqualTo("128"); when(configuration.isBytePodResourceEnabled()).thenReturn(true); podResources = converter.buildV1ResourceRequirements(containerResources); assertThat(podResources.getLimits().get("memory").toSuffixedString()).isEqualTo("2Mi"); assertThat(podResources.getLimits().get("ephemeral-storage").toSuffixedString()).isEqualTo("4Mi"); assertThat(podResources.getLimits().get("titus/network").toSuffixedString()).isEqualTo("128M"); }