use of io.fabric8.kubernetes.api.model.GenericKubernetesResourceBuilder in project jkube by eclipse.
the class KubernetesClientUtilTest method doDeleteAndWait_withExistingResource_shouldDeleteAndReachWaitLimit.
@Test
public void doDeleteAndWait_withExistingResource_shouldDeleteAndReachWaitLimit() {
// Given
GenericKubernetesResource resource = new GenericKubernetesResourceBuilder().withApiVersion("org.eclipse.jkube/v1beta1").withKind("JKubeCustomResource").withNewMetadata().withName("name").endMetadata().build();
// When
doDeleteAndWait(kubernetesClient, resource, "namespace", 2L);
// Then
// @formatter:off
new Verifications() {
{
kubernetesClient.genericKubernetesResources("org.eclipse.jkube/v1beta1", "JKubeCustomResource").inNamespace("namespace").withName("name").delete();
times = 1;
}
};
// @formatter:on
}
use of io.fabric8.kubernetes.api.model.GenericKubernetesResourceBuilder in project jkube by eclipse.
the class ApplyServiceTest method testProcessCustomEntitiesRecreateModeTrue.
@Test
public void testProcessCustomEntitiesRecreateModeTrue() throws Exception {
// Given
File gatewayFragment = new File(getClass().getResource("/gateway-cr.yml").getFile());
File virtualServiceFragment = new File(getClass().getResource("/virtualservice-cr.yml").getFile());
GenericKubernetesResource gateway = Serialization.yamlMapper().readValue(gatewayFragment, GenericKubernetesResource.class);
GenericKubernetesResource virtualService = Serialization.yamlMapper().readValue(virtualServiceFragment, GenericKubernetesResource.class);
WebServerEventCollector collector = new WebServerEventCollector();
mockServer.expect().get().withPath("/apis/networking.istio.io/v1alpha3").andReply(collector.record("get-resources").andReturn(HTTP_OK, new APIResourceListBuilder().addToResources(virtualServiceResource(), gatewayResource()).build())).times(2);
mockServer.expect().get().withPath("/apis/networking.istio.io/v1alpha3/namespaces/default/gateways?fieldSelector=metadata.name%3Dmygateway-https").andReturn(HTTP_OK, new GenericKubernetesResourceBuilder().withApiVersion("networking.istio.io/v1alpha3").withKind("Gateway").withNewMetadata().withName("mygateway-https").endMetadata().build()).once();
mockServer.expect().get().withPath("/apis/networking.istio.io/v1alpha3/namespaces/default/virtualservices?fieldSelector=metadata.name%3Dreviews-route").andReturn(HTTP_OK, new GenericKubernetesResourceBuilder().withApiVersion("networking.istio.io/v1alpha3").withKind("VirtualService").withNewMetadata().withName("reviews-route").endMetadata().build()).once();
mockServer.expect().delete().withPath("/apis/networking.istio.io/v1alpha3/namespaces/default/virtualservices/reviews-route").andReply(collector.record("delete-cr-virtualservice").andReturn(HTTP_OK, "{\"kind\":\"Status\",\"status\":\"Success\"}")).once();
mockServer.expect().delete().withPath("/apis/networking.istio.io/v1alpha3/namespaces/default/gateways/mygateway-https").andReply(collector.record("delete-cr-gateway").andReturn(HTTP_OK, "{\"kind\":\"Status\",\"status\":\"Success\"}")).once();
mockServer.expect().post().withPath("/apis/networking.istio.io/v1alpha3/namespaces/default/virtualservices").andReply(collector.record("post-cr-virtualservice").andReturn(HTTP_OK, "{}")).once();
mockServer.expect().post().withPath("/apis/networking.istio.io/v1alpha3/namespaces/default/gateways").andReply(collector.record("post-cr-gateway").andReturn(HTTP_OK, "{}")).once();
applyService.setRecreateMode(true);
// When
applyService.applyGenericKubernetesResource(gateway, gatewayFragment.getName());
applyService.applyGenericKubernetesResource(virtualService, virtualServiceFragment.getName());
// Then
collector.assertEventsRecordedInOrder("delete-cr-gateway", "post-cr-gateway", "delete-cr-virtualservice", "post-cr-virtualservice");
assertEquals(8, mockServer.getOpenShiftMockServer().getRequestCount());
applyService.setRecreateMode(false);
}
use of io.fabric8.kubernetes.api.model.GenericKubernetesResourceBuilder in project jkube by eclipse.
the class KubernetesHelperTest method testGetFullyQualifiedApiGroupWithKind.
@Test
public void testGetFullyQualifiedApiGroupWithKind() {
// Given
GenericKubernetesResource cr1 = new GenericKubernetesResourceBuilder().withApiVersion("networking.istio.io/v1alpha3").withKind("VirtualService").build();
GenericKubernetesResource cr2 = new GenericKubernetesResourceBuilder().withApiVersion("networking.istio.io/v1alpha3").withKind("Gateway").build();
// When
String result1 = KubernetesHelper.getFullyQualifiedApiGroupWithKind(cr1);
String result2 = KubernetesHelper.getFullyQualifiedApiGroupWithKind(cr2);
// Then
assertEquals("networking.istio.io/v1alpha3#VirtualService", result1);
assertEquals("networking.istio.io/v1alpha3#Gateway", result2);
}
use of io.fabric8.kubernetes.api.model.GenericKubernetesResourceBuilder in project jkube by eclipse.
the class DefaultMetadataEnricherTest method setUp.
@Before
public void setUp() throws Exception {
Configuration configuration = Configuration.builder().resource(ResourceConfig.builder().annotations(MetaDataConfig.builder().all(properties("all-annotation", 1)).deployment(properties("deployment", "Deployment")).ingress(properties("ingress", "Ingress")).serviceAccount(properties("service-account", "ServiceAccount")).build()).labels(MetaDataConfig.builder().all(properties("all-label", 10L)).deployment(properties("deployment-label", "Deployment")).ingress(properties("ingress-label", "Ingress")).serviceAccount(properties("service-account-label", "ServiceAccount")).build()).build()).build();
// @formatter:off
new Expectations() {
{
buildContext.getConfiguration();
result = configuration;
}
};
// @formatter:on
defaultMetadataEnricher = new DefaultMetadataEnricher(buildContext);
configMap = new ConfigMapBuilder().withNewMetadata().endMetadata();
deployment = new DeploymentBuilder();
genericResource = new GenericKubernetesResourceBuilder().withNewMetadata().endMetadata();
ingressV1 = new io.fabric8.kubernetes.api.model.networking.v1.IngressBuilder();
ingressV1beta1 = new io.fabric8.kubernetes.api.model.networking.v1beta1.IngressBuilder();
serviceAccount = new ServiceAccountBuilder();
klb = new KubernetesListBuilder().addToItems(configMap).addToItems(deployment).addToItems(genericResource).addToItems(ingressV1).addToItems(ingressV1beta1).addToItems(serviceAccount);
}
use of io.fabric8.kubernetes.api.model.GenericKubernetesResourceBuilder in project jkube by eclipse.
the class KubernetesUndeployServiceTest method undeployWithManifestAndCustomResourcesShouldDeleteAllEntities.
@Test
public void undeployWithManifestAndCustomResourcesShouldDeleteAllEntities(@Mocked ResourceConfig resourceConfig) throws Exception {
// Given
final File manifest = temporaryFolder.newFile("temp.yml");
final File crManifest = temporaryFolder.newFile("temp-cr.yml");
final String crdId = "org.eclipse.jkube/v1alpha1#Crd";
final Service service = new Service();
final GenericKubernetesResource customResource = new GenericKubernetesResourceBuilder().withApiVersion("org.eclipse.jkube/v1alpha1").withKind("Crd").build();
customResource.setMetadata(new ObjectMetaBuilder().withName("my-cr").build());
final APIResource customResourceApiResource = new APIResourceBuilder().withGroup("org.eclipse.jkube").withNamespaced(false).withKind("Crd").withName("crds").withSingularName("crd").build();
// @formatter:off
new Expectations() {
{
kubernetesHelper.loadResources(manifest);
result = Arrays.asList(service, customResource);
kubernetesHelper.getFullyQualifiedApiGroupWithKind(customResource);
result = crdId;
}
};
// @formatter:on
// When
kubernetesUndeployService.undeploy(null, resourceConfig, manifest);
// Then
// @formatter:off
new Verifications() {
{
jKubeServiceHub.getClient().genericKubernetesResources("org.eclipse.jkube/v1alpha1", "Crd").inNamespace(null).withName("my-cr").delete();
times = 1;
}
};
// @formatter:on
}
Aggregations