def create_deployment_object(data):
    # Configureate Pod template container

    template_spec = common.create_pod_template_spec(data=data)

    labels_array = data["labels"].split(',')
    labels = dict(s.split('=') for s in labels_array)

    meta = client.V1ObjectMeta(labels=labels)

    annotations = None
    if "annotations" in data:
        annotations_array = data["annotations"].split(',')
        annotations = dict(s.split('=') for s in annotations_array)
        meta.annotations = annotations

    # Create and configurate a spec section
    template = client.V1PodTemplateSpec(
        metadata=meta,
        spec=template_spec
    )
    # Create the specification of deployment
    spec = client.ExtensionsV1beta1DeploymentSpec(
        replicas=int(data["replicas"]),
        template=template)
    # Instantiate the deployment object
    deployment = client.ExtensionsV1beta1Deployment(
        api_version=data["api_version"],
        kind="Deployment",
        metadata=client.V1ObjectMeta(labels=labels,
                                     namespace=data["namespace"],
                                     name=data["name"]),
        spec=spec)

    return deployment
Exemplo n.º 2
0
def create_pod(data):
    labels_array = data["labels"].split(',')
    labels = dict(s.split('=') for s in labels_array)

    metadata = client.V1ObjectMeta(labels=labels,
                                   namespace=data["namespace"],
                                   name=data["name"])

    template_spec = common.create_pod_template_spec(data)

    pod = client.V1Pod(api_version=data["api_version"],
                       kind="Pod",
                       metadata=metadata,
                       spec=template_spec)

    return pod