| @@ -385,41 +385,44 @@ public class K8sClientUtil { | |||
| //设置选择节点,pod反亲和性 | |||
| Map<String, String> selector = new LinkedHashMap<>(); | |||
| selector.put("k8s-jupyter", "CPU-GPU"); | |||
| Map<String, String> nodeSelector = new LinkedHashMap<>(); | |||
| nodeSelector.put("resource-type", "CPU-GPU"); | |||
| V1Affinity v1Affinity = new V1Affinity(); | |||
| if (Constant.Computing_Resource_GPU.equals(devEnvironment.getComputingResource())) { | |||
| selector.put("k8s-jupyter", "CPU-GPU"); | |||
| nodeSelector.put("resource-type", "CPU-GPU"); | |||
| V1LabelSelectorRequirement labelSelectorRequirement = new V1LabelSelectorRequirement() | |||
| .key("k8s-jupyter").operator("NotIn").values(Collections.singletonList("CPU-GPU")); | |||
| V1LabelSelectorRequirement labelSelectorRequirement = new V1LabelSelectorRequirement() | |||
| .key("k8s-jupyter").operator("NotIn").values(Collections.singletonList("CPU-GPU")); | |||
| V1LabelSelector labelSelector = new V1LabelSelector() | |||
| .matchExpressions(Collections.singletonList(labelSelectorRequirement)); | |||
| V1LabelSelector labelSelector = new V1LabelSelector() | |||
| .matchExpressions(Collections.singletonList(labelSelectorRequirement)); | |||
| V1PodAffinityTerm podAffinityTerm = new V1PodAffinityTerm() | |||
| .labelSelector(labelSelector) | |||
| .namespaces(Collections.singletonList(namespace)) | |||
| .topologyKey("kubernetes.io/hostname"); | |||
| V1PodAffinityTerm podAffinityTerm = new V1PodAffinityTerm() | |||
| .labelSelector(labelSelector) | |||
| .namespaces(Collections.singletonList(namespace)) | |||
| .topologyKey("kubernetes.io/hostname"); | |||
| V1PodAffinity podAffinity = new V1PodAffinity() | |||
| .requiredDuringSchedulingIgnoredDuringExecution(Collections.singletonList(podAffinityTerm)); | |||
| V1PodAffinity podAffinity = new V1PodAffinity() | |||
| .requiredDuringSchedulingIgnoredDuringExecution(Collections.singletonList(podAffinityTerm)); | |||
| V1LabelSelectorRequirement antiLabelSelectorRequirement = new V1LabelSelectorRequirement() | |||
| .key("k8s-jupyter").operator("In").values(Collections.singletonList("CPU-GPU")); | |||
| V1LabelSelectorRequirement antiLabelSelectorRequirement = new V1LabelSelectorRequirement() | |||
| .key("k8s-jupyter").operator("In").values(Collections.singletonList("CPU-GPU")); | |||
| V1LabelSelector antiLabelSelector = new V1LabelSelector() | |||
| .matchExpressions(Collections.singletonList(antiLabelSelectorRequirement)); | |||
| V1LabelSelector antiLabelSelector = new V1LabelSelector() | |||
| .matchExpressions(Collections.singletonList(antiLabelSelectorRequirement)); | |||
| V1PodAffinityTerm antiPodAffinityTerm = new V1PodAffinityTerm() | |||
| .labelSelector(antiLabelSelector) | |||
| .namespaces(Collections.singletonList(namespace)) | |||
| .topologyKey("kubernetes.io/hostname"); | |||
| V1PodAffinityTerm antiPodAffinityTerm = new V1PodAffinityTerm() | |||
| .labelSelector(antiLabelSelector) | |||
| .namespaces(Collections.singletonList(namespace)) | |||
| .topologyKey("kubernetes.io/hostname"); | |||
| V1PodAntiAffinity podAntiAffinity = new V1PodAntiAffinity() | |||
| .requiredDuringSchedulingIgnoredDuringExecution(Collections.singletonList(antiPodAffinityTerm)); | |||
| V1PodAntiAffinity podAntiAffinity = new V1PodAntiAffinity() | |||
| .requiredDuringSchedulingIgnoredDuringExecution(Collections.singletonList(antiPodAffinityTerm)); | |||
| V1Affinity v1Affinity = new V1Affinity() | |||
| .podAffinity(podAffinity) | |||
| .podAntiAffinity(podAntiAffinity); | |||
| v1Affinity.podAffinity(podAffinity).podAntiAffinity(podAntiAffinity); | |||
| } else { | |||
| selector.put("k8s-jupyter", "CPU"); | |||
| } | |||
| // 创建Pod | |||
| CoreV1Api api = new CoreV1Api(apiClient); | |||
| @@ -454,9 +457,10 @@ public class K8sClientUtil { | |||
| //配置资源 | |||
| JSONObject standardJson = new JSONObject(devEnvironment.getStandard()); | |||
| JSONObject valueJson = (JSONObject)standardJson.get("value"); | |||
| int cpu = (int)valueJson.get("cpu"); | |||
| String memory = (String)valueJson.get("memory"); | |||
| JSONObject valueJson = (JSONObject) standardJson.get("value"); | |||
| int cpu = (int) valueJson.get("cpu"); | |||
| String memory = (String) valueJson.get("memory"); | |||
| memory = memory.substring(0, memory.length() - 1).concat("i"); | |||
| HashMap<String, Quantity> limitMap = new HashMap<>(); | |||
| if (Constant.Computing_Resource_GPU.equals(devEnvironment.getComputingResource())) { | |||