Search in sources :

Example 81 with Builder

use of io.fabric8.maven.docker.config.CopyConfiguration.Builder 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 82 with Builder

use of io.fabric8.maven.docker.config.CopyConfiguration.Builder 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 83 with Builder

use of io.fabric8.maven.docker.config.CopyConfiguration.Builder 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 84 with Builder

use of io.fabric8.maven.docker.config.CopyConfiguration.Builder in project fabric8-maven-plugin by fabric8io.

the class InitContainerHandler method removeInitContainer.

public void removeInitContainer(PodTemplateSpecBuilder builder, String initContainerName) {
    if (hasInitContainer(builder, initContainerName)) {
        ObjectMeta meta = builder.buildMetadata();
        Map<String, String> annos = meta.getAnnotations();
        JSONArray newInitContainers = removeFromInitContainersJson(annos.get(INIT_CONTAINER_ANNOTATION), initContainerName);
        if (newInitContainers.length() > 0) {
            annos.put(INIT_CONTAINER_ANNOTATION, newInitContainers.toString());
        } else {
            annos.remove(INIT_CONTAINER_ANNOTATION);
        }
        meta.setAnnotations(annos);
    }
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) JSONArray(org.json.JSONArray)

Example 85 with Builder

use of io.fabric8.maven.docker.config.CopyConfiguration.Builder 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

Test (org.junit.Test)60 ProfileBuilder (io.fabric8.api.ProfileBuilder)34 Profile (io.fabric8.api.Profile)33 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)27 FabricService (io.fabric8.api.FabricService)24 InputStream (java.io.InputStream)21 Deployment (org.jboss.arquillian.container.test.api.Deployment)21 OSGiManifestBuilder (org.jboss.osgi.metadata.OSGiManifestBuilder)21 Asset (org.jboss.shrinkwrap.api.asset.Asset)21 JavaArchive (org.jboss.shrinkwrap.api.spec.JavaArchive)21 ServiceTracker (org.osgi.util.tracker.ServiceTracker)20 HashMap (java.util.HashMap)19 Map (java.util.Map)19 Logger (org.slf4j.Logger)19 CommandSupport (io.fabric8.itests.support.CommandSupport)18 ConfigurationAdmin (org.osgi.service.cm.ConfigurationAdmin)17 ServiceLocator (io.fabric8.api.gravia.ServiceLocator)16 IOException (java.io.IOException)16 Action (org.apache.felix.gogo.commands.Action)16 AbstractCommand (org.apache.felix.gogo.commands.basic.AbstractCommand)16