-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Allow uploading of ISO for creating kubernetes supported versions #9561
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 4.20
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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() { | ||
Check warning on line 76 in plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java
|
||
if(StringUtils.isEmpty(semanticVersion)) { | ||
throw new InvalidParameterValueException("Version can not be null"); | ||
Check warning on line 78 in plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java
|
||
} | ||
if(!semanticVersion.matches("[0-9]+(\\.[0-9]+)*")) { | ||
throw new IllegalArgumentException("Invalid version format. Semantic version needed"); | ||
Check warning on line 81 in plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java
|
||
} | ||
return semanticVersion; | ||
} | ||
Check warning on line 84 in plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java
|
||
|
||
public String getChecksum() { | ||
return checksum; | ||
} | ||
Check warning on line 88 in plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java
|
||
|
||
public Integer getMinimumCpu() { | ||
return minimumCpu; | ||
} | ||
Check warning on line 92 in plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java
|
||
|
||
public Integer getMinimumRamSize() { | ||
return minimumRamSize; | ||
} | ||
Check warning on line 96 in plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java
|
||
|
||
@Override | ||
public long getEntityOwnerId() { | ||
return CallContext.current().getCallingAccountId(); | ||
} | ||
Check warning on line 101 in plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java
|
||
|
||
@Override | ||
public ApiCommandResourceType getApiResourceType() { | ||
return ApiCommandResourceType.KubernetesSupportedVersion; | ||
} | ||
Check warning on line 106 in plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java
|
||
|
||
///////////////////////////////////////////////////// | ||
/////////////// API Implementation/////////////////// | ||
///////////////////////////////////////////////////// | ||
@Override | ||
public void execute() throws ServerApiException, ConcurrentOperationException { | ||
Check warning on line 112 in plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java
|
||
if (getZoneId() <= 0) { | ||
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Invalid zoneid"); | ||
Check warning on line 114 in plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java
|
||
} | ||
try { | ||
GetUploadParamsResponse response = kubernetesVersionService.registerKubernetesSupportedVersionForPostUpload(this); | ||
Check warning on line 117 in plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java
|
||
if (response == null) { | ||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add Kubernetes supported version"); | ||
Check warning on line 119 in plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java
|
||
} | ||
response.setResponseName(getCommandName()); | ||
setResponseObject(response); | ||
} catch (CloudRuntimeException ex) { | ||
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); | ||
} | ||
} | ||
Check warning on line 126 in plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java
|
||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.