io.fabric8.kubernetes.api.model.KubernetesList Java Examples

The following examples show how to use io.fabric8.kubernetes.api.model.KubernetesList. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OpenshiftHelperTest.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testProcessTemplatesLocallyNull() throws IOException {
    //Given
    Template template = new TemplateBuilder()
            .withNewMetadata().withName("redis-template").endMetadata()
            .addNewParameter()
            .withDescription("Password used for Redis authentication")
            .withFrom("[A-Z0-9]{8}")
            .withGenerate("expression")
            .withName("REDIS_PASSWORD")
            .endParameter()
            .build();
    boolean failOnMissingParameterValue = true;
    //When
    KubernetesList result = OpenshiftHelper.processTemplatesLocally(template, failOnMissingParameterValue);
    //Then
    assertNull(result);
}
 
Example #2
Source File: WithOpenshiftResources.java    From dekorate with Apache License 2.0 6 votes vote down vote up
/**
 * Load an unmarshal the {@KubernetesList} from the manifest file.
 * @return  The kubernetes list if found or an empty kubernetes list otherwise.
 */
default KubernetesList fromManifest() {
  KubernetesList result = new KubernetesList();
  URL manifestUrl = WithOpenshiftResources.class.getClassLoader().getResource(getProject().getDekorateOutputDir() + File.separatorChar + MANIFEST_PATH);
  if (manifestUrl == null)  {
    return result;
  }

  System.out.println("Apply test resources from:" + manifestUrl);
  try (InputStream is = manifestUrl.openStream()) {
      result = Serialization.unmarshalAsList(is);
  } catch (IOException e) {
     throw DekorateException.launderThrowable(e);
  }
  return result;
}
 
Example #3
Source File: ResourceListTest.java    From kubernetes-client with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateOrReplaceWithoutDeleteExisting() throws Exception {
  server.expect().get().withPath("/api/v1/namespaces/ns1/services/my-service").andReturn(200 , service).times(2);
  server.expect().get().withPath("/api/v1/namespaces/ns1/configmaps/my-configmap").andReturn(200, configMap).times(2);
  server.expect().put().withPath("/api/v1/namespaces/ns1/services/my-service").andReturn(200, updatedService).once();
  server.expect().put().withPath("/api/v1/namespaces/ns1/configmaps/my-configmap").andReturn(200, updatedConfigMap).once();

  KubernetesClient client = server.getClient();
  KubernetesList list = new KubernetesListBuilder().withItems(updatedService, updatedConfigMap).build();
  client.resourceList(list).inNamespace("ns1").createOrReplace();

  assertEquals(6, server.getMockServer().getRequestCount());
  RecordedRequest request = server.getLastRequest();
  assertEquals("/api/v1/namespaces/ns1/configmaps/my-configmap", request.getPath());
  assertEquals("PUT", request.getMethod());
}
 
Example #4
Source File: Session.java    From dekorate with Apache License 2.0 6 votes vote down vote up
/**
 * Close the session an get all resource groups.
 * @return A map of {@link KubernetesList} by group name.
 */
private Map<String, KubernetesList> generate() {
  Set<Handler> handlersToRemove = handlers.stream().filter(h -> disabledGroups.contains(h.getKey()) || (!enabledGroups.isEmpty() && !enabledGroups.contains(h.getKey()))).collect(Collectors.toSet());
  this.handlers.removeAll(handlersToRemove);

  Set<String> generatorsToRemove = generators.keySet().stream().filter(g -> disabledGroups.contains(g) || (!enabledGroups.isEmpty() && !enabledGroups.contains(g))).collect(Collectors.toSet());
  generatorsToRemove.forEach(g -> generators.remove(g));
                                         
  if (generated.compareAndSet(false, true)) {
    LOGGER.info("Generating manifests.");
    closed.set(true);
    readExistingResources();
    populateFallbackConfig();
    handlers.forEach(h -> handle(h, configurators));
    this.generatedResources.putAll(resources.generate());
  }
  return Collections.unmodifiableMap(generatedResources);
}
 
Example #5
Source File: KubernetesComponentToWorkspaceApplierTest.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void shouldProvisionEnvironmentWithCorrectRecipeTypeAndContentFromK8SList()
    throws Exception {
  // given
  String yamlRecipeContent = getResource("devfile/petclinic.yaml");
  doReturn(toK8SList(yamlRecipeContent).getItems()).when(k8sRecipeParser).parse(anyString());
  ComponentImpl component = new ComponentImpl();
  component.setType(KUBERNETES_COMPONENT_TYPE);
  component.setReference(REFERENCE_FILENAME);
  component.setAlias(COMPONENT_NAME);

  // when
  applier.apply(workspaceConfig, component, s -> yamlRecipeContent);

  // then
  KubernetesList list = toK8SList(yamlRecipeContent);
  replaceImagePullPolicy(list, "Always");
  verify(k8sEnvProvisioner)
      .provision(
          eq(workspaceConfig), eq(KubernetesEnvironment.TYPE), eq(list.getItems()), anyMap());
}
 
Example #6
Source File: KubernetesComponentToWorkspaceApplierTest.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void shouldUseReferenceContentAsRecipeIfPresent() throws Exception {
  String yamlRecipeContent = getResource("devfile/petclinic.yaml");
  doReturn(toK8SList(yamlRecipeContent).getItems()).when(k8sRecipeParser).parse(anyString());
  ComponentImpl component = new ComponentImpl();
  component.setType(KUBERNETES_COMPONENT_TYPE);
  component.setReference(REFERENCE_FILENAME);
  component.setReferenceContent(yamlRecipeContent);
  component.setAlias(COMPONENT_NAME);

  applier.apply(workspaceConfig, component, new URLFileContentProvider(null, null));

  KubernetesList list = toK8SList(yamlRecipeContent);
  replaceImagePullPolicy(list, "Always");

  verify(k8sEnvProvisioner)
      .provision(
          eq(workspaceConfig), eq(KubernetesEnvironment.TYPE), eq(list.getItems()), anyMap());
}
 
Example #7
Source File: ApplyStepExecution.java    From kubernetes-pipeline-plugin with Apache License 2.0 6 votes vote down vote up
private void addEnvironmentAnnotations(Iterable<HasMetadata> items) throws Exception {
    if (items != null) {
        for (HasMetadata item : items) {
            if (item instanceof KubernetesList) {
                KubernetesList list = (KubernetesList) item;
                addEnvironmentAnnotations(list.getItems());
            } else if (item instanceof Template) {
                Template template = (Template) item;
                addEnvironmentAnnotations(template.getObjects());
            } else if (item instanceof ReplicationController) {
                addEnvironmentAnnotations(item);
            } else if (item instanceof DeploymentConfig) {
                addEnvironmentAnnotations(item);
            }
        }
    }
}
 
Example #8
Source File: WithKubernetesResources.java    From dekorate with Apache License 2.0 6 votes vote down vote up
/**
 * Inject an instance of {@link KubernetesList} to the specified {@link Field}.
 *
 * @param context      The execution context.
 * @param testInstance The target test instance.
 * @param field        The field to inject.
 */
default void injectKubernetesResources(ExtensionContext context, Object testInstance, Field field) {
  if (!field.getType().isAssignableFrom(KubernetesList.class)) {
    return;
  }

  //This is to make sure we don't write on fields by accident.
  //Note: we don't require the exact annotation. Any annotation named Inject will do (be it javax, guice etc)
  if (!stream(field.getDeclaredAnnotations()).filter(a -> a.annotationType().getSimpleName().equalsIgnoreCase("Inject")).findAny().isPresent()) {
    return;
  }

  field.setAccessible(true);
  try {
    field.set(testInstance, getKubernetesResources(context));
  } catch (IllegalAccessException e) {
    throw DekorateException.launderThrowable(e);
  }
}
 
Example #9
Source File: WithKubernetesResources.java    From dekorate with Apache License 2.0 6 votes vote down vote up
/**
 * Load an unmarshal the {@KubernetesList} from the manifest file.
 * @return  The kubernetes list if found or an empty kubernetes list otherwise.
 */
default KubernetesList fromManifest() {
  KubernetesList result = new KubernetesList();
  URL manifestUrl = WithKubernetesResources.class.getClassLoader().getResource(getProject().getDekorateOutputDir() + File.separatorChar + MANIFEST_PATH);
  if (manifestUrl == null)  {
    return result;
  }

  System.out.println("Apply test resources from:" + manifestUrl);
  try (InputStream is = manifestUrl.openStream()) {
    result = Serialization.unmarshalAsList(is);
  } catch (IOException e) {
     throw DekorateException.launderThrowable(e);
  }
  return result;
}
 
Example #10
Source File: AptReader.java    From dekorate with Apache License 2.0 6 votes vote down vote up
private Map<String, KubernetesList> read(File file) {
  try (InputStream is = new FileInputStream(file)) {
    final Matcher fileNameMatcher = inputFileIncludePattern.matcher(file.getName());
    final String name = fileNameMatcher.find() ? fileNameMatcher.group(1) : "invalid-name";
    final KubernetesResource resource = Serialization.unmarshal(is, KubernetesResource.class);
    if (resource instanceof KubernetesList) {
      return Collections.singletonMap(name,  (KubernetesList) resource);
    } else if (resource instanceof HasMetadata) {
      final KubernetesListBuilder klb = new KubernetesListBuilder();
      klb.addToItems((HasMetadata) resource);
      return Collections.singletonMap(name, klb.build());
    }
  } catch (IOException e) {
    processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, file.getAbsolutePath() + " not found.");
  }
  return null;
}
 
Example #11
Source File: ServiceCatalogExampleTest.java    From dekorate with Apache License 2.0 6 votes vote down vote up
@Test
 public void shouldContainServiceInstanceAndBinding() {
  KubernetesList list = Serialization.unmarshalAsList(ServiceCatalogExampleTest.class.getClassLoader().getResourceAsStream("META-INF/dekorate/kubernetes.yml"));
  assertNotNull(list);
  assertTrue(findFirst(list, ServiceInstance.class).isPresent());
  assertTrue(findFirst(list, ServiceBinding.class).isPresent());
  Optional<Deployment> deployment = findFirst(list, Deployment.class);
  assertTrue(deployment.isPresent());

  AtomicBoolean hasBindingEnv = new AtomicBoolean(false);
  new DeploymentBuilder(deployment.get()).accept(new TypedVisitor<EnvFromSourceFluent>() {
    @Override
    public void visit(EnvFromSourceFluent env) {
      if (env.hasSecretRef()) {
        hasBindingEnv.set(true);
      }
    }
  });
  assertTrue(hasBindingEnv.get());
}
 
Example #12
Source File: HelmMojo.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
private List<Template> findTemplates() throws IOException {
  final List<Template> ret = new ArrayList<>();
  final File[] sourceFiles;
  if (kubernetesTemplate != null && kubernetesTemplate.isDirectory()) {
    sourceFiles = kubernetesTemplate.listFiles((dir, filename) -> filename.endsWith("-template.yml"));
  } else if (kubernetesTemplate != null) {
    sourceFiles = new File[] { kubernetesTemplate };
  } else {
    sourceFiles = new File[0];
  }
  for (File sourceFile : Objects.requireNonNull(sourceFiles, "No template files found in the provided directory")) {
    final KubernetesResource dto = ResourceUtil.load(sourceFile, KubernetesResource.class, ResourceFileType.yaml);
    if (dto instanceof  Template) {
      ret.add((Template) dto);
    } else if (dto instanceof KubernetesList) {
      Optional.ofNullable(((KubernetesList)dto).getItems())
          .map(List::stream)
          .map(items -> items.filter(Template.class::isInstance).map(item -> (Template)item).collect(Collectors.toList()))
          .ifPresent(ret::addAll);
    }
  }
  return ret;
}
 
Example #13
Source File: KubernetesResourceUtilTest.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void readWholeDir() throws IOException {
    ResourceVersioning v = new ResourceVersioning()
            .withCoreVersion("v2")
            .withExtensionsVersion("extensions/v2");

    KubernetesListBuilder builder =
        KubernetesResourceUtil.readResourceFragmentsFrom(PlatformMode.kubernetes, v, "pong", new File(jkubeDir, "read-dir").listFiles());
    KubernetesList list = builder.build();
    assertEquals(2,list.getItems().size());
    for (HasMetadata item : list.getItems() ) {
        assertTrue("Service".equals(item.getKind()) || "ReplicationController".equals(item.getKind()));
        assertEquals("pong",item.getMetadata().getName());
        assertEquals("v2",item.getApiVersion());
    }
}
 
Example #14
Source File: Issue421Test.java    From dekorate with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldHavePort() {
  KubernetesList list = Serialization.unmarshalAsList(Issue421Test.class.getClassLoader().getResourceAsStream("META-INF/dekorate/kubernetes.yml"));
  assertNotNull(list);
  Deployment d = findFirst(list, Deployment.class).orElseThrow(() -> new IllegalStateException());
  assertNotNull(d);
  Container c = d.getSpec().getTemplate().getSpec().getContainers().get(0);
  assertNotNull(c);

  List<ContainerPort> ports = c.getPorts();
  assertNotNull(ports);
  assertEquals(1, ports.size());

  ContainerPort port = ports.get(0);
  assertEquals("HTTP", port.getName());
  assertEquals(8080, port.getContainerPort());
}
 
Example #15
Source File: ResourceMojo.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
private void resolveTemplateVariablesIfAny(KubernetesList resources) throws MojoExecutionException {
    Template template = findTemplate(resources);
    if (template != null) {
        List<io.fabric8.openshift.api.model.Parameter> parameters = template.getParameters();
        if (parameters == null || parameters.isEmpty()) {
            return;
        }
        File kubernetesYaml = new File(this.targetDir, "kubernetes.yml");
        resolveTemplateVariables(parameters, kubernetesYaml);
        File kubernetesResourceDir = new File(this.targetDir, "kubernetes");
        File[] kubernetesResources = kubernetesResourceDir.listFiles((dir, filename) -> filename.endsWith(".yml"));
        if (kubernetesResources != null) {
            for (File kubernetesResource : kubernetesResources) {
                resolveTemplateVariables(parameters, kubernetesResource);
            }
        }
    }
}
 
Example #16
Source File: KubernetesEnvironmentProvisionerTest.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void shouldProvisionEnvironmentWithCorrectRecipeTypeAndContentFromK8SList()
    throws Exception {
  // given
  String yamlRecipeContent = getResource("devfile/petclinic.yaml");
  List<HasMetadata> componentsObjects = toK8SList(yamlRecipeContent).getItems();

  // when
  k8sEnvProvisioner.provision(
      workspaceConfig, KubernetesEnvironment.TYPE, componentsObjects, emptyMap());

  // then
  String defaultEnv = workspaceConfig.getDefaultEnv();
  assertNotNull(defaultEnv);
  EnvironmentImpl environment = workspaceConfig.getEnvironments().get(defaultEnv);
  assertNotNull(environment);
  RecipeImpl recipe = environment.getRecipe();
  assertNotNull(recipe);
  assertEquals(recipe.getType(), KUBERNETES_COMPONENT_TYPE);
  assertEquals(recipe.getContentType(), YAML_CONTENT_TYPE);

  // it is expected that applier wrap original recipes objects in new Kubernetes list
  KubernetesList expectedKubernetesList =
      new KubernetesListBuilder().withItems(toK8SList(yamlRecipeContent).getItems()).build();
  assertEquals(toK8SList(recipe.getContent()).getItems(), expectedKubernetesList.getItems());
}
 
Example #17
Source File: ResourceMojo.java    From jkube with Eclipse Public License 2.0 6 votes vote down vote up
private void addProfiledResourcesFromSubdirectories(PlatformMode platformMode, KubernetesListBuilder builder, File resourceDir,
    EnricherManager enricherManager) throws IOException, MojoExecutionException {
    File[] profileDirs = resourceDir.listFiles(File::isDirectory);
    if (profileDirs != null) {
        for (File profileDir : profileDirs) {
            Profile foundProfile = ProfileUtil.findProfile(profileDir.getName(), resourceDir);
            ProcessorConfig enricherConfig = foundProfile.getEnricherConfig();
            File[] resourceFiles = KubernetesResourceUtil.listResourceFragments(profileDir);
            if (resourceFiles.length > 0) {
                KubernetesListBuilder profileBuilder = readResourceFragments(platformMode, resourceFiles);
                enricherManager.createDefaultResources(platformMode, enricherConfig, profileBuilder);
                enricherManager.enrich(platformMode, enricherConfig, profileBuilder);
                KubernetesList profileItems = profileBuilder.build();
                for (HasMetadata item : profileItems.getItems()) {
                    builder.addToItems(item);
                }
            }
        }
    }
}
 
Example #18
Source File: KnativeApplicationGenerator.java    From dekorate with Apache License 2.0 5 votes vote down vote up
default void onClosed() {
  //We ned to set the TTCL, becuase the KubenretesClient used in this part of code, needs TTCL so that java.util.ServiceLoader can work.
  ClassLoader tccl = Thread.currentThread().getContextClassLoader();
  try {
    Session session = getSession();
    Project project = getProject();
    Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
    KnativeConfig config = session.configurators().get(KnativeConfig.class).get();
    Optional<ImageConfiguration> imageConfiguration = session.configurators().getImageConfig(BuildServiceFactories.supplierMatches(project));
    imageConfiguration.ifPresent(i -> {
      String name = i.getName();
      if (i.isAutoBuildEnabled() || config.isAutoDeployEnabled()) {
        KubernetesList generated = session.getGeneratedResources().get("knative");
        BuildService buildService;
        try {
          buildService = imageConfiguration.map(BuildServiceFactories.create(getProject(), generated.getItems()))
              .orElseThrow(() -> new IllegalStateException("No applicable BuildServiceFactory found."));
        } catch (Exception e) {
          throw DekorateException.launderThrowable("Failed to lookup BuildService.", e);
        }

        ImageBuildHook hook = new ImageBuildHook(getProject(), buildService);
        hook.register();
      }
    });
  } finally {
    Thread.currentThread().setContextClassLoader(tccl);
  }
}
 
Example #19
Source File: KubernetesListTest.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testLoadAndCreate() {
 server.expect().withPath("/api/v1/namespaces/test/replicationcontrollers").andReturn(201, replicationController1).times(2);

  KubernetesClient client = server.getClient();
  InputStream is = KubernetesListTest.class.getResourceAsStream("/test-rclist.json");
  KubernetesList result = client.lists().inNamespace("test").load(is).create();

  assertNotNull(result);
  assertEquals(2, result.getItems().size());
}
 
Example #20
Source File: SpringBootOnOpenshiftTest.java    From dekorate with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldContainService() {
  KubernetesList list = Serialization.unmarshalAsList(SpringBootOnOpenshiftTest.class.getClassLoader().getResourceAsStream("META-INF/dekorate/openshift.yml"));
  assertNotNull(list);
  Service s = findFirst(list, Service.class).orElseThrow(()-> new IllegalStateException());
  assertNotNull(s);
}
 
Example #21
Source File: KubernetesListHandler.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Override
public KubernetesList replace(OkHttpClient client, Config config, String namespace, KubernetesList item) {
  List<HasMetadata> replacedItems = new ArrayList<>();

  for (HasMetadata metadata : item.getItems()) {
    ResourceHandler<HasMetadata, HasMetadataVisitiableBuilder> handler = Handlers.get(item.getKind(), item.getApiVersion());
    if (handler == null) {
      LOGGER.warn("No handler found for:" + item.getKind() + ". Ignoring");
    } else {
      replacedItems.add(handler.replace(client, config, namespace, metadata));
    }
  }
  return new KubernetesListBuilder(item).withItems(replacedItems).build();
}
 
Example #22
Source File: KnativeExampleTest.java    From dekorate with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldContainServiceWithPortNamedHttp1() {
  KubernetesList list = Serialization.unmarshalAsList(KnativeExampleTest.class.getClassLoader().getResourceAsStream("META-INF/dekorate/knative.yml"));
  assertNotNull(list);
  assertEquals(1, list.getItems().size());
  Service s = findFirst(list, Service.class).orElseThrow(() -> new IllegalStateException("No knative service found!"));
  assertNotNull(s);
  Container c = s.getSpec().getTemplate().getSpec().getContainers().get(0);
  assertEquals("http1", c.getPorts().get(0).getName());

}
 
Example #23
Source File: TemplateTest.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testEmptyParameterMapValueShouldNotThrowNullPointerException() {
  server.expect().withPath("/apis/template.openshift.io/v1/namespaces/test/templates/tmpl1").andReturn(200, new TemplateBuilder()
    .withNewMetadata().withName("tmpl1").endMetadata()
    .withParameters(new ParameterBuilder().withName("key").build())
    .build()).once();
  OpenShiftClient client = server.getOpenshiftClient();
  Map<String, String> emptyValueMap = singletonMap("key", "");
  KubernetesList list = client.templates().withName("tmpl1").processLocally(emptyValueMap);
  assertNotNull(list);
}
 
Example #24
Source File: ResourceMojo.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns the Template if the list contains a single Template only otherwise returns null
 */
protected static Template getSingletonTemplate(KubernetesList resources) {
    // if the list contains a single Template lets unwrap it
    if (resources != null) {
        List<HasMetadata> items = resources.getItems();
        if (items != null && items.size() == 1) {
            HasMetadata singleEntity = items.get(0);
            if (singleEntity instanceof Template) {
                return (Template) singleEntity;
            }
        }
    }
    return null;
}
 
Example #25
Source File: TemplateTest.java    From kubernetes-client with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldLoadTemplateWithNumberParameters() throws Exception {
  OpenShiftClient client = new DefaultOpenShiftClient(new OpenShiftConfigBuilder().build());
  Map<String, String> map = new HashMap<>();
  map.put("PORT", "8080");
  KubernetesList list = client.templates().withParameters(map).load(getClass().getResourceAsStream("/template-with-number-params.yml")).processLocally(map);
  assertListIsServiceWithPort8080(list);
}
 
Example #26
Source File: SpringBootWithTektonTest.java    From dekorate with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldContainTaskWithM2Workspace() {
  KubernetesList list = Serialization.unmarshalAsList(getClass().getClassLoader().getResourceAsStream("META-INF/dekorate/tekton-task.yml"));
  assertNotNull(list);
  Task t = findFirst(list, Task.class).orElseThrow(() -> new IllegalStateException());
  assertNotNull(t);
  assertTrue(t.getSpec().getWorkspaces().stream().filter(w -> w.getName().equals("m2")).findAny().isPresent(), "Pipeline should contain workspace named 'pipeline-m2-ws'");
}
 
Example #27
Source File: KNativeDiscoveredServiceWorkItemHandlerTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Test
public void whenExistsAServiceWithKNative() {
    final RecreateFromServerGettable<KubernetesList, KubernetesList, ?> serviceResource =
            this.getClient().lists().load(this.getClass().getResource("/mock/responses/ocp4.x/knative/serving.knative.dev-services.json"));
    this.getClient().lists().create(serviceResource.get());

    final DiscoveredServiceWorkItemHandler handler = new TestDiscoveredServiceWorkItemHandler(this);
    final ServiceInfo serviceInfo = handler.findEndpoint(MOCK_NAMESPACE, "employeeValidation");
    assertThat(serviceInfo, notNullValue());
    assertThat(serviceInfo.getUrl(), is("http://172.30.101.218:80/employeeValidation"));
    assertThat(serviceInfo.getHeaders().get("HOST"), is("onboarding-hr.test.apps.example.com"));
}
 
Example #28
Source File: FmpExampleTest.java    From dekorate with Apache License 2.0 5 votes vote down vote up
@Test
void shouldHaveFabric8KubernetesManifest() {
  final KubernetesList list = Serialization.unmarshalAsList(FmpExampleTest.class.getClassLoader().getResourceAsStream("META-INF/fabric8/kubernetes.yml"));

  assertNotNull(list);
  assertFalse(list.getItems().isEmpty());
  final Optional<Deployment> deployment = list.getItems().stream()
    .filter(Deployment.class::isInstance)
    .map(Deployment.class::cast)
    .filter(hasLabel("provider", "fabric8"))
    .filter(hasLabel("decorated-by", "dekorate").negate())
    .findAny();
  assertTrue(deployment.isPresent());
}
 
Example #29
Source File: SpringBootOnKubernetesTest.java    From dekorate with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldContainDeployment() {
  KubernetesList list = Serialization.unmarshalAsList(SpringBootOnKubernetesTest.class.getClassLoader().getResourceAsStream("META-INF/dekorate/kubernetes.yml"));
  assertNotNull(list);
  Deployment d = findFirst(list, Deployment.class).orElseThrow(() -> new IllegalStateException());
  assertNotNull(d);
}
 
Example #30
Source File: FmpExampleTest.java    From dekorate with Apache License 2.0 5 votes vote down vote up
@Test
void shouldHaveMergedOpenshiftManifests() {
  final KubernetesList list = Serialization.unmarshalAsList(FmpExampleTest.class.getClassLoader().getResourceAsStream("META-INF/fabric8/openshift.yml"));

  assertNotNull(list);
  assertFalse(list.getItems().isEmpty());
  final Optional<DeploymentConfig> deploymentConfig = list.getItems().stream()
    .filter(DeploymentConfig.class::isInstance)
    .map(DeploymentConfig.class::cast)
    .filter(hasLabel("provider", "fabric8"))
    .filter(hasLabel("decorated-by", "dekorate"))
    .findAny();
  assertTrue(deploymentConfig.isPresent());
}