forked from eclipse-jkube/jkube
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(common): kubernetes mock server config can be exported to a vali…
…d .kube/config file fix (jkube-kit/common) : Update `KubernetesHelper.exportKubernetesClientConfigToFile` 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]> --- review: KubernetesMockServerUtil is chained to KubernetesHelper Signed-off-by: Marc Nuri <[email protected]>
- Loading branch information
1 parent
dfe163d
commit 4da625e
Showing
3 changed files
with
81 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
46 changes: 46 additions & 0 deletions
46
...-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,46 @@ | ||
/* | ||
* 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 io.fabric8.kubernetes.client.ConfigBuilder; | ||
import io.fabric8.kubernetes.client.KubernetesClient; | ||
import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer; | ||
|
||
import java.nio.file.Path; | ||
|
||
public class KubernetesMockServerUtil { | ||
|
||
private KubernetesMockServerUtil() { } | ||
|
||
// TODO: Remove after https://github.com/fabric8io/kubernetes-client/issues/6068 is fixed | ||
public static Path exportKubernetesClientConfigToFile(KubernetesMockServer mockServer, Path targetKubeConfig) { | ||
final KubernetesClient client = mockServer.createClient(); | ||
final NamedContext mockServerContext = new NamedContextBuilder() | ||
.withName("mock-server") | ||
.withNewContext() | ||
.withNamespace(client.getNamespace()) | ||
.withCluster(String.format("%s:%d", mockServer.getHostName(), mockServer.getPort())) | ||
.withUser("mock-server-user") | ||
.endContext() | ||
.build(); | ||
final Config kubernetesClientConfig = new ConfigBuilder(client.getConfiguration()) | ||
.addToContexts(mockServerContext) | ||
.withCurrentContext(mockServerContext) | ||
.build(); | ||
return KubernetesHelper.exportKubernetesClientConfigToFile(kubernetesClientConfig, targetKubeConfig); | ||
} | ||
} |