use of com.cloud.kubernetes.cluster.KubernetesClusterVmMapVO in project cloudstack by apache.
the class KubernetesClusterDestroyWorker method deleteKubernetesClusterNetworkRules.
private void deleteKubernetesClusterNetworkRules() throws ManagementServerException {
NetworkVO network = networkDao.findById(kubernetesCluster.getNetworkId());
if (network == null) {
return;
}
List<Long> removedVmIds = new ArrayList<>();
if (!CollectionUtils.isEmpty(clusterVMs)) {
for (KubernetesClusterVmMapVO clusterVM : clusterVMs) {
removedVmIds.add(clusterVM.getVmId());
}
}
IpAddress publicIp = getSourceNatIp(network);
if (publicIp == null) {
throw new ManagementServerException(String.format("No source NAT IP addresses found for network : %s", network.getName()));
}
try {
removeLoadBalancingRule(publicIp, network, owner, CLUSTER_API_PORT);
} catch (ResourceUnavailableException e) {
throw new ManagementServerException(String.format("Failed to KubernetesCluster load balancing rule for network : %s", network.getName()));
}
FirewallRule firewallRule = removeApiFirewallRule(publicIp);
if (firewallRule == null) {
logMessage(Level.WARN, "Firewall rule for API access can't be removed", null);
}
firewallRule = removeSshFirewallRule(publicIp);
if (firewallRule == null) {
logMessage(Level.WARN, "Firewall rule for SSH access can't be removed", null);
}
try {
removePortForwardingRules(publicIp, network, owner, removedVmIds);
} catch (ResourceUnavailableException e) {
throw new ManagementServerException(String.format("Failed to KubernetesCluster port forwarding rules for network : %s", network.getName()));
}
}
use of com.cloud.kubernetes.cluster.KubernetesClusterVmMapVO in project cloudstack by apache.
the class KubernetesClusterActionWorker method fetchControlVmIfMissing.
private UserVm fetchControlVmIfMissing(final UserVm controlVm) {
if (controlVm != null) {
return controlVm;
}
List<KubernetesClusterVmMapVO> clusterVMs = kubernetesClusterVmMapDao.listByClusterId(kubernetesCluster.getId());
if (CollectionUtils.isEmpty(clusterVMs)) {
LOGGER.warn(String.format("Unable to retrieve VMs for Kubernetes cluster : %s", kubernetesCluster.getName()));
return null;
}
List<Long> vmIds = new ArrayList<>();
for (KubernetesClusterVmMapVO vmMap : clusterVMs) {
vmIds.add(vmMap.getVmId());
}
Collections.sort(vmIds);
return userVmDao.findById(vmIds.get(0));
}
use of com.cloud.kubernetes.cluster.KubernetesClusterVmMapVO in project cloudstack by apache.
the class KubernetesClusterActionWorker method taintControlNodes.
protected boolean taintControlNodes() {
StringBuilder commands = new StringBuilder();
List<KubernetesClusterVmMapVO> vmMapVOList = getKubernetesClusterVMMaps();
for (KubernetesClusterVmMapVO vmMap : vmMapVOList) {
if (!vmMap.isControlNode()) {
continue;
}
String name = userVmDao.findById(vmMap.getVmId()).getDisplayName().toLowerCase();
String command = String.format("sudo /opt/bin/kubectl annotate node %s cluster-autoscaler.kubernetes.io/scale-down-disabled=true ; ", name);
commands.append(command);
}
try {
File pkFile = getManagementServerSshPublicKeyFile();
Pair<String, Integer> publicIpSshPort = getKubernetesClusterServerIpSshPort(null);
publicIpAddress = publicIpSshPort.first();
sshPort = publicIpSshPort.second();
Pair<Boolean, String> result = SshHelper.sshExecute(publicIpAddress, sshPort, getControlNodeLoginUser(), pkFile, null, commands.toString(), 10000, 10000, 60000);
return result.first();
} catch (Exception e) {
String msg = String.format("Failed to taint control nodes on : %s : %s", kubernetesCluster.getName(), e.getMessage());
logMessage(Level.ERROR, msg, e);
return false;
}
}
use of com.cloud.kubernetes.cluster.KubernetesClusterVmMapVO in project cloudstack by apache.
the class KubernetesClusterActionWorker method getKubernetesClusterVMs.
protected List<UserVm> getKubernetesClusterVMs() {
List<UserVm> vmList = new ArrayList<>();
List<KubernetesClusterVmMapVO> clusterVMs = getKubernetesClusterVMMaps();
if (!CollectionUtils.isEmpty(clusterVMs)) {
for (KubernetesClusterVmMapVO vmMap : clusterVMs) {
vmList.add(userVmDao.findById(vmMap.getVmId()));
}
}
return vmList;
}
use of com.cloud.kubernetes.cluster.KubernetesClusterVmMapVO in project cloudstack by apache.
the class KubernetesClusterVmMapDaoImpl method listByClusterId.
@Override
public List<KubernetesClusterVmMapVO> listByClusterId(long clusterId) {
SearchCriteria<KubernetesClusterVmMapVO> sc = clusterIdSearch.create();
sc.setParameters("clusterId", clusterId);
Filter filter = new Filter(KubernetesClusterVmMapVO.class, "id", Boolean.TRUE, null, null);
return listBy(sc, filter);
}
Aggregations