46
46
import io .kubernetes .client .custom .V1Patch ;
47
47
import io .kubernetes .client .openapi .ApiClient ;
48
48
import io .kubernetes .client .openapi .ApiException ;
49
+ import io .kubernetes .client .openapi .Configuration ;
49
50
import io .kubernetes .client .openapi .apis .AppsV1Api ;
50
51
import io .kubernetes .client .openapi .models .V1Container ;
51
52
import io .kubernetes .client .openapi .models .V1ContainerPort ;
@@ -72,12 +73,18 @@ public class AppsV1Controller extends KubernetesController {
72
73
73
74
private static final String ENV_SHARD_ID = "SHARD_ID" ;
74
75
75
- private final AppsV1Api client ;
76
+ private final AppsV1Api appsClient ;
76
77
77
78
AppsV1Controller (Config configuration , Config runtimeConfiguration ) {
78
79
super (configuration , runtimeConfiguration );
79
- final ApiClient apiClient = new ApiClient ().setBasePath (getKubernetesUri ());
80
- client = new AppsV1Api (apiClient );
80
+ try {
81
+ final ApiClient apiClient = io .kubernetes .client .util .Config .defaultClient ();
82
+ Configuration .setDefaultApiClient (apiClient );
83
+ appsClient = new AppsV1Api (apiClient );
84
+ } catch (IOException e ) {
85
+ LOG .log (Level .SEVERE , "Failed to setup Kubernetes client" + e );
86
+ throw new RuntimeException (e );
87
+ }
81
88
}
82
89
83
90
@ Override
@@ -99,7 +106,7 @@ boolean submit(PackingPlan packingPlan) {
99
106
100
107
try {
101
108
final V1StatefulSet response =
102
- client .createNamespacedStatefulSet (getNamespace (), statefulSet , null ,
109
+ appsClient .createNamespacedStatefulSet (getNamespace (), statefulSet , null ,
103
110
null , null );
104
111
} catch (ApiException e ) {
105
112
KubernetesUtils .logExceptionWithDetails (LOG , "Error creating topology" , e );
@@ -180,20 +187,21 @@ private void doPatch(V1StatefulSetSpec patchedSpec) throws ApiException {
180
187
String .format (JSON_PATCH_STATEFUL_SET_REPLICAS_FORMAT ,
181
188
patchedSpec .getReplicas ().toString ());
182
189
final V1Patch patch = new V1Patch (body );
183
- client .patchNamespacedStatefulSet (getTopologyName (),
190
+ appsClient .patchNamespacedStatefulSet (getTopologyName (),
184
191
getNamespace (), patch , null , null , null , null );
185
192
}
186
193
187
194
private static final String JSON_PATCH_STATEFUL_SET_REPLICAS_FORMAT =
188
195
"{\" op\" :\" replace\" ,\" path\" :\" /spec/replicas\" ,\" value\" :%s}" ;
189
196
190
197
V1StatefulSet getStatefulSet () throws ApiException {
191
- return client .readNamespacedStatefulSet (getTopologyName (), getNamespace (), null , null , null );
198
+ return appsClient .readNamespacedStatefulSet (getTopologyName (), getNamespace (),
199
+ null , null , null );
192
200
}
193
201
194
202
boolean deleteStatefulSet () {
195
203
try {
196
- final Response response = client .deleteNamespacedStatefulSetCall (getTopologyName (),
204
+ final Response response = appsClient .deleteNamespacedStatefulSetCall (getTopologyName (),
197
205
getNamespace (), null , null , 0 , null ,
198
206
KubernetesConstants .DELETE_OPTIONS_PROPAGATION_POLICY , null , null ).execute ();
199
207
@@ -219,7 +227,7 @@ boolean deleteStatefulSet() {
219
227
boolean isStatefulSet () {
220
228
try {
221
229
final V1StatefulSet response =
222
- client .readNamespacedStatefulSet (getTopologyName (), getNamespace (),
230
+ appsClient .readNamespacedStatefulSet (getTopologyName (), getNamespace (),
223
231
null , null , null );
224
232
return response .getKind ().equals ("StatefulSet" );
225
233
} catch (ApiException e ) {
0 commit comments