Search in sources :

Example 1 with KubernetesClusterStartWorker

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

the class KubernetesClusterManagerImpl method startKubernetesCluster.

/**
 * Start operation can be performed at two different life stages of Kubernetes cluster. First when a freshly created cluster
 * in which case there are no resources provisioned for the Kubernetes cluster. So during start all the resources
 * are provisioned from scratch. Second kind of start, happens on  Stopped Kubernetes cluster, in which all resources
 * are provisioned (like volumes, nics, networks etc). It just that VM's are not in running state. So just
 * start the VM's (which can possibly implicitly start the network also).
 * @param kubernetesClusterId
 * @param onCreate
 * @return
 * @throws CloudRuntimeException
 */
@Override
public boolean startKubernetesCluster(long kubernetesClusterId, boolean onCreate) throws CloudRuntimeException {
    if (!KubernetesServiceEnabled.value()) {
        logAndThrow(Level.ERROR, "Kubernetes Service plugin is disabled");
    }
    final KubernetesClusterVO kubernetesCluster = kubernetesClusterDao.findById(kubernetesClusterId);
    if (kubernetesCluster == null) {
        throw new InvalidParameterValueException("Failed to find Kubernetes cluster with given ID");
    }
    if (kubernetesCluster.getRemoved() != null) {
        throw new InvalidParameterValueException(String.format("Kubernetes cluster : %s is already deleted", kubernetesCluster.getName()));
    }
    accountManager.checkAccess(CallContext.current().getCallingAccount(), SecurityChecker.AccessType.OperateEntry, false, kubernetesCluster);
    if (kubernetesCluster.getState().equals(KubernetesCluster.State.Running)) {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug(String.format("Kubernetes cluster : %s is in running state", kubernetesCluster.getName()));
        }
        return true;
    }
    if (kubernetesCluster.getState().equals(KubernetesCluster.State.Starting)) {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug(String.format("Kubernetes cluster : %s is already in starting state", kubernetesCluster.getName()));
        }
        return true;
    }
    final DataCenter zone = dataCenterDao.findById(kubernetesCluster.getZoneId());
    if (zone == null) {
        logAndThrow(Level.WARN, String.format("Unable to find zone for Kubernetes cluster : %s", kubernetesCluster.getName()));
    }
    KubernetesClusterStartWorker startWorker = new KubernetesClusterStartWorker(kubernetesCluster, this);
    startWorker = ComponentContext.inject(startWorker);
    if (onCreate) {
        // Start for Kubernetes cluster in 'Created' state
        Account owner = accountService.getActiveAccountById(kubernetesCluster.getAccountId());
        String[] keys = getServiceUserKeys(owner);
        startWorker.setKeys(keys);
        return startWorker.startKubernetesClusterOnCreate();
    } else {
        // Start for Kubernetes cluster in 'Stopped' state. Resources are already provisioned, just need to be started
        return startWorker.startStoppedKubernetesCluster();
    }
}
Also used : UserAccount(com.cloud.user.UserAccount) Account(com.cloud.user.Account) DataCenter(com.cloud.dc.DataCenter) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) KubernetesClusterStartWorker(com.cloud.kubernetes.cluster.actionworkers.KubernetesClusterStartWorker)

Aggregations

DataCenter (com.cloud.dc.DataCenter)1 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 KubernetesClusterStartWorker (com.cloud.kubernetes.cluster.actionworkers.KubernetesClusterStartWorker)1 Account (com.cloud.user.Account)1 UserAccount (com.cloud.user.UserAccount)1