mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
cks: assorted bug fixes (#4116)
Fixes #4056 Fixes #4107 Fixes #4113 Fixes #4133 Fixes deployment, template and network deletion. Also allows filetering in listKubernetesSupportedVersions with keyword Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
This commit is contained in:
parent
407e34d4e7
commit
a7f56d41c8
@ -36,7 +36,7 @@ public interface VMTemplateDao extends GenericDao<VMTemplateVO, Long>, StateDao<
|
|||||||
|
|
||||||
public VMTemplateVO findByTemplateName(String templateName);
|
public VMTemplateVO findByTemplateName(String templateName);
|
||||||
|
|
||||||
// public void update(VMTemplateVO template);
|
public VMTemplateVO findValidByTemplateName(String templateName);
|
||||||
|
|
||||||
public List<VMTemplateVO> listAllSystemVMTemplates();
|
public List<VMTemplateVO> listAllSystemVMTemplates();
|
||||||
|
|
||||||
|
|||||||
@ -136,6 +136,13 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
|
|||||||
return findOneIncludingRemovedBy(sc);
|
return findOneIncludingRemovedBy(sc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VMTemplateVO findValidByTemplateName(String templateName) {
|
||||||
|
SearchCriteria<VMTemplateVO> sc = NameSearch.create();
|
||||||
|
sc.setParameters("name", templateName);
|
||||||
|
return findOneBy(sc);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<VMTemplateVO> listByParentTemplatetId(long parentTemplatetId) {
|
public List<VMTemplateVO> listByParentTemplatetId(long parentTemplatetId) {
|
||||||
SearchCriteria<VMTemplateVO> sc = ParentTemplateIdSearch.create();
|
SearchCriteria<VMTemplateVO> sc = ParentTemplateIdSearch.create();
|
||||||
|
|||||||
@ -51,7 +51,6 @@ import org.apache.cloudstack.api.response.KubernetesClusterResponse;
|
|||||||
import org.apache.cloudstack.api.response.ListResponse;
|
import org.apache.cloudstack.api.response.ListResponse;
|
||||||
import org.apache.cloudstack.context.CallContext;
|
import org.apache.cloudstack.context.CallContext;
|
||||||
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
|
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
|
||||||
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
|
|
||||||
import org.apache.cloudstack.framework.config.ConfigKey;
|
import org.apache.cloudstack.framework.config.ConfigKey;
|
||||||
import org.apache.cloudstack.managed.context.ManagedContextRunnable;
|
import org.apache.cloudstack.managed.context.ManagedContextRunnable;
|
||||||
import org.apache.commons.codec.binary.Base64;
|
import org.apache.commons.codec.binary.Base64;
|
||||||
@ -63,7 +62,6 @@ import com.cloud.api.ApiDBUtils;
|
|||||||
import com.cloud.api.query.dao.NetworkOfferingJoinDao;
|
import com.cloud.api.query.dao.NetworkOfferingJoinDao;
|
||||||
import com.cloud.api.query.dao.TemplateJoinDao;
|
import com.cloud.api.query.dao.TemplateJoinDao;
|
||||||
import com.cloud.api.query.vo.NetworkOfferingJoinVO;
|
import com.cloud.api.query.vo.NetworkOfferingJoinVO;
|
||||||
import com.cloud.api.query.vo.TemplateJoinVO;
|
|
||||||
import com.cloud.capacity.CapacityManager;
|
import com.cloud.capacity.CapacityManager;
|
||||||
import com.cloud.dc.ClusterDetailsDao;
|
import com.cloud.dc.ClusterDetailsDao;
|
||||||
import com.cloud.dc.ClusterDetailsVO;
|
import com.cloud.dc.ClusterDetailsVO;
|
||||||
@ -82,6 +80,7 @@ import com.cloud.exception.PermissionDeniedException;
|
|||||||
import com.cloud.exception.ResourceAllocationException;
|
import com.cloud.exception.ResourceAllocationException;
|
||||||
import com.cloud.host.Host.Type;
|
import com.cloud.host.Host.Type;
|
||||||
import com.cloud.host.HostVO;
|
import com.cloud.host.HostVO;
|
||||||
|
import com.cloud.host.dao.HostDao;
|
||||||
import com.cloud.hypervisor.Hypervisor;
|
import com.cloud.hypervisor.Hypervisor;
|
||||||
import com.cloud.kubernetes.cluster.actionworkers.KubernetesClusterActionWorker;
|
import com.cloud.kubernetes.cluster.actionworkers.KubernetesClusterActionWorker;
|
||||||
import com.cloud.kubernetes.cluster.actionworkers.KubernetesClusterDestroyWorker;
|
import com.cloud.kubernetes.cluster.actionworkers.KubernetesClusterDestroyWorker;
|
||||||
@ -122,9 +121,7 @@ import com.cloud.resource.ResourceManager;
|
|||||||
import com.cloud.service.ServiceOfferingVO;
|
import com.cloud.service.ServiceOfferingVO;
|
||||||
import com.cloud.service.dao.ServiceOfferingDao;
|
import com.cloud.service.dao.ServiceOfferingDao;
|
||||||
import com.cloud.storage.VMTemplateVO;
|
import com.cloud.storage.VMTemplateVO;
|
||||||
import com.cloud.storage.VMTemplateZoneVO;
|
|
||||||
import com.cloud.storage.dao.VMTemplateDao;
|
import com.cloud.storage.dao.VMTemplateDao;
|
||||||
import com.cloud.storage.dao.VMTemplateZoneDao;
|
|
||||||
import com.cloud.user.Account;
|
import com.cloud.user.Account;
|
||||||
import com.cloud.user.AccountManager;
|
import com.cloud.user.AccountManager;
|
||||||
import com.cloud.user.AccountService;
|
import com.cloud.user.AccountService;
|
||||||
@ -181,12 +178,12 @@ public class KubernetesClusterManagerImpl extends ManagerBase implements Kuberne
|
|||||||
@Inject
|
@Inject
|
||||||
protected ClusterDetailsDao clusterDetailsDao;
|
protected ClusterDetailsDao clusterDetailsDao;
|
||||||
@Inject
|
@Inject
|
||||||
|
protected HostDao hostDao;
|
||||||
|
@Inject
|
||||||
protected ServiceOfferingDao serviceOfferingDao;
|
protected ServiceOfferingDao serviceOfferingDao;
|
||||||
@Inject
|
@Inject
|
||||||
protected VMTemplateDao templateDao;
|
protected VMTemplateDao templateDao;
|
||||||
@Inject
|
@Inject
|
||||||
protected VMTemplateZoneDao templateZoneDao;
|
|
||||||
@Inject
|
|
||||||
protected TemplateJoinDao templateJoinDao;
|
protected TemplateJoinDao templateJoinDao;
|
||||||
@Inject
|
@Inject
|
||||||
protected AccountService accountService;
|
protected AccountService accountService;
|
||||||
@ -300,8 +297,7 @@ public class KubernetesClusterManagerImpl extends ManagerBase implements Kuberne
|
|||||||
LOGGER.warn(String.format("Unable to find the template %s to be used for provisioning Kubernetes cluster nodes", templateName));
|
LOGGER.warn(String.format("Unable to find the template %s to be used for provisioning Kubernetes cluster nodes", templateName));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
List<VMTemplateZoneVO> listZoneTemplate = templateZoneDao.listByZoneTemplate(zone.getId(), template.getId());
|
if (CollectionUtils.isEmpty(templateJoinDao.newTemplateView(template, zone.getId(), true))) {
|
||||||
if (listZoneTemplate == null || listZoneTemplate.isEmpty()) {
|
|
||||||
LOGGER.warn(String.format("The template ID: %s, name: %s is not available for use in zone ID: %s provisioning Kubernetes cluster nodes", template.getUuid(), templateName, zone.getUuid()));
|
LOGGER.warn(String.format("The template ID: %s, name: %s is not available for use in zone ID: %s provisioning Kubernetes cluster nodes", template.getUuid(), templateName, zone.getUuid()));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -394,7 +390,7 @@ public class KubernetesClusterManagerImpl extends ManagerBase implements Kuberne
|
|||||||
tempalteName = KubernetesClusterXenserverTemplateName.value();
|
tempalteName = KubernetesClusterXenserverTemplateName.value();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return templateDao.findByTemplateName(tempalteName);
|
return templateDao.findValidByTemplateName(tempalteName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean validateIsolatedNetwork(Network network, int clusterTotalNodeCount) {
|
private boolean validateIsolatedNetwork(Network network, int clusterTotalNodeCount) {
|
||||||
@ -523,6 +519,10 @@ public class KubernetesClusterManagerImpl extends ManagerBase implements Kuberne
|
|||||||
for (Map.Entry<String, Pair<HostVO, Integer>> hostEntry : hosts_with_resevered_capacity.entrySet()) {
|
for (Map.Entry<String, Pair<HostVO, Integer>> hostEntry : hosts_with_resevered_capacity.entrySet()) {
|
||||||
Pair<HostVO, Integer> hp = hostEntry.getValue();
|
Pair<HostVO, Integer> hp = hostEntry.getValue();
|
||||||
HostVO h = hp.first();
|
HostVO h = hp.first();
|
||||||
|
hostDao.loadHostTags(h);
|
||||||
|
if (!Strings.isNullOrEmpty(offering.getHostTag()) && !(h.getHostTags() != null && h.getHostTags().contains(offering.getHostTag()))) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
int reserved = hp.second();
|
int reserved = hp.second();
|
||||||
reserved++;
|
reserved++;
|
||||||
ClusterVO cluster = clusterDao.findById(h.getClusterId());
|
ClusterVO cluster = clusterDao.findById(h.getClusterId());
|
||||||
@ -545,7 +545,7 @@ public class KubernetesClusterManagerImpl extends ManagerBase implements Kuberne
|
|||||||
}
|
}
|
||||||
if (!suitable_host_found) {
|
if (!suitable_host_found) {
|
||||||
if (LOGGER.isInfoEnabled()) {
|
if (LOGGER.isInfoEnabled()) {
|
||||||
LOGGER.info(String.format("Suitable hosts not found in datacenter ID: %s for node %d", zone.getUuid(), i));
|
LOGGER.info(String.format("Suitable hosts not found in datacenter ID: %s for node %d with offering ID: %s", zone.getUuid(), i, offering.getUuid()));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -556,8 +556,8 @@ public class KubernetesClusterManagerImpl extends ManagerBase implements Kuberne
|
|||||||
}
|
}
|
||||||
return new DeployDestination(zone, null, planCluster, null);
|
return new DeployDestination(zone, null, planCluster, null);
|
||||||
}
|
}
|
||||||
String msg = String.format("Cannot find enough capacity for Kubernetes cluster(requested cpu=%1$s memory=%2$s)",
|
String msg = String.format("Cannot find enough capacity for Kubernetes cluster(requested cpu=%d memory=%d) with offering ID: %s",
|
||||||
cpu_requested * nodesCount, ram_requested * nodesCount);
|
cpu_requested * nodesCount, ram_requested * nodesCount, offering.getUuid());
|
||||||
LOGGER.warn(msg);
|
LOGGER.warn(msg);
|
||||||
throw new InsufficientServerCapacityException(msg, DataCenter.class, zone.getId());
|
throw new InsufficientServerCapacityException(msg, DataCenter.class, zone.getId());
|
||||||
}
|
}
|
||||||
@ -684,12 +684,12 @@ public class KubernetesClusterManagerImpl extends ManagerBase implements Kuberne
|
|||||||
throw new InvalidParameterValueException(String.format("Kubernetes version ID: %s is not available for zone ID: %s", clusterKubernetesVersion.getUuid(), zone.getUuid()));
|
throw new InvalidParameterValueException(String.format("Kubernetes version ID: %s is not available for zone ID: %s", clusterKubernetesVersion.getUuid(), zone.getUuid()));
|
||||||
}
|
}
|
||||||
|
|
||||||
TemplateJoinVO iso = templateJoinDao.findById(clusterKubernetesVersion.getIsoId());
|
VMTemplateVO iso = templateDao.findById(clusterKubernetesVersion.getIsoId());
|
||||||
if (iso == null) {
|
if (iso == null) {
|
||||||
throw new InvalidParameterValueException(String.format("Invalid ISO associated with version ID: %s", clusterKubernetesVersion.getUuid()));
|
throw new InvalidParameterValueException(String.format("Invalid ISO associated with version ID: %s", clusterKubernetesVersion.getUuid()));
|
||||||
}
|
}
|
||||||
if (!ObjectInDataStoreStateMachine.State.Ready.equals(iso.getState())) {
|
if (CollectionUtils.isEmpty(templateJoinDao.newTemplateView(iso, zone.getId(), true))) {
|
||||||
throw new InvalidParameterValueException(String.format("ISO associated with version ID: %s is not in Ready state", clusterKubernetesVersion.getUuid()));
|
throw new InvalidParameterValueException(String.format("ISO associated with version ID: %s is not in Ready state for datacenter ID: %s", clusterKubernetesVersion.getUuid(), zone.getUuid()));
|
||||||
}
|
}
|
||||||
|
|
||||||
ServiceOffering serviceOffering = serviceOfferingDao.findById(serviceOfferingId);
|
ServiceOffering serviceOffering = serviceOfferingDao.findById(serviceOfferingId);
|
||||||
@ -887,6 +887,15 @@ public class KubernetesClusterManagerImpl extends ManagerBase implements Kuberne
|
|||||||
if (clusterSize < 1) {
|
if (clusterSize < 1) {
|
||||||
throw new InvalidParameterValueException(String.format("Kubernetes cluster ID: %s cannot be scaled for size, %d", kubernetesCluster.getUuid(), clusterSize));
|
throw new InvalidParameterValueException(String.format("Kubernetes cluster ID: %s cannot be scaled for size, %d", kubernetesCluster.getUuid(), clusterSize));
|
||||||
}
|
}
|
||||||
|
if (clusterSize > kubernetesCluster.getNodeCount()) { // Upscale
|
||||||
|
VMTemplateVO template = templateDao.findById(kubernetesCluster.getTemplateId());
|
||||||
|
if (template == null) {
|
||||||
|
throw new InvalidParameterValueException(String.format("Invalid template associated with Kubernetes cluster ID: %s", kubernetesCluster.getUuid()));
|
||||||
|
}
|
||||||
|
if (CollectionUtils.isEmpty(templateJoinDao.newTemplateView(template, zone.getId(), true))) {
|
||||||
|
throw new InvalidParameterValueException(String.format("Template ID: %s associated with Kubernetes cluster ID: %s is not in Ready state for datacenter ID: %s", template.getUuid(), kubernetesCluster.getUuid(), zone.getUuid()));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -908,6 +917,10 @@ public class KubernetesClusterManagerImpl extends ManagerBase implements Kuberne
|
|||||||
if (!KubernetesCluster.State.Running.equals(kubernetesCluster.getState())) {
|
if (!KubernetesCluster.State.Running.equals(kubernetesCluster.getState())) {
|
||||||
throw new InvalidParameterValueException(String.format("Kubernetes cluster ID: %s is not in running state", kubernetesCluster.getUuid()));
|
throw new InvalidParameterValueException(String.format("Kubernetes cluster ID: %s is not in running state", kubernetesCluster.getUuid()));
|
||||||
}
|
}
|
||||||
|
final DataCenter zone = dataCenterDao.findById(kubernetesCluster.getZoneId());
|
||||||
|
if (zone == null) {
|
||||||
|
logAndThrow(Level.WARN, String.format("Unable to find zone for Kubernetes cluster ID: %s", kubernetesCluster.getUuid()));
|
||||||
|
}
|
||||||
KubernetesSupportedVersionVO upgradeVersion = kubernetesSupportedVersionDao.findById(upgradeVersionId);
|
KubernetesSupportedVersionVO upgradeVersion = kubernetesSupportedVersionDao.findById(upgradeVersionId);
|
||||||
if (upgradeVersion == null || upgradeVersion.getRemoved() != null) {
|
if (upgradeVersion == null || upgradeVersion.getRemoved() != null) {
|
||||||
throw new InvalidParameterValueException("Invalid Kubernetes version ID");
|
throw new InvalidParameterValueException("Invalid Kubernetes version ID");
|
||||||
@ -939,12 +952,12 @@ public class KubernetesClusterManagerImpl extends ManagerBase implements Kuberne
|
|||||||
throw new InvalidParameterValueException(e.getMessage());
|
throw new InvalidParameterValueException(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
TemplateJoinVO iso = templateJoinDao.findById(upgradeVersion.getIsoId());
|
VMTemplateVO iso = templateDao.findById(upgradeVersion.getIsoId());
|
||||||
if (iso == null) {
|
if (iso == null) {
|
||||||
throw new InvalidParameterValueException(String.format("Invalid ISO associated with version ID: %s", upgradeVersion.getUuid()));
|
throw new InvalidParameterValueException(String.format("Invalid ISO associated with version ID: %s", upgradeVersion.getUuid()));
|
||||||
}
|
}
|
||||||
if (!ObjectInDataStoreStateMachine.State.Ready.equals(iso.getState())) {
|
if (CollectionUtils.isEmpty(templateJoinDao.newTemplateView(iso, zone.getId(), true))) {
|
||||||
throw new InvalidParameterValueException(String.format("ISO associated with version ID: %s is not in Ready state", upgradeVersion.getUuid()));
|
throw new InvalidParameterValueException(String.format("ISO associated with version ID: %s is not in Ready state for datacenter ID: %s", upgradeVersion.getUuid(), zone.getUuid()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -122,6 +122,7 @@ public class KubernetesClusterActionWorker {
|
|||||||
|
|
||||||
protected KubernetesCluster kubernetesCluster;
|
protected KubernetesCluster kubernetesCluster;
|
||||||
protected Account owner;
|
protected Account owner;
|
||||||
|
protected VirtualMachineTemplate clusterTemplate;
|
||||||
protected File sshKeyFile;
|
protected File sshKeyFile;
|
||||||
protected String publicIpAddress;
|
protected String publicIpAddress;
|
||||||
protected int sshPort;
|
protected int sshPort;
|
||||||
@ -136,6 +137,7 @@ public class KubernetesClusterActionWorker {
|
|||||||
|
|
||||||
protected void init() {
|
protected void init() {
|
||||||
this.owner = accountDao.findById(kubernetesCluster.getAccountId());
|
this.owner = accountDao.findById(kubernetesCluster.getAccountId());
|
||||||
|
this.clusterTemplate = templateDao.findById(kubernetesCluster.getTemplateId());
|
||||||
this.sshKeyFile = getManagementServerSshPublicKeyFile();
|
this.sshKeyFile = getManagementServerSshPublicKeyFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -37,7 +37,6 @@ import com.cloud.kubernetes.cluster.KubernetesClusterVO;
|
|||||||
import com.cloud.kubernetes.cluster.KubernetesClusterVmMap;
|
import com.cloud.kubernetes.cluster.KubernetesClusterVmMap;
|
||||||
import com.cloud.kubernetes.cluster.KubernetesClusterVmMapVO;
|
import com.cloud.kubernetes.cluster.KubernetesClusterVmMapVO;
|
||||||
import com.cloud.network.IpAddress;
|
import com.cloud.network.IpAddress;
|
||||||
import com.cloud.network.Network;
|
|
||||||
import com.cloud.network.dao.NetworkVO;
|
import com.cloud.network.dao.NetworkVO;
|
||||||
import com.cloud.network.rules.FirewallRule;
|
import com.cloud.network.rules.FirewallRule;
|
||||||
import com.cloud.user.Account;
|
import com.cloud.user.Account;
|
||||||
@ -48,6 +47,8 @@ import com.cloud.utils.exception.CloudRuntimeException;
|
|||||||
import com.cloud.vm.ReservationContext;
|
import com.cloud.vm.ReservationContext;
|
||||||
import com.cloud.vm.ReservationContextImpl;
|
import com.cloud.vm.ReservationContextImpl;
|
||||||
import com.cloud.vm.UserVmVO;
|
import com.cloud.vm.UserVmVO;
|
||||||
|
import com.cloud.vm.VMInstanceVO;
|
||||||
|
import com.cloud.vm.VirtualMachine;
|
||||||
|
|
||||||
public class KubernetesClusterDestroyWorker extends KubernetesClusterResourceModifierActionWorker {
|
public class KubernetesClusterDestroyWorker extends KubernetesClusterResourceModifierActionWorker {
|
||||||
|
|
||||||
@ -129,7 +130,7 @@ public class KubernetesClusterDestroyWorker extends KubernetesClusterResourceMod
|
|||||||
|
|
||||||
private void deleteKubernetesClusterNetworkRules() throws ManagementServerException {
|
private void deleteKubernetesClusterNetworkRules() throws ManagementServerException {
|
||||||
NetworkVO network = networkDao.findById(kubernetesCluster.getNetworkId());
|
NetworkVO network = networkDao.findById(kubernetesCluster.getNetworkId());
|
||||||
if (network == null || !Network.GuestType.Isolated.equals(network.getGuestType())) {
|
if (network == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
List<Long> removedVmIds = new ArrayList<>();
|
List<Long> removedVmIds = new ArrayList<>();
|
||||||
@ -189,17 +190,39 @@ public class KubernetesClusterDestroyWorker extends KubernetesClusterResourceMod
|
|||||||
public boolean destroy() throws CloudRuntimeException {
|
public boolean destroy() throws CloudRuntimeException {
|
||||||
init();
|
init();
|
||||||
validateClusterSate();
|
validateClusterSate();
|
||||||
if (LOGGER.isInfoEnabled()) {
|
|
||||||
LOGGER.info(String.format("Destroying Kubernetes cluster ID: %s", kubernetesCluster.getUuid()));
|
|
||||||
}
|
|
||||||
stateTransitTo(kubernetesCluster.getId(), KubernetesCluster.Event.DestroyRequested);
|
|
||||||
this.clusterVMs = kubernetesClusterVmMapDao.listByClusterId(kubernetesCluster.getId());
|
this.clusterVMs = kubernetesClusterVmMapDao.listByClusterId(kubernetesCluster.getId());
|
||||||
boolean vmsDestroyed = destroyClusterVMs();
|
|
||||||
boolean cleanupNetwork = true;
|
boolean cleanupNetwork = true;
|
||||||
final KubernetesClusterDetailsVO clusterDetails = kubernetesClusterDetailsDao.findDetail(kubernetesCluster.getId(), "networkCleanup");
|
final KubernetesClusterDetailsVO clusterDetails = kubernetesClusterDetailsDao.findDetail(kubernetesCluster.getId(), "networkCleanup");
|
||||||
if (clusterDetails != null) {
|
if (clusterDetails != null) {
|
||||||
cleanupNetwork = Boolean.parseBoolean(clusterDetails.getValue());
|
cleanupNetwork = Boolean.parseBoolean(clusterDetails.getValue());
|
||||||
}
|
}
|
||||||
|
if (cleanupNetwork) { // if network has additional VM, cannot proceed with cluster destroy
|
||||||
|
NetworkVO network = networkDao.findById(kubernetesCluster.getNetworkId());
|
||||||
|
if (network == null) {
|
||||||
|
logAndThrow(Level.ERROR, String.format("Failed to find network for Kubernetes cluster ID: %s", kubernetesCluster.getUuid()));
|
||||||
|
}
|
||||||
|
List<VMInstanceVO> networkVMs = vmInstanceDao.listNonRemovedVmsByTypeAndNetwork(network.getId(), VirtualMachine.Type.User);
|
||||||
|
if (networkVMs.size() > clusterVMs.size()) {
|
||||||
|
logAndThrow(Level.ERROR, String.format("Network ID: %s for Kubernetes cluster ID: %s has instances using it which are not part of the Kubernetes cluster", network.getUuid(), kubernetesCluster.getUuid()));
|
||||||
|
}
|
||||||
|
for (VMInstanceVO vm : networkVMs) {
|
||||||
|
boolean vmFoundInKubernetesCluster = false;
|
||||||
|
for (KubernetesClusterVmMap clusterVM : clusterVMs) {
|
||||||
|
if (vm.getId() == clusterVM.getVmId()) {
|
||||||
|
vmFoundInKubernetesCluster = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!vmFoundInKubernetesCluster) {
|
||||||
|
logAndThrow(Level.ERROR, String.format("VM ID: %s which is not a part of Kubernetes cluster ID: %s is using Kubernetes cluster network ID: %s", vm.getUuid(), kubernetesCluster.getUuid(), network.getUuid()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (LOGGER.isInfoEnabled()) {
|
||||||
|
LOGGER.info(String.format("Destroying Kubernetes cluster ID: %s", kubernetesCluster.getUuid()));
|
||||||
|
}
|
||||||
|
stateTransitTo(kubernetesCluster.getId(), KubernetesCluster.Event.DestroyRequested);
|
||||||
|
boolean vmsDestroyed = destroyClusterVMs();
|
||||||
// if there are VM's that were not expunged, we can not delete the network
|
// if there are VM's that were not expunged, we can not delete the network
|
||||||
if (vmsDestroyed) {
|
if (vmsDestroyed) {
|
||||||
if (cleanupNetwork) {
|
if (cleanupNetwork) {
|
||||||
|
|||||||
@ -50,6 +50,7 @@ import com.cloud.exception.ResourceAllocationException;
|
|||||||
import com.cloud.exception.ResourceUnavailableException;
|
import com.cloud.exception.ResourceUnavailableException;
|
||||||
import com.cloud.host.Host;
|
import com.cloud.host.Host;
|
||||||
import com.cloud.host.HostVO;
|
import com.cloud.host.HostVO;
|
||||||
|
import com.cloud.host.dao.HostDao;
|
||||||
import com.cloud.hypervisor.Hypervisor;
|
import com.cloud.hypervisor.Hypervisor;
|
||||||
import com.cloud.kubernetes.cluster.KubernetesCluster;
|
import com.cloud.kubernetes.cluster.KubernetesCluster;
|
||||||
import com.cloud.kubernetes.cluster.KubernetesClusterDetailsVO;
|
import com.cloud.kubernetes.cluster.KubernetesClusterDetailsVO;
|
||||||
@ -69,7 +70,6 @@ import com.cloud.network.rules.RulesService;
|
|||||||
import com.cloud.network.rules.dao.PortForwardingRulesDao;
|
import com.cloud.network.rules.dao.PortForwardingRulesDao;
|
||||||
import com.cloud.offering.ServiceOffering;
|
import com.cloud.offering.ServiceOffering;
|
||||||
import com.cloud.resource.ResourceManager;
|
import com.cloud.resource.ResourceManager;
|
||||||
import com.cloud.template.VirtualMachineTemplate;
|
|
||||||
import com.cloud.user.Account;
|
import com.cloud.user.Account;
|
||||||
import com.cloud.user.SSHKeyPairVO;
|
import com.cloud.user.SSHKeyPairVO;
|
||||||
import com.cloud.uservm.UserVm;
|
import com.cloud.uservm.UserVm;
|
||||||
@ -97,6 +97,8 @@ public class KubernetesClusterResourceModifierActionWorker extends KubernetesClu
|
|||||||
@Inject
|
@Inject
|
||||||
protected ClusterDetailsDao clusterDetailsDao;
|
protected ClusterDetailsDao clusterDetailsDao;
|
||||||
@Inject
|
@Inject
|
||||||
|
protected HostDao hostDao;
|
||||||
|
@Inject
|
||||||
protected FirewallRulesDao firewallRulesDao;
|
protected FirewallRulesDao firewallRulesDao;
|
||||||
@Inject
|
@Inject
|
||||||
protected FirewallService firewallService;
|
protected FirewallService firewallService;
|
||||||
@ -208,6 +210,13 @@ public class KubernetesClusterResourceModifierActionWorker extends KubernetesClu
|
|||||||
for (Map.Entry<String, Pair<HostVO, Integer>> hostEntry : hosts_with_resevered_capacity.entrySet()) {
|
for (Map.Entry<String, Pair<HostVO, Integer>> hostEntry : hosts_with_resevered_capacity.entrySet()) {
|
||||||
Pair<HostVO, Integer> hp = hostEntry.getValue();
|
Pair<HostVO, Integer> hp = hostEntry.getValue();
|
||||||
HostVO h = hp.first();
|
HostVO h = hp.first();
|
||||||
|
if (!h.getHypervisorType().equals(clusterTemplate.getHypervisorType())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
hostDao.loadHostTags(h);
|
||||||
|
if (!Strings.isNullOrEmpty(offering.getHostTag()) && !(h.getHostTags() != null && h.getHostTags().contains(offering.getHostTag()))) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
int reserved = hp.second();
|
int reserved = hp.second();
|
||||||
reserved++;
|
reserved++;
|
||||||
ClusterVO cluster = clusterDao.findById(h.getClusterId());
|
ClusterVO cluster = clusterDao.findById(h.getClusterId());
|
||||||
@ -229,7 +238,7 @@ public class KubernetesClusterResourceModifierActionWorker extends KubernetesClu
|
|||||||
}
|
}
|
||||||
if (!suitable_host_found) {
|
if (!suitable_host_found) {
|
||||||
if (LOGGER.isInfoEnabled()) {
|
if (LOGGER.isInfoEnabled()) {
|
||||||
LOGGER.info(String.format("Suitable hosts not found in datacenter ID: %s for node %d", zone.getUuid(), i));
|
LOGGER.info(String.format("Suitable hosts not found in datacenter ID: %s for node %d, with offering ID: %s and hypervisor: %s", zone.getUuid(), i, offering.getUuid(), clusterTemplate.getHypervisorType().toString()));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -240,8 +249,8 @@ public class KubernetesClusterResourceModifierActionWorker extends KubernetesClu
|
|||||||
}
|
}
|
||||||
return new DeployDestination(zone, null, null, null);
|
return new DeployDestination(zone, null, null, null);
|
||||||
}
|
}
|
||||||
String msg = String.format("Cannot find enough capacity for Kubernetes cluster(requested cpu=%1$s memory=%2$s)",
|
String msg = String.format("Cannot find enough capacity for Kubernetes cluster(requested cpu=%d memory=%d) with offering ID: %s and hypervisor: %s",
|
||||||
cpu_requested * nodesCount, ram_requested * nodesCount);
|
cpu_requested * nodesCount, ram_requested * nodesCount, offering.getUuid(), clusterTemplate.getHypervisorType().toString());
|
||||||
LOGGER.warn(msg);
|
LOGGER.warn(msg);
|
||||||
throw new InsufficientServerCapacityException(msg, DataCenter.class, zone.getId());
|
throw new InsufficientServerCapacityException(msg, DataCenter.class, zone.getId());
|
||||||
}
|
}
|
||||||
@ -306,7 +315,6 @@ public class KubernetesClusterResourceModifierActionWorker extends KubernetesClu
|
|||||||
UserVm nodeVm = null;
|
UserVm nodeVm = null;
|
||||||
DataCenter zone = dataCenterDao.findById(kubernetesCluster.getZoneId());
|
DataCenter zone = dataCenterDao.findById(kubernetesCluster.getZoneId());
|
||||||
ServiceOffering serviceOffering = serviceOfferingDao.findById(kubernetesCluster.getServiceOfferingId());
|
ServiceOffering serviceOffering = serviceOfferingDao.findById(kubernetesCluster.getServiceOfferingId());
|
||||||
VirtualMachineTemplate template = templateDao.findById(kubernetesCluster.getTemplateId());
|
|
||||||
List<Long> networkIds = new ArrayList<Long>();
|
List<Long> networkIds = new ArrayList<Long>();
|
||||||
networkIds.add(kubernetesCluster.getNetworkId());
|
networkIds.add(kubernetesCluster.getNetworkId());
|
||||||
Account owner = accountDao.findById(kubernetesCluster.getAccountId());
|
Account owner = accountDao.findById(kubernetesCluster.getAccountId());
|
||||||
@ -319,12 +327,12 @@ public class KubernetesClusterResourceModifierActionWorker extends KubernetesClu
|
|||||||
String hostName = getKubernetesClusterNodeAvailableName(String.format("%s-node-%s", kubernetesClusterNodeNamePrefix, nodeInstance));
|
String hostName = getKubernetesClusterNodeAvailableName(String.format("%s-node-%s", kubernetesClusterNodeNamePrefix, nodeInstance));
|
||||||
String k8sNodeConfig = null;
|
String k8sNodeConfig = null;
|
||||||
try {
|
try {
|
||||||
k8sNodeConfig = getKubernetesNodeConfig(joinIp, Hypervisor.HypervisorType.VMware.equals(template.getHypervisorType()));
|
k8sNodeConfig = getKubernetesNodeConfig(joinIp, Hypervisor.HypervisorType.VMware.equals(clusterTemplate.getHypervisorType()));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logAndThrow(Level.ERROR, "Failed to read Kubernetes node configuration file", e);
|
logAndThrow(Level.ERROR, "Failed to read Kubernetes node configuration file", e);
|
||||||
}
|
}
|
||||||
String base64UserData = Base64.encodeBase64String(k8sNodeConfig.getBytes(StringUtils.getPreferredCharset()));
|
String base64UserData = Base64.encodeBase64String(k8sNodeConfig.getBytes(StringUtils.getPreferredCharset()));
|
||||||
nodeVm = userVmService.createAdvancedVirtualMachine(zone, serviceOffering, template, networkIds, owner,
|
nodeVm = userVmService.createAdvancedVirtualMachine(zone, serviceOffering, clusterTemplate, networkIds, owner,
|
||||||
hostName, hostName, null, null, null,
|
hostName, hostName, null, null, null,
|
||||||
null, BaseCmd.HTTPMethod.POST, base64UserData, kubernetesCluster.getKeyPair(),
|
null, BaseCmd.HTTPMethod.POST, base64UserData, kubernetesCluster.getKeyPair(),
|
||||||
null, addrs, null, null, null, customParameterMap, null, null, null, null);
|
null, addrs, null, null, null, customParameterMap, null, null, null, null);
|
||||||
|
|||||||
@ -60,7 +60,6 @@ import com.cloud.network.Network;
|
|||||||
import com.cloud.network.addr.PublicIp;
|
import com.cloud.network.addr.PublicIp;
|
||||||
import com.cloud.network.rules.LoadBalancer;
|
import com.cloud.network.rules.LoadBalancer;
|
||||||
import com.cloud.offering.ServiceOffering;
|
import com.cloud.offering.ServiceOffering;
|
||||||
import com.cloud.template.VirtualMachineTemplate;
|
|
||||||
import com.cloud.user.Account;
|
import com.cloud.user.Account;
|
||||||
import com.cloud.user.SSHKeyPairVO;
|
import com.cloud.user.SSHKeyPairVO;
|
||||||
import com.cloud.uservm.UserVm;
|
import com.cloud.uservm.UserVm;
|
||||||
@ -172,7 +171,6 @@ public class KubernetesClusterStartWorker extends KubernetesClusterResourceModif
|
|||||||
UserVm masterVm = null;
|
UserVm masterVm = null;
|
||||||
DataCenter zone = dataCenterDao.findById(kubernetesCluster.getZoneId());
|
DataCenter zone = dataCenterDao.findById(kubernetesCluster.getZoneId());
|
||||||
ServiceOffering serviceOffering = serviceOfferingDao.findById(kubernetesCluster.getServiceOfferingId());
|
ServiceOffering serviceOffering = serviceOfferingDao.findById(kubernetesCluster.getServiceOfferingId());
|
||||||
VirtualMachineTemplate template = templateDao.findById(kubernetesCluster.getTemplateId());
|
|
||||||
List<Long> networkIds = new ArrayList<Long>();
|
List<Long> networkIds = new ArrayList<Long>();
|
||||||
networkIds.add(kubernetesCluster.getNetworkId());
|
networkIds.add(kubernetesCluster.getNetworkId());
|
||||||
Pair<String, Map<Long, Network.IpAddresses>> ipAddresses = getKubernetesMasterIpAddresses(zone, network, owner);
|
Pair<String, Map<Long, Network.IpAddresses>> ipAddresses = getKubernetesMasterIpAddresses(zone, network, owner);
|
||||||
@ -195,12 +193,12 @@ public class KubernetesClusterStartWorker extends KubernetesClusterResourceModif
|
|||||||
boolean haSupported = isKubernetesVersionSupportsHA();
|
boolean haSupported = isKubernetesVersionSupportsHA();
|
||||||
String k8sMasterConfig = null;
|
String k8sMasterConfig = null;
|
||||||
try {
|
try {
|
||||||
k8sMasterConfig = getKubernetesMasterConfig(masterIp, serverIp, hostName, haSupported, Hypervisor.HypervisorType.VMware.equals(template.getHypervisorType()));
|
k8sMasterConfig = getKubernetesMasterConfig(masterIp, serverIp, hostName, haSupported, Hypervisor.HypervisorType.VMware.equals(clusterTemplate.getHypervisorType()));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logAndThrow(Level.ERROR, "Failed to read Kubernetes master configuration file", e);
|
logAndThrow(Level.ERROR, "Failed to read Kubernetes master configuration file", e);
|
||||||
}
|
}
|
||||||
String base64UserData = Base64.encodeBase64String(k8sMasterConfig.getBytes(StringUtils.getPreferredCharset()));
|
String base64UserData = Base64.encodeBase64String(k8sMasterConfig.getBytes(StringUtils.getPreferredCharset()));
|
||||||
masterVm = userVmService.createAdvancedVirtualMachine(zone, serviceOffering, template, networkIds, owner,
|
masterVm = userVmService.createAdvancedVirtualMachine(zone, serviceOffering, clusterTemplate, networkIds, owner,
|
||||||
hostName, hostName, null, null, null,
|
hostName, hostName, null, null, null,
|
||||||
null, BaseCmd.HTTPMethod.POST, base64UserData, kubernetesCluster.getKeyPair(),
|
null, BaseCmd.HTTPMethod.POST, base64UserData, kubernetesCluster.getKeyPair(),
|
||||||
requestedIps, addrs, null, null, null, customParameterMap, null, null, null, null);
|
requestedIps, addrs, null, null, null, customParameterMap, null, null, null, null);
|
||||||
@ -238,7 +236,6 @@ public class KubernetesClusterStartWorker extends KubernetesClusterResourceModif
|
|||||||
UserVm additionalMasterVm = null;
|
UserVm additionalMasterVm = null;
|
||||||
DataCenter zone = dataCenterDao.findById(kubernetesCluster.getZoneId());
|
DataCenter zone = dataCenterDao.findById(kubernetesCluster.getZoneId());
|
||||||
ServiceOffering serviceOffering = serviceOfferingDao.findById(kubernetesCluster.getServiceOfferingId());
|
ServiceOffering serviceOffering = serviceOfferingDao.findById(kubernetesCluster.getServiceOfferingId());
|
||||||
VirtualMachineTemplate template = templateDao.findById(kubernetesCluster.getTemplateId());
|
|
||||||
List<Long> networkIds = new ArrayList<Long>();
|
List<Long> networkIds = new ArrayList<Long>();
|
||||||
networkIds.add(kubernetesCluster.getNetworkId());
|
networkIds.add(kubernetesCluster.getNetworkId());
|
||||||
Network.IpAddresses addrs = new Network.IpAddresses(null, null);
|
Network.IpAddresses addrs = new Network.IpAddresses(null, null);
|
||||||
@ -250,12 +247,12 @@ public class KubernetesClusterStartWorker extends KubernetesClusterResourceModif
|
|||||||
String hostName = getKubernetesClusterNodeAvailableName(String.format("%s-master-%d", kubernetesClusterNodeNamePrefix, additionalMasterNodeInstance + 1));
|
String hostName = getKubernetesClusterNodeAvailableName(String.format("%s-master-%d", kubernetesClusterNodeNamePrefix, additionalMasterNodeInstance + 1));
|
||||||
String k8sMasterConfig = null;
|
String k8sMasterConfig = null;
|
||||||
try {
|
try {
|
||||||
k8sMasterConfig = getKubernetesAdditionalMasterConfig(joinIp, Hypervisor.HypervisorType.VMware.equals(template.getHypervisorType()));
|
k8sMasterConfig = getKubernetesAdditionalMasterConfig(joinIp, Hypervisor.HypervisorType.VMware.equals(clusterTemplate.getHypervisorType()));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logAndThrow(Level.ERROR, "Failed to read Kubernetes master configuration file", e);
|
logAndThrow(Level.ERROR, "Failed to read Kubernetes master configuration file", e);
|
||||||
}
|
}
|
||||||
String base64UserData = Base64.encodeBase64String(k8sMasterConfig.getBytes(StringUtils.getPreferredCharset()));
|
String base64UserData = Base64.encodeBase64String(k8sMasterConfig.getBytes(StringUtils.getPreferredCharset()));
|
||||||
additionalMasterVm = userVmService.createAdvancedVirtualMachine(zone, serviceOffering, template, networkIds, owner,
|
additionalMasterVm = userVmService.createAdvancedVirtualMachine(zone, serviceOffering, clusterTemplate, networkIds, owner,
|
||||||
hostName, hostName, null, null, null,
|
hostName, hostName, null, null, null,
|
||||||
null, BaseCmd.HTTPMethod.POST, base64UserData, kubernetesCluster.getKeyPair(),
|
null, BaseCmd.HTTPMethod.POST, base64UserData, kubernetesCluster.getKeyPair(),
|
||||||
null, addrs, null, null, null, customParameterMap, null, null, null, null);
|
null, addrs, null, null, null, customParameterMap, null, null, null, null);
|
||||||
|
|||||||
@ -52,6 +52,9 @@ import com.cloud.template.VirtualMachineTemplate;
|
|||||||
import com.cloud.user.AccountManager;
|
import com.cloud.user.AccountManager;
|
||||||
import com.cloud.utils.component.ComponentContext;
|
import com.cloud.utils.component.ComponentContext;
|
||||||
import com.cloud.utils.component.ManagerBase;
|
import com.cloud.utils.component.ManagerBase;
|
||||||
|
import com.cloud.utils.db.Filter;
|
||||||
|
import com.cloud.utils.db.SearchBuilder;
|
||||||
|
import com.cloud.utils.db.SearchCriteria;
|
||||||
import com.cloud.utils.exception.CloudRuntimeException;
|
import com.cloud.utils.exception.CloudRuntimeException;
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
|
|
||||||
@ -246,19 +249,25 @@ public class KubernetesVersionManagerImpl extends ManagerBase implements Kuberne
|
|||||||
}
|
}
|
||||||
minimumSemanticVersion = minVersion.getSemanticVersion();
|
minimumSemanticVersion = minVersion.getSemanticVersion();
|
||||||
}
|
}
|
||||||
List <KubernetesSupportedVersionVO> versions = new ArrayList<>();
|
Filter searchFilter = new Filter(KubernetesSupportedVersionVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal());
|
||||||
|
SearchBuilder<KubernetesSupportedVersionVO> sb = kubernetesSupportedVersionDao.createSearchBuilder();
|
||||||
|
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
|
||||||
|
sb.and("keyword", sb.entity().getName(), SearchCriteria.Op.LIKE);
|
||||||
|
SearchCriteria<KubernetesSupportedVersionVO> sc = sb.create();
|
||||||
|
String keyword = cmd.getKeyword();
|
||||||
if (versionId != null) {
|
if (versionId != null) {
|
||||||
KubernetesSupportedVersionVO version = kubernetesSupportedVersionDao.findById(versionId);
|
sc.setParameters("id", versionId);
|
||||||
if (version != null && (zoneId == null || version.getZoneId() == null || version.getZoneId().equals(zoneId))) {
|
|
||||||
versions.add(version);
|
|
||||||
}
|
}
|
||||||
} else {
|
if (zoneId != null) {
|
||||||
if (zoneId == null) {
|
SearchCriteria<KubernetesSupportedVersionVO> scc = kubernetesSupportedVersionDao.createSearchCriteria();
|
||||||
versions = kubernetesSupportedVersionDao.listAll();
|
scc.addOr("zoneId", SearchCriteria.Op.EQ, zoneId);
|
||||||
} else {
|
scc.addOr("zoneId", SearchCriteria.Op.NULL);
|
||||||
versions = kubernetesSupportedVersionDao.listAllInZone(zoneId);
|
sc.addAnd("zoneId", SearchCriteria.Op.SC, scc);
|
||||||
}
|
}
|
||||||
|
if(keyword != null){
|
||||||
|
sc.setParameters("keyword", "%" + keyword + "%");
|
||||||
}
|
}
|
||||||
|
List <KubernetesSupportedVersionVO> versions = kubernetesSupportedVersionDao.search(sc, searchFilter);
|
||||||
versions = filterKubernetesSupportedVersions(versions, minimumSemanticVersion);
|
versions = filterKubernetesSupportedVersions(versions, minimumSemanticVersion);
|
||||||
|
|
||||||
return createKubernetesSupportedVersionListResponse(versions);
|
return createKubernetesSupportedVersionListResponse(versions);
|
||||||
|
|||||||
@ -36,7 +36,7 @@ import com.cloud.kubernetes.version.KubernetesVersionService;
|
|||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
|
|
||||||
@APICommand(name = ListKubernetesSupportedVersionsCmd.APINAME,
|
@APICommand(name = ListKubernetesSupportedVersionsCmd.APINAME,
|
||||||
description = "Lists container clusters",
|
description = "Lists supported Kubernetes version",
|
||||||
responseObject = KubernetesSupportedVersionResponse.class,
|
responseObject = KubernetesSupportedVersionResponse.class,
|
||||||
responseView = ResponseObject.ResponseView.Restricted,
|
responseView = ResponseObject.ResponseView.Restricted,
|
||||||
authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User})
|
authorized = {RoleType.Admin, RoleType.ResourceAdmin, RoleType.DomainAdmin, RoleType.User})
|
||||||
|
|||||||
@ -65,6 +65,9 @@ import com.cloud.user.AccountVO;
|
|||||||
import com.cloud.user.User;
|
import com.cloud.user.User;
|
||||||
import com.cloud.user.UserVO;
|
import com.cloud.user.UserVO;
|
||||||
import com.cloud.utils.component.ComponentContext;
|
import com.cloud.utils.component.ComponentContext;
|
||||||
|
import com.cloud.utils.db.Filter;
|
||||||
|
import com.cloud.utils.db.SearchBuilder;
|
||||||
|
import com.cloud.utils.db.SearchCriteria;
|
||||||
import com.cloud.utils.exception.CloudRuntimeException;
|
import com.cloud.utils.exception.CloudRuntimeException;
|
||||||
|
|
||||||
@RunWith(PowerMockRunner.class)
|
@RunWith(PowerMockRunner.class)
|
||||||
@ -101,6 +104,15 @@ public class KubernetesVersionServiceTest {
|
|||||||
|
|
||||||
overrideDefaultConfigValue(KubernetesClusterService.KubernetesServiceEnabled, "_defaultValue", "true");
|
overrideDefaultConfigValue(KubernetesClusterService.KubernetesServiceEnabled, "_defaultValue", "true");
|
||||||
|
|
||||||
|
final SearchBuilder<KubernetesSupportedVersionVO> versionSearchBuilder = Mockito.mock(SearchBuilder.class);
|
||||||
|
final SearchCriteria<KubernetesSupportedVersionVO> versionSearchCriteria = Mockito.mock(SearchCriteria.class);
|
||||||
|
when(kubernetesSupportedVersionDao.createSearchBuilder()).thenReturn(versionSearchBuilder);
|
||||||
|
final KubernetesSupportedVersionVO kubernetesSupportedVersionVO = Mockito.mock(KubernetesSupportedVersionVO.class);
|
||||||
|
when(versionSearchBuilder.entity()).thenReturn(kubernetesSupportedVersionVO);
|
||||||
|
when(versionSearchBuilder.entity()).thenReturn(kubernetesSupportedVersionVO);
|
||||||
|
when(versionSearchBuilder.create()).thenReturn(versionSearchCriteria);
|
||||||
|
when(kubernetesSupportedVersionDao.createSearchCriteria()).thenReturn(versionSearchCriteria);
|
||||||
|
|
||||||
DataCenterVO zone = Mockito.mock(DataCenterVO.class);
|
DataCenterVO zone = Mockito.mock(DataCenterVO.class);
|
||||||
when(zone.getId()).thenReturn(1L);
|
when(zone.getId()).thenReturn(1L);
|
||||||
when(dataCenterDao.findById(Mockito.anyLong())).thenReturn(zone);
|
when(dataCenterDao.findById(Mockito.anyLong())).thenReturn(zone);
|
||||||
@ -127,9 +139,8 @@ public class KubernetesVersionServiceTest {
|
|||||||
KubernetesSupportedVersionVO versionVO = Mockito.mock(KubernetesSupportedVersionVO.class);
|
KubernetesSupportedVersionVO versionVO = Mockito.mock(KubernetesSupportedVersionVO.class);
|
||||||
when(versionVO.getSemanticVersion()).thenReturn(KubernetesVersionService.MIN_KUBERNETES_VERSION);
|
when(versionVO.getSemanticVersion()).thenReturn(KubernetesVersionService.MIN_KUBERNETES_VERSION);
|
||||||
versionVOs.add(versionVO);
|
versionVOs.add(versionVO);
|
||||||
when(kubernetesSupportedVersionDao.listAll()).thenReturn(versionVOs);
|
|
||||||
when(kubernetesSupportedVersionDao.listAllInZone(Mockito.anyLong())).thenReturn(versionVOs);
|
|
||||||
when(kubernetesSupportedVersionDao.findById(Mockito.anyLong())).thenReturn(versionVO);
|
when(kubernetesSupportedVersionDao.findById(Mockito.anyLong())).thenReturn(versionVO);
|
||||||
|
when(kubernetesSupportedVersionDao.search(Mockito.any(SearchCriteria.class), Mockito.any(Filter.class))).thenReturn(versionVOs);
|
||||||
kubernetesVersionService.listKubernetesSupportedVersions(cmd);
|
kubernetesVersionService.listKubernetesSupportedVersions(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user