12
12
import io .fabric8 .kubernetes .client .KubernetesClient ;
13
13
import io .javaoperatorsdk .operator .api .config .LeaderElectionConfiguration ;
14
14
15
+ import static io .fabric8 .kubernetes .client .Config .KUBERNETES_AUTH_TRYKUBECONFIG_SYSTEM_PROPERTY ;
15
16
import static io .fabric8 .kubernetes .client .Config .KUBERNETES_NAMESPACE_FILE ;
16
17
import static org .junit .jupiter .api .Assertions .assertThrows ;
17
18
import static org .junit .jupiter .api .Assertions .assertTrue ;
@@ -33,6 +34,7 @@ void setUp() {
33
34
@ AfterEach
34
35
void tearDown () {
35
36
System .getProperties ().remove (KUBERNETES_NAMESPACE_FILE );
37
+ System .getProperties ().remove (KUBERNETES_AUTH_TRYKUBECONFIG_SYSTEM_PROPERTY );
36
38
}
37
39
38
40
@ Test
@@ -47,6 +49,7 @@ void testInitInferLeaseNamespace(@TempDir Path tempDir) throws IOException {
47
49
var namespacePath = tempDir .resolve ("namespace" );
48
50
Files .writeString (namespacePath , namespace );
49
51
52
+ System .setProperty (KUBERNETES_AUTH_TRYKUBECONFIG_SYSTEM_PROPERTY , "false" );
50
53
System .setProperty (KUBERNETES_NAMESPACE_FILE , namespacePath .toString ());
51
54
52
55
leaderElectionManager .init (new LeaderElectionConfiguration ("test" ), kubernetesClient );
@@ -55,6 +58,15 @@ void testInitInferLeaseNamespace(@TempDir Path tempDir) throws IOException {
55
58
56
59
@ Test
57
60
void testFailedToInitInferLeaseNamespace () {
61
+ System .setProperty (KUBERNETES_AUTH_TRYKUBECONFIG_SYSTEM_PROPERTY , "false" );
62
+ assertThrows (
63
+ IllegalArgumentException .class ,
64
+ () -> leaderElectionManager .init (new LeaderElectionConfiguration ("test" ),
65
+ kubernetesClient ));
66
+ }
67
+
68
+ @ Test
69
+ void testFailedToInitInferLeaseNamespaceProbablyUsingKubeConfig () {
58
70
assertThrows (
59
71
IllegalArgumentException .class ,
60
72
() -> leaderElectionManager .init (new LeaderElectionConfiguration ("test" ),
0 commit comments