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());
}
}
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());
}
}
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());
}
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");
}
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'");
}
}
Aggregations