Search in sources :

Example 6 with KubernetesSupportedVersion

use of com.cloud.kubernetes.version.KubernetesSupportedVersion in project cloudstack by apache.

the class KubernetesClusterManagerImpl method createKubernetesCluster.

@Override
public KubernetesCluster createKubernetesCluster(CreateKubernetesClusterCmd cmd) throws CloudRuntimeException {
    if (!KubernetesServiceEnabled.value()) {
        logAndThrow(Level.ERROR, "Kubernetes Service plugin is disabled");
    }
    validateKubernetesClusterCreateParameters(cmd);
    final DataCenter zone = dataCenterDao.findById(cmd.getZoneId());
    final long controlNodeCount = cmd.getControlNodes();
    final long clusterSize = cmd.getClusterSize();
    final long totalNodeCount = controlNodeCount + clusterSize;
    final ServiceOffering serviceOffering = serviceOfferingDao.findById(cmd.getServiceOfferingId());
    final Account owner = accountService.getActiveAccountById(cmd.getEntityOwnerId());
    final KubernetesSupportedVersion clusterKubernetesVersion = kubernetesSupportedVersionDao.findById(cmd.getKubernetesVersionId());
    DeployDestination deployDestination = null;
    try {
        deployDestination = plan(totalNodeCount, zone, serviceOffering);
    } catch (InsufficientCapacityException e) {
        logAndThrow(Level.ERROR, String.format("Creating Kubernetes cluster failed due to insufficient capacity for %d nodes cluster in zone : %s with service offering : %s", totalNodeCount, zone.getName(), serviceOffering.getName()));
    }
    if (deployDestination == null || deployDestination.getCluster() == null) {
        logAndThrow(Level.ERROR, String.format("Creating Kubernetes cluster failed due to error while finding suitable deployment plan for cluster in zone : %s", zone.getName()));
    }
    final Network defaultNetwork = getKubernetesClusterNetworkIfMissing(cmd.getName(), zone, owner, (int) controlNodeCount, (int) clusterSize, cmd.getExternalLoadBalancerIpAddress(), cmd.getNetworkId());
    final VMTemplateVO finalTemplate = getKubernetesServiceTemplate(zone, deployDestination.getCluster().getHypervisorType());
    final long cores = serviceOffering.getCpu() * (controlNodeCount + clusterSize);
    final long memory = serviceOffering.getRamSize() * (controlNodeCount + clusterSize);
    final KubernetesClusterVO cluster = Transaction.execute(new TransactionCallback<KubernetesClusterVO>() {

        @Override
        public KubernetesClusterVO doInTransaction(TransactionStatus status) {
            KubernetesClusterVO newCluster = new KubernetesClusterVO(cmd.getName(), cmd.getDisplayName(), zone.getId(), clusterKubernetesVersion.getId(), serviceOffering.getId(), finalTemplate.getId(), defaultNetwork.getId(), owner.getDomainId(), owner.getAccountId(), controlNodeCount, clusterSize, KubernetesCluster.State.Created, cmd.getSSHKeyPairName(), cores, memory, cmd.getNodeRootDiskSize(), "");
            kubernetesClusterDao.persist(newCluster);
            return newCluster;
        }
    });
    addKubernetesClusterDetails(cluster, defaultNetwork, cmd);
    if (LOGGER.isInfoEnabled()) {
        LOGGER.info(String.format("Kubernetes cluster name: %s and ID: %s has been created", cluster.getName(), cluster.getUuid()));
    }
    return cluster;
}
Also used : KubernetesSupportedVersion(com.cloud.kubernetes.version.KubernetesSupportedVersion) UserAccount(com.cloud.user.UserAccount) Account(com.cloud.user.Account) ServiceOffering(com.cloud.offering.ServiceOffering) VMTemplateVO(com.cloud.storage.VMTemplateVO) TransactionStatus(com.cloud.utils.db.TransactionStatus) DataCenter(com.cloud.dc.DataCenter) DeployDestination(com.cloud.deploy.DeployDestination) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException)

Aggregations

KubernetesSupportedVersion (com.cloud.kubernetes.version.KubernetesSupportedVersion)6 VMTemplateVO (com.cloud.storage.VMTemplateVO)4 DataCenter (com.cloud.dc.DataCenter)3 Network (com.cloud.network.Network)3 PhysicalNetwork (com.cloud.network.PhysicalNetwork)3 ServiceOffering (com.cloud.offering.ServiceOffering)3 Account (com.cloud.user.Account)3 UserAccount (com.cloud.user.UserAccount)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 DeployDestination (com.cloud.deploy.DeployDestination)2 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)2 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)2 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)2 SSHKeyPairVO (com.cloud.user.SSHKeyPairVO)2 ApiDBUtils (com.cloud.api.ApiDBUtils)1 NetworkOfferingJoinDao (com.cloud.api.query.dao.NetworkOfferingJoinDao)1 TemplateJoinDao (com.cloud.api.query.dao.TemplateJoinDao)1 UserVmJoinDao (com.cloud.api.query.dao.UserVmJoinDao)1 NetworkOfferingJoinVO (com.cloud.api.query.vo.NetworkOfferingJoinVO)1 UserVmJoinVO (com.cloud.api.query.vo.UserVmJoinVO)1