GabrielBrascher commented on a change in pull request #5254:
URL: https://github.com/apache/cloudstack/pull/5254#discussion_r682037350



##########
File path: 
plugins/integrations/kubernetes-service/src/main/resources/script/deploy-cloudstack-secret
##########
@@ -0,0 +1,69 @@
+

Review comment:
       The first line is blank, instead of containing the bash _shebang #!_.

##########
File path: 
plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/actionworkers/KubernetesClusterActionWorker.java
##########
@@ -380,4 +394,108 @@ protected boolean stateTransitTo(long 
kubernetesClusterId, KubernetesCluster.Eve
             return false;
         }
     }
+
+    protected boolean createCloudStackSecret(String[] keys) {
+        File pkFile = getManagementServerSshPublicKeyFile();
+        Pair<String, Integer> publicIpSshPort = 
getKubernetesClusterServerIpSshPort(null);
+        publicIpAddress = publicIpSshPort.first();
+        sshPort = publicIpSshPort.second();
+
+        try {
+            Pair<Boolean, String> result = 
SshHelper.sshExecute(publicIpAddress, sshPort, CLUSTER_NODE_VM_USER,
+                pkFile, null, String.format("sudo 
/opt/bin/deploy-cloudstack-secret -u '%s' -k '%s' -s '%s'",
+                    ApiServiceConfiguration.ApiServletPath.value(), keys[0], 
keys[1]),
+                    10000, 10000, 60000);
+            return result.first();
+        } catch (Exception e) {
+            String msg = String.format("Failed to add cloudstack-secret to 
Kubernetes cluster: %s", kubernetesCluster.getName());
+            LOGGER.warn(msg, e);
+        }
+        return false;
+    }
+
+    protected File retrieveScriptFile(String filename) {
+        File file = null;
+        try {
+            String data = readResourceFile("/script/" + filename);
+            file = File.createTempFile(filename, ".sh");
+            BufferedWriter writer = new BufferedWriter(new FileWriter(file));
+            writer.write(data);
+            writer.close();
+        } catch (IOException e) {
+            logAndThrow(Level.ERROR, String.format("Kubernetes Cluster %s : 
Failed to to fetch script %s",
+                kubernetesCluster.getName(), filename), e);
+        }
+        return file;
+    }
+
+    protected void retrieveScriptFiles() {
+        deploySecretsScriptFile = 
retrieveScriptFile(deploySecretsScriptFilename);
+        deployProviderScriptFile = 
retrieveScriptFile(deployProviderScriptFilename);
+    }
+
+    protected void copyScripts(String nodeAddress, final int sshPort) {
+        try {
+            SshHelper.scpTo(nodeAddress, sshPort, CLUSTER_NODE_VM_USER, 
sshKeyFile, null,
+                    "~/", deploySecretsScriptFile.getAbsolutePath(), "0755");
+            SshHelper.scpTo(nodeAddress, sshPort, CLUSTER_NODE_VM_USER, 
sshKeyFile, null,
+                    "~/", deployProviderScriptFile.getAbsolutePath(), "0755");
+            String cmdStr = String.format("sudo mv ~/%s /opt/bin/%s", 
deploySecretsScriptFile.getName(), deploySecretsScriptFilename);
+            SshHelper.sshExecute(publicIpAddress, sshPort, 
CLUSTER_NODE_VM_USER, sshKeyFile, null,
+                cmdStr, 10000, 10000, 10 * 60 * 1000);
+            cmdStr = String.format("sudo mv ~/%s /opt/bin/%s", 
deployProviderScriptFile.getName(), deployProviderScriptFilename);
+            SshHelper.sshExecute(publicIpAddress, sshPort, 
CLUSTER_NODE_VM_USER, sshKeyFile, null,
+                cmdStr, 10000, 10000, 10 * 60 * 1000);
+        } catch (Exception e) {
+            throw new CloudRuntimeException(e);
+        }
+    }
+
+    protected boolean deployProvider() {
+        Network network = 
networkDao.findById(kubernetesCluster.getNetworkId());
+        // Since the provider creates IP addresses, don't deploy it unless the 
underlying network supports it
+        if (network.getGuestType() != GuestType.Isolated) {
+            logMessage(Level.INFO, String.format("Skipping adding the provider 
as %s is not on an isolated network",
+                kubernetesCluster.getName()), null);
+            return true;
+        }
+        File pkFile = getManagementServerSshPublicKeyFile();
+        Pair<String, Integer> publicIpSshPort = 
getKubernetesClusterServerIpSshPort(null);
+        publicIpAddress = publicIpSshPort.first();
+        sshPort = publicIpSshPort.second();
+
+        try {
+            String command = "sudo /opt/bin/deploy-provider";

Review comment:
       This could also be extracted to a constant, or append the existing 
String constant `deployProviderScriptFilename`.

##########
File path: 
plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/actionworkers/KubernetesClusterActionWorker.java
##########
@@ -380,4 +394,108 @@ protected boolean stateTransitTo(long 
kubernetesClusterId, KubernetesCluster.Eve
             return false;
         }
     }
+
+    protected boolean createCloudStackSecret(String[] keys) {
+        File pkFile = getManagementServerSshPublicKeyFile();
+        Pair<String, Integer> publicIpSshPort = 
getKubernetesClusterServerIpSshPort(null);
+        publicIpAddress = publicIpSshPort.first();
+        sshPort = publicIpSshPort.second();
+
+        try {
+            Pair<Boolean, String> result = 
SshHelper.sshExecute(publicIpAddress, sshPort, CLUSTER_NODE_VM_USER,
+                pkFile, null, String.format("sudo 
/opt/bin/deploy-cloudstack-secret -u '%s' -k '%s' -s '%s'",

Review comment:
       Maybe instead of `String.format("sudo /opt/bin/deploy-cloudstack-secret 
..."...)` it could use some of the existing, such as 
`deploySecretsScriptFilename`.

##########
File path: 
plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java
##########
@@ -644,7 +652,15 @@ public KubernetesClusterResponse 
createKubernetesClusterResponse(long kubernetes
         return response;
     }
 
+    private void validateEndpointUrl() {
+        String csUrl = ApiServiceConfiguration.ApiServletPath.value();
+        if (csUrl == null || csUrl.contains("localhost")) {
+            throw new InvalidParameterValueException("Global setting 
endpointe.url has to be set to the Management Server's API end point");

Review comment:
       Would be better to retrieve as @nvazquez said. Thus, if/when this gets 
fixed it will automatically reflect in this message.




-- 
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]


Reply via email to