Search in sources :

Example 11 with KubernetesListBuilder

use of io.fabric8.kubernetes.api.model.KubernetesListBuilder in project fabric8-maven-plugin by fabric8io.

the class RevisionHistoryEnricherTest method testDefaultRevisionHistoryLimit.

@Test
public void testDefaultRevisionHistoryLimit() throws JsonProcessingException {
    // Given
    KubernetesListBuilder builder = new KubernetesListBuilder().addNewDeploymentItem().endDeploymentItem();
    RevisionHistoryEnricher enricher = new RevisionHistoryEnricher(context);
    // When
    enricher.addMissingResources(builder);
    // Then
    assertRevisionHistory(builder.build(), Configs.asInt(RevisionHistoryEnricher.Config.limit.def()));
}
Also used : KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) Test(org.junit.Test)

Example 12 with KubernetesListBuilder

use of io.fabric8.kubernetes.api.model.KubernetesListBuilder in project fabric8-maven-plugin by fabric8io.

the class RevisionHistoryEnricherTest method testCustomRevisionHistoryLimit.

@Test
public void testCustomRevisionHistoryLimit() throws JsonProcessingException {
    // Setup mock behaviour
    final String revisionNumber = "10";
    new Expectations() {

        {
            context.getConfig();
            result = prepareEnricherConfig(revisionNumber);
        }
    };
    // Given
    KubernetesListBuilder builder = new KubernetesListBuilder().addNewDeploymentItem().endDeploymentItem();
    RevisionHistoryEnricher enricher = new RevisionHistoryEnricher(context);
    // When
    enricher.addMissingResources(builder);
    // Then
    assertRevisionHistory(builder.build(), Integer.parseInt(revisionNumber));
}
Also used : Expectations(mockit.Expectations) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) Test(org.junit.Test)

Example 13 with KubernetesListBuilder

use of io.fabric8.kubernetes.api.model.KubernetesListBuilder in project fabric8-maven-plugin by fabric8io.

the class KubernetesResourceUtilTest method readWholeDir.

@Test
public void readWholeDir() throws IOException {
    ResourceVersioning v = new ResourceVersioning().withCoreVersion("v2").withExtensionsVersion("extensions/v2");
    KubernetesListBuilder builder = KubernetesResourceUtil.readResourceFragmentsFrom(v, "pong", new File(fabric8Dir, "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());
    }
}
Also used : KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) File(java.io.File) Test(org.junit.Test)

Example 14 with KubernetesListBuilder

use of io.fabric8.kubernetes.api.model.KubernetesListBuilder in project fabric8-maven-plugin by fabric8io.

the class DebugEnricher method addMissingResources.

@Override
public void addMissingResources(KubernetesListBuilder builder) {
    if (debugEnabled()) {
        int count = 0;
        List<HasMetadata> items = builder.getItems();
        if (items != null) {
            for (HasMetadata item : items) {
                if (enableDebug(item)) {
                    count++;
                }
            }
        }
        if (count > 0) {
            builder.withItems(items);
        }
        log.verbose("Enabled debugging on " + count + " resource(s) thanks to the " + ENABLE_DEBUG_MAVEN_PROPERTY + " property");
    } else {
        log.verbose("Debugging not enabled. To enable try setting the " + ENABLE_DEBUG_MAVEN_PROPERTY + " maven or system property to 'true'");
    }
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata)

Example 15 with KubernetesListBuilder

use of io.fabric8.kubernetes.api.model.KubernetesListBuilder in project fabric8-maven-plugin by fabric8io.

the class KubernetesResourceUtil method readResourceFragmentsFrom.

/**
 * Read all Kubernetes resource fragments from a directory and create a {@link KubernetesListBuilder} which
 * can be adapted later.
 *
 * @param apiVersions the api versions to use
 * @param defaultName the default name to use when none is given
 * @param resourceFiles files to add.
 * @return the list builder
 * @throws IOException
 */
public static KubernetesListBuilder readResourceFragmentsFrom(ResourceVersioning apiVersions, String defaultName, File[] resourceFiles) throws IOException {
    KubernetesListBuilder builder = new KubernetesListBuilder();
    if (resourceFiles != null) {
        for (File file : resourceFiles) {
            HasMetadata resource = getResource(apiVersions, file, defaultName);
            builder.addToItems(resource);
        }
    }
    return builder;
}
Also used : KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) File(java.io.File)

Aggregations

KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)30 Test (org.junit.Test)25 KubernetesList (io.fabric8.kubernetes.api.model.KubernetesList)17 Expectations (mockit.Expectations)13 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)8 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)5 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)5 File (java.io.File)5 ProcessorConfig (io.fabric8.maven.core.config.ProcessorConfig)4 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)4 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)3 Secret (io.fabric8.kubernetes.api.model.Secret)3 Fabric8ServiceException (io.fabric8.maven.core.service.Fabric8ServiceException)3 IOException (java.io.IOException)3 Map (java.util.Map)3 JSONArray (org.json.JSONArray)3 JSONObject (org.json.JSONObject)3 Visitable (io.fabric8.kubernetes.api.builder.Visitable)2 Visitor (io.fabric8.kubernetes.api.builder.Visitor)2 KubernetesResource (io.fabric8.kubernetes.api.model.KubernetesResource)2