Esempio n. 1
0
 def _make_volumes(self, app_spec):
     if self._use_in_memory_emptydirs:
         empty_dir_volume_source = EmptyDirVolumeSource(medium="Memory")
     else:
         empty_dir_volume_source = EmptyDirVolumeSource()
     volumes = [
         Volume(name="{}-secret".format(app_spec.name), emptyDir=empty_dir_volume_source),
         Volume(name="{}-config".format(self.SECRETS_INIT_CONTAINER_NAME),
                configMap=ConfigMapVolumeSource(name=self.SECRETS_INIT_CONTAINER_NAME, optional=True)),
     ]
     return volumes
Esempio n. 2
0
 def _make_volumes(self, app_spec):
     volumes = []
     volumes.append(
         Volume(name="{}-config".format(app_spec.name),
                configMap=ConfigMapVolumeSource(name=app_spec.name,
                                                optional=True)))
     if self._use_in_memory_emptydirs:
         empty_dir_volume_source = EmptyDirVolumeSource(medium="Memory")
     else:
         empty_dir_volume_source = EmptyDirVolumeSource()
     volumes.append(Volume(name="tmp", emptyDir=empty_dir_volume_source))
     return volumes
Esempio n. 3
0
def _create_pod():
    object_meta = ObjectMeta(name=NAME,
                             namespace=NAMESPACE,
                             labels={
                                 "test": "true",
                                 "app": NAME
                             })
    container_port = ContainerPort(name="http5000", containerPort=5000)
    secrets_volume_mounts = [
        VolumeMount(
            name=NAME,
            readOnly=True,
            mountPath="/var/run/secrets/kubernetes.io/kubernetes-secrets")
    ]
    secret_volumes = [
        Volume(name=NAME, secret=SecretVolumeSource(secretName=NAME))
    ]
    container = Container(name="container",
                          image="dummy_image",
                          ports=[container_port],
                          volumeMounts=secrets_volume_mounts)
    image_pull_secret = LocalObjectReference(name="image_pull_secret")
    pod_spec = PodSpec(containers=[container],
                       imagePullSecrets=[image_pull_secret],
                       volumes=secret_volumes,
                       serviceAccountName="default")
    first = Pod(metadata=object_meta, spec=pod_spec)
    return first
Esempio n. 4
0
    def test_lifecycle(self, logger):
        object_meta = ObjectMeta(name=NAME, namespace=NAMESPACE, labels={"test": "true", "app": NAME})
        container_port = ContainerPort(name="http5000", containerPort=5000)
        secrets_volume_mounts = [VolumeMount(name=NAME, readOnly=True, mountPath="/var/run/secrets/kubernetes.io/kubernetes-secrets")]
        secret_volumes = [Volume(name=NAME, secret=SecretVolumeSource(secretName=NAME))]
        container = Container(name="container", image="dummy_image", ports=[container_port], volumeMounts=secrets_volume_mounts)
        image_pull_secret = LocalObjectReference(name="image_pull_secret")
        pod_spec = PodSpec(containers=[container], imagePullSecrets=[image_pull_secret],
                           volumes=secret_volumes, serviceAccountName="default")
        first = Pod(metadata=object_meta, spec=pod_spec)
        logger.debug(pformat(first.as_dict()))
        first.save()

        pods = Pod.find(NAME, NAMESPACE)
        assert len(pods) == 1
        second = pods[0]
        assert first.metadata.name == second.metadata.name
        assert first.metadata.namespace == second.metadata.namespace
Esempio n. 5
0
 def _make_volumes(self, app_spec):
     volumes = [
         Volume(name="{}-secret".format(app_spec.name),
                secret=SecretVolumeSource(secretName=app_spec.name, optional=True)),
     ]
     return volumes