use of io.fabric8.kubernetes.api.model.HasMetadata in project fabric8 by jboss-fuse.
the class ProcessTemplateLocallyTest method testProcessTemplateLocally.
@Test
public void testProcessTemplateLocally() throws Exception {
Template template = assertParseExampleFile("template.json", Template.class);
List<HasMetadata> objects = template.getObjects();
assertNotEmpty("objects", objects);
KubernetesList list = Templates.processTemplatesLocally(template, true);
assertThat(list).describedAs("results").isNotNull();
List<HasMetadata> items = list.getItems();
assertThat(items).describedAs("items").isNotNull();
ReplicationController rc = (ReplicationController) items.get(1);
assertEquals("Template value not replaced: items[1].spec.template.spec.containers[0].env[0].value", "https://github.com/fabric8io/jenkins-pipeline-dsl.git", rc.getSpec().getTemplate().getSpec().getContainers().get(0).getEnv().get(0).getValue());
System.out.println("Created JSON: " + toJson(list));
}
use of io.fabric8.kubernetes.api.model.HasMetadata in project fabric8 by jboss-fuse.
the class Util method cleanupAllMatching.
public static void cleanupAllMatching(KubernetesClient client, Session session, List<Throwable> errors, List<KubernetesList> kubeConfigs) throws MultiException {
String sessionNamespace = session.getNamespace();
session.getLogger().info("Removing provisioned resources in namespace " + sessionNamespace);
/**
* Lets use a loop to ensure we really do delete all the matching resources
*/
for (int i = 0; i < 10; i++) {
for (KubernetesList list : kubeConfigs) {
List<HasMetadata> items = list.getItems();
if (items != null) {
for (HasMetadata item : items) {
cleanupItem(client, session, item, errors);
}
}
}
}
}
use of io.fabric8.kubernetes.api.model.HasMetadata in project carbon-apimgt by wso2.
the class KubernetesGatewayImplTestCase method testCreateServiceResourceForInvalidResource.
@Test
public void testCreateServiceResourceForInvalidResource() throws Exception {
OpenShiftClient openShiftClient = Mockito.mock(OpenShiftClient.class, Mockito.RETURNS_DEEP_STUBS);
KubernetesGatewayImpl kubernetesGateway = getKubernetesGatewayImpl(openShiftClient);
HasMetadata invalidMetadata = Mockito.mock(Deployment.class);
List<HasMetadata> serviceResources = new ArrayList<>();
serviceResources.add(invalidMetadata);
Mockito.when(openShiftClient.load(Mockito.any()).get()).thenReturn(serviceResources);
API api = SampleTestObjectCreator.createDefaultAPI().build();
try {
kubernetesGateway.createContainerGateway(ContainerBasedGatewayConstants.PRIVATE_JET_API_PREFIX + LABEL_SUFFIX, api);
} catch (ContainerBasedGatewayException e) {
Assert.assertEquals(e.getErrorHandler(), ExceptionCodes.LOADED_RESOURCE_DEFINITION_IS_NOT_VALID);
}
}
use of io.fabric8.kubernetes.api.model.HasMetadata in project carbon-apimgt by wso2.
the class KubernetesGatewayImplTestCase method testCreateDeploymentResourceForInvalidResource.
@Test
public void testCreateDeploymentResourceForInvalidResource() throws Exception {
OpenShiftClient openShiftClient = Mockito.mock(OpenShiftClient.class, Mockito.RETURNS_DEEP_STUBS);
KubernetesGatewayImpl kubernetesGateway = getKubernetesGatewayImpl(openShiftClient);
HasMetadata invalidMetadata = Mockito.mock(Service.class);
List<HasMetadata> deploymentResources = new ArrayList<>();
deploymentResources.add(invalidMetadata);
Mockito.when(openShiftClient.load(Mockito.any()).get()).thenReturn(getServiceResources(), deploymentResources);
NonNamespaceOperation nonNamespaceOperation = Mockito.mock(NonNamespaceOperation.class);
ScalableResource scalableResource = Mockito.mock(ScalableResource.class);
Mockito.when(scalableResource.get()).thenReturn(null);
Service service = createService(openShiftClient, nonNamespaceOperation);
Mockito.when(nonNamespaceOperation.create(Mockito.any())).thenReturn(service);
API api = SampleTestObjectCreator.createDefaultAPI().build();
try {
kubernetesGateway.createContainerGateway(ContainerBasedGatewayConstants.PRIVATE_JET_API_PREFIX + LABEL_SUFFIX, api);
} catch (ContainerBasedGatewayException e) {
Assert.assertEquals(e.getErrorHandler(), ExceptionCodes.LOADED_RESOURCE_DEFINITION_IS_NOT_VALID);
}
}
use of io.fabric8.kubernetes.api.model.HasMetadata in project vertx-openshift-it by cescoffier.
the class ConfigurationIT method deployApp.
private static String deployApp(String name, String templatePath) throws IOException {
String appName;
List<? extends HasMetadata> entities = deploymentAssistant.deploy(name, new File(templatePath));
Optional<String> first = entities.stream().filter(hm -> hm instanceof DeploymentConfig).map(hm -> (DeploymentConfig) hm).map(dc -> dc.getMetadata().getName()).findFirst();
if (first.isPresent()) {
appName = first.get();
} else {
throw new IllegalStateException("Application deployment config not found");
}
Route route = deploymentAssistant.getRoute(appName);
assertThat(route).isNotNull();
return "http://" + route.getSpec().getHost();
}
Aggregations