Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,34 @@ public Long getProjectId() {
return projectId;
}

public void setName(String name) {
this.name = name;
}

public void setFormat(String format) {
this.format = format;
}

public void setZoneId(Long zoneId) {
this.zoneId = zoneId;
}

public void setChecksum(String checksum) {
this.checksum = checksum;
}

public void setAccountName(String accountName) {
this.accountName = accountName;
}

public void setDomainId(Long domainId) {
this.domainId = domainId;
}

public void setProjectId(Long projectId) {
this.projectId = projectId;
}

public GetUploadParamsResponse createGetUploadParamsResponse(UUID id, URL postURL, String metadata, String timeout, String signature) {
return new GetUploadParamsResponse(id, postURL, metadata, timeout, signature);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,29 @@ public Long getOsTypeId() {
return osTypeId;
}

public void setBootable(Boolean bootable) {
this.bootable = bootable;
}

public void setDisplayText(String displayText) {
this.displayText = displayText;
}

public void setFeatured(Boolean featured) {
this.featured = featured;
}

public void setPublicIso(Boolean publicIso) {
this.publicIso = publicIso;
}

public void setExtractable(Boolean extractable) {
this.extractable = extractable;
}

public void setOsTypeId(Long osTypeId) {
this.osTypeId = osTypeId;
}

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ public GetUploadParamsResponse() {
setObjectName("getuploadparams");
}

public UUID getId() {
return id;
}

public void setId(UUID id) {
this.id = id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package com.cloud.kubernetes.version;

import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -26,10 +27,13 @@
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.command.admin.kubernetes.version.AddKubernetesSupportedVersionCmd;
import org.apache.cloudstack.api.command.admin.kubernetes.version.DeleteKubernetesSupportedVersionCmd;
import org.apache.cloudstack.api.command.admin.kubernetes.version.GetUploadParamsForKubernetesSupportedVersionCmd;
import org.apache.cloudstack.api.command.admin.kubernetes.version.UpdateKubernetesSupportedVersionCmd;
import org.apache.cloudstack.api.command.user.iso.DeleteIsoCmd;
import org.apache.cloudstack.api.command.user.iso.GetUploadParamsForIsoCmd;
import org.apache.cloudstack.api.command.user.iso.RegisterIsoCmd;
import org.apache.cloudstack.api.command.user.kubernetes.version.ListKubernetesSupportedVersionsCmd;
import org.apache.cloudstack.api.response.GetUploadParamsResponse;
import org.apache.cloudstack.api.response.KubernetesSupportedVersionResponse;
import org.apache.cloudstack.api.response.ListResponse;
import org.apache.cloudstack.context.CallContext;
Expand Down Expand Up @@ -162,6 +166,33 @@ private List <KubernetesSupportedVersionVO> filterKubernetesSupportedVersions(Li
return versions;
}

private GetUploadParamsResponse registerKubernetesVersionIsoForUpload(final Long zoneId, final String versionName, final String isoChecksum) {
CallContext.register(CallContext.current(), ApiCommandResourceType.Iso);
String isoName = String.format("%s-Kubernetes-Binaries-ISO", versionName);
GetUploadParamsForIsoCmd uploadIso = new GetUploadParamsForIsoCmd();
uploadIso = ComponentContext.inject(uploadIso);
uploadIso.setName(isoName);
uploadIso.setPublicIso(true);
if (zoneId != null) {
uploadIso.setZoneId(zoneId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zoneId - seems to be a mandatory param for upload iso, so I wonder if this could cause some failure if upload iso is done by a user / dom admin
considering https://github.com/apache/cloudstack/blob/main/server/src/main/java/com/cloud/template/TemplateAdapterBase.java#L194-L197

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I followed the existing checks in AddKubernetesSupportedVersionCmd for the upload command.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also need to check if we allow domain admin or a user to add kubernetes versions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like by default we do not allow registering kubernetes iso for dom admins. Corner case is when we add custom roles. But I think that can be overlooked.

}
uploadIso.setDisplayText(isoName);
uploadIso.setBootable(false);
if (StringUtils.isNotEmpty(isoChecksum)) {
uploadIso.setChecksum(isoChecksum);
}
uploadIso.setAccountName(accountManager.getSystemAccount().getAccountName());
uploadIso.setDomainId(accountManager.getSystemAccount().getDomainId());
try {
return templateService.registerIsoForPostUpload(uploadIso);
} catch (MalformedURLException | ResourceAllocationException e) {
logger.error(String.format("Unable to register binaries ISO for supported kubernetes version, %s", versionName), e);
throw new CloudRuntimeException(String.format("Unable to register binaries ISO for supported kubernetes version, %s", versionName), e);
} finally {
CallContext.unregister();
}
}

private VirtualMachineTemplate registerKubernetesVersionIso(final Long zoneId, final String versionName, final String isoUrl, final String isoChecksum, final boolean directDownload, CPU.CPUArch arch) throws IllegalAccessException, NoSuchFieldException,
IllegalArgumentException, ResourceAllocationException {
CallContext.register(CallContext.current(), ApiCommandResourceType.Iso);
Expand Down Expand Up @@ -316,23 +347,8 @@ public ListResponse<KubernetesSupportedVersionResponse> listKubernetesSupportedV
return createKubernetesSupportedVersionListResponse(versions, versionsAndCount.second());
}

@Override
@ActionEvent(eventType = KubernetesVersionEventTypes.EVENT_KUBERNETES_VERSION_ADD,
eventDescription = "Adding Kubernetes supported version")
public KubernetesSupportedVersionResponse addKubernetesSupportedVersion(final AddKubernetesSupportedVersionCmd cmd) {
if (!KubernetesClusterService.KubernetesServiceEnabled.value()) {
throw new CloudRuntimeException("Kubernetes Service plugin is disabled");
}
String name = cmd.getName();
final String semanticVersion = cmd.getSemanticVersion();
final Long zoneId = cmd.getZoneId();
final String isoUrl = cmd.getUrl();
final String isoChecksum = cmd.getChecksum();
final Integer minimumCpu = cmd.getMinimumCpu();
final Integer minimumRamSize = cmd.getMinimumRamSize();
final boolean isDirectDownload = cmd.isDirectDownload();
CPU.CPUArch arch = cmd.getArch();

private void validateKubernetesSupportedVersion(Long zoneId, String semanticVersion, Integer minimumCpu,
Integer minimumRamSize, boolean isDirectDownload) {
if (minimumCpu == null || minimumCpu < KubernetesClusterService.MIN_KUBERNETES_CLUSTER_NODE_CPU) {
throw new InvalidParameterValueException(String.format("Invalid value for %s parameter. Minimum %d vCPUs required.", ApiConstants.MIN_CPU_NUMBER, KubernetesClusterService.MIN_KUBERNETES_CLUSTER_NODE_CPU));
}
Expand All @@ -351,6 +367,27 @@ public KubernetesSupportedVersionResponse addKubernetesSupportedVersion(final Ad
throw new InvalidParameterValueException(String.format("Zone: %s supports only direct download Kubernetes versions", zone.getName()));
}
}
}

@Override
@ActionEvent(eventType = KubernetesVersionEventTypes.EVENT_KUBERNETES_VERSION_ADD,
eventDescription = "Adding Kubernetes supported version")
public KubernetesSupportedVersionResponse addKubernetesSupportedVersion(final AddKubernetesSupportedVersionCmd cmd) {
if (!KubernetesClusterService.KubernetesServiceEnabled.value()) {
throw new CloudRuntimeException("Kubernetes Service plugin is disabled");
}
String name = cmd.getName();
final String semanticVersion = cmd.getSemanticVersion();
final Long zoneId = cmd.getZoneId();
final String isoUrl = cmd.getUrl();
final String isoChecksum = cmd.getChecksum();
final Integer minimumCpu = cmd.getMinimumCpu();
final Integer minimumRamSize = cmd.getMinimumRamSize();
final boolean isDirectDownload = cmd.isDirectDownload();
CPU.CPUArch arch = cmd.getArch();

validateKubernetesSupportedVersion(zoneId, semanticVersion, minimumCpu, minimumRamSize, isDirectDownload);

if (StringUtils.isEmpty(isoUrl)) {
throw new InvalidParameterValueException(String.format("Invalid URL for ISO specified, %s", isoUrl));
}
Expand All @@ -377,6 +414,30 @@ public KubernetesSupportedVersionResponse addKubernetesSupportedVersion(final Ad
return createKubernetesSupportedVersionResponse(supportedVersionVO);
}

@Override
public GetUploadParamsResponse registerKubernetesSupportedVersionForPostUpload(GetUploadParamsForKubernetesSupportedVersionCmd cmd) {
if (!KubernetesClusterService.KubernetesServiceEnabled.value()) {
throw new CloudRuntimeException("Kubernetes Service plugin is disabled");
}
String name = cmd.getName();
final String semanticVersion = cmd.getSemanticVersion();
final Long zoneId = cmd.getZoneId();
final String isoChecksum = cmd.getChecksum();
final Integer minimumCpu = cmd.getMinimumCpu();
final Integer minimumRamSize = cmd.getMinimumRamSize();

validateKubernetesSupportedVersion(zoneId, semanticVersion, minimumCpu, minimumRamSize, false);

GetUploadParamsResponse response = registerKubernetesVersionIsoForUpload(zoneId, name, isoChecksum);

VMTemplateVO template = templateDao.findByUuid(response.getId().toString());
KubernetesSupportedVersionVO supportedVersionVO = new KubernetesSupportedVersionVO(name, semanticVersion, template.getId(), zoneId, minimumCpu, minimumRamSize);
supportedVersionVO = kubernetesSupportedVersionDao.persist(supportedVersionVO);
CallContext.current().putContextParameter(KubernetesSupportedVersion.class, supportedVersionVO.getUuid());

return response;
}

@Override
@ActionEvent(eventType = KubernetesVersionEventTypes.EVENT_KUBERNETES_VERSION_DELETE,
eventDescription = "deleting Kubernetes supported version", async = true)
Expand Down Expand Up @@ -445,6 +506,7 @@ public List<Class<?>> getCommands() {
return cmdList;
}
cmdList.add(AddKubernetesSupportedVersionCmd.class);
cmdList.add(GetUploadParamsForKubernetesSupportedVersionCmd.class);
cmdList.add(ListKubernetesSupportedVersionsCmd.class);
cmdList.add(DeleteKubernetesSupportedVersionCmd.class);
cmdList.add(UpdateKubernetesSupportedVersionCmd.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@

import org.apache.cloudstack.api.command.admin.kubernetes.version.AddKubernetesSupportedVersionCmd;
import org.apache.cloudstack.api.command.admin.kubernetes.version.DeleteKubernetesSupportedVersionCmd;
import org.apache.cloudstack.api.command.admin.kubernetes.version.GetUploadParamsForKubernetesSupportedVersionCmd;
import org.apache.cloudstack.api.command.admin.kubernetes.version.UpdateKubernetesSupportedVersionCmd;
import org.apache.cloudstack.api.command.user.kubernetes.version.ListKubernetesSupportedVersionsCmd;
import org.apache.cloudstack.api.response.GetUploadParamsResponse;
import org.apache.cloudstack.api.response.KubernetesSupportedVersionResponse;
import org.apache.cloudstack.api.response.ListResponse;

Expand All @@ -31,6 +33,7 @@ public interface KubernetesVersionService extends PluggableService {
static final String MIN_KUBERNETES_VERSION = "1.11.0";
ListResponse<KubernetesSupportedVersionResponse> listKubernetesSupportedVersions(ListKubernetesSupportedVersionsCmd cmd);
KubernetesSupportedVersionResponse addKubernetesSupportedVersion(AddKubernetesSupportedVersionCmd cmd) throws CloudRuntimeException;
GetUploadParamsResponse registerKubernetesSupportedVersionForPostUpload(GetUploadParamsForKubernetesSupportedVersionCmd cmd);
boolean deleteKubernetesSupportedVersion(DeleteKubernetesSupportedVersionCmd cmd) throws CloudRuntimeException;
KubernetesSupportedVersionResponse updateKubernetesSupportedVersion(UpdateKubernetesSupportedVersionCmd cmd) throws CloudRuntimeException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.apache.cloudstack.api.command.admin.kubernetes.version;

import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.kubernetes.version.KubernetesSupportedVersion;
import com.cloud.kubernetes.version.KubernetesVersionService;
import com.cloud.utils.exception.CloudRuntimeException;
import org.apache.cloudstack.acl.RoleType;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.AbstractGetUploadParamsCmd;
import org.apache.cloudstack.api.ApiCommandResourceType;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ResponseObject;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.command.admin.AdminCmd;
import org.apache.cloudstack.api.response.GetUploadParamsResponse;
import org.apache.cloudstack.api.response.KubernetesSupportedVersionResponse;
import org.apache.cloudstack.context.CallContext;
import org.apache.commons.lang3.StringUtils;

import javax.inject.Inject;

@APICommand(name = "getUploadParamsForKubernetesSupportedVersion",
description = "Upload a supported Kubernetes version",
responseObject = KubernetesSupportedVersionResponse.class,
responseView = ResponseObject.ResponseView.Full,
entityType = {KubernetesSupportedVersion.class},
authorized = {RoleType.Admin})
public class GetUploadParamsForKubernetesSupportedVersionCmd extends AbstractGetUploadParamsCmd implements AdminCmd {

@Inject
private KubernetesVersionService kubernetesVersionService;

/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@Parameter(name = ApiConstants.SEMANTIC_VERSION, type = CommandType.STRING, required = true,
description = "the semantic version of the Kubernetes version. It needs to be specified in MAJOR.MINOR.PATCH format")
private String semanticVersion;

@Parameter(name = ApiConstants.CHECKSUM, type = CommandType.STRING,
description = "the checksum value of the binaries ISO. " + ApiConstants.CHECKSUM_PARAMETER_PREFIX_DESCRIPTION)
private String checksum;

@Parameter(name = ApiConstants.MIN_CPU_NUMBER, type = CommandType.INTEGER, required = true,
description = "the minimum number of CPUs to be set with the Kubernetes version")
private Integer minimumCpu;

@Parameter(name = ApiConstants.MIN_MEMORY, type = CommandType.INTEGER, required = true,
description = "the minimum RAM size in MB to be set with the Kubernetes version")
private Integer minimumRamSize;

/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////

public String getSemanticVersion() {
if(StringUtils.isEmpty(semanticVersion)) {
throw new InvalidParameterValueException("Version can not be null");
}
if(!semanticVersion.matches("[0-9]+(\\.[0-9]+)*")) {
throw new IllegalArgumentException("Invalid version format. Semantic version needed");
}
return semanticVersion;
}

public String getChecksum() {
return checksum;
}

public Integer getMinimumCpu() {
return minimumCpu;
}

public Integer getMinimumRamSize() {
return minimumRamSize;
}

@Override
public long getEntityOwnerId() {
return CallContext.current().getCallingAccountId();
}

@Override
public ApiCommandResourceType getApiResourceType() {
return ApiCommandResourceType.KubernetesSupportedVersion;
}

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public void execute() throws ServerApiException, ConcurrentOperationException {
if (getZoneId() <= 0) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Invalid zoneid");
}
try {
GetUploadParamsResponse response = kubernetesVersionService.registerKubernetesSupportedVersionForPostUpload(this);
if (response == null) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add Kubernetes supported version");
}
response.setResponseName(getCommandName());
setResponseObject(response);
} catch (CloudRuntimeException ex) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
}
}
}
1 change: 1 addition & 0 deletions ui/public/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1390,6 +1390,7 @@
"label.kubernetes.version.add": "Add Kubernetes version",
"label.kubernetes.version.delete": "Delete Kubernetes version",
"label.kubernetes.version.update": "Manage Kubernetes version",
"label.kubernetes.version.from.local": "Add Kubernetes version from local",
"label.kubernetesversionid": "Kubernetes version",
"label.kubernetesversionname": "Kubernetes version",
"label.kvm": "KVM",
Expand Down
9 changes: 9 additions & 0 deletions ui/src/config/section/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,15 @@ export default {
show: isZoneCreated,
component: shallowRef(defineAsyncComponent(() => import('@/views/image/AddKubernetesSupportedVersion.vue')))
},
{
api: 'getUploadParamsForKubernetesSupportedVersion',
icon: 'cloud-upload-outlined',
label: 'label.kubernetes.version.from.local',
listView: true,
popup: true,
show: isZoneCreated,
component: shallowRef(defineAsyncComponent(() => import('@/views/image/AddKubernetesSupportedVersion.vue')))
},
{
api: 'updateKubernetesSupportedVersion',
icon: 'edit-outlined',
Expand Down
Loading
Loading