Search in sources :

Example 1 with KubernetesClusterVmMapVO

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()));
    }
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) ManagementServerException(com.cloud.exception.ManagementServerException) ArrayList(java.util.ArrayList) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) IpAddress(com.cloud.network.IpAddress) FirewallRule(com.cloud.network.rules.FirewallRule) KubernetesClusterVmMapVO(com.cloud.kubernetes.cluster.KubernetesClusterVmMapVO)

Example 2 with KubernetesClusterVmMapVO

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));
}
Also used : ArrayList(java.util.ArrayList) KubernetesClusterVmMapVO(com.cloud.kubernetes.cluster.KubernetesClusterVmMapVO)

Example 3 with KubernetesClusterVmMapVO

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;
    }
}
Also used : File(java.io.File) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) KubernetesClusterVmMapVO(com.cloud.kubernetes.cluster.KubernetesClusterVmMapVO)

Example 4 with KubernetesClusterVmMapVO

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;
}
Also used : UserVm(com.cloud.uservm.UserVm) ArrayList(java.util.ArrayList) KubernetesClusterVmMapVO(com.cloud.kubernetes.cluster.KubernetesClusterVmMapVO)

Example 5 with KubernetesClusterVmMapVO

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);
}
Also used : Filter(com.cloud.utils.db.Filter) KubernetesClusterVmMapVO(com.cloud.kubernetes.cluster.KubernetesClusterVmMapVO)

Aggregations

KubernetesClusterVmMapVO (com.cloud.kubernetes.cluster.KubernetesClusterVmMapVO)12 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)4 UserVmVO (com.cloud.vm.UserVmVO)4 ManagementServerException (com.cloud.exception.ManagementServerException)3 UserVm (com.cloud.uservm.UserVm)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 ArrayList (java.util.ArrayList)3 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)2 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)2 File (java.io.File)2 IOException (java.io.IOException)2 DataCenter (com.cloud.dc.DataCenter)1 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)1 VirtualMachineMigrationException (com.cloud.exception.VirtualMachineMigrationException)1 IpAddress (com.cloud.network.IpAddress)1 NetworkVO (com.cloud.network.dao.NetworkVO)1 FirewallRule (com.cloud.network.rules.FirewallRule)1 ServiceOffering (com.cloud.offering.ServiceOffering)1 Filter (com.cloud.utils.db.Filter)1 UserVmDetailVO (com.cloud.vm.UserVmDetailVO)1