Skip to content

Commit 0c1dfca

Browse files
committed
Add support for adding k8s supported version by iso id
1 parent f84e043 commit 0c1dfca

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/version/KubernetesVersionManagerImpl.java

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import javax.inject.Inject;
2424

25+
import org.apache.cloudstack.acl.SecurityChecker;
2526
import org.apache.cloudstack.api.ApiCommandResourceType;
2627
import org.apache.cloudstack.api.ApiConstants;
2728
import org.apache.cloudstack.api.command.admin.kubernetes.version.AddKubernetesSupportedVersionCmd;
@@ -312,6 +313,7 @@ public KubernetesSupportedVersionResponse addKubernetesSupportedVersion(final Ad
312313
final String semanticVersion = cmd.getSemanticVersion();
313314
final Long zoneId = cmd.getZoneId();
314315
final String isoUrl = cmd.getUrl();
316+
final Long isoId = cmd.getIsoId();
315317
final String isoChecksum = cmd.getChecksum();
316318
final Integer minimumCpu = cmd.getMinimumCpu();
317319
final Integer minimumRamSize = cmd.getMinimumRamSize();
@@ -334,8 +336,8 @@ public KubernetesSupportedVersionResponse addKubernetesSupportedVersion(final Ad
334336
throw new InvalidParameterValueException(String.format("Zone: %s supports only direct download Kubernetes versions", zone.getName()));
335337
}
336338
}
337-
if (StringUtils.isEmpty(isoUrl)) {
338-
throw new InvalidParameterValueException(String.format("Invalid URL for ISO specified, %s", isoUrl));
339+
if (StringUtils.isEmpty(isoUrl) && isoId == null) {
340+
throw new InvalidParameterValueException(String.format("Either %s or %s parameter is required", ApiConstants.URL, ApiConstants.ISO_ID));
339341
}
340342
if (StringUtils.isEmpty(name)) {
341343
name = String.format("v%s", semanticVersion);
@@ -345,12 +347,23 @@ public KubernetesSupportedVersionResponse addKubernetesSupportedVersion(final Ad
345347
}
346348

347349
VMTemplateVO template = null;
348-
try {
349-
VirtualMachineTemplate vmTemplate = registerKubernetesVersionIso(zoneId, name, isoUrl, isoChecksum, isDirectDownload);
350-
template = templateDao.findById(vmTemplate.getId());
351-
} catch (IllegalAccessException | NoSuchFieldException | IllegalArgumentException | ResourceAllocationException ex) {
352-
logger.error(String.format("Unable to register binaries ISO for supported kubernetes version, %s, with url: %s", name, isoUrl), ex);
353-
throw new CloudRuntimeException(String.format("Unable to register binaries ISO for supported kubernetes version, %s, with url: %s", name, isoUrl));
350+
351+
if (isoId != null) {
352+
template = templateDao.findById(isoId);
353+
if (template == null) {
354+
throw new InvalidParameterValueException(String.format("Invalid ISO ID specified, %s", isoId));
355+
}
356+
accountManager.checkAccess(CallContext.current().getCallingAccount(), SecurityChecker.AccessType.UseEntry, true, template);
357+
}
358+
if (template == null) {
359+
try {
360+
VirtualMachineTemplate vmTemplate = registerKubernetesVersionIso(zoneId, name, isoUrl, isoChecksum, isDirectDownload);
361+
template = templateDao.findById(vmTemplate.getId());
362+
} catch (IllegalAccessException | NoSuchFieldException | IllegalArgumentException |
363+
ResourceAllocationException ex) {
364+
logger.error(String.format("Unable to register binaries ISO for supported kubernetes version, %s, with url: %s", name, isoUrl), ex);
365+
throw new CloudRuntimeException(String.format("Unable to register binaries ISO for supported kubernetes version, %s, with url: %s", name, isoUrl));
366+
}
354367
}
355368

356369
KubernetesSupportedVersionVO supportedVersionVO = new KubernetesSupportedVersionVO(name, semanticVersion, template.getId(), zoneId, minimumCpu, minimumRamSize);

plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/AddKubernetesSupportedVersionCmd.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.apache.cloudstack.api.ServerApiException;
3131
import org.apache.cloudstack.api.command.admin.AdminCmd;
3232
import org.apache.cloudstack.api.response.KubernetesSupportedVersionResponse;
33+
import org.apache.cloudstack.api.response.TemplateResponse;
3334
import org.apache.cloudstack.api.response.ZoneResponse;
3435
import org.apache.cloudstack.context.CallContext;
3536
import org.apache.commons.lang3.StringUtils;
@@ -71,6 +72,10 @@ public class AddKubernetesSupportedVersionCmd extends BaseCmd implements AdminCm
7172
description = "the URL of the binaries ISO for Kubernetes supported version")
7273
private String url;
7374

75+
@Parameter(name = ApiConstants.ISO_ID, type = CommandType.UUID, entityType = TemplateResponse.class,
76+
description = "the ID of the binaries ISO for Kubernetes supported version")
77+
private Long isoId;
78+
7479
@Parameter(name = ApiConstants.CHECKSUM, type = CommandType.STRING,
7580
description = "the checksum value of the binaries ISO. " + ApiConstants.CHECKSUM_PARAMETER_PREFIX_DESCRIPTION)
7681
private String checksum;
@@ -114,6 +119,10 @@ public String getUrl() {
114119
return url;
115120
}
116121

122+
public Long getIsoId() {
123+
return isoId;
124+
}
125+
117126
public String getChecksum() {
118127
return checksum;
119128
}

0 commit comments

Comments
 (0)