forked from fabric8io/kubernetes-client
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KubernetesMockServer should not read local .kubeconfig
KubernetesMockServer is using ConfigBuilder which tries to autoconfigure Config by reading it automatically from local kubeconfig. this results in issues where some code might accidentally read token/context set in KubernetesClient's config which is set by Config autoconfigure. This PR explicitly sets token, contexts to null/empty so that mockServer tests run independently of local Kubernetes config
- Loading branch information
1 parent
6932324
commit 3dad6fa
Showing
9 changed files
with
100 additions
and
11 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
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
54 changes: 54 additions & 0 deletions
54
...mock/src/test/java/io/fabric8/kubernetes/client/server/mock/MockServerKubeconfigTest.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,54 @@ | ||
/** | ||
* Copyright (C) 2015 Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.fabric8.kubernetes.client.server.mock; | ||
|
||
import io.fabric8.kubernetes.client.KubernetesClient; | ||
|
||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
|
||
import java.util.Objects; | ||
|
||
class MockServerKubeconfigTest { | ||
|
||
@BeforeEach | ||
void setKubeConfigProperty() { | ||
System.setProperty("kubeconfig", Objects.requireNonNull(getClass().getResource("/testkubeconfig")).getFile()); | ||
} | ||
|
||
@Test | ||
void mockServerShouldNotPickTokenAndNameContextIfKubeConfigFound() { | ||
// Given | ||
KubernetesMockServer server = new KubernetesMockServer(); | ||
|
||
// When | ||
KubernetesClient client = server.createClient(); | ||
|
||
// Then | ||
Assertions.assertNotNull(client); | ||
Assertions.assertNull(client.getConfiguration().getOauthToken()); | ||
Assertions.assertNull(client.getConfiguration().getCurrentContext()); | ||
Assertions.assertTrue(client.getConfiguration().getContexts().isEmpty()); | ||
} | ||
|
||
@AfterEach | ||
public void cleanup() { | ||
System.clearProperty("kubeconfig"); | ||
} | ||
} |
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,19 @@ | ||
apiVersion: v1 | ||
clusters: | ||
- cluster: | ||
insecure-skip-tls-verify: true | ||
server: https://api.crc.testing:6443 | ||
name: api-crc-testing:6443 | ||
contexts: | ||
- context: | ||
cluster: api-crc-testing:6443 | ||
namespace: default | ||
user: kubeadmin/api-crc-testing:6443 | ||
name: default/api-crc-testing:6443/kubeadmin | ||
current-context: default/api-crc-testing:6443/kubeadmin | ||
kind: Config | ||
preferences: {} | ||
users: | ||
- name: kubeadmin/api-crc-testing:6443 | ||
user: | ||
token: sha256~iYtvbJNJEE0_QSxYE0Wl1MJJxpSvDUsNyYfzkCIoDkw |
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
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