-
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
...api/command/admin/kubernetes/version/GetUploadParamsForKubernetesSupportedVersionCmd.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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()); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
AddKubernetesSupportedVersionCmdfor 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.