Skip to content

Commit 8712305

Browse files
authored
Fix function de-registration (#159)
1 parent 078656d commit 8712305

2 files changed

Lines changed: 30 additions & 19 deletions

File tree

mesh-worker-service/src/main/java/io/functionmesh/compute/rest/api/MeshComponentImpl.java

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -113,28 +113,22 @@ public void deregisterFunction(final String tenant,
113113
null
114114
);
115115
executeCall(call, null);
116-
} catch (Exception e) {
117-
log.error("deregister {}/{}/{} function failed, error message: {}", tenant, namespace, componentName, e);
118-
throw new RestException(javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR, e.getMessage());
119-
}
120116

121-
try {
122-
Call call = worker().getCustomObjectsApi().deleteNamespacedCustomObjectCall(
123-
group,
124-
version,
125-
namespace,
126-
plural,
127-
componentName,
128-
null,
129-
null,
130-
null,
131-
null,
132-
null,
133-
null
134-
);
117+
call = worker().getCoreV1Api()
118+
.deleteNamespacedConfigMapCall(
119+
KubernetesUtils.getConfigMapName("auth", tenant, namespace, componentName),
120+
KubernetesUtils.getNamespace(worker().getFactoryConfig()),
121+
null,
122+
null,
123+
30,
124+
false,
125+
null,
126+
null,
127+
null
128+
);
135129
executeCall(call, null);
136130
} catch (Exception e) {
137-
log.error("deregister {}/{}/{} {} failed, error message: {}", tenant, namespace, componentName, plural, e);
131+
log.error("deregister {}/{}/{} {} failed", tenant, namespace, componentName, plural, e);
138132
throw new RestException(javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR, e.getMessage());
139133
}
140134
}

mesh-worker-service/src/test/java/io/functionmesh/compute/rest/api/FunctionsImplTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import io.kubernetes.client.openapi.ApiClient;
2929
import io.kubernetes.client.openapi.ApiException;
3030
import io.kubernetes.client.openapi.JSON;
31+
import io.kubernetes.client.openapi.apis.CoreV1Api;
3132
import io.kubernetes.client.openapi.apis.CustomObjectsApi;
3233
import okhttp3.Call;
3334
import okhttp3.Response;
@@ -526,6 +527,22 @@ public void deregisterFunctionTest() throws ApiException, IOException {
526527
PowerMockito.when(responseBody.string()).thenReturn("{\"Status\": \"Success\"}");
527528
PowerMockito.when(meshWorkerService.getApiClient()).thenReturn(apiClient);
528529
FunctionsImpl functions = spy(new FunctionsImpl(meshWorkerServiceSupplier));
530+
531+
CoreV1Api coreV1Api = PowerMockito.mock(CoreV1Api.class);
532+
PowerMockito.when(meshWorkerService.getCoreV1Api()).thenReturn(coreV1Api);
533+
Call deleteConfigMapCall = PowerMockito.mock(Call.class);
534+
PowerMockito.when(coreV1Api.deleteNamespacedConfigMapCall(
535+
KubernetesUtils.getConfigMapName("auth", tenant, namespace, functionName),
536+
namespace,
537+
null,
538+
null,
539+
30,
540+
false,
541+
null,
542+
null,
543+
null
544+
)).thenReturn(deleteConfigMapCall);
545+
PowerMockito.when(deleteConfigMapCall.execute()).thenReturn(response);
529546
try {
530547
functions.deregisterFunction(tenant, namespace, functionName, null, null);
531548
} catch (Exception exception) {

0 commit comments

Comments
 (0)