Exemplo n.º 1
0
    def status(self, with_loadbalancer_info=False):
        # Locking so that a create is not meddling with status
        s = self._get_from_provider()
        if s is None:
            raise AXNotFoundException("Could not find Route {}.{}".format(
                self.name, self.namespace))
        ep = self._get_ep_from_provider()
        if ep is None:
            raise AXNotFoundException(
                "Could not find Route Endpoint for {}.{}".format(
                    self.name, self.namespace))

        field_map = {
            "name": "metadata.name",
            "application": "metadata.namespace",
            "ip": "spec.cluster_ip"
        }

        if with_loadbalancer_info:
            field_map["loadbalancer"] = "status.load_balancer.ingress.hostname"

        ret = KubeObject.swagger_obj_extract(s, field_map)
        field_map = {"ips": "subsets.addresses.ip"}
        ret["endpoints"] = KubeObject.swagger_obj_extract(ep, field_map)
        return ret
Exemplo n.º 2
0
Arquivo: pod.py Projeto: zhan849/argo
    def massage_pod_status(v1pod):
        pod_field_map = {
            "name": "metadata.name",
            "generation": "metadata.annotations.ax_generation",
            "phase": "status.phase",
            "startTime": "status.start_time",
            "message": "status.message",
            "reason": "status.reason",
            "labels": "metadata.labels"
        }

        container_field_map = {
            "name": "name",
            "container_id": "container_id",
            "state": "state",
            "ready": "ready",
            "restart_count": "restart_count",
            "image": "image",
            "image_id": "image_id"
        }

        # Get information from pod_field_map
        pstatus = KubeObject.swagger_obj_extract(v1pod, pod_field_map, serializable=True)

        # fill containers in pod
        pstatus["containers"] = []
        for container_status in v1pod.status.container_statuses or []:
            cstatus = KubeObject.swagger_obj_extract(container_status, container_field_map, serializable=True)
            if cstatus["name"] == DIND_CONTAINER_NAME:
                continue
            # fix container_id field
            if cstatus["container_id"]:
                cstatus["container_id"] = cstatus["container_id"][len("docker://"):]
            pstatus["containers"].append(cstatus)
        return pstatus
Exemplo n.º 3
0
    def status(self):
        """
        Get the status of the deployment.
        Returns: Returns the entire V1Deployment as a dict.
        If deployment is not found then this will raise an AXNotFoundException (404)
        """
        # STEP 1: Get status of deployment
        stat = self._deployment_status()
        if stat is None:
            raise AXNotFoundException("Deployment {} not found in application {}".format(self.name, self.application))

        dep_field_map = {
            "name": "metadata.name",
            "generation": "metadata.annotations.ax_generation",
            "desired_replicas": "status.replicas",
            "available_replicas": "status.available_replicas",
            "unavailable_replicas": "status.unavailable_replicas"
        }
        ret = KubeObject.swagger_obj_extract(stat, dep_field_map, serializable=True)

        # STEP 2: Get the pods for the deployment and events associated
        podlist = self._deployment_pods().items
        dep_events = self._app_obj.events(name=self.name)
        event_field_map = {
            "message": "message",
            "reason": "reason",
            "source": "source.component",
            "host": "source.host",
            "firstTS": "first_timestamp",
            "lastTS": "last_timestamp",
            "count": "count",
            "container": "involved_object.field_path",
            "type": "type"
        }
        ret["events"] = []
        for event in dep_events:
            ret["events"].append(KubeObject.swagger_obj_extract(event, event_field_map, serializable=True))

        ret["pods"] = []
        for pod in podlist or []:
            # fill pod status and containers
            pstatus = Pod.massage_pod_status(pod)

            # fill events for pod
            pstatus["events"] = []

            events = self._app_obj.events(name=pod.metadata.name)
            for event in events:
                pstatus["events"].append(KubeObject.swagger_obj_extract(event, event_field_map, serializable=True))

            # fill pod failure information for pod based on events
            pstatus["failure"] = Deployment._pod_failed_info(pstatus)

            ret["pods"].append(pstatus)

        # STEP 3: From the deployment spec get the resources created by deployment
        # TODO: Add this when services are created by deployment

        return ret
Exemplo n.º 4
0
    def get_labels(self):
        """
        Get a dict of labels used for this deployment
        """
        state = self._deployment_status()
        if state is None:
            raise AXNotFoundException("Did not find deployment {} in application {}".format(self.name, self.application))

        return KubeObject.swagger_obj_extract(state, {"labels": "spec.selector.match_labels"})['labels']
Exemplo n.º 5
0
 def _load_kube_objects_from_steps(self, steps):
     """
     Extract kube objects from steps in config, and load them into memory
     :param steps: list
     :return:
     """
     for object_group in steps:
         assert isinstance(object_group, AXPlatformObjectGroup)
         for obj in object_group.object_set:
             assert isinstance(obj, AXPlatformObject)
             name = obj.name
             filename = obj.manifest
             namespace = obj.namespace
             if name in self._kube_objects:
                 raise ValueError("Duplicated object name {}".format(name))
             kubeobj_conf_path = os.path.join(self._manifest_root, filename)
             self._kube_objects[name] = KubeObject(
                 config_file=kubeobj_conf_path,
                 kubepoll=self.kube_poll,
                 replacing=None,
                 kube_config=self._kube_config,
                 kube_namespace=namespace)