-
Notifications
You must be signed in to change notification settings - Fork 835
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #408 from cliveseldon/cluster_manager_cache_bug
Cluster Manager Cache Fix
- Loading branch information
Showing
19 changed files
with
494 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
cluster-manager/src/main/java/io/seldon/clustermanager/k8s/client/K8sApiProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
package io.seldon.clustermanager.k8s.client; | ||
|
||
import io.kubernetes.client.ApiClient; | ||
import io.kubernetes.client.apis.CoreV1Api; | ||
import io.kubernetes.client.apis.CustomObjectsApi; | ||
import io.kubernetes.client.apis.ExtensionsV1beta1Api; | ||
|
||
public interface K8sApiProvider { | ||
|
||
public CustomObjectsApi getCustomObjectsApi(ApiClient client); | ||
public ExtensionsV1beta1Api getExtensionsV1beta1Api(ApiClient client); | ||
public CoreV1Api getCoreV1Api(ApiClient client); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
cluster-manager/src/test/java/io/seldon/clustermanager/k8s/KubeCRDHandlerImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package io.seldon.clustermanager.k8s; | ||
|
||
import static org.mockito.Matchers.any; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import io.kubernetes.client.ApiClient; | ||
import io.kubernetes.client.ApiException; | ||
import io.kubernetes.client.apis.CoreV1Api; | ||
import io.kubernetes.client.apis.ExtensionsV1beta1Api; | ||
import io.kubernetes.client.models.ExtensionsV1beta1DeploymentList; | ||
import io.kubernetes.client.models.V1ServiceList; | ||
import io.seldon.clustermanager.k8s.client.K8sApiProvider; | ||
import io.seldon.protos.DeploymentProtos.SeldonDeployment; | ||
|
||
|
||
public class KubeCRDHandlerImplTest extends End2EndBase { | ||
|
||
@Test | ||
public void validSeldonDeploymentTest() throws Exception | ||
{ | ||
createMocks("src/test/resources/model_simple.json"); | ||
KubeCRDHandler crdHandler = new KubeCRDHandlerImpl(mockK8sApiProvider, mockK8sClientProvider, props); | ||
|
||
SeldonDeployment sDep = crdHandler.getSeldonDeployment("a", "b"); | ||
Assert.assertNotNull(sDep); | ||
} | ||
|
||
@Test | ||
public void invalidSeldonDeploymentJsonTest() throws Exception | ||
{ | ||
createMocks("src/test/resources/invalid.json"); | ||
KubeCRDHandler crdHandler = new KubeCRDHandlerImpl(mockK8sApiProvider, mockK8sClientProvider, props); | ||
|
||
SeldonDeployment sDep = crdHandler.getSeldonDeployment("a", "b"); | ||
Assert.assertNull(sDep); | ||
} | ||
|
||
@Test | ||
public void invalidSeldonDeploymentTest() throws Exception | ||
{ | ||
createMocks("src/test/resources/model_invalid.json"); | ||
KubeCRDHandler crdHandler = new KubeCRDHandlerImpl(mockK8sApiProvider, mockK8sClientProvider, props); | ||
|
||
SeldonDeployment sDep = crdHandler.getSeldonDeployment("a", "b"); | ||
Assert.assertNull(sDep); | ||
} | ||
|
||
|
||
@Test | ||
public void getOwnedDeploymentsTest() throws Exception | ||
{ | ||
createMocks("src/test/resources/model_simple.json"); | ||
K8sApiProvider mockApiProvider = mock(K8sApiProvider.class); | ||
ExtensionsV1beta1DeploymentList l = new ExtensionsV1beta1DeploymentList(); | ||
ExtensionsV1beta1Api mockExtensionsApi = mock(ExtensionsV1beta1Api.class); | ||
when(mockApiProvider.getExtensionsV1beta1Api(any(ApiClient.class))).thenReturn(mockExtensionsApi); | ||
when(mockExtensionsApi.listNamespacedDeployment(any(String.class), any(String.class), any(String.class), | ||
any(String.class), any(Boolean.class), any(String.class), any(Integer.class), | ||
any(String.class),any(Integer.class),any(Boolean.class))).thenReturn(l); | ||
KubeCRDHandler crdHandler = new KubeCRDHandlerImpl(mockApiProvider, mockK8sClientProvider, props); | ||
ExtensionsV1beta1DeploymentList l2 = crdHandler.getOwnedDeployments("a", "b"); | ||
Assert.assertNotNull(l2); | ||
Assert.assertEquals(l, l2); | ||
} | ||
|
||
@Test | ||
public void getOwnedDeploymentsExceptionTest() throws Exception | ||
{ | ||
createMocks("src/test/resources/model_simple.json"); | ||
K8sApiProvider mockApiProvider = mock(K8sApiProvider.class); | ||
ExtensionsV1beta1DeploymentList l = new ExtensionsV1beta1DeploymentList(); | ||
ExtensionsV1beta1Api mockExtensionsApi = mock(ExtensionsV1beta1Api.class); | ||
when(mockApiProvider.getExtensionsV1beta1Api(any(ApiClient.class))).thenReturn(mockExtensionsApi); | ||
when(mockExtensionsApi.listNamespacedDeployment(any(String.class), any(String.class), any(String.class), | ||
any(String.class), any(Boolean.class), any(String.class), any(Integer.class), | ||
any(String.class),any(Integer.class),any(Boolean.class))).thenThrow(new ApiException()); | ||
KubeCRDHandler crdHandler = new KubeCRDHandlerImpl(mockApiProvider, mockK8sClientProvider, props); | ||
ExtensionsV1beta1DeploymentList l2 = crdHandler.getOwnedDeployments("a", "b"); | ||
Assert.assertNull(l2); | ||
} | ||
|
||
@Test | ||
public void getOwnedServicesTest() throws Exception | ||
{ | ||
createMocks("src/test/resources/model_simple.json"); | ||
K8sApiProvider mockApiProvider = mock(K8sApiProvider.class); | ||
V1ServiceList l = new V1ServiceList(); | ||
CoreV1Api mockCoreApi = mock(CoreV1Api.class); | ||
when(mockApiProvider.getCoreV1Api(any(ApiClient.class))).thenReturn(mockCoreApi); | ||
when(mockCoreApi.listNamespacedService(any(String.class), any(String.class), any(String.class), | ||
any(String.class), any(Boolean.class), any(String.class), any(Integer.class), | ||
any(String.class),any(Integer.class),any(Boolean.class))).thenReturn(l); | ||
KubeCRDHandler crdHandler = new KubeCRDHandlerImpl(mockApiProvider, mockK8sClientProvider, props); | ||
V1ServiceList l2 = crdHandler.getOwnedServices("a", "b"); | ||
Assert.assertNotNull(l2); | ||
Assert.assertEquals(l, l2); | ||
} | ||
|
||
@Test | ||
public void getOwnedServicesExceptionTest() throws Exception | ||
{ | ||
createMocks("src/test/resources/model_simple.json"); | ||
K8sApiProvider mockApiProvider = mock(K8sApiProvider.class); | ||
V1ServiceList l = new V1ServiceList(); | ||
CoreV1Api mockCoreApi = mock(CoreV1Api.class); | ||
when(mockApiProvider.getCoreV1Api(any(ApiClient.class))).thenReturn(mockCoreApi); | ||
when(mockCoreApi.listNamespacedService(any(String.class), any(String.class), any(String.class), | ||
any(String.class), any(Boolean.class), any(String.class), any(Integer.class), | ||
any(String.class),any(Integer.class),any(Boolean.class))).thenThrow(new ApiException()); | ||
KubeCRDHandler crdHandler = new KubeCRDHandlerImpl(mockApiProvider, mockK8sClientProvider, props); | ||
V1ServiceList l2 = crdHandler.getOwnedServices("a", "b"); | ||
Assert.assertNull(l2); | ||
} | ||
|
||
} |
Oops, something went wrong.