shwstppr commented on a change in pull request #3680: [WIP: DO NOT MERGE] 
CloudStack Kubernetes Service
URL: https://github.com/apache/cloudstack/pull/3680#discussion_r365752650
 
 

 ##########
 File path: 
plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/utils/KubernetesClusterUtil.java
 ##########
 @@ -0,0 +1,306 @@
+// 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 com.cloud.kubernetes.cluster.utils;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.net.URL;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.log4j.Logger;
+
+import com.cloud.kubernetes.cluster.KubernetesCluster;
+import com.cloud.uservm.UserVm;
+import com.cloud.utils.Pair;
+import com.cloud.utils.StringUtils;
+import com.cloud.utils.ssh.SshHelper;
+import com.google.common.base.Strings;
+
+public class KubernetesClusterUtil {
+
+    protected static final Logger LOGGER = 
Logger.getLogger(KubernetesClusterUtil.class);
+
+    public static boolean isKubernetesClusterNodeReady(KubernetesCluster 
kubernetesCluster, String ipAddress, int port,
+                                                       String user, File 
sshKeyFile, String nodeName) throws Exception {
+        Pair<Boolean, String> result = SshHelper.sshExecute(ipAddress, port,
+                user, sshKeyFile, null,
+                String.format("sudo kubectl get nodes | awk '{if ($1 == \"%s\" 
&& $2 == \"Ready\") print $1}'", nodeName.toLowerCase()),
+                10000, 10000, 20000);
+        if (result.first() && nodeName.equals(result.second().trim())) {
+            return true;
+        }
+        if (LOGGER.isDebugEnabled()) {
+            LOGGER.debug(String.format("Failed to retrieve status for node: %s 
in Kubernetes cluster ID: %s. Output: %s", nodeName, 
kubernetesCluster.getUuid(), result.second()));
+        }
+        return false;
+    }
+
+    public static boolean isKubernetesClusterNodeReady(KubernetesCluster 
kubernetesCluster, String ipAddress, int port,
+                                                       String user, File 
sshKeyFile, String nodeName, int retries,
+                                                       int waitDuration) {
+        int retryCounter = 0;
+        while (retryCounter < retries) {
+            boolean ready = false;
+            try {
+                ready = isKubernetesClusterNodeReady(kubernetesCluster, 
ipAddress, port, user, sshKeyFile, nodeName);
+            } catch (Exception e) {
+                LOGGER.warn(String.format("Failed to retrieve state of node: 
%s in Kubernetes cluster ID: %s", nodeName, kubernetesCluster.getUuid()), e);
+            }
+            if (ready) {
+                return true;
+            }
+            try {
+                Thread.sleep(waitDuration);
+            } catch (InterruptedException ie) {
+                LOGGER.error(String.format("Error while waiting for Kubernetes 
cluster ID: %s node: %s to become ready", kubernetesCluster.getUuid(), 
nodeName), ie);
+            }
+            retryCounter++;
+        }
+        return false;
+    }
+
+    public static boolean uncordonKubernetesClusterNode(KubernetesCluster 
kubernetesCluster, String ipAddress, int port,
 
 Review comment:
   @DaanHoogland Named so because that is the Kubernetes action performed here, 
https://github.com/apache/cloudstack/blob/b46dcc6cde3441010f14dd9c0f59910db00ab966/plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/utils/KubernetesClusterUtil.java#L89-L91
   Should I add javadoc?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to