Test setting of pod name and metadata
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/7c85eefe Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/7c85eefe Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/7c85eefe Branch: refs/heads/master Commit: 7c85eefe6b310855432116a87f0be57e38a77398 Parents: 0520ae2 Author: Andrew Donald Kennedy <[email protected]> Authored: Tue Jan 31 07:17:08 2017 +0000 Committer: Andrew Donald Kennedy <[email protected]> Committed: Fri May 19 14:01:20 2017 +0100 ---------------------------------------------------------------------- .../KubernetesLocationYamlLiveTest.java | 45 +++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/7c85eefe/kubernetes-location/src/test/java/io/cloudsoft/amp/containerservice/kubernetes/location/KubernetesLocationYamlLiveTest.java ---------------------------------------------------------------------- diff --git a/kubernetes-location/src/test/java/io/cloudsoft/amp/containerservice/kubernetes/location/KubernetesLocationYamlLiveTest.java b/kubernetes-location/src/test/java/io/cloudsoft/amp/containerservice/kubernetes/location/KubernetesLocationYamlLiveTest.java index d623efa..83c0abe 100644 --- a/kubernetes-location/src/test/java/io/cloudsoft/amp/containerservice/kubernetes/location/KubernetesLocationYamlLiveTest.java +++ b/kubernetes-location/src/test/java/io/cloudsoft/amp/containerservice/kubernetes/location/KubernetesLocationYamlLiveTest.java @@ -17,6 +17,7 @@ import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; import java.util.List; +import java.util.Map; import org.apache.brooklyn.api.entity.Entity; import org.apache.brooklyn.api.location.MachineLocation; @@ -31,6 +32,8 @@ import org.apache.brooklyn.entity.software.base.EmptySoftwareProcess; import org.apache.brooklyn.entity.software.base.SoftwareProcess; import org.apache.brooklyn.entity.software.base.VanillaSoftwareProcess; import org.apache.brooklyn.location.ssh.SshMachineLocation; +import org.apache.brooklyn.util.core.config.ConfigBag; +import org.apache.brooklyn.util.guava.Maybe; import org.apache.brooklyn.util.net.Networking; import org.apache.brooklyn.util.text.Identifiers; import org.apache.logging.log4j.util.Strings; @@ -45,6 +48,8 @@ import com.google.common.net.HostAndPort; import io.cloudsoft.amp.containerservice.dockercontainer.DockerContainer; import io.cloudsoft.amp.containerservice.kubernetes.entity.KubernetesPod; import io.cloudsoft.amp.containerservice.kubernetes.entity.KubernetesResource; +import io.fabric8.kubernetes.api.model.Pod; +import io.fabric8.kubernetes.client.KubernetesClient; /** * Live tests for deploying simple blueprints. Particularly useful during dev, but not so useful @@ -201,6 +206,30 @@ public class KubernetesLocationYamlLiveTest extends AbstractYamlTest { } @Test(groups={"Live"}) + public void testTomcatPodExtras() throws Exception { + String yaml = Joiner.on("\n").join( + locationYaml, + "services:", + " - type: " + KubernetesPod.class.getName(), + " brooklyn.config:", + " docker.container.imageName: tomcat", + " docker.container.inboundPorts: [ \"8080\" ]", + " pod: tomcat-pod", + " metadata:", + " extra: test"); + + DockerContainer entity = runTomcat(yaml); + assertAttributeEqualsEventually(entity, KubernetesPod.KUBERNETES_POD, "tomcat-pod"); + + String namespace = entity.sensors().get(KubernetesPod.KUBERNETES_NAMESPACE); + KubernetesClient client = getClient(entity); + Pod pod = client.pods().inNamespace(namespace).withName("tomcat-pod").get(); + Map<String, String> labels = pod.getMetadata().getLabels(); + assertTrue(labels.containsKey("extra")); + assertEquals(labels.get("extra"), "test"); + } + + @Test(groups={"Live"}) public void testTomcatContainer() throws Exception { String yaml = Joiner.on("\n").join( locationYaml, @@ -216,7 +245,7 @@ public class KubernetesLocationYamlLiveTest extends AbstractYamlTest { /** * Assumes that the {@link DockerContainer} entity uses port 8080. */ - protected void runTomcat(String yaml) throws Exception { + protected DockerContainer runTomcat(String yaml) throws Exception { Entity app = createStartWaitAndLogApplication(yaml); DockerContainer entity = Iterables.getOnlyElement(Entities.descendantsAndSelf(app, DockerContainer.class)); @@ -226,6 +255,8 @@ public class KubernetesLocationYamlLiveTest extends AbstractYamlTest { assertReachableEventually(publicPort); assertHttpStatusCodeEventuallyEquals("http://"+publicPort.getHostText()+":"+publicPort.getPort(), 200); + + return entity; } @@ -410,4 +441,16 @@ public class KubernetesLocationYamlLiveTest extends AbstractYamlTest { assertTrue(Networking.isReachable(hostAndPort), "publicPort="+hostAndPort); }}); } + + public KubernetesClient getClient(Entity entity) { + Maybe<KubernetesLocation> location = Machines.findUniqueElement(entity.getLocations(), KubernetesLocation.class); + if (location.isPresentAndNonNull()) { + KubernetesLocation kubernetes = location.get(); + ConfigBag config = kubernetes.config().getBag(); + KubernetesClientRegistry registry = kubernetes.config().get(KubernetesLocationConfig.KUBERNETES_CLIENT_REGISTRY); + KubernetesClient client = registry.getKubernetesClient(config); + return client; + } + throw new IllegalStateException("Cannot find KubernetesLocation on entity: " + Iterables.toString(entity.getLocations())); + } }
