Skip to content

Commit

Permalink
Fix function de-registration (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
fantapsody authored May 18, 2021
1 parent 078656d commit 8712305
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,28 +113,22 @@ public void deregisterFunction(final String tenant,
null
);
executeCall(call, null);
} catch (Exception e) {
log.error("deregister {}/{}/{} function failed, error message: {}", tenant, namespace, componentName, e);
throw new RestException(javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR, e.getMessage());
}

try {
Call call = worker().getCustomObjectsApi().deleteNamespacedCustomObjectCall(
group,
version,
namespace,
plural,
componentName,
null,
null,
null,
null,
null,
null
);
call = worker().getCoreV1Api()
.deleteNamespacedConfigMapCall(
KubernetesUtils.getConfigMapName("auth", tenant, namespace, componentName),
KubernetesUtils.getNamespace(worker().getFactoryConfig()),
null,
null,
30,
false,
null,
null,
null
);
executeCall(call, null);
} catch (Exception e) {
log.error("deregister {}/{}/{} {} failed, error message: {}", tenant, namespace, componentName, plural, e);
log.error("deregister {}/{}/{} {} failed", tenant, namespace, componentName, plural, e);
throw new RestException(javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR, e.getMessage());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import io.kubernetes.client.openapi.ApiClient;
import io.kubernetes.client.openapi.ApiException;
import io.kubernetes.client.openapi.JSON;
import io.kubernetes.client.openapi.apis.CoreV1Api;
import io.kubernetes.client.openapi.apis.CustomObjectsApi;
import okhttp3.Call;
import okhttp3.Response;
Expand Down Expand Up @@ -526,6 +527,22 @@ public void deregisterFunctionTest() throws ApiException, IOException {
PowerMockito.when(responseBody.string()).thenReturn("{\"Status\": \"Success\"}");
PowerMockito.when(meshWorkerService.getApiClient()).thenReturn(apiClient);
FunctionsImpl functions = spy(new FunctionsImpl(meshWorkerServiceSupplier));

CoreV1Api coreV1Api = PowerMockito.mock(CoreV1Api.class);
PowerMockito.when(meshWorkerService.getCoreV1Api()).thenReturn(coreV1Api);
Call deleteConfigMapCall = PowerMockito.mock(Call.class);
PowerMockito.when(coreV1Api.deleteNamespacedConfigMapCall(
KubernetesUtils.getConfigMapName("auth", tenant, namespace, functionName),
namespace,
null,
null,
30,
false,
null,
null,
null
)).thenReturn(deleteConfigMapCall);
PowerMockito.when(deleteConfigMapCall.execute()).thenReturn(response);
try {
functions.deregisterFunction(tenant, namespace, functionName, null, null);
} catch (Exception exception) {
Expand Down

0 comments on commit 8712305

Please sign in to comment.