Example #1
0
def simple_replicaset():
    """Return the Kubernetes config matching the simple-replicaset.yaml manifest."""
    return client.V1ReplicaSet(
        api_version="apps/v1",
        kind="ReplicaSet",
        metadata=client.V1ObjectMeta(
            name="frontend",
            labels={
                "app": "guestbook",
                "tier": "frontend",
            },
        ),
        spec=client.V1ReplicaSetSpec(
            replicas=3,
            selector=client.V1LabelSelector(match_labels={
                "tier": "frontend",
            }, ),
            template=client.V1PodTemplateSpec(
                metadata=client.V1ObjectMeta(labels={
                    "tier": "frontend",
                }, ),
                spec=client.V1PodSpec(containers=[
                    client.V1Container(
                        name="php-redis",
                        image="gcr.io/google_samples/gb-frontend:v3",
                    ),
                ], ),
            ),
        ),
    )
Example #2
0
def simple_replicaset():
    """Return the Kubernetes config matching the simple-replicaset.yaml manifest."""
    return client.V1ReplicaSet(
        api_version='apps/v1',
        kind='ReplicaSet',
        metadata=client.V1ObjectMeta(
            name='frontend',
            labels={
                'app': 'guestbook',
                'tier': 'frontend',
            },
        ),
        spec=client.V1ReplicaSetSpec(
            replicas=3,
            selector=client.V1LabelSelector(match_labels={
                'tier': 'frontend',
            }, ),
            template=client.V1PodTemplateSpec(
                metadata=client.V1ObjectMeta(labels={
                    'tier': 'frontend',
                }, ),
                spec=client.V1PodSpec(containers=[
                    client.V1Container(
                        name='php-redis',
                        image='gcr.io/google_samples/gb-frontend:v3',
                    ),
                ], ),
            ),
        ),
    )
Example #3
0
    def __init__(self, name, storage_pvc):
        internal_volume_name = 'nfs-server-volume'
        mount_path = '/exports'

        ctr = client.V1Container(
            name=name,
            image=self.IMAGE,
            ports=[
                client.V1ContainerPort(name=k, container_port=v)
                for k, v in self.PORTS.items()
            ],
            security_context=client.V1SecurityContext(privileged=True),
            volume_mounts=[
                client.V1VolumeMount(mount_path=mount_path,
                                     name=internal_volume_name)
            ])
        volume_source = client.V1PersistentVolumeClaimVolumeSource(
            claim_name=storage_pvc)
        volume = client.V1Volume(name=internal_volume_name,
                                 persistent_volume_claim=volume_source)
        pod_spec = client.V1PodSpec(containers=[ctr], volumes=[volume])
        pod_metadata = client.V1ObjectMeta(labels=self.LABELS)
        pod_template = client.V1PodTemplateSpec(metadata=pod_metadata,
                                                spec=pod_spec)
        rs_spec = client.V1ReplicaSetSpec(
            replicas=1,
            selector=client.V1LabelSelector(match_labels=self.LABELS),
            template=pod_template)
        metadata = client.V1ObjectMeta(name=name, labels=self.LABELS)
        super(NFSDeployment, self).__init__(metadata=metadata, spec=rs_spec)
Example #4
0
def construct_replica_set(name, owner_deployment=None):
    """Construct a fake ReplicaSet body"""
    if owner_deployment:
        owner_references = [
            client.V1OwnerReference(
                api_version=owner_deployment.api_version,
                uid=uuid.uuid4().hex,
                name=owner_deployment.metadata.name,
                kind='Deployment',
            )
        ]
        match_labels = owner_deployment.spec.selector.match_labels
    else:
        owner_references = []
        match_labels = {'rs-name': name}

    return client.V1ReplicaSet(
        api_version='extensions/v1beta1',
        kind='ReplicaSet',
        metadata=client.V1ObjectMeta(
            name=name,
            # Set owner reference to deployment
            owner_references=owner_references,
        ),
        spec=client.V1ReplicaSetSpec(
            replicas=1,
            selector=client.V1LabelSelector(match_labels=match_labels),
            template=client.V1PodTemplateSpec(
                spec=client.V1PodSpec(containers=[
                    client.V1Container(image="busybox",
                                       name="main",
                                       command=["sleep", "3600"])
                ]),
                metadata=client.V1ObjectMeta(labels=match_labels, name=name),
            ),
        ),
    )