weizhouapache commented on code in PR #7515:
URL: https://github.com/apache/cloudstack/pull/7515#discussion_r1191321686
##########
plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/cluster/CreateKubernetesClusterCmd.java:
##########
@@ -232,6 +236,13 @@ public Long getNodeRootDiskSize() {
}
}
+ public boolean getManaged() {
+ if (managed == null) {
+ return true;
+ }
+ return managed;
Review Comment:
this can be done by just one line
##########
plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/cluster/AddVirtualMachinesToKubernetesClusterCmd.java:
##########
@@ -0,0 +1,109 @@
+// 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.user.kubernetes.cluster;
+
+import com.cloud.kubernetes.cluster.KubernetesClusterService;
+import com.cloud.utils.exception.CloudRuntimeException;
+import org.apache.cloudstack.acl.RoleType;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.KubernetesClusterResponse;
+import org.apache.cloudstack.api.response.SuccessResponse;
+import org.apache.cloudstack.api.response.UserVmResponse;
+import org.apache.cloudstack.context.CallContext;
+import org.apache.log4j.Logger;
+
+import javax.inject.Inject;
+import java.util.List;
+
+
+@APICommand(name = "addVirtualMachinesToKubernetesCluster",
+ description = "Add VM to a kubernetes cluster",
+ responseObject = SuccessResponse.class,
+ since = "4.19.0",
+ authorized = {RoleType.Admin, RoleType.ResourceAdmin,
RoleType.DomainAdmin, RoleType.User})
+public class AddVirtualMachinesToKubernetesClusterCmd extends BaseCmd {
+ public static final Logger LOGGER =
Logger.getLogger(AddVirtualMachinesToKubernetesClusterCmd.class.getName());
+
+ @Inject
+ public KubernetesClusterService kubernetesClusterService;
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+ @Parameter(name = ApiConstants.ID, type = CommandType.UUID,
+ entityType = KubernetesClusterResponse.class,
+ required = true,
+ description = "the ID of the Kubernetes cluster")
+ private Long id;
+
+ @Parameter(name = ApiConstants.VIRTUAL_MACHINE_IDS, type =
CommandType.LIST,
+ collectionType=CommandType.UUID,
+ entityType = UserVmResponse.class,
+ required = true,
+ description = "the ID of the Kubernetes cluster")
+ private List<Long> vmIds;
+
+ @Parameter(name = "isControlNode", type = CommandType.BOOLEAN,
+ description = "Is control node or not? Defaults to false.")
+ private Boolean isControlNode;
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+ public Long getId() {
+ return id;
+ }
+
+ public List<Long> getVmIds() {
+ return vmIds;
+ }
+
+ public boolean isControlNode() {
Review Comment:
this can be done by just one line
##########
plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/cluster/RemoveVmsFromKubernetesClusterCmd.java:
##########
@@ -0,0 +1,98 @@
+// 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.user.kubernetes.cluster;
+
+import com.cloud.kubernetes.cluster.KubernetesClusterService;
+import com.cloud.utils.exception.CloudRuntimeException;
+import org.apache.cloudstack.acl.RoleType;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.KubernetesClusterResponse;
+import org.apache.cloudstack.api.response.SuccessResponse;
+import org.apache.cloudstack.api.response.UserVmResponse;
+import org.apache.cloudstack.context.CallContext;
+import org.apache.log4j.Logger;
+
+import javax.inject.Inject;
+import java.util.List;
+
+
+@APICommand(name = "removeVmsFromKubernetesCluster",
+ description = "Remove VMs from a kubernetes cluster",
+ responseObject = SuccessResponse.class,
+ authorized = {RoleType.Admin, RoleType.ResourceAdmin,
RoleType.DomainAdmin, RoleType.User})
+public class RemoveVmsFromKubernetesClusterCmd extends BaseCmd {
+ public static final Logger LOGGER =
Logger.getLogger(RemoveVmsFromKubernetesClusterCmd.class.getName());
+
+ @Inject
+ public KubernetesClusterService kubernetesClusterService;
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+ @Parameter(name = ApiConstants.ID, type = CommandType.UUID,
+ entityType = KubernetesClusterResponse.class,
+ required = true,
+ description = "the ID of the Kubernetes cluster")
+ private Long id;
+
+ @Parameter(name = ApiConstants.VIRTUAL_MACHINE_IDS, type =
CommandType.LIST,
+ collectionType=CommandType.UUID,
+ entityType = UserVmResponse.class,
+ required = true,
+ description = "the ID of the Kubernetes cluster")
Review Comment:
the description needs to be corrected
##########
plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/cluster/CreateKubernetesClusterCmd.java:
##########
@@ -232,6 +236,13 @@ public Long getNodeRootDiskSize() {
}
}
+ public boolean getManaged() {
Review Comment:
it seems `isManaged` is more widely used than `getManaged`
##########
plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/cluster/RemoveVmsFromKubernetesClusterCmd.java:
##########
@@ -0,0 +1,98 @@
+// 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.user.kubernetes.cluster;
+
+import com.cloud.kubernetes.cluster.KubernetesClusterService;
+import com.cloud.utils.exception.CloudRuntimeException;
+import org.apache.cloudstack.acl.RoleType;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.KubernetesClusterResponse;
+import org.apache.cloudstack.api.response.SuccessResponse;
+import org.apache.cloudstack.api.response.UserVmResponse;
+import org.apache.cloudstack.context.CallContext;
+import org.apache.log4j.Logger;
+
+import javax.inject.Inject;
+import java.util.List;
+
+
+@APICommand(name = "removeVmsFromKubernetesCluster",
Review Comment:
I have same concern as addVmsToKubernetesCluster
##########
plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/cluster/StartKubernetesClusterCmd.java:
##########
@@ -99,6 +99,9 @@ public KubernetesCluster validateRequest() {
if (kubernetesCluster == null) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Given
Kubernetes cluster was not found");
}
+ if (!kubernetesCluster.getManaged()) {
+ throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Given
Kubernetes cluster is not managed by Apache CloudStack");
Review Comment:
any update on other CKS apis ?
[deleteKubernetesCluster
(A)](https://cloudstack.apache.org/api/apidocs-4.18/apis/deleteKubernetesCluster.html)
[getKubernetesClusterConfig](https://cloudstack.apache.org/api/apidocs-4.18/apis/getKubernetesClusterConfig.html)
[listKubernetesClusters](https://cloudstack.apache.org/api/apidocs-4.18/apis/listKubernetesClusters.html)
[scaleKubernetesCluster
(A)](https://cloudstack.apache.org/api/apidocs-4.18/apis/scaleKubernetesCluster.html)[startKubernetesCluster
(A)](https://cloudstack.apache.org/api/apidocs-4.18/apis/startKubernetesCluster.html)
[startKubernetesCluster
(A)](https://cloudstack.apache.org/api/apidocs-4.18/apis/startKubernetesCluster.html)
(done)
[stopKubernetesCluster
(A)](https://cloudstack.apache.org/api/apidocs-4.18/apis/stopKubernetesCluster.html)
[upgradeKubernetesCluster
(A)](https://cloudstack.apache.org/api/apidocs-4.18/apis/upgradeKubernetesCluster.html)
##########
plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java:
##########
@@ -36,17 +37,20 @@
import javax.inject.Inject;
import javax.naming.ConfigurationException;
+import com.google.common.base.Strings;
Review Comment:
normally we use StringUtils
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]