Search in sources :

Example 6 with KubernetesClusterVO

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

the class KubernetesClusterUpgradeWorker method upgradeCluster.

public boolean upgradeCluster() throws CloudRuntimeException {
    init();
    if (LOGGER.isInfoEnabled()) {
        LOGGER.info(String.format("Upgrading Kubernetes cluster : %s", kubernetesCluster.getName()));
    }
    upgradeTimeoutTime = System.currentTimeMillis() + KubernetesClusterService.KubernetesClusterUpgradeTimeout.value() * 1000;
    Pair<String, Integer> publicIpSshPort = getKubernetesClusterServerIpSshPort(null);
    publicIpAddress = publicIpSshPort.first();
    sshPort = publicIpSshPort.second();
    if (StringUtils.isEmpty(publicIpAddress)) {
        logAndThrow(Level.ERROR, String.format("Upgrade failed for Kubernetes cluster : %s, unable to retrieve associated public IP", kubernetesCluster.getName()));
    }
    clusterVMs = getKubernetesClusterVMs();
    if (CollectionUtils.isEmpty(clusterVMs)) {
        logAndThrow(Level.ERROR, String.format("Upgrade failed for Kubernetes cluster : %s, unable to retrieve VMs for cluster", kubernetesCluster.getName()));
    }
    retrieveScriptFiles();
    stateTransitTo(kubernetesCluster.getId(), KubernetesCluster.Event.UpgradeRequested);
    attachIsoKubernetesVMs(clusterVMs, upgradeVersion);
    upgradeKubernetesClusterNodes();
    detachIsoKubernetesVMs(clusterVMs);
    KubernetesClusterVO kubernetesClusterVO = kubernetesClusterDao.findById(kubernetesCluster.getId());
    kubernetesClusterVO.setKubernetesVersionId(upgradeVersion.getId());
    boolean updated = kubernetesClusterDao.update(kubernetesCluster.getId(), kubernetesClusterVO);
    if (!updated) {
        stateTransitTo(kubernetesCluster.getId(), KubernetesCluster.Event.OperationFailed);
    } else {
        stateTransitTo(kubernetesCluster.getId(), KubernetesCluster.Event.OperationSucceeded);
    }
    return updated;
}
Also used : KubernetesClusterVO(com.cloud.kubernetes.cluster.KubernetesClusterVO)

Example 7 with KubernetesClusterVO

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

the class KubernetesClusterDaoImpl method updateState.

@Override
public boolean updateState(KubernetesCluster.State currentState, KubernetesCluster.Event event, KubernetesCluster.State nextState, KubernetesCluster vo, Object data) {
    // TODO: ensure this update is correct
    TransactionLegacy txn = TransactionLegacy.currentTxn();
    txn.start();
    KubernetesClusterVO ccVo = (KubernetesClusterVO) vo;
    ccVo.setState(nextState);
    super.update(ccVo.getId(), ccVo);
    txn.commit();
    return true;
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) KubernetesClusterVO(com.cloud.kubernetes.cluster.KubernetesClusterVO)

Example 8 with KubernetesClusterVO

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

the class KubernetesClusterStartWorker method updateKubernetesClusterEntryEndpoint.

private void updateKubernetesClusterEntryEndpoint() {
    KubernetesClusterVO kubernetesClusterVO = kubernetesClusterDao.findById(kubernetesCluster.getId());
    kubernetesClusterVO.setEndpoint(String.format("https://%s:%d/", publicIpAddress, CLUSTER_API_PORT));
    kubernetesClusterDao.update(kubernetesCluster.getId(), kubernetesClusterVO);
}
Also used : KubernetesClusterVO(com.cloud.kubernetes.cluster.KubernetesClusterVO)

Example 9 with KubernetesClusterVO

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

the class KubernetesClusterScaleWorker method scaleUpKubernetesClusterSize.

private void scaleUpKubernetesClusterSize(final long newVmCount) throws CloudRuntimeException {
    if (!kubernetesCluster.getState().equals(KubernetesCluster.State.Scaling)) {
        stateTransitTo(kubernetesCluster.getId(), KubernetesCluster.Event.ScaleUpRequested);
    }
    List<UserVm> clusterVMs = new ArrayList<>();
    LaunchPermissionVO launchPermission = new LaunchPermissionVO(clusterTemplate.getId(), owner.getId());
    launchPermissionDao.persist(launchPermission);
    try {
        clusterVMs = provisionKubernetesClusterNodeVms((int) (newVmCount + kubernetesCluster.getNodeCount()), (int) kubernetesCluster.getNodeCount(), publicIpAddress);
        updateLoginUserDetails(clusterVMs.stream().map(InternalIdentity::getId).collect(Collectors.toList()));
    } catch (CloudRuntimeException | ManagementServerException | ResourceUnavailableException | InsufficientCapacityException e) {
        logTransitStateToFailedIfNeededAndThrow(Level.ERROR, String.format("Scaling failed for Kubernetes cluster : %s, unable to provision node VM in the cluster", kubernetesCluster.getName()), e);
    }
    try {
        List<Long> clusterVMIds = getKubernetesClusterVMMaps().stream().map(KubernetesClusterVmMapVO::getVmId).collect(Collectors.toList());
        scaleKubernetesClusterNetworkRules(clusterVMIds);
    } catch (ManagementServerException e) {
        logTransitStateToFailedIfNeededAndThrow(Level.ERROR, String.format("Scaling failed for Kubernetes cluster : %s, unable to update network rules", kubernetesCluster.getName()), e);
    }
    attachIsoKubernetesVMs(clusterVMs);
    KubernetesClusterVO kubernetesClusterVO = kubernetesClusterDao.findById(kubernetesCluster.getId());
    kubernetesClusterVO.setNodeCount(clusterSize);
    boolean readyNodesCountValid = KubernetesClusterUtil.validateKubernetesClusterReadyNodesCount(kubernetesClusterVO, publicIpAddress, sshPort, getControlNodeLoginUser(), sshKeyFile, scaleTimeoutTime, 15000);
    detachIsoKubernetesVMs(clusterVMs);
    deleteTemplateLaunchPermission();
    if (!readyNodesCountValid) {
        // Scaling failed
        logTransitStateToFailedIfNeededAndThrow(Level.ERROR, String.format("Scaling unsuccessful for Kubernetes cluster : %s as it does not have desired number of nodes in ready state", kubernetesCluster.getName()));
    }
}
Also used : ArrayList(java.util.ArrayList) KubernetesClusterVO(com.cloud.kubernetes.cluster.KubernetesClusterVO) LaunchPermissionVO(com.cloud.storage.LaunchPermissionVO) UserVm(com.cloud.uservm.UserVm) ManagementServerException(com.cloud.exception.ManagementServerException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) InternalIdentity(org.apache.cloudstack.api.InternalIdentity)

Aggregations

KubernetesClusterVO (com.cloud.kubernetes.cluster.KubernetesClusterVO)9 ArrayList (java.util.ArrayList)3 VMTemplateVO (com.cloud.storage.VMTemplateVO)2 AccountVO (com.cloud.user.AccountVO)2 UserVO (com.cloud.user.UserVO)2 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 DeleteKubernetesSupportedVersionCmd (org.apache.cloudstack.api.command.admin.kubernetes.version.DeleteKubernetesSupportedVersionCmd)2 Test (org.junit.Test)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 ActionEvent (com.cloud.event.ActionEvent)1 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)1 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 ManagementServerException (com.cloud.exception.ManagementServerException)1 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)1 ServiceOffering (com.cloud.offering.ServiceOffering)1 LaunchPermissionVO (com.cloud.storage.LaunchPermissionVO)1 UserVm (com.cloud.uservm.UserVm)1 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)1 InternalIdentity (org.apache.cloudstack.api.InternalIdentity)1 DeleteIsoCmd (org.apache.cloudstack.api.command.user.iso.DeleteIsoCmd)1