Exemplo n.º 1
0
def fake_api_service_error():
    return client.V1APIService(
        api_version='apiregistration.k8s.io/v1',
        kind='APIService',
        metadata=client.V1ObjectMeta(name='curry-test001',
                                     namespace='curryns'),
        status=client.V1APIServiceStatus(conditions=[
            client.V1APIServiceCondition(type='Unavailable', status='True')
        ]))
Exemplo n.º 2
0
def create_service_object():

    spec = client.V1ServiceSpec(
        cluster_ip="10.109.222.57",
        ports=client.V1ServicePort(name="nginx", port="81", protocol="TCP", target_port="81"),
        selector={"app": "nginx"}
    )
    service = client.V1APIService(
        api_version="v1",
        kind="Service",
        metadata=client.V1ObjectMeta(name=SERVICE_NAME, labels={"app": "nginx"}),
        spec=spec)
    return service
Exemplo n.º 3
0
def setup_paasta_namespace_services(
    kube_client: KubeClient,
    paasta_namespaces: AbstractSet,
    existing_namespace_services: Set[str],
    existing_virtual_services: Set[str],
) -> Iterator:
    for namespace in paasta_namespaces:
        service = sanitise_kubernetes_service_name(namespace)
        if service not in existing_namespace_services:
            log.info(
                f"Creating k8s service {service} because it does not exist yet."
            )

            service_meta = k8s.V1ObjectMeta(name=service,
                                            annotations=ANNOTATIONS)
            port_spec = k8s.V1ServicePort(name="http",
                                          port=PAASTA_SVC_PORT,
                                          protocol="TCP",
                                          app_protocol="http")
            service_spec = k8s.V1ServiceSpec(
                selector={registration_label(namespace): "true"},
                ports=[port_spec])
            service_object = k8s.V1APIService(metadata=service_meta,
                                              spec=service_spec)
            yield partial(
                kube_client.core.create_namespaced_service,
                PAASTA_NAMESPACE,
                service_object,
            )

        if service not in existing_virtual_services:
            log.info(
                f"Creating istio virtualservice {service} because it does not exist yet."
            )

            route = dict(destination=dict(host=service,
                                          port=dict(number=PAASTA_SVC_PORT)))
            virtual_service = dict(
                apiVersion="networking.istio.io/v1alpha3",
                kind="VirtualService",
                metadata=dict(name=service, namespace=PAASTA_NAMESPACE),
                spec=dict(http=[dict(route=[route])]),
            )
            yield partial(
                kube_client.custom.create_namespaced_custom_object,
                "networking.istio.io",
                "v1alpha3",
                PAASTA_NAMESPACE,
                "virtualservices",
                virtual_service,
            )
Exemplo n.º 4
0
    def _build_service(self, metadata):
        """Build service Kubernetes object.

        :param metadata: Common Kubernetes metadata for the interactive
            deployment.
        """
        spec = client.V1ServiceSpec(
            type="NodePort",
            ports=[
                client.V1ServicePort(
                    port=InteractiveDeploymentK8sBuilder.internal_service_port,
                    target_port=self.port,
                )
            ],
            selector={"app": self.deployment_name},
        )
        service = client.V1APIService(
            api_version="v1",
            kind="Service",
            spec=spec,
            metadata=metadata,
        )
        return service
Exemplo n.º 5
0
def setup_paasta_routing(kube_client: KubeClient,
                         namespaces: Mapping) -> Iterator:
    # Add smartstack ports for routing, Clients can connect to this
    # Directly without need of setting x-yelp-svc header
    # Add port 1337 for envoy unified listener.
    # Clients can connect to this listenner and set x-yelp-svc header for routing
    port_list = sorted(val["proxy_port"] for val in namespaces.values()
                       if val.get("proxy_port"))
    ports = [
        k8s.V1ServicePort(
            name=f"p{port}",
            port=port,
            protocol="TCP",
            target_port=PAASTA_SVC_PORT,
            app_protocol="http",
        ) for port in [1337, *port_list]
    ]

    service_meta = k8s.V1ObjectMeta(name=UNIFIED_K8S_SVC_NAME,
                                    annotations=ANNOTATIONS)
    service_spec = k8s.V1ServiceSpec(ports=ports)
    service_object = k8s.V1APIService(metadata=service_meta, spec=service_spec)
    yield partial(kube_client.core.create_namespaced_service, PAASTA_NAMESPACE,
                  service_object)

    sorted_namespaces = sorted(namespaces.keys())
    x_yelp_svc_routes = [
        dict(
            match=[dict(headers={"x-yelp-svc": dict(exact=mesh_ns)})],
            delegate=dict(
                name=sanitise_kubernetes_service_name(mesh_ns),
                namespace=PAASTA_NAMESPACE,
            ),
        ) for mesh_ns in sorted_namespaces
    ]
    port_routes = [
        dict(
            match=[dict(port=namespaces[mesh_ns]["proxy_port"])],
            delegate=dict(
                name=sanitise_kubernetes_service_name(mesh_ns),
                namespace=PAASTA_NAMESPACE,
            ),
        ) for mesh_ns in sorted_namespaces
        if namespaces[mesh_ns].get("proxy_port")
    ]
    virtual_service = dict(
        apiVersion="networking.istio.io/v1alpha3",
        kind="VirtualService",
        metadata=dict(
            name="paasta-routing",
            namespace=PAASTA_NAMESPACE,
        ),
        spec=dict(
            hosts=["paasta-routing", "169.254.255.254"],
            http=x_yelp_svc_routes + port_routes,
        ),
    )

    yield partial(
        kube_client.custom.create_namespaced_custom_object,
        "networking.istio.io",
        "v1alpha3",
        PAASTA_NAMESPACE,
        "virtualservices",
        virtual_service,
    )