Beispiel #1
0
def _create_default_deployment():
    labels = {"test": "true"}
    object_meta = ObjectMeta(name=NAME, namespace=NAMESPACE, labels=labels)
    container_port = ContainerPort(name="http5000", containerPort=5000)
    http = HTTPGetAction(path="/", port="http5000")
    liveness = Probe(httpGet=http)
    tcp = TCPSocketAction(port=5000)
    readiness = Probe(tcpSocket=tcp)
    container = Container(name="container",
                          image="dummy_image",
                          ports=[container_port],
                          livenessProbe=liveness,
                          readinessProbe=readiness)
    image_pull_secret = LocalObjectReference(name="image_pull_secret")
    pod_spec = PodSpec(containers=[container],
                       imagePullSecrets=[image_pull_secret],
                       serviceAccountName="default")
    pod_template_spec = PodTemplateSpec(metadata=object_meta, spec=pod_spec)
    deployer_spec = DeploymentSpec(replicas=2,
                                   selector=LabelSelector(matchLabels=labels),
                                   template=pod_template_spec,
                                   revisionHistoryLimit=5)
    deployment = Deployment(metadata=object_meta, spec=deployer_spec)

    return deployment
    def test_lifecycle(self, logger):
        object_meta = ObjectMeta(name=NAME,
                                 namespace=NAMESPACE,
                                 labels={"test": "true"})
        container_port = ContainerPort(name="http5000", containerPort=5000)
        http = HTTPGetAction(path="/", port="http5000")
        liveness = Probe(httpGet=http)
        tcp = TCPSocketAction(port=5000)
        readiness = Probe(tcpSocket=tcp)
        container = Container(name="container",
                              image="dummy_image",
                              ports=[container_port],
                              livenessProbe=liveness,
                              readinessProbe=readiness)
        image_pull_secret = LocalObjectReference(name="image_pull_secret")
        pod_spec = PodSpec(containers=[container],
                           imagePullSecrets=[image_pull_secret],
                           serviceAccountName="default")
        pod_template_spec = PodTemplateSpec(metadata=object_meta,
                                            spec=pod_spec)
        rc_spec = ReplicationControllerSpec(replicas=2,
                                            selector={"test": "true"},
                                            template=pod_template_spec)
        first = ReplicationController(metadata=object_meta, spec=rc_spec)
        logger.debug(pformat(first.as_dict()))
        first.save()

        second = ReplicationController.get(NAME, NAMESPACE)
        assert first.metadata.name == second.metadata.name
        assert first.metadata.namespace == second.metadata.namespace
def deployment():
    main_container = Container(
        env=[EnvVar(name=CANARY_NAME, value=CANARY_VALUE)])
    pod_spec = PodSpec(containers=[main_container])
    pod_metadata = ObjectMeta(annotations={CANARY_NAME: CANARY_VALUE})
    pod_template_spec = PodTemplateSpec(spec=pod_spec, metadata=pod_metadata)
    deployment_spec = DeploymentSpec(template=pod_template_spec)
    return Deployment(spec=deployment_spec)
Beispiel #4
0
def _create_deployment(available_replicas, namespace, image):
    container = Container(image=image)
    pod_spec = PodSpec(containers=[container])
    pod_template_spec = PodTemplateSpec(spec=pod_spec)
    spec = DeploymentSpec(replicas=1, template=pod_template_spec)
    status = DeploymentStatus(availableReplicas=available_replicas)
    metadata = ObjectMeta(name=NAME, namespace=namespace)
    return Deployment(metadata=metadata, spec=spec, status=status)
Beispiel #5
0
def _create_default_job():
    labels = {"test": "true"}
    object_meta = ObjectMeta(name=NAME, namespace=NAMESPACE, labels=labels)
    container = Container(name="container", image="dummy_image")
    image_pull_secret = LocalObjectReference(name="image_pull_secret")
    pod_spec = PodSpec(containers=[container],
                       imagePullSecrets=[image_pull_secret],
                       serviceAccountName="default",
                       restartPolicy="Never")
    pod_template_spec = PodTemplateSpec(metadata=object_meta, spec=pod_spec)
    job_spec = JobSpec(template=pod_template_spec)
    job = Job(metadata=object_meta, spec=job_spec)

    return job
Beispiel #6
0
def _create_default_cronjob():
    object_meta = ObjectMeta(name=NAME, namespace=NAMESPACE)
    container = Container(name="container", image="dummy_image")
    pod_spec = PodSpec(containers=[container],
                       serviceAccountName="default",
                       restartPolicy="OnFailure")
    pod_template_spec = PodTemplateSpec(metadata=object_meta, spec=pod_spec)
    job_spec = JobSpec(template=pod_template_spec)
    job_template_spec = JobTemplateSpec(metadata=object_meta, spec=job_spec)
    cronjob_spec = CronJobSpec(concurencyPolicy="Allow",
                               failedJobsHistoryLimit=0,
                               jobTemplate=job_template_spec,
                               schedule="*/1 * * * *",
                               startingDeadlineSeconds=5,
                               successfulJobsHistoryLimit=100,
                               suspend=True)
    cronjob = CronJob(metadata=object_meta, spec=cronjob_spec)

    return cronjob
Beispiel #7
0
 def deployment(self):
     main_container = Container(env=[EnvVar(name="DUMMY", value="CANARY")])
     pod_spec = PodSpec(containers=[main_container])
     pod_template_spec = PodTemplateSpec(spec=pod_spec)
     deployment_spec = DeploymentSpec(template=pod_template_spec)
     return Deployment(spec=deployment_spec)
 def deployment(self):
     metadata = ObjectMeta(annotations={"dummy": "annotations"})
     pod_template_spec = PodTemplateSpec(metadata=metadata)
     deployment_spec = DeploymentSpec(template=pod_template_spec)
     return Deployment(spec=deployment_spec)