File tree Expand file tree Collapse file tree 5 files changed +78
-0
lines changed Expand file tree Collapse file tree 5 files changed +78
-0
lines changed Original file line number Diff line number Diff line change 96
96
'host ' => env ('KUBE_HOST ' , 'https://kubernetes.default.svc.cluster.local ' ),
97
97
],
98
98
99
+ /*
100
+ |--------------------------------------------------------------------------
101
+ | Environment Variable Driver
102
+ |--------------------------------------------------------------------------
103
+ |
104
+ | The environment variable driver leverages your current (possibly set)
105
+ | KUBECONFIG environment variable. The variable contains a list of paths
106
+ | towards multiple kubeconfig files that will be read, merged and based
107
+ | on the selected context from the configuration, it will connect
108
+ | to the cluster, just like the "kubeconfig" driver.
109
+ |
110
+ | Read more: https://kubernetes.io/docs/tasks/access-application-cluster/configure-access-multiple-clusters/
111
+ |
112
+ */
113
+
114
+ 'environment ' => [
115
+ 'driver ' => 'environment ' ,
116
+ 'context ' => env ('KUBECONFIG_CONTEXT ' , 'minikube ' ),
117
+ ],
118
+
99
119
],
100
120
101
121
];
Original file line number Diff line number Diff line change @@ -55,6 +55,7 @@ protected function loadFromConfig(array $config)
55
55
case 'http ' : $ this ->configureWithHttpAuth ($ config ); break ;
56
56
case 'token ' : $ this ->configureWithToken ($ config ); break ;
57
57
case 'cluster ' : $ this ->configureInCluster ($ config ); break ;
58
+ case 'variable ' : $ this ->configureWithKubeConfigVariable ($ config ); break ;
58
59
default : break ;
59
60
}
60
61
}
@@ -144,6 +145,18 @@ protected function configureInCluster(array $config)
144
145
$ this ->cluster = PhpK8sCluster::inClusterConfiguration ();
145
146
}
146
147
148
+ /**
149
+ * Configure the cluster using the
150
+ * KUBECONFIG environment variable.
151
+ *
152
+ * @param array $config
153
+ * @return void
154
+ */
155
+ protected function configureWithKubeConfigVariable (array $ config )
156
+ {
157
+ $ this ->cluster = PhpK8sCluster::fromKubeConfigVariable ($ config ['context ' ]);
158
+ }
159
+
147
160
/**
148
161
* Get the initialized cluster.
149
162
*
Original file line number Diff line number Diff line change @@ -130,4 +130,29 @@ public function test_in_cluster_config()
130
130
$ this ->assertEquals ('/var/run/secrets/kubernetes.io/serviceaccount/ca.crt ' , $ caPath );
131
131
$ this ->assertEquals ('some-namespace ' , K8sResource::$ defaultNamespace );
132
132
}
133
+
134
+ /**
135
+ * @dataProvider environmentVariableContextProvider
136
+ */
137
+ public function test_from_environment_variable (string $ context = null , string $ expectedDomain )
138
+ {
139
+ $ _SERVER ['KUBECONFIG ' ] = __DIR__ .'/cluster/kubeconfig.yaml:: ' .__DIR__ .'/cluster/kubeconfig-2.yaml ' ;
140
+
141
+ $ this ->app ['config ' ]->set ('k8s.default ' , 'variable ' );
142
+ $ this ->app ['config ' ]->set ('k8s.connections.variable ' , [
143
+ 'driver ' => 'variable ' ,
144
+ 'context ' => $ context ,
145
+ ]);
146
+
147
+ $ cluster = LaravelK8sFacade::connection ('variable ' )->getCluster ();
148
+
149
+ $ this ->assertSame ("https:// {$ expectedDomain }:8443/? " , $ cluster ->getCallableUrl ('/ ' , []));
150
+ }
151
+
152
+ public function environmentVariableContextProvider (): iterable
153
+ {
154
+ yield [null , 'minikube ' ];
155
+ yield ['minikube-2 ' , 'minikube-2 ' ];
156
+ yield ['minikube-3 ' , 'minikube-3 ' ];
157
+ }
133
158
}
Original file line number Diff line number Diff line change 6
6
7
7
abstract class TestCase extends Orchestra
8
8
{
9
+ /**
10
+ * {@inheritDoc}
11
+ */
12
+ public function tearDown (): void
13
+ {
14
+ parent ::tearDown ();
15
+
16
+ unset($ _SERVER ['KUBECONFIG ' ]);
17
+ }
18
+
9
19
/**
10
20
* {@inheritdoc}
11
21
*/
Original file line number Diff line number Diff line change
1
+ clusters :
2
+ - cluster :
3
+ certificate-authority-data : c29tZS1jYQo= # "some-ca"
4
+ server : https://minikube-3:8443
5
+ name : minikube-3
6
+ contexts :
7
+ - context :
8
+ cluster : minikube-3
9
+ user : minikube
10
+ name : minikube-3
You can’t perform that action at this time.
0 commit comments