Skip to content

Commit 2dbc86a

Browse files
Fix CKS cluster creation not honoring the CKS ISO arch (apache#11902)
* Fix CKS cluster creation not honouring the CKS ISO arch * Fix arch type reference to choose right template * Include template name on the CKS clusters response --------- Co-authored-by: Harikrishna Patnala <[email protected]>
1 parent f52a27c commit 2dbc86a

File tree

6 files changed

+35
-12
lines changed

6 files changed

+35
-12
lines changed

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
@@ -556,7 +556,7 @@ protected String getCksClusterPreferredArch(String systemVMPreferredArchitecture
556556
if (cksIso == null) {
557557
return systemVMPreferredArchitecture;
558558
}
559-
String cksIsoArchName = cksIso.getArch().name();
559+
String cksIsoArchName = cksIso.getArch().getType();
560560
return cksIsoArchName.equals(systemVMPreferredArchitecture) ? systemVMPreferredArchitecture : cksIsoArchName;
561561
}
562562

@@ -807,6 +807,7 @@ public KubernetesClusterResponse createKubernetesClusterResponse(long kubernetes
807807
VMTemplateVO template = ApiDBUtils.findTemplateById(kubernetesCluster.getTemplateId());
808808
if (template != null) {
809809
response.setTemplateId(template.getUuid());
810+
response.setTemplateName(template.getName());
810811
}
811812
ServiceOfferingVO offering = serviceOfferingDao.findByIdIncludingRemoved(kubernetesCluster.getServiceOfferingId());
812813
if (offering != null) {

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);

plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/response/KubernetesClusterResponse.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ public class KubernetesClusterResponse extends BaseResponseWithAnnotations imple
9191
@Param(description = "the ID of the template of the Kubernetes cluster")
9292
private String templateId;
9393

94+
@SerializedName(ApiConstants.TEMPLATE_NAME)
95+
@Param(description = "the name of the template of the Kubernetes cluster")
96+
private String templateName;
97+
9498
@SerializedName(ApiConstants.NETWORK_ID)
9599
@Param(description = "the ID of the network of the Kubernetes cluster")
96100
private String networkId;
@@ -267,6 +271,14 @@ public void setTemplateId(String templateId) {
267271
this.templateId = templateId;
268272
}
269273

274+
public String getTemplateName() {
275+
return templateName;
276+
}
277+
278+
public void setTemplateName(String templateName) {
279+
this.templateName = templateName;
280+
}
281+
270282
public String getNetworkId() {
271283
return networkId;
272284
}

plugins/integrations/kubernetes-service/src/test/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImplTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ public void testGetCksClusterPreferredArchDifferentArchsPreferCKSIsoArch() {
430430
VMTemplateVO cksIso = Mockito.mock(VMTemplateVO.class);
431431
Mockito.when(cksIso.getArch()).thenReturn(CPU.CPUArch.arm64);
432432
String cksClusterPreferredArch = kubernetesClusterManager.getCksClusterPreferredArch(systemVMArch, cksIso);
433-
Assert.assertEquals(CPU.CPUArch.arm64.name(), cksClusterPreferredArch);
433+
Assert.assertEquals(CPU.CPUArch.arm64.getType(), cksClusterPreferredArch);
434434
}
435435

436436
@Test
@@ -439,6 +439,6 @@ public void testGetCksClusterPreferredArchSameArch() {
439439
VMTemplateVO cksIso = Mockito.mock(VMTemplateVO.class);
440440
Mockito.when(cksIso.getArch()).thenReturn(CPU.CPUArch.amd64);
441441
String cksClusterPreferredArch = kubernetesClusterManager.getCksClusterPreferredArch(systemVMArch, cksIso);
442-
Assert.assertEquals(CPU.CPUArch.amd64.name(), cksClusterPreferredArch);
442+
Assert.assertEquals(CPU.CPUArch.amd64.getType(), cksClusterPreferredArch);
443443
}
444444
}

0 commit comments

Comments
 (0)