Damans227 commented on code in PR #12386:
URL: https://github.com/apache/cloudstack/pull/12386#discussion_r2843019311
##########
plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java:
##########
@@ -2348,6 +2417,100 @@ private List<Long> validateNodes(List<Long> nodeIds,
Long networkId, String netw
return validNodeIds;
}
+ protected void validateNodeAffinityGroups(List<Long> nodeIds,
KubernetesCluster cluster) {
+ List<Long> workerAffinityGroupIds =
kubernetesClusterAffinityGroupMapDao.listAffinityGroupIdsByClusterIdAndNodeType(
+ cluster.getId(), WORKER.name());
+ if (CollectionUtils.isEmpty(workerAffinityGroupIds)) {
+ return;
+ }
+
+ Set<Long> existingWorkerHostIds = getExistingWorkerHostIds(cluster);
+
+ for (Long affinityGroupId : workerAffinityGroupIds) {
+ AffinityGroupVO affinityGroup =
affinityGroupDao.findById(affinityGroupId);
+ if (affinityGroup == null) {
+ continue;
+ }
+
+ validateNodesAgainstExistingWorkers(nodeIds,
existingWorkerHostIds, affinityGroup, cluster);
+ validateNewNodesAntiAffinity(nodeIds, affinityGroup, cluster);
+ }
+ }
+
+ protected Set<Long> getExistingWorkerHostIds(KubernetesCluster cluster) {
+ List<KubernetesClusterVmMapVO> existingWorkerVms =
kubernetesClusterVmMapDao.listByClusterIdAndVmType(cluster.getId(), WORKER);
+ Set<Long> existingWorkerHostIds = new HashSet<>();
+ for (KubernetesClusterVmMapVO workerVmMap : existingWorkerVms) {
+ VMInstanceVO workerVm =
vmInstanceDao.findById(workerVmMap.getVmId());
+ if (workerVm != null && workerVm.getHostId() != null) {
+ existingWorkerHostIds.add(workerVm.getHostId());
+ }
+ }
+ return existingWorkerHostIds;
+ }
+
+ protected void validateNodesAgainstExistingWorkers(List<Long> nodeIds,
Set<Long> existingWorkerHostIds,
+ AffinityGroupVO
affinityGroup, KubernetesCluster cluster) {
+ String affinityGroupType = affinityGroup.getType();
+
+ for (Long nodeId : nodeIds) {
+ VMInstanceVO node = vmInstanceDao.findById(nodeId);
+ if (node == null || node.getHostId() == null) {
+ continue;
+ }
+ Long nodeHostId = node.getHostId();
+ String nodeHostName = getHostName(nodeHostId);
+
+ if ("host anti-affinity".equalsIgnoreCase(affinityGroupType)) {
Review Comment:
@nvazquez I tried the `instanceof` approach but it creates a
plugin-to-plugin Maven dependency (kubernetes-service to
host-affinity/host-anti-affinity plugins) which breaks the packaging build.
So, instead, I've added AFFINITY_TYPE_HOST and AFFINITY_TYPE_HOST_ANTI
constants in AffinityProcessorBase and use those.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]