Skip to content

Commit

Permalink
Enable openshift client autoconfiguration
Browse files Browse the repository at this point in the history
  • Loading branch information
asmigala authored and avano committed Feb 9, 2023
1 parent dee43ea commit 34faf0f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class OpenshiftConfiguration extends Configuration {
public static final String OPENSHIFT_NAMESPACE = "openshift.namespace";
public static final String OPENSHIFT_NAMESPACE_DELETE = "openshift.namespace.delete";
public static final String OPENSHIFT_KUBECONFIG = "openshift.kubeconfig";
public static final String KUBECONFIG = "kubeconfig";
public static final String OPENSHIFT_HTTPS_PROXY = "openshift.https.proxy";
public static final String OPENSHIFT_DEPLOYMENT_LABEL = "openshift.deployment.label";

Expand Down Expand Up @@ -68,7 +69,8 @@ public static boolean openshiftNamespaceDelete() {
}

public static Path openshiftKubeconfig() {
return Paths.get(getProperty(OPENSHIFT_KUBECONFIG, System.getProperty("user.home") + "/.kube/config"));
String kubeconfig = getProperty(OPENSHIFT_KUBECONFIG, getProperty(KUBECONFIG));
return kubeconfig == null ? null : Paths.get(kubeconfig);
}

public static String openshiftDeploymentLabel() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,17 @@ protected OpenshiftClient(OpenShiftConfig openShiftConfig) {
private static OpenshiftClient createInstance() {
OpenShiftConfigBuilder configBuilder;

if (OpenshiftConfiguration.openshiftUrl() == null) {
configBuilder = new OpenShiftConfigBuilder(
new OpenShiftConfig(Config.fromKubeconfig(IOUtils.readFile(OpenshiftConfiguration.openshiftKubeconfig()))));
} else {
if (OpenshiftConfiguration.openshiftUrl() != null) {
configBuilder = new OpenShiftConfigBuilder()
.withMasterUrl(OpenshiftConfiguration.openshiftUrl())
.withUsername(OpenshiftConfiguration.openshiftUsername())
.withPassword(OpenshiftConfiguration.openshiftPassword());
} else if (OpenshiftConfiguration.openshiftKubeconfig() != null) {
configBuilder = new OpenShiftConfigBuilder(
new OpenShiftConfig(Config.fromKubeconfig(IOUtils.readFile(OpenshiftConfiguration.openshiftKubeconfig()))));
} else {
LOG.info("Auto-configuring openshift client");
configBuilder = new OpenShiftConfigBuilder(new OpenShiftConfig(Config.autoConfigure(null)));
}

String namespace = OpenshiftConfiguration.openshiftNamespace();
Expand Down

0 comments on commit 34faf0f

Please sign in to comment.