Search in sources :

Example 6 with KubernetesClusterVmMapVO

use of com.cloud.kubernetes.cluster.KubernetesClusterVmMapVO in project cloudstack by apache.

the class KubernetesClusterActionWorker method createCloudStackSecret.

protected boolean createCloudStackSecret(String[] keys) {
    File pkFile = getManagementServerSshPublicKeyFile();
    Pair<String, Integer> publicIpSshPort = getKubernetesClusterServerIpSshPort(null);
    List<KubernetesClusterVmMapVO> vmMapVOList = getKubernetesClusterVMMaps();
    publicIpAddress = publicIpSshPort.first();
    sshPort = publicIpSshPort.second();
    try {
        final String command = String.format("sudo %s/%s -u '%s' -k '%s' -s '%s'", scriptPath, deploySecretsScriptFilename, ApiServiceConfiguration.ApiServletPath.value(), keys[0], keys[1]);
        Pair<Boolean, String> result = SshHelper.sshExecute(publicIpAddress, sshPort, getControlNodeLoginUser(), pkFile, null, command, 10000, 10000, 60000);
        return result.first();
    } catch (Exception e) {
        String msg = String.format("Failed to add cloudstack-secret to Kubernetes cluster: %s", kubernetesCluster.getName());
        LOGGER.warn(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 7 with KubernetesClusterVmMapVO

use of com.cloud.kubernetes.cluster.KubernetesClusterVmMapVO in project cloudstack by apache.

the class KubernetesClusterActionWorker method getControlNodeLoginUser.

protected String getControlNodeLoginUser() {
    List<KubernetesClusterVmMapVO> vmMapVOList = getKubernetesClusterVMMaps();
    if (vmMapVOList.size() > 0) {
        long vmId = vmMapVOList.get(0).getVmId();
        UserVmVO userVM = userVmDao.findById(vmId);
        if (userVM == null) {
            throw new CloudRuntimeException("Failed to find login user, Unable to log in to node to fetch details");
        }
        Set<String> vm = new HashSet<>();
        vm.add(userVM.getName());
        UserVmDetailVO vmDetail = userVmDetailsDao.findDetail(vmId, VmDetailConstants.CKS_CONTROL_NODE_LOGIN_USER);
        if (vmDetail != null && !org.apache.commons.lang3.StringUtils.isEmpty(vmDetail.getValue())) {
            return vmDetail.getValue();
        } else {
            return CLUSTER_NODE_VM_USER;
        }
    } else {
        return CLUSTER_NODE_VM_USER;
    }
}
Also used : UserVmDetailVO(com.cloud.vm.UserVmDetailVO) UserVmVO(com.cloud.vm.UserVmVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) KubernetesClusterVmMapVO(com.cloud.kubernetes.cluster.KubernetesClusterVmMapVO) HashSet(java.util.HashSet)

Example 8 with KubernetesClusterVmMapVO

use of com.cloud.kubernetes.cluster.KubernetesClusterVmMapVO in project cloudstack by apache.

the class KubernetesClusterScaleWorker method scaleKubernetesClusterOffering.

private void scaleKubernetesClusterOffering() throws CloudRuntimeException {
    validateKubernetesClusterScaleOfferingParameters();
    if (!kubernetesCluster.getState().equals(KubernetesCluster.State.Scaling)) {
        stateTransitTo(kubernetesCluster.getId(), KubernetesCluster.Event.ScaleUpRequested);
    }
    if (KubernetesCluster.State.Created.equals(originalState)) {
        kubernetesCluster = updateKubernetesClusterEntry(null, serviceOffering);
        return;
    }
    final long size = kubernetesCluster.getTotalNodeCount();
    List<KubernetesClusterVmMapVO> vmList = kubernetesClusterVmMapDao.listByClusterId(kubernetesCluster.getId());
    final long tobeScaledVMCount = Math.min(vmList.size(), size);
    for (long i = 0; i < tobeScaledVMCount; i++) {
        KubernetesClusterVmMapVO vmMapVO = vmList.get((int) i);
        UserVmVO userVM = userVmDao.findById(vmMapVO.getVmId());
        boolean result = false;
        try {
            result = userVmManager.upgradeVirtualMachine(userVM.getId(), serviceOffering.getId(), new HashMap<String, String>());
        } catch (ResourceUnavailableException | ManagementServerException | ConcurrentOperationException | VirtualMachineMigrationException e) {
            logTransitStateAndThrow(Level.ERROR, String.format("Scaling Kubernetes cluster : %s failed, unable to scale cluster VM : %s", kubernetesCluster.getName(), userVM.getDisplayName()), kubernetesCluster.getId(), KubernetesCluster.Event.OperationFailed, e);
        }
        if (!result) {
            logTransitStateAndThrow(Level.WARN, String.format("Scaling Kubernetes cluster : %s failed, unable to scale cluster VM : %s", kubernetesCluster.getName(), userVM.getDisplayName()), kubernetesCluster.getId(), KubernetesCluster.Event.OperationFailed);
        }
        if (System.currentTimeMillis() > scaleTimeoutTime) {
            logTransitStateAndThrow(Level.WARN, String.format("Scaling Kubernetes cluster : %s failed, scaling action timed out", kubernetesCluster.getName()), kubernetesCluster.getId(), KubernetesCluster.Event.OperationFailed);
        }
    }
    kubernetesCluster = updateKubernetesClusterEntry(null, serviceOffering);
}
Also used : UserVmVO(com.cloud.vm.UserVmVO) ManagementServerException(com.cloud.exception.ManagementServerException) HashMap(java.util.HashMap) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) VirtualMachineMigrationException(com.cloud.exception.VirtualMachineMigrationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) KubernetesClusterVmMapVO(com.cloud.kubernetes.cluster.KubernetesClusterVmMapVO)

Example 9 with KubernetesClusterVmMapVO

use of com.cloud.kubernetes.cluster.KubernetesClusterVmMapVO in project cloudstack by apache.

the class KubernetesClusterDestroyWorker method destroyClusterVMs.

private boolean destroyClusterVMs() {
    boolean vmDestroyed = true;
    if (!CollectionUtils.isEmpty(clusterVMs)) {
        for (KubernetesClusterVmMapVO clusterVM : clusterVMs) {
            long vmID = clusterVM.getVmId();
            // delete only if VM exists and is not removed
            UserVmVO userVM = userVmDao.findById(vmID);
            if (userVM == null || userVM.isRemoved()) {
                continue;
            }
            try {
                UserVm vm = userVmService.destroyVm(vmID, true);
                if (!userVmManager.expunge(userVM, CallContext.current().getCallingUserId(), CallContext.current().getCallingAccount())) {
                    LOGGER.warn(String.format("Unable to expunge VM %s : %s, destroying Kubernetes cluster will probably fail", vm.getInstanceName(), vm.getUuid()));
                }
                kubernetesClusterVmMapDao.expunge(clusterVM.getId());
                if (LOGGER.isInfoEnabled()) {
                    LOGGER.info(String.format("Destroyed VM : %s as part of Kubernetes cluster : %s cleanup", vm.getDisplayName(), kubernetesCluster.getName()));
                }
            } catch (ResourceUnavailableException | ConcurrentOperationException e) {
                LOGGER.warn(String.format("Failed to destroy VM : %s part of the Kubernetes cluster : %s cleanup. Moving on with destroying remaining resources provisioned for the Kubernetes cluster", userVM.getDisplayName(), kubernetesCluster.getName()), e);
                return false;
            }
        }
    }
    return vmDestroyed;
}
Also used : UserVmVO(com.cloud.vm.UserVmVO) UserVm(com.cloud.uservm.UserVm) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) KubernetesClusterVmMapVO(com.cloud.kubernetes.cluster.KubernetesClusterVmMapVO)

Example 10 with KubernetesClusterVmMapVO

use of com.cloud.kubernetes.cluster.KubernetesClusterVmMapVO in project cloudstack by apache.

the class KubernetesClusterScaleWorker method validateKubernetesClusterScaleOfferingParameters.

private void validateKubernetesClusterScaleOfferingParameters() throws CloudRuntimeException {
    if (KubernetesCluster.State.Created.equals(originalState)) {
        return;
    }
    final long originalNodeCount = kubernetesCluster.getTotalNodeCount();
    List<KubernetesClusterVmMapVO> vmList = kubernetesClusterVmMapDao.listByClusterId(kubernetesCluster.getId());
    if (vmList == null || vmList.isEmpty() || vmList.size() < originalNodeCount) {
        logTransitStateToFailedIfNeededAndThrow(Level.WARN, String.format("Scaling Kubernetes cluster : %s failed, it is in unstable state as not enough existing VM instances found!", kubernetesCluster.getName()));
    } else {
        for (KubernetesClusterVmMapVO vmMapVO : vmList) {
            VMInstanceVO vmInstance = vmInstanceDao.findById(vmMapVO.getVmId());
            if (vmInstance != null && vmInstance.getState().equals(VirtualMachine.State.Running) && vmInstance.getHypervisorType() != Hypervisor.HypervisorType.XenServer && vmInstance.getHypervisorType() != Hypervisor.HypervisorType.VMware && vmInstance.getHypervisorType() != Hypervisor.HypervisorType.Simulator) {
                logTransitStateToFailedIfNeededAndThrow(Level.WARN, String.format("Scaling Kubernetes cluster : %s failed, scaling Kubernetes cluster with running VMs on hypervisor %s is not supported!", kubernetesCluster.getName(), vmInstance.getHypervisorType()));
            }
        }
    }
}
Also used : VMInstanceVO(com.cloud.vm.VMInstanceVO) 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