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;
}
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;
}
}
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);
}
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;
}
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()));
}
}
}
}
Aggregations