Ejemplo n.º 1
0
 def test_create_service_with_auto_node_port(self):
     spec = {}
     test = WorkloadManifest("myapp", self.docker, spec, self.tpl.repositories)
     self.assertEqual(
         test.services.get("docker-container-nodeport").type, "NodePort"
     )
     self.assertEqual(
         test.services.get("docker-container-nodeport")
         .resource.get("spec")
         .get("type"),
         "NodePort",
     )
     self.assertEqual(
         test.services.get("docker-container-nodeport")
         .resource.get("spec")
         .get("ports")[0]
         .get("targetPort"),
         "3000",
     )
     self.assertEqual(
         test.services.get("docker-container-nodeport")
         .resource.get("spec")
         .get("ports")[0]
         .get("port"),
         3030,
     )
     self.assertEqual(
         test.services.get("docker-container-nodeport")
         .resource.get("spec")
         .get("ports")[0]
         .get("nodePort"),
         30000,
     )
Ejemplo n.º 2
0
 def test_create_service_overwrite_type(self):
     spec = {}
     test = WorkloadManifest("myapp", self.docker, spec, self.tpl.repositories)
     self.assertEqual(
         len(
             test.services.get("docker-container-loadbalancer")
             .resource.get("spec")
             .get("ports")
         ),
         1,
     )
     self.assertEqual(
         test.services.get("docker-container-loadbalancer").type, "LoadBalancer"
     )
     self.assertEqual(
         test.services.get("docker-container-loadbalancer")
         .resource.get("spec")
         .get("type"),
         "LoadBalancer",
     )
     self.assertEqual(
         test.services.get("docker-container-loadbalancer")
         .resource.get("spec")
         .get("ports")[0]
         .get("port"),
         1000,
     )
     self.assertEqual(
         test.services.get("docker-container-loadbalancer")
         .resource.get("spec")
         .get("ports")[0]
         .get("nodePort"),
         30009,
     )
Ejemplo n.º 3
0
 def test_attach_configs_to_pods(self):
     spec = {}
     test = WorkloadManifest("myapp", self.docker, spec, self.tpl.repositories)
     [mount] = [
         x
         for x in test.pod.get("spec").get("containers")[0].get("volumeMounts")
         if x.get("name") == "fake-config-volume"
     ]
     [mount_abst] = [
         x
         for x in test.pod.get("spec").get("containers")[0].get("volumeMounts")
         if x.get("name") == "fake-config-abst-volume"
     ]
     self.assertTrue(mount)
     self.assertTrue(mount_abst)
     [mount] = [
         x
         for x in test.pod.get("spec").get("volumes")
         if x.get("name") == "fake-config-volume"
     ]
     [mount_abst] = [
         x
         for x in test.pod.get("spec").get("volumes")
         if x.get("name") == "fake-config-abst-volume"
     ]
     self.assertTrue(mount.get("configMap"))
     self.assertTrue(mount_abst.get("configMap"))
Ejemplo n.º 4
0
 def test_custom_pod_label_no_overwrite(self):
     spec = {
         "configure": {"metadata": {"labels": {"app.kubernetes.io/name": "newname"}}}
     }
     test = WorkloadManifest("myapp", self.docker, spec, self.tpl.repositories)
     self.assertNotEqual(
         test.pod.get("metadata").get("labels").get("app.kubernetes.io/name"),
         "newname",
     )
Ejemplo n.º 5
0
 def test_attach_volume_default_path(self):
     spec = {}
     test = WorkloadManifest("myapp", self.docker, spec, self.tpl.repositories)
     [mount] = [
         x
         for x in test.pod.get("spec").get("containers")[0].get("volumeMounts")
         if x.get("name") == "fake-vol"
     ]
     self.assertEqual(mount.get("mountPath"), "/etc/micado/volumes")
Ejemplo n.º 6
0
 def test_attach_volume_path_in_volume_properties(self):
     spec = {}
     test = WorkloadManifest("myapp", self.docker, spec, self.tpl.repositories)
     [mount] = [
         x
         for x in test.pod.get("spec").get("containers")[0].get("volumeMounts")
         if x.get("name") == "fake-vol-abst-no-rel"
     ]
     self.assertEqual(mount.get("mountPath"), "volinprop")
Ejemplo n.º 7
0
 def test_create_host_port(self):
     spec = {}
     test = WorkloadManifest("myapp", self.docker, spec, self.tpl.repositories)
     self.assertEqual(
         test.pod["spec"]["containers"][0].get("ports")[1].get("containerPort"), 5000
     )
     self.assertEqual(
         test.pod["spec"]["containers"][0].get("ports")[1].get("hostPort"), 5050
     )
Ejemplo n.º 8
0
 def test_containers_to_pod_label_first_wins(self):
     cont = self.getContainerbyName("add-containers-to-bare-pod")
     spec = {}
     test = WorkloadManifest("myapp", cont, spec, self.tpl.repositories)
     self.assertEqual(
         test.resource.get("metadata")
         .get("labels")
         .get("app.kubernetes.io/version"),
         "v123",
     )
Ejemplo n.º 9
0
 def test_container_to_workload_label_no_overwrite(self):
     cont = self.getContainerbyName("add-container-to-workload")
     spec = {}
     test = WorkloadManifest("myapp", cont, spec, self.tpl.repositories)
     self.assertEqual(
         test.resource.get("metadata")
         .get("labels")
         .get("app.kubernetes.io/version"),
         "v1000",
     )
Ejemplo n.º 10
0
 def test_create_service_use_service_namespace(self):
     cont = self.getContainerbyName("docker-by-kube-service")
     spec = {"create": {"metadata": {"namespace": "custom-ns"}}}
     test = WorkloadManifest("myapp", cont, spec, self.tpl.repositories)
     self.assertEqual(test.services.get("docker-by-kube-service").namespace, "service-ns")
     self.assertEqual(
         test.services.get("docker-by-kube-service")
         .resource.get("metadata")
         .get("namespace"),
         "service-ns",
     )
Ejemplo n.º 11
0
 def test_create_service_with_multiple_ports(self):
     spec = {}
     test = WorkloadManifest("myapp", self.docker, spec, self.tpl.repositories)
     self.assertEqual(
         len(
             test.services.get("docker-container-nodeport")
             .resource.get("spec")
             .get("ports")
         ),
         2,
     )
Ejemplo n.º 12
0
 def test_attach_volume_to_pod(self):
     spec = {}
     test = WorkloadManifest("myapp", self.docker, spec, self.tpl.repositories)
     [mount] = [
         x
         for x in test.pod.get("spec").get("volumes")
         if x.get("name") == "fake-vol"
     ]
     [mount_abst] = [
         x
         for x in test.pod.get("spec").get("volumes")
         if x.get("name") == "fake-vol-abst"
     ]
     self.assertTrue(mount)
     self.assertTrue(mount_abst)
Ejemplo n.º 13
0
 def test_create_service_with_custom_name(self):
     spec = {}
     test = WorkloadManifest("myapp", self.docker, spec, self.tpl.repositories)
     self.assertEqual(
         len(test.services.get("my-custom-name").resource.get("spec").get("ports")),
         1,
     )
     self.assertEqual(
         test.services.get("my-custom-name")
         .resource.get("spec")
         .get("ports")[0]
         .get("port"),
         1000,
     )
     self.assertEqual(
         test.services.get("my-custom-name")
         .resource.get("spec")
         .get("ports")[0]
         .get("nodePort"),
         30006,
     )
Ejemplo n.º 14
0
 def test_create_service_with_docker_long_syntax(self):
     spec = {}
     test = WorkloadManifest("myapp", self.docker, spec, self.tpl.repositories)
     self.assertEqual(
         len(
             test.services.get("docker-container").resource.get("spec").get("ports")
         ),
         1,
     )
     self.assertEqual(
         test.services.get("docker-container")
         .resource.get("spec")
         .get("ports")[0]
         .get("port"),
         4000,
     )
     self.assertEqual(
         test.services.get("docker-container")
         .resource.get("spec")
         .get("ports")[0]
         .get("protocol"),
         "UDP",
     )
Ejemplo n.º 15
0
 def test_get_hosted_on(self):
     spec = {}
     test = WorkloadManifest("myapp", self.docker, spec, self.tpl.repositories)
     self.assertIn("nodeAffinity", test.pod.get("spec").get("affinity"))
Ejemplo n.º 16
0
 def test_auto_pod_spec_in_configure(self):
     spec = {"configure": {"metadata": {}, "subdomain": "mysubdomain"}}
     test = WorkloadManifest("myapp", self.docker, spec, self.tpl.repositories)
     self.assertTrue(test.pod.get("spec").get("subdomain"))
Ejemplo n.º 17
0
 def test_no_template_for_pod(self):
     spec = {"create": {"kind": "Pod"}}
     test = WorkloadManifest("myapp", self.docker, spec, self.tpl.repositories)
     self.assertFalse(test.resource.get("spec").get("template"))
Ejemplo n.º 18
0
 def test_workload_spec_to_pod(self):
     spec = {"create": {"kind": "doesnt-matter", "subdomain": "mysubdomain"}}
     test = WorkloadManifest("myapp", self.docker, spec, self.tpl.repositories)
     self.assertTrue(
         test.resource.get("spec").get("template").get("spec").get("subdomain")
     )
Ejemplo n.º 19
0
 def test_pod_property_from_container(self):
     spec = {}
     test = WorkloadManifest("myapp", self.docker, spec, self.tpl.repositories)
     self.assertTrue(test.pod.get("spec").get("hostPID"))
Ejemplo n.º 20
0
 def test_workload_namespace(self):
     spec = {"create": {"metadata": {"namespace": "my-ns"}}}
     test = WorkloadManifest("myapp", self.docker, spec, self.tpl.repositories)
     self.assertEqual(test.resource.get("metadata").get("namespace"), "my-ns")
     self.assertEqual(test.namespace, "my-ns")
Ejemplo n.º 21
0
 def test_multiple_containers_to_bare_pod(self):
     cont = self.getContainerbyName("add-containers-to-bare-pod")
     spec = {}
     test = WorkloadManifest("myapp", cont, spec, self.tpl.repositories)
     self.assertEqual(len(test.pod.get("spec").get("containers")), 2)
Ejemplo n.º 22
0
 def test_template_selector_container_for_workloads(self):
     spec = {}
     test = WorkloadManifest("myapp", self.docker, spec, self.tpl.repositories)
     self.assertTrue(test.resource.get("spec").get("template"))
     self.assertTrue(test.resource.get("spec").get("selector"))
     self.assertEqual(len(test.pod.get("spec").get("containers")), 1)
Ejemplo n.º 23
0
 def test_attach_volumes_configs_to_pods(self):
     spec = {}
     test = WorkloadManifest("myapp", self.docker, spec, self.tpl.repositories)
     self.assertEqual(
         len(test.pod.get("spec").get("containers")[0].get("volumeMounts")), 6
     )
Ejemplo n.º 24
0
 def test_manual_pod_spec_in_create(self):
     spec = {
         "create": {"spec": {"template": {"spec": {"subdomain": "mysubdomain"}}}}
     }
     test = WorkloadManifest("myapp", self.docker, spec, self.tpl.repositories)
     self.assertTrue(test.pod.get("spec").get("subdomain"))
Ejemplo n.º 25
0
 def test_custom_pod_label(self):
     spec = {"configure": {"metadata": {"labels": {"custom": "label"}}}}
     test = WorkloadManifest("myapp", self.docker, spec, self.tpl.repositories)
     self.assertTrue(test.pod.get("metadata").get("labels").get("custom"))
Ejemplo n.º 26
0
 def test_workload_super(self):
     spec = {"create": {"kind": "doesnt-matter", "strategy": "Recreate"}}
     test = WorkloadManifest("myapp", self.docker, spec, self.tpl.repositories)
     self.assertTrue(test.resource.get("spec").get("strategy"))
Ejemplo n.º 27
0
 def test_no_selector_for_jobs(self):
     spec = {"create": {"kind": "Job"}}
     test = WorkloadManifest("myapp", self.docker, spec, self.tpl.repositories)
     self.assertFalse(test.resource.get("spec").get("selector"))