-
Notifications
You must be signed in to change notification settings - Fork 529
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix (jkube-kit/common) : Update `KubernetesHelper.exportKubernetesCli…
…entConfigToFile` to add opinionated Cluster Context When using KubernetesClient with Kubernetes Mock Server, `kubernetesClient.getConfiguration()` returns a Config object with no context set. Handle this case in KubernetesMockServerUtil to create opinionated Context until this gets fixed in KubernetesMockServer Signed-off-by: Rohan Kumar <[email protected]>
- Loading branch information
1 parent
8b3ddfa
commit ef64498
Showing
3 changed files
with
89 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...-kit/common/src/test/java/org/eclipse/jkube/kit/common/util/KubernetesMockServerUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright (c) 2019 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at: | ||
* | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.jkube.kit.common.util; | ||
|
||
import io.fabric8.kubernetes.api.model.NamedContext; | ||
import io.fabric8.kubernetes.api.model.NamedContextBuilder; | ||
import io.fabric8.kubernetes.client.Config; | ||
import org.eclipse.jkube.kit.common.JKubeException; | ||
|
||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.util.Optional; | ||
|
||
public class KubernetesMockServerUtil { | ||
private KubernetesMockServerUtil() { } | ||
|
||
public static NamedContext createOpinionatedKubernetesContextForMockKubernetesClientConfiguration(Config kubernetesClientConfig) { | ||
try { | ||
if (kubernetesClientConfig != null && kubernetesClientConfig.getCurrentContext() == null) { | ||
URI uri = new URI(kubernetesClientConfig.getMasterUrl()); | ||
return new NamedContextBuilder() | ||
.withName("jkube-context") | ||
.withNewContext() | ||
.withNamespace(kubernetesClientConfig.getNamespace()) | ||
.withCluster(String.format("%s:%d", uri.getHost(), uri.getPort())) | ||
.withUser(Optional.ofNullable(kubernetesClientConfig.getUsername()) | ||
.orElse("jkube")) | ||
.endContext() | ||
.build(); | ||
} | ||
return null; | ||
} catch (URISyntaxException uriSyntaxException) { | ||
throw new JKubeException("Invalid Kubernetes cluster url ", uriSyntaxException); | ||
} | ||
} | ||
} |