File tree Expand file tree Collapse file tree 5 files changed +52
-5
lines changed Expand file tree Collapse file tree 5 files changed +52
-5
lines changed Original file line number Diff line number Diff line change 53
53
54
54
- name : Install dependencies
55
55
run : |
56
- composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "orchestra/database:${{ matrix.testbench }}" --no-interaction --no-update
56
+ composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
57
57
composer update --${{ matrix.prefer }} --prefer-dist --no-interaction --no-suggest
58
58
59
+ - name : Setup in-cluster config
60
+ run : |
61
+ sudo mkdir -p /var/run/secrets/kubernetes.io/serviceaccount
62
+ echo "some-token" | sudo tee /var/run/secrets/kubernetes.io/serviceaccount/token
63
+ echo "c29tZS1jZXJ0Cg==" | sudo tee /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
64
+ echo "some-namespace" | sudo tee /var/run/secrets/kubernetes.io/serviceaccount/namespace
65
+ sudo chmod -R 777 /var/run/secrets/kubernetes.io/serviceaccount/
66
+
59
67
- name : Run tests
60
68
run : |
61
69
vendor/bin/phpunit --coverage-text --coverage-clover=coverage.xml
Original file line number Diff line number Diff line change 12
12
}
13
13
],
14
14
"require" : {
15
- "renoki-co/php-k8s" : " ^2.0 "
15
+ "renoki-co/php-k8s" : " ^2.2 "
16
16
},
17
17
"autoload" : {
18
18
"psr-4" : {
28
28
"test" : " vendor/bin/phpunit"
29
29
},
30
30
"require-dev" : {
31
- "laravel/legacy-factories" : " ^1.1" ,
32
31
"mockery/mockery" : " ^1.4" ,
33
- "orchestra/testbench" : " ^5.0|^6.0" ,
34
- "orchestra/database" : " ^5.0|^6.0"
32
+ "orchestra/testbench" : " ^5.0|^6.0"
35
33
},
36
34
"config" : {
37
35
"sort-packages" : true
Original file line number Diff line number Diff line change 80
80
'token ' => env ('KUBE_BEARER_TOKEN ' , null ),
81
81
],
82
82
83
+ /*
84
+ |--------------------------------------------------------------------------
85
+ | In-Cluster Driver
86
+ |--------------------------------------------------------------------------
87
+ |
88
+ | In-Cluster Driver works only if the written PHP app runs
89
+ | inside a Kubernetes Pod, within a Cluster. The configuration
90
+ | is being loaded automatically.
91
+ |
92
+ */
93
+
94
+ 'cluster ' => [
95
+ 'driver ' => 'cluster ' ,
96
+ ],
97
+
83
98
],
84
99
85
100
];
Original file line number Diff line number Diff line change @@ -53,6 +53,7 @@ protected function loadFromConfig(array $config)
53
53
case 'kubeconfig ' : $ this ->configureWithKubeConfigFile ($ config ); break ;
54
54
case 'http ' : $ this ->configureWithHttpAuth ($ config ); break ;
55
55
case 'token ' : $ this ->configureWithToken ($ config ); break ;
56
+ case 'cluster ' : $ this ->configureInCluster (); break ;
56
57
default : break ;
57
58
}
58
59
}
@@ -131,6 +132,16 @@ protected function configureWithToken(array $config)
131
132
$ this ->cluster ->withToken ($ config ['token ' ]);
132
133
}
133
134
135
+ /**
136
+ * Load the In-Cluster configuration.
137
+ *
138
+ * @return void
139
+ */
140
+ protected function configureInCluster ()
141
+ {
142
+ $ this ->cluster ->inClusterConfiguration ();
143
+ }
144
+
134
145
/**
135
146
* Get the initialized cluster.
136
147
*
Original file line number Diff line number Diff line change 3
3
namespace RenokiCo \LaravelK8s \Test ;
4
4
5
5
use RenokiCo \LaravelK8s \LaravelK8sFacade ;
6
+ use RenokiCo \PhpK8s \Kinds \K8sResource ;
6
7
7
8
class ConfigurationTest extends TestCase
8
9
{
@@ -108,4 +109,18 @@ public function test_token_authentication()
108
109
109
110
$ this ->assertEquals ('Bearer some-token ' , $ token );
110
111
}
112
+
113
+ public function test_in_cluster_config ()
114
+ {
115
+ $ cluster = LaravelK8sFacade::connection ('cluster ' )->getCluster ();
116
+
117
+ [
118
+ 'headers ' => ['authorization ' => $ token ],
119
+ 'verify ' => $ caPath ,
120
+ ] = $ cluster ->getClient ()->getConfig ();
121
+
122
+ $ this ->assertEquals ('Bearer some-token ' , $ token );
123
+ $ this ->assertEquals ('/var/run/secrets/kubernetes.io/serviceaccount/ca.crt ' , $ caPath );
124
+ $ this ->assertEquals ('some-namespace ' , K8sResource::$ defaultNamespace );
125
+ }
111
126
}
You can’t perform that action at this time.
0 commit comments