Search in sources :

Example 16 with HasMetadata

use of io.fabric8.kubernetes.api.model.HasMetadata 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 17 with HasMetadata

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

the class KubernetesResourceUtilTest method simple.

@Test
public void simple() throws IOException {
    for (String ext : new String[] { "yaml", "json" }) {
        HasMetadata ret = getResource(DEFAULT_RESOURCE_VERSIONING, new File(fabric8Dir, "simple-rc." + ext), "app");
        assertEquals(API_VERSION, ret.getApiVersion());
        assertEquals("ReplicationController", ret.getKind());
        assertEquals("simple", ret.getMetadata().getName());
    }
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) File(java.io.File) Test(org.junit.Test)

Example 18 with HasMetadata

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

the class KubernetesResourceUtilTest method noNameInFile.

@Test
public void noNameInFile() throws IOException {
    HasMetadata ret = getResource(DEFAULT_RESOURCE_VERSIONING, new File(fabric8Dir, "rc.yml"), "app");
    assertEquals("flipper", ret.getMetadata().getName());
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) File(java.io.File) Test(org.junit.Test)

Example 19 with HasMetadata

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

the class MergeResourceTest method testMergeDeploymentTemplateMetadata.

@Test
public void testMergeDeploymentTemplateMetadata() throws Exception {
    Deployment resource = new DeploymentBuilder().withNewMetadata().withName("cheese").endMetadata().withNewSpec().withNewTemplate().withNewSpec().addNewContainer().withImage("cheese-image").endContainer().endSpec().withNewMetadata().addToAnnotations("overwriteKey", "originalValue").addToAnnotations("unchangedKey", "shouldNotChange").addToAnnotations("unchangedBlankKey", "").addToAnnotations("deletedKey", "shouldBeDeleted").endMetadata().endTemplate().endSpec().build();
    Deployment override = new DeploymentBuilder().withNewMetadata().withName("cheese").endMetadata().withNewSpec().withNewTemplate().withNewSpec().addNewContainer().addToEnv(new EnvVarBuilder().withName("ENV_FOO").withValue("FOO_VALUE").build()).endContainer().endSpec().withNewMetadata().addToAnnotations("overwriteKey", "newValue").addToAnnotations("deletedKey", "").endMetadata().endTemplate().endSpec().build();
    HasMetadata answer = KubernetesResourceUtil.mergeResources(resource, override, log, false);
    assertNotNull(answer);
    log.info("Override metadata on Deployment generated: " + KubernetesHelper.toYaml(answer));
    assertThat(answer).describedAs("mergeResult").isInstanceOf(Deployment.class);
    Deployment deployment = (Deployment) answer;
    Map<String, String> annotations = deployment.getSpec().getTemplate().getMetadata().getAnnotations();
    assertDataModified(annotations, "Deployment.spec.template.metadata.annotations");
    assertDataNotModified(resource.getSpec().getTemplate().getMetadata().getAnnotations(), "Original Deployment.spec.template.metadata.annotations");
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment) EnvVarBuilder(io.fabric8.kubernetes.api.model.EnvVarBuilder) DeploymentBuilder(io.fabric8.kubernetes.api.model.extensions.DeploymentBuilder) Test(org.junit.Test)

Example 20 with HasMetadata

use of io.fabric8.kubernetes.api.model.HasMetadata 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)

Aggregations

HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)79 Test (org.junit.Test)25 File (java.io.File)21 ArrayList (java.util.ArrayList)21 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)16 IOException (java.io.IOException)16 Template (io.fabric8.openshift.api.model.Template)15 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)14 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)13 KubernetesList (io.fabric8.kubernetes.api.model.KubernetesList)13 Service (io.fabric8.kubernetes.api.model.Service)13 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)13 DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)13 ReplicationController (io.fabric8.kubernetes.api.model.ReplicationController)11 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)10 HashMap (java.util.HashMap)9 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)8 ReplicaSet (io.fabric8.kubernetes.api.model.extensions.ReplicaSet)8 Map (java.util.Map)8 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)7