Beispiel #1
0
def init_pod(host: Host, additional_labels, generate_name, container, sa_name="default"):
    pod = k8s.client.V1Pod()
    labels = {k: v for k, v in host.pod_labels.items()}
    for k, v in additional_labels.items():
        labels[k] = v
    validate_cleanup_in(labels)
    pod.metadata = k8s.client.V1ObjectMeta(generate_name=generate_name,
                                           namespace=host.namespace,
                                           labels=labels)
    pod.spec = k8s.client.V1PodSpec(containers=[container], service_account_name=sa_name)
    return pod
Beispiel #2
0
def init_svc(host: Host, additional_selector_labels, svc_labels, name, port_nums):
    svc_meta = k8s.client.V1ObjectMeta(name=name, namespace=host.namespace)
    svc = k8s.client.V1Service(api_version="v1", kind="Service", metadata=svc_meta)
    svc.spec = k8s.client.V1ServiceSpec()
    svc.spec.selector = {k: v for k, v in host.pod_labels.items()}
    for key, value in additional_selector_labels.items():
        svc.spec.selector[key] = value
    svc.metadata.labels = svc_labels
    validate_cleanup_in(svc.metadata.labels)
    # TODO: support for other protocols missing, target port might not work like that for multiple ports
    ports = [k8s.client.V1ServicePort(protocol="TCP", port=portNum, target_port=80) for portNum in port_nums]
    svc.spec.ports = ports
    return svc
def create_pod_manifest(host: Host, additional_labels, generate_name,
                        container):
    """
    Creates a pod manifest with given parameters
    """
    pod = k8s.client.V1Pod()
    labels = {key: value for key, value in host.pod_labels.items()}
    for key, value in additional_labels.items():
        labels[key] = value
    validate_cleanup_in(labels)
    pod.metadata = k8s.client.V1ObjectMeta(generate_name=generate_name,
                                           namespace=host.namespace,
                                           labels=labels)
    pod.spec = k8s.client.V1PodSpec(containers=[container],
                                    automount_service_account_token=False)
    return pod
Beispiel #4
0
def create_service_manifest(host: Host, additional_selector_labels, svc_labels,
                            port_nums):
    """
    Creates and returns a service manifest with given parameters
    """
    svc_meta = k8s.client.V1ObjectMeta(generate_name="illuminatio-test-target",
                                       namespace=host.namespace)
    svc = k8s.client.V1Service(api_version="v1",
                               kind="Service",
                               metadata=svc_meta)
    svc.spec = k8s.client.V1ServiceSpec()
    svc.spec.selector = {k: v for k, v in host.pod_labels.items()}
    for key, value in additional_selector_labels.items():
        svc.spec.selector[key] = value
    svc.metadata.labels = svc_labels
    validate_cleanup_in(svc.metadata.labels)
    # TODO: support for other protocols missing, target port might not work like that for multiple ports
    ports = [
        k8s.client.V1ServicePort(protocol="TCP", port=portNum, target_port=80)
        for portNum in port_nums
    ]
    svc.spec.ports = ports
    return svc