Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
cks: use HttpsURLConnection for checking api server
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
  • Loading branch information
shwstppr committed Feb 2, 2021
commit 84d68a816a931b535d92d9214e660c82139fcdfd
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,22 @@

package com.cloud.kubernetes.cluster.utils;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.URL;
import java.util.stream.Collectors;

import javax.net.ssl.HttpsURLConnection;

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;

Expand Down Expand Up @@ -218,7 +221,10 @@ public static boolean isKubernetesClusterServerRunning(final KubernetesCluster k
boolean k8sApiServerSetup = false;
while (System.currentTimeMillis() < timeoutTime) {
try {
String versionOutput = IOUtils.toString(new URL(String.format("https://%s:%d/version", ipAddress, port)), StringUtils.getPreferredCharset());
URL url = new URL(String.format("https://%s:%d/version", ipAddress, port));
HttpsURLConnection con = (HttpsURLConnection)url.openConnection();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we configure it to ignore ssl cert validation?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and get more static analysis reports as issues?

BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));
String versionOutput = br.lines().collect(Collectors.joining());
if (!Strings.isNullOrEmpty(versionOutput)) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info(String.format("Kubernetes cluster ID: %s API has been successfully provisioned, %s", kubernetesCluster.getUuid(), versionOutput));
Expand Down