Skip to content

Commit 81c6f5a

Browse files
committed
Find system VM templates for CKS cluster honouring the preferred architecture
1 parent 823080c commit 81c6f5a

File tree

5 files changed

+18
-6
lines changed

5 files changed

+18
-6
lines changed

engine/schema/src/main/java/com/cloud/storage/dao/VMTemplateDao.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public interface VMTemplateDao extends GenericDao<VMTemplateVO, Long>, StateDao<
7272

7373
VMTemplateVO findSystemVMTemplate(long zoneId);
7474

75-
VMTemplateVO findSystemVMReadyTemplate(long zoneId, HypervisorType hypervisorType);
75+
VMTemplateVO findSystemVMReadyTemplate(long zoneId, HypervisorType hypervisorType, String preferredArch);
7676

7777
List<VMTemplateVO> findSystemVMReadyTemplates(long zoneId, HypervisorType hypervisorType, String preferredArch);
7878

engine/schema/src/main/java/com/cloud/storage/dao/VMTemplateDaoImpl.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.HashMap;
2424
import java.util.List;
2525
import java.util.Map;
26+
import java.util.stream.Collectors;
2627

2728
import javax.inject.Inject;
2829
import javax.naming.ConfigurationException;
@@ -578,11 +579,19 @@ public List<VMTemplateVO> listAllReadySystemVMTemplates(Long zoneId) {
578579
}
579580

580581
@Override
581-
public VMTemplateVO findSystemVMReadyTemplate(long zoneId, HypervisorType hypervisorType) {
582+
public VMTemplateVO findSystemVMReadyTemplate(long zoneId, HypervisorType hypervisorType, String preferredArch) {
582583
List<VMTemplateVO> templates = listAllReadySystemVMTemplates(zoneId);
583584
if (CollectionUtils.isEmpty(templates)) {
584585
return null;
585586
}
587+
if (StringUtils.isNotBlank(preferredArch)) {
588+
templates = templates.stream()
589+
.filter(x -> x.getArch().getType().equalsIgnoreCase(preferredArch))
590+
.collect(Collectors.toList());
591+
if (CollectionUtils.isEmpty(templates)) {
592+
return null;
593+
}
594+
}
586595
if (hypervisorType == HypervisorType.Any) {
587596
return templates.get(0);
588597
}

plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,8 @@ private IpAddress getSourceNatIp(Network network) {
434434
}
435435

436436
public VMTemplateVO getKubernetesServiceTemplate(DataCenter dataCenter, Hypervisor.HypervisorType hypervisorType) {
437-
VMTemplateVO template = templateDao.findSystemVMReadyTemplate(dataCenter.getId(), hypervisorType);
437+
ConfigKey<String> preferredArchitecture = ResourceManager.SystemVmPreferredArchitecture;
438+
VMTemplateVO template = templateDao.findSystemVMReadyTemplate(dataCenter.getId(), hypervisorType, preferredArchitecture.value());
438439
if (DataCenter.Type.Edge.equals(dataCenter.getType()) && template != null && !template.isDirectDownload()) {
439440
logger.debug(String.format("Template %s can not be used for edge zone %s", template, dataCenter));
440441
template = templateDao.findRoutingTemplate(hypervisorType, networkHelper.getHypervisorRouterTemplateConfigMap().get(hypervisorType).valueIn(dataCenter.getId()));

plugins/storage/sharedfs/storagevm/src/main/java/org/apache/cloudstack/storage/sharedfs/lifecycle/StorageVmSharedFSLifeCycle.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
import org.apache.cloudstack.api.ApiCommandResourceType;
6262
import org.apache.cloudstack.api.BaseCmd;
6363
import org.apache.cloudstack.context.CallContext;
64+
import org.apache.cloudstack.framework.config.ConfigKey;
6465
import org.apache.cloudstack.storage.sharedfs.SharedFS;
6566
import org.apache.cloudstack.storage.sharedfs.SharedFSLifeCycle;
6667
import org.apache.commons.codec.binary.Base64;
@@ -174,10 +175,11 @@ private UserVm deploySharedFSVM(Long zoneId, Account owner, List<Long> networkId
174175
customParameterMap.put("maxIopsDo", maxIops.toString());
175176
}
176177
List<String> keypairs = new ArrayList<String>();
178+
ConfigKey<String> preferredArchitecture = ResourceManager.SystemVmPreferredArchitecture;
177179

178180
for (final Iterator<Hypervisor.HypervisorType> iter = hypervisors.iterator(); iter.hasNext();) {
179181
final Hypervisor.HypervisorType hypervisor = iter.next();
180-
VMTemplateVO template = templateDao.findSystemVMReadyTemplate(zoneId, hypervisor);
182+
VMTemplateVO template = templateDao.findSystemVMReadyTemplate(zoneId, hypervisor, preferredArchitecture.value());
181183
if (template == null && !iter.hasNext()) {
182184
throw new CloudRuntimeException(String.format("Unable to find the systemvm template for %s or it was not downloaded in %s.", hypervisor.toString(), zone.toString()));
183185
}

plugins/storage/sharedfs/storagevm/src/test/java/org/apache/cloudstack/storage/sharedfs/lifecycle/StorageVmSharedFSLifeCycleTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ private SharedFS prepareDeploySharedFS() throws ResourceUnavailableException, In
236236
when(serviceOfferingDao.findById(s_serviceOfferingId)).thenReturn(serviceOffering);
237237

238238
VMTemplateVO template = mock(VMTemplateVO.class);
239-
when(templateDao.findSystemVMReadyTemplate(s_zoneId, Hypervisor.HypervisorType.KVM)).thenReturn(template);
239+
when(templateDao.findSystemVMReadyTemplate(s_zoneId, Hypervisor.HypervisorType.KVM, null)).thenReturn(template);
240240
when(template.getId()).thenReturn(s_templateId);
241241

242242
return sharedFS;
@@ -298,7 +298,7 @@ public void testDeploySharedFSTemplateNotFound() throws ResourceUnavailableExcep
298298
when(dataCenterDao.findById(s_zoneId)).thenReturn(zone);
299299
when(resourceMgr.getSupportedHypervisorTypes(s_zoneId, false, null)).thenReturn(List.of(Hypervisor.HypervisorType.KVM));
300300

301-
when(templateDao.findSystemVMReadyTemplate(s_zoneId, Hypervisor.HypervisorType.KVM)).thenReturn(null);
301+
when(templateDao.findSystemVMReadyTemplate(s_zoneId, Hypervisor.HypervisorType.KVM, null)).thenReturn(null);
302302
lifeCycle.deploySharedFS(sharedFS, s_networkId, s_diskOfferingId, s_size, s_minIops, s_maxIops);
303303
}
304304

0 commit comments

Comments
 (0)