mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Merge branch '4.20'
This commit is contained in:
commit
8ac8a22163
@ -74,7 +74,7 @@ public interface VMTemplateDao extends GenericDao<VMTemplateVO, Long>, StateDao<
|
|||||||
|
|
||||||
VMTemplateVO findSystemVMTemplate(long zoneId);
|
VMTemplateVO findSystemVMTemplate(long zoneId);
|
||||||
|
|
||||||
VMTemplateVO findSystemVMReadyTemplate(long zoneId, HypervisorType hypervisorType);
|
VMTemplateVO findSystemVMReadyTemplate(long zoneId, HypervisorType hypervisorType, String preferredArch);
|
||||||
|
|
||||||
List<VMTemplateVO> findSystemVMReadyTemplates(long zoneId, HypervisorType hypervisorType, String preferredArch);
|
List<VMTemplateVO> findSystemVMReadyTemplates(long zoneId, HypervisorType hypervisorType, String preferredArch);
|
||||||
|
|
||||||
|
|||||||
@ -24,6 +24,7 @@ import java.util.Date;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.naming.ConfigurationException;
|
import javax.naming.ConfigurationException;
|
||||||
@ -621,11 +622,19 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VMTemplateVO findSystemVMReadyTemplate(long zoneId, HypervisorType hypervisorType) {
|
public VMTemplateVO findSystemVMReadyTemplate(long zoneId, HypervisorType hypervisorType, String preferredArch) {
|
||||||
List<VMTemplateVO> templates = listAllReadySystemVMTemplates(zoneId);
|
List<VMTemplateVO> templates = listAllReadySystemVMTemplates(zoneId);
|
||||||
if (CollectionUtils.isEmpty(templates)) {
|
if (CollectionUtils.isEmpty(templates)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
if (StringUtils.isNotBlank(preferredArch)) {
|
||||||
|
// Sort the templates by preferred architecture first
|
||||||
|
templates = templates.stream()
|
||||||
|
.sorted(Comparator.comparing(
|
||||||
|
x -> !x.getArch().getType().equalsIgnoreCase(preferredArch)
|
||||||
|
))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
if (hypervisorType == HypervisorType.Any) {
|
if (hypervisorType == HypervisorType.Any) {
|
||||||
return templates.get(0);
|
return templates.get(0);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,6 +36,7 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.InjectMocks;
|
import org.mockito.InjectMocks;
|
||||||
@ -316,4 +317,24 @@ public class VMTemplateDaoImplTest {
|
|||||||
verify(searchCriteria).setParameters("extensionId", extensionId);
|
verify(searchCriteria).setParameters("extensionId", extensionId);
|
||||||
verify(templateDao).customSearchIncludingRemoved(eq(searchCriteria), isNull());
|
verify(templateDao).customSearchIncludingRemoved(eq(searchCriteria), isNull());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFindSystemVMReadyTemplate() {
|
||||||
|
Long zoneId = 1L;
|
||||||
|
VMTemplateVO systemVmTemplate1 = mock(VMTemplateVO.class);
|
||||||
|
Mockito.when(systemVmTemplate1.getArch()).thenReturn(CPU.CPUArch.x86);
|
||||||
|
VMTemplateVO systemVmTemplate2 = mock(VMTemplateVO.class);
|
||||||
|
Mockito.when(systemVmTemplate2.getArch()).thenReturn(CPU.CPUArch.x86);
|
||||||
|
VMTemplateVO systemVmTemplate3 = mock(VMTemplateVO.class);
|
||||||
|
Mockito.when(systemVmTemplate3.getArch()).thenReturn(CPU.CPUArch.arm64);
|
||||||
|
Mockito.when(systemVmTemplate3.getHypervisorType()).thenReturn(Hypervisor.HypervisorType.KVM);
|
||||||
|
List<VMTemplateVO> templates = Arrays.asList(systemVmTemplate1, systemVmTemplate2, systemVmTemplate3);
|
||||||
|
Mockito.when(hostDao.listDistinctHypervisorTypes(zoneId)).thenReturn(Arrays.asList(Hypervisor.HypervisorType.KVM));
|
||||||
|
SearchBuilder<VMTemplateVO> sb = mock(SearchBuilder.class);
|
||||||
|
templateDao.readySystemTemplateSearch = sb;
|
||||||
|
when(sb.create()).thenReturn(mock(SearchCriteria.class));
|
||||||
|
doReturn(templates).when(templateDao).listBy(any(SearchCriteria.class), any(Filter.class));
|
||||||
|
VMTemplateVO readyTemplate = templateDao.findSystemVMReadyTemplate(zoneId, Hypervisor.HypervisorType.KVM, CPU.CPUArch.arm64.getType());
|
||||||
|
Assert.assertEquals(CPU.CPUArch.arm64, readyTemplate.getArch());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -482,8 +482,14 @@ public class KubernetesClusterManagerImpl extends ManagerBase implements Kuberne
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public VMTemplateVO getKubernetesServiceTemplate(DataCenter dataCenter, Hypervisor.HypervisorType hypervisorType, Map<String, Long> templateNodeTypeMap, KubernetesClusterNodeType nodeType) {
|
public VMTemplateVO getKubernetesServiceTemplate(DataCenter dataCenter, Hypervisor.HypervisorType hypervisorType, Map<String, Long> templateNodeTypeMap, KubernetesClusterNodeType nodeType,
|
||||||
VMTemplateVO template = templateDao.findSystemVMReadyTemplate(dataCenter.getId(), hypervisorType);
|
KubernetesSupportedVersion clusterKubernetesVersion) {
|
||||||
|
String systemVMPreferredArchitecture = ResourceManager.SystemVmPreferredArchitecture.valueIn(dataCenter.getId());
|
||||||
|
VMTemplateVO cksIso = clusterKubernetesVersion != null ?
|
||||||
|
templateDao.findById(clusterKubernetesVersion.getIsoId()) :
|
||||||
|
null;
|
||||||
|
String preferredArchitecture = getCksClusterPreferredArch(systemVMPreferredArchitecture, cksIso);
|
||||||
|
VMTemplateVO template = templateDao.findSystemVMReadyTemplate(dataCenter.getId(), hypervisorType, preferredArchitecture);
|
||||||
if (DataCenter.Type.Edge.equals(dataCenter.getType()) && template != null && !template.isDirectDownload()) {
|
if (DataCenter.Type.Edge.equals(dataCenter.getType()) && template != null && !template.isDirectDownload()) {
|
||||||
logger.debug(String.format("Template %s can not be used for edge zone %s", template, dataCenter));
|
logger.debug(String.format("Template %s can not be used for edge zone %s", template, dataCenter));
|
||||||
template = templateDao.findRoutingTemplate(hypervisorType, networkHelper.getHypervisorRouterTemplateConfigMap().get(hypervisorType).valueIn(dataCenter.getId()));
|
template = templateDao.findRoutingTemplate(hypervisorType, networkHelper.getHypervisorRouterTemplateConfigMap().get(hypervisorType).valueIn(dataCenter.getId()));
|
||||||
@ -510,6 +516,14 @@ public class KubernetesClusterManagerImpl extends ManagerBase implements Kuberne
|
|||||||
throw new CloudRuntimeException("Not able to find the System or Routing template in ready state for the zone " + datacenterId);
|
throw new CloudRuntimeException("Not able to find the System or Routing template in ready state for the zone " + datacenterId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected String getCksClusterPreferredArch(String systemVMPreferredArchitecture, VMTemplateVO cksIso) {
|
||||||
|
if (cksIso == null) {
|
||||||
|
return systemVMPreferredArchitecture;
|
||||||
|
}
|
||||||
|
String cksIsoArchName = cksIso.getArch().name();
|
||||||
|
return cksIsoArchName.equals(systemVMPreferredArchitecture) ? systemVMPreferredArchitecture : cksIsoArchName;
|
||||||
|
}
|
||||||
|
|
||||||
protected void validateIsolatedNetworkIpRules(long ipId, FirewallRule.Purpose purpose, Network network, int clusterTotalNodeCount) {
|
protected void validateIsolatedNetworkIpRules(long ipId, FirewallRule.Purpose purpose, Network network, int clusterTotalNodeCount) {
|
||||||
List<FirewallRuleVO> rules = firewallRulesDao.listByIpPurposeProtocolAndNotRevoked(ipId, purpose, NetUtils.TCP_PROTO);
|
List<FirewallRuleVO> rules = firewallRulesDao.listByIpPurposeProtocolAndNotRevoked(ipId, purpose, NetUtils.TCP_PROTO);
|
||||||
for (FirewallRuleVO rule : rules) {
|
for (FirewallRuleVO rule : rules) {
|
||||||
@ -1541,11 +1555,12 @@ public class KubernetesClusterManagerImpl extends ManagerBase implements Kuberne
|
|||||||
}
|
}
|
||||||
|
|
||||||
Map<String, Long> templateNodeTypeMap = cmd.getTemplateNodeTypeMap();
|
Map<String, Long> templateNodeTypeMap = cmd.getTemplateNodeTypeMap();
|
||||||
final VMTemplateVO finalTemplate = getKubernetesServiceTemplate(zone, hypervisorType, templateNodeTypeMap, DEFAULT);
|
final VMTemplateVO finalTemplate = getKubernetesServiceTemplate(zone, hypervisorType, templateNodeTypeMap, DEFAULT, clusterKubernetesVersion);
|
||||||
final VMTemplateVO controlNodeTemplate = getKubernetesServiceTemplate(zone, hypervisorType, templateNodeTypeMap, CONTROL);
|
final VMTemplateVO controlNodeTemplate = getKubernetesServiceTemplate(zone, hypervisorType, templateNodeTypeMap, CONTROL, clusterKubernetesVersion);
|
||||||
final VMTemplateVO workerNodeTemplate = getKubernetesServiceTemplate(zone, hypervisorType, templateNodeTypeMap, WORKER);
|
final VMTemplateVO workerNodeTemplate = getKubernetesServiceTemplate(zone, hypervisorType, templateNodeTypeMap, WORKER, clusterKubernetesVersion);
|
||||||
final VMTemplateVO etcdNodeTemplate = getKubernetesServiceTemplate(zone, hypervisorType, templateNodeTypeMap, ETCD);
|
final VMTemplateVO etcdNodeTemplate = getKubernetesServiceTemplate(zone, hypervisorType, templateNodeTypeMap, ETCD, clusterKubernetesVersion);
|
||||||
final Network defaultNetwork = getKubernetesClusterNetworkIfMissing(cmd.getName(), zone, owner, (int)controlNodeCount, (int)clusterSize, cmd.getExternalLoadBalancerIpAddress(), cmd.getNetworkId(), asNumber);
|
final Network defaultNetwork = getKubernetesClusterNetworkIfMissing(cmd.getName(), zone, owner, (int)controlNodeCount, (int)clusterSize, cmd.getExternalLoadBalancerIpAddress(), cmd.getNetworkId(), asNumber);
|
||||||
|
|
||||||
final SecurityGroup finalSecurityGroup = securityGroup;
|
final SecurityGroup finalSecurityGroup = securityGroup;
|
||||||
final KubernetesClusterVO cluster = Transaction.execute(new TransactionCallback<KubernetesClusterVO>() {
|
final KubernetesClusterVO cluster = Transaction.execute(new TransactionCallback<KubernetesClusterVO>() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -36,6 +36,7 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import com.cloud.kubernetes.version.KubernetesSupportedVersionVO;
|
||||||
import org.apache.logging.log4j.Level;
|
import org.apache.logging.log4j.Level;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
@ -257,7 +258,8 @@ public class KubernetesClusterActionWorker {
|
|||||||
DataCenterVO dataCenterVO = dataCenterDao.findById(zoneId);
|
DataCenterVO dataCenterVO = dataCenterDao.findById(zoneId);
|
||||||
VMTemplateVO template = templateDao.findById(templateId);
|
VMTemplateVO template = templateDao.findById(templateId);
|
||||||
Hypervisor.HypervisorType type = template.getHypervisorType();
|
Hypervisor.HypervisorType type = template.getHypervisorType();
|
||||||
this.clusterTemplate = manager.getKubernetesServiceTemplate(dataCenterVO, type, null, KubernetesClusterNodeType.DEFAULT);
|
KubernetesSupportedVersionVO kubernetesSupportedVersion = kubernetesSupportedVersionDao.findById(this.kubernetesCluster.getKubernetesVersionId());
|
||||||
|
this.clusterTemplate = manager.getKubernetesServiceTemplate(dataCenterVO, type, null, KubernetesClusterNodeType.DEFAULT, kubernetesSupportedVersion);
|
||||||
this.controlNodeTemplate = templateDao.findById(this.kubernetesCluster.getControlNodeTemplateId());
|
this.controlNodeTemplate = templateDao.findById(this.kubernetesCluster.getControlNodeTemplateId());
|
||||||
this.workerNodeTemplate = templateDao.findById(this.kubernetesCluster.getWorkerNodeTemplateId());
|
this.workerNodeTemplate = templateDao.findById(this.kubernetesCluster.getWorkerNodeTemplateId());
|
||||||
this.etcdTemplate = templateDao.findById(this.kubernetesCluster.getEtcdNodeTemplateId());
|
this.etcdTemplate = templateDao.findById(this.kubernetesCluster.getEtcdNodeTemplateId());
|
||||||
|
|||||||
@ -212,7 +212,7 @@ 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())) {
|
if (!h.getHypervisorType().equals(clusterTemplate.getHypervisorType()) || !h.getArch().equals(clusterTemplate.getArch())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
hostDao.loadHostTags(h);
|
hostDao.loadHostTags(h);
|
||||||
|
|||||||
@ -21,6 +21,7 @@ package com.cloud.kubernetes.cluster;
|
|||||||
|
|
||||||
import com.cloud.api.query.dao.TemplateJoinDao;
|
import com.cloud.api.query.dao.TemplateJoinDao;
|
||||||
import com.cloud.api.query.vo.TemplateJoinVO;
|
import com.cloud.api.query.vo.TemplateJoinVO;
|
||||||
|
import com.cloud.cpu.CPU;
|
||||||
import com.cloud.dc.DataCenter;
|
import com.cloud.dc.DataCenter;
|
||||||
import com.cloud.exception.InvalidParameterValueException;
|
import com.cloud.exception.InvalidParameterValueException;
|
||||||
import com.cloud.exception.PermissionDeniedException;
|
import com.cloud.exception.PermissionDeniedException;
|
||||||
@ -422,4 +423,22 @@ public class KubernetesClusterManagerImplTest {
|
|||||||
Assert.assertEquals(workerOffering, mapping.get(WORKER.name()));
|
Assert.assertEquals(workerOffering, mapping.get(WORKER.name()));
|
||||||
Assert.assertEquals(controlOffering, mapping.get(CONTROL.name()));
|
Assert.assertEquals(controlOffering, mapping.get(CONTROL.name()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetCksClusterPreferredArchDifferentArchsPreferCKSIsoArch() {
|
||||||
|
String systemVMArch = "x86_64";
|
||||||
|
VMTemplateVO cksIso = Mockito.mock(VMTemplateVO.class);
|
||||||
|
Mockito.when(cksIso.getArch()).thenReturn(CPU.CPUArch.arm64);
|
||||||
|
String cksClusterPreferredArch = kubernetesClusterManager.getCksClusterPreferredArch(systemVMArch, cksIso);
|
||||||
|
Assert.assertEquals(CPU.CPUArch.arm64.name(), cksClusterPreferredArch);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetCksClusterPreferredArchSameArch() {
|
||||||
|
String systemVMArch = "x86_64";
|
||||||
|
VMTemplateVO cksIso = Mockito.mock(VMTemplateVO.class);
|
||||||
|
Mockito.when(cksIso.getArch()).thenReturn(CPU.CPUArch.amd64);
|
||||||
|
String cksClusterPreferredArch = kubernetesClusterManager.getCksClusterPreferredArch(systemVMArch, cksIso);
|
||||||
|
Assert.assertEquals(CPU.CPUArch.amd64.name(), cksClusterPreferredArch);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -175,10 +175,11 @@ public class StorageVmSharedFSLifeCycle implements SharedFSLifeCycle {
|
|||||||
customParameterMap.put("maxIopsDo", maxIops.toString());
|
customParameterMap.put("maxIopsDo", maxIops.toString());
|
||||||
}
|
}
|
||||||
List<String> keypairs = new ArrayList<String>();
|
List<String> keypairs = new ArrayList<String>();
|
||||||
|
String preferredArchitecture = ResourceManager.SystemVmPreferredArchitecture.valueIn(zoneId);
|
||||||
|
|
||||||
for (final Iterator<Hypervisor.HypervisorType> iter = hypervisors.iterator(); iter.hasNext();) {
|
for (final Iterator<Hypervisor.HypervisorType> iter = hypervisors.iterator(); iter.hasNext();) {
|
||||||
final Hypervisor.HypervisorType hypervisor = iter.next();
|
final Hypervisor.HypervisorType hypervisor = iter.next();
|
||||||
VMTemplateVO template = templateDao.findSystemVMReadyTemplate(zoneId, hypervisor);
|
VMTemplateVO template = templateDao.findSystemVMReadyTemplate(zoneId, hypervisor, preferredArchitecture);
|
||||||
if (template == null && !iter.hasNext()) {
|
if (template == null && !iter.hasNext()) {
|
||||||
throw new CloudRuntimeException(String.format("Unable to find the systemvm template for %s or it was not downloaded in %s.", hypervisor.toString(), zone.toString()));
|
throw new CloudRuntimeException(String.format("Unable to find the systemvm template for %s or it was not downloaded in %s.", hypervisor.toString(), zone.toString()));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -235,7 +235,7 @@ public class StorageVmSharedFSLifeCycleTest {
|
|||||||
when(serviceOfferingDao.findById(s_serviceOfferingId)).thenReturn(serviceOffering);
|
when(serviceOfferingDao.findById(s_serviceOfferingId)).thenReturn(serviceOffering);
|
||||||
|
|
||||||
VMTemplateVO template = mock(VMTemplateVO.class);
|
VMTemplateVO template = mock(VMTemplateVO.class);
|
||||||
when(templateDao.findSystemVMReadyTemplate(s_zoneId, Hypervisor.HypervisorType.KVM)).thenReturn(template);
|
when(templateDao.findSystemVMReadyTemplate(s_zoneId, Hypervisor.HypervisorType.KVM, ResourceManager.SystemVmPreferredArchitecture.defaultValue())).thenReturn(template);
|
||||||
when(template.getId()).thenReturn(s_templateId);
|
when(template.getId()).thenReturn(s_templateId);
|
||||||
|
|
||||||
return sharedFS;
|
return sharedFS;
|
||||||
@ -302,7 +302,6 @@ public class StorageVmSharedFSLifeCycleTest {
|
|||||||
when(dataCenterDao.findById(s_zoneId)).thenReturn(zone);
|
when(dataCenterDao.findById(s_zoneId)).thenReturn(zone);
|
||||||
when(resourceMgr.getSupportedHypervisorTypes(s_zoneId, false, null)).thenReturn(List.of(Hypervisor.HypervisorType.KVM));
|
when(resourceMgr.getSupportedHypervisorTypes(s_zoneId, false, null)).thenReturn(List.of(Hypervisor.HypervisorType.KVM));
|
||||||
|
|
||||||
when(templateDao.findSystemVMReadyTemplate(s_zoneId, Hypervisor.HypervisorType.KVM)).thenReturn(null);
|
|
||||||
lifeCycle.deploySharedFS(sharedFS, s_networkId, s_diskOfferingId, s_size, s_minIops, s_maxIops);
|
lifeCycle.deploySharedFS(sharedFS, s_networkId, s_diskOfferingId, s_size, s_minIops, s_maxIops);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user