Skip to content

Commit 671c672

Browse files
committed
Fix CKS cluster creation not honouring the CKS ISO arch
1 parent b1851ba commit 671c672

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
import javax.inject.Inject;
3838

39+
import com.cloud.cpu.CPU;
3940
import com.cloud.deploy.DataCenterDeployment;
4041
import com.cloud.deploy.DeploymentPlan;
4142
import com.cloud.dc.DedicatedResourceVO;
@@ -177,7 +178,7 @@ protected void init() {
177178
}
178179

179180
protected DeployDestination plan(final long nodesCount, final DataCenter zone, final ServiceOffering offering,
180-
final Long domainId, final Long accountId, final Hypervisor.HypervisorType hypervisorType) throws InsufficientServerCapacityException {
181+
final Long domainId, final Long accountId, final Hypervisor.HypervisorType hypervisorType, CPU.CPUArch arch) throws InsufficientServerCapacityException {
181182
final int cpu_requested = offering.getCpu() * offering.getSpeed();
182183
final long ram_requested = offering.getRamSize() * 1024L * 1024L;
183184
boolean useDedicatedHosts = false;
@@ -201,6 +202,15 @@ protected DeployDestination plan(final long nodesCount, final DataCenter zone, f
201202
if (hypervisorType != null) {
202203
hosts = hosts.stream().filter(x -> x.getHypervisorType() == hypervisorType).collect(Collectors.toList());
203204
}
205+
if (arch != null) {
206+
hosts = hosts.stream().filter(x -> x.getArch().equals(arch)).collect(Collectors.toList());
207+
}
208+
if (CollectionUtils.isEmpty(hosts)) {
209+
String msg = String.format("Cannot find enough capacity for Kubernetes cluster(requested cpu=%d memory=%s) with offering: %s hypervisor: %s and arch: %s",
210+
cpu_requested * nodesCount, toHumanReadableSize(ram_requested * nodesCount), offering.getName(), clusterTemplate.getHypervisorType().toString(), arch.getType());
211+
logAndThrow(Level.WARN, msg, new InsufficientServerCapacityException(msg, DataCenter.class, zone.getId()));
212+
}
213+
204214
final Map<String, Pair<HostVO, Integer>> hosts_with_resevered_capacity = new ConcurrentHashMap<String, Pair<HostVO, Integer>>();
205215
for (HostVO h : hosts) {
206216
hosts_with_resevered_capacity.put(h.getUuid(), new Pair<HostVO, Integer>(h, 0));
@@ -254,8 +264,8 @@ protected DeployDestination plan(final long nodesCount, final DataCenter zone, f
254264
}
255265
return new DeployDestination(zone, null, null, null);
256266
}
257-
String msg = String.format("Cannot find enough capacity for Kubernetes cluster(requested cpu=%d memory=%s) with offering: %s and hypervisor: %s",
258-
cpu_requested * nodesCount, toHumanReadableSize(ram_requested * nodesCount), offering.getName(), clusterTemplate.getHypervisorType().toString());
267+
String msg = String.format("Cannot find enough capacity for Kubernetes cluster(requested cpu=%d memory=%s) with offering: %s hypervisor: %s and arch: %s",
268+
cpu_requested * nodesCount, toHumanReadableSize(ram_requested * nodesCount), offering.getName(), clusterTemplate.getHypervisorType().toString(), arch.getType());
259269

260270
logger.warn(msg);
261271
throw new InsufficientServerCapacityException(msg, DataCenter.class, zone.getId());
@@ -265,7 +275,7 @@ protected DeployDestination plan(final long nodesCount, final DataCenter zone, f
265275
* Plan Kubernetes Cluster Deployment
266276
* @return a map of DeployDestination per node type
267277
*/
268-
protected Map<String, DeployDestination> planKubernetesCluster(Long domainId, Long accountId, Hypervisor.HypervisorType hypervisorType) throws InsufficientServerCapacityException {
278+
protected Map<String, DeployDestination> planKubernetesCluster(Long domainId, Long accountId, Hypervisor.HypervisorType hypervisorType, CPU.CPUArch arch) throws InsufficientServerCapacityException {
269279
Map<String, DeployDestination> destinationMap = new HashMap<>();
270280
DataCenter zone = dataCenterDao.findById(kubernetesCluster.getZoneId());
271281
if (logger.isDebugEnabled()) {
@@ -286,7 +296,7 @@ protected Map<String, DeployDestination> planKubernetesCluster(Long domainId, Lo
286296
if (logger.isDebugEnabled()) {
287297
logger.debug("Checking deployment destination for {} nodes on Kubernetes cluster : {} in zone : {}", nodeType.name(), kubernetesCluster.getName(), zone.getName());
288298
}
289-
DeployDestination planForNodeType = plan(nodes, zone, nodeOffering, domainId, accountId, hypervisorType);
299+
DeployDestination planForNodeType = plan(nodes, zone, nodeOffering, domainId, accountId, hypervisorType, arch);
290300
destinationMap.put(nodeType.name(), planForNodeType);
291301
}
292302
return destinationMap;
@@ -322,7 +332,7 @@ protected void startKubernetesVM(final UserVm vm, final Long domainId, final Lon
322332
if (Objects.nonNull(domainId) && !listDedicatedHostsInDomain(domainId).isEmpty()) {
323333
DeployDestination dest = null;
324334
try {
325-
Map<String, DeployDestination> destinationMap = planKubernetesCluster(domainId, accountId, vm.getHypervisorType());
335+
Map<String, DeployDestination> destinationMap = planKubernetesCluster(domainId, accountId, vm.getHypervisorType(), clusterTemplate.getArch());
326336
dest = destinationMap.get(nodeType.name());
327337
} catch (InsufficientCapacityException e) {
328338
logTransitStateAndThrow(Level.ERROR, String.format("Provisioning the cluster failed due to insufficient capacity in the Kubernetes cluster: %s", kubernetesCluster.getUuid()), kubernetesCluster.getId(), KubernetesCluster.Event.CreateFailed, e);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,9 @@ private void validateKubernetesClusterScaleSizeParameters() throws CloudRuntimeE
341341
VMTemplateVO clusterTemplate = templateDao.findById(kubernetesCluster.getTemplateId());
342342
try {
343343
if (originalState.equals(KubernetesCluster.State.Running)) {
344-
plan(newVmRequiredCount, zone, clusterServiceOffering, kubernetesCluster.getDomainId(), kubernetesCluster.getAccountId(), clusterTemplate.getHypervisorType());
344+
plan(newVmRequiredCount, zone, clusterServiceOffering, kubernetesCluster.getDomainId(), kubernetesCluster.getAccountId(), clusterTemplate.getHypervisorType(), clusterTemplate.getArch());
345345
} else {
346-
plan(kubernetesCluster.getTotalNodeCount() + newVmRequiredCount, zone, clusterServiceOffering, kubernetesCluster.getDomainId(), kubernetesCluster.getAccountId(), clusterTemplate.getHypervisorType());
346+
plan(kubernetesCluster.getTotalNodeCount() + newVmRequiredCount, zone, clusterServiceOffering, kubernetesCluster.getDomainId(), kubernetesCluster.getAccountId(), clusterTemplate.getHypervisorType(), clusterTemplate.getArch());
347347
}
348348
} catch (InsufficientCapacityException e) {
349349
logTransitStateToFailedIfNeededAndThrow(Level.WARN, String.format("Scaling failed for Kubernetes cluster : %s in zone : %s, insufficient capacity", kubernetesCluster.getName(), zone.getName()));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ public boolean startKubernetesClusterOnCreate(Long domainId, Long accountId, Lon
749749
DeployDestination dest = null;
750750
try {
751751
VMTemplateVO clusterTemplate = templateDao.findById(kubernetesCluster.getTemplateId());
752-
Map<String, DeployDestination> destinationMap = planKubernetesCluster(domainId, accountId, clusterTemplate.getHypervisorType());
752+
Map<String, DeployDestination> destinationMap = planKubernetesCluster(domainId, accountId, clusterTemplate.getHypervisorType(), clusterTemplate.getArch());
753753
dest = destinationMap.get(WORKER.name());
754754
} catch (InsufficientCapacityException e) {
755755
logTransitStateAndThrow(Level.ERROR, String.format("Provisioning the cluster failed due to insufficient capacity in the Kubernetes cluster: %s", kubernetesCluster.getUuid()), kubernetesCluster.getId(), KubernetesCluster.Event.CreateFailed, e);

0 commit comments

Comments
 (0)