remove affinity group mappings when a cluster is deleted

This commit is contained in:
Daman Arora 2026-01-07 09:15:46 -05:00
parent af97ea3911
commit c58dee04d7
3 changed files with 15 additions and 0 deletions

View File

@ -2068,6 +2068,7 @@ public class KubernetesClusterManagerImpl extends ManagerBase implements Kuberne
return Transaction.execute((TransactionCallback<Boolean>) status -> {
kubernetesClusterDetailsDao.removeDetails(kubernetesClusterId);
kubernetesClusterVmMapDao.removeByClusterId(kubernetesClusterId);
kubernetesClusterAffinityGroupMapDao.removeByClusterId(kubernetesClusterId);
if (kubernetesClusterDao.remove(kubernetesClusterId)) {
deleteProjectKubernetesAccountIfNeeded(cluster);
return true;

View File

@ -26,4 +26,6 @@ public interface KubernetesClusterAffinityGroupMapDao extends GenericDao<Kuberne
List<KubernetesClusterAffinityGroupMapVO> listByClusterIdAndNodeType(long clusterId, String nodeType);
List<Long> listAffinityGroupIdsByClusterIdAndNodeType(long clusterId, String nodeType);
int removeByClusterId(long clusterId);
}

View File

@ -28,12 +28,17 @@ public class KubernetesClusterAffinityGroupMapDaoImpl extends GenericDaoBase<Kub
implements KubernetesClusterAffinityGroupMapDao {
private final SearchBuilder<KubernetesClusterAffinityGroupMapVO> clusterIdAndNodeTypeSearch;
private final SearchBuilder<KubernetesClusterAffinityGroupMapVO> clusterIdSearch;
public KubernetesClusterAffinityGroupMapDaoImpl() {
clusterIdAndNodeTypeSearch = createSearchBuilder();
clusterIdAndNodeTypeSearch.and("clusterId", clusterIdAndNodeTypeSearch.entity().getClusterId(), SearchCriteria.Op.EQ);
clusterIdAndNodeTypeSearch.and("nodeType", clusterIdAndNodeTypeSearch.entity().getNodeType(), SearchCriteria.Op.EQ);
clusterIdAndNodeTypeSearch.done();
clusterIdSearch = createSearchBuilder();
clusterIdSearch.and("clusterId", clusterIdSearch.entity().getClusterId(), SearchCriteria.Op.EQ);
clusterIdSearch.done();
}
@Override
@ -49,4 +54,11 @@ public class KubernetesClusterAffinityGroupMapDaoImpl extends GenericDaoBase<Kub
List<KubernetesClusterAffinityGroupMapVO> maps = listByClusterIdAndNodeType(clusterId, nodeType);
return maps.stream().map(KubernetesClusterAffinityGroupMapVO::getAffinityGroupId).collect(Collectors.toList());
}
@Override
public int removeByClusterId(long clusterId) {
SearchCriteria<KubernetesClusterAffinityGroupMapVO> sc = clusterIdSearch.create();
sc.setParameters("clusterId", clusterId);
return remove(sc);
}
}