You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by GitBox <gi...@apache.org> on 2022/03/17 17:42:35 UTC

[GitHub] [libcloud] dimgal1 opened a new pull request #1667: Update Kubernetes driver

dimgal1 opened a new pull request #1667:
URL: https://github.com/apache/libcloud/pull/1667


   ## Updates for  Kubernetes driver
   
   ### Description
   
   Implement list methods for Kubernetes nodes,services,deployments and node/pod metrics. 
   Add more fields to pods & containers.
   Rename clusters to namespaces since cluster was used as an alias for namespace. 
   Add type hints
   
   ### Status
   
   - done, ready for review
   
   ### Checklist (tick everything that applies)
   
   - [x] [Code linting](http://libcloud.readthedocs.org/en/latest/development.html#code-style-guide) (required, can be done after the PR checks)
   - [ ] Documentation
   - [x] [Tests](http://libcloud.readthedocs.org/en/latest/testing.html)
   - [ ] [ICLA](http://libcloud.readthedocs.org/en/latest/development.html#contributing-bigger-changes) (required for bigger changes)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@libcloud.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [libcloud] Kami commented on a change in pull request #1667: Update Kubernetes driver

Posted by GitBox <gi...@apache.org>.
Kami commented on a change in pull request #1667:
URL: https://github.com/apache/libcloud/pull/1667#discussion_r834163223



##########
File path: libcloud/container/base.py
##########
@@ -45,6 +45,7 @@ def __init__(
         ip_addresses,  # type: List[str]
         driver,  # type: ContainerDriver
         extra=None,  # type: dict
+        created_at=None,  # type: str

Review comment:
       Yeah, I think it should be fine adding it to the base API since it's added to the end and shouldn't break existing code.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@libcloud.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [libcloud] Kami commented on a change in pull request #1667: Update Kubernetes driver

Posted by GitBox <gi...@apache.org>.
Kami commented on a change in pull request #1667:
URL: https://github.com/apache/libcloud/pull/1667#discussion_r834169524



##########
File path: libcloud/container/drivers/kubernetes.py
##########
@@ -30,20 +33,178 @@
 from libcloud.container.providers import Provider
 from libcloud.container.types import ContainerState
 
-__all__ = ["KubernetesContainerDriver"]
+from libcloud.compute.types import NodeState
+from libcloud.compute.base import Node
+from libcloud.compute.base import NodeSize
+from libcloud.compute.base import NodeImage
+from libcloud.common.exceptions import BaseHTTPError
+
+__all__ = [
+    "KubernetesContainerDriver",
+    "to_n_bytes",
+    "to_memory_str",
+    "to_cpu_str",
+    "to_n_cpus",
+]
 
 
 ROOT_URL = "/api/"
 
 
+K8S_UNIT_MAP = OrderedDict(
+    {
+        "K": 1000,
+        "Ki": 1024,
+        "M": 1000 * 1000,
+        "Mi": 1024 * 1024,
+        "G": 1000 * 1000 * 1000,
+        "Gi": 1024 * 1024 * 1024,
+    }
+)
+
+
+def to_n_bytes(memory_str: str) -> int:

Review comment:
       It also wouldn't hurt to add direct test cases for all those utility conversion functions :)




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@libcloud.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [libcloud] codecov-commenter commented on pull request #1667: Update Kubernetes driver

Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on pull request #1667:
URL: https://github.com/apache/libcloud/pull/1667#issuecomment-1071146007


   # [Codecov](https://codecov.io/gh/apache/libcloud/pull/1667?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#1667](https://codecov.io/gh/apache/libcloud/pull/1667?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (a05aa53) into [trunk](https://codecov.io/gh/apache/libcloud/commit/8c4f229c98f521281a468070507f5387f6255bef?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (8c4f229) will **decrease** coverage by `0.01%`.
   > The diff coverage is `78.21%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/libcloud/pull/1667/graphs/tree.svg?width=650&height=150&src=pr&token=PYoduksh69&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)](https://codecov.io/gh/apache/libcloud/pull/1667?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   
   ```diff
   @@            Coverage Diff             @@
   ##            trunk    #1667      +/-   ##
   ==========================================
   - Coverage   83.27%   83.25%   -0.02%     
   ==========================================
     Files         400      400              
     Lines       87227    87463     +236     
     Branches     9260     9294      +34     
   ==========================================
   + Hits        72638    72819     +181     
   - Misses      11448    11488      +40     
   - Partials     3141     3156      +15     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/libcloud/pull/1667?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [libcloud/container/drivers/kubernetes.py](https://codecov.io/gh/apache/libcloud/pull/1667/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-bGliY2xvdWQvY29udGFpbmVyL2RyaXZlcnMva3ViZXJuZXRlcy5weQ==) | `68.75% <67.20%> (-6.56%)` | :arrow_down: |
   | [libcloud/container/base.py](https://codecov.io/gh/apache/libcloud/pull/1667/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-bGliY2xvdWQvY29udGFpbmVyL2Jhc2UucHk=) | `89.23% <100.00%> (+0.16%)` | :arrow_up: |
   | [libcloud/test/container/test\_kubernetes.py](https://codecov.io/gh/apache/libcloud/pull/1667/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-bGliY2xvdWQvdGVzdC9jb250YWluZXIvdGVzdF9rdWJlcm5ldGVzLnB5) | `98.52% <100.00%> (+1.86%)` | :arrow_up: |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/libcloud/pull/1667?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/libcloud/pull/1667?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [8c4f229...a05aa53](https://codecov.io/gh/apache/libcloud/pull/1667?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@libcloud.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [libcloud] codecov-commenter commented on pull request #1667: Update Kubernetes driver

Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on pull request #1667:
URL: https://github.com/apache/libcloud/pull/1667#issuecomment-1071146007


   # [Codecov](https://codecov.io/gh/apache/libcloud/pull/1667?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#1667](https://codecov.io/gh/apache/libcloud/pull/1667?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (a05aa53) into [trunk](https://codecov.io/gh/apache/libcloud/commit/8c4f229c98f521281a468070507f5387f6255bef?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (8c4f229) will **decrease** coverage by `0.01%`.
   > The diff coverage is `78.21%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/libcloud/pull/1667/graphs/tree.svg?width=650&height=150&src=pr&token=PYoduksh69&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)](https://codecov.io/gh/apache/libcloud/pull/1667?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   
   ```diff
   @@            Coverage Diff             @@
   ##            trunk    #1667      +/-   ##
   ==========================================
   - Coverage   83.27%   83.25%   -0.02%     
   ==========================================
     Files         400      400              
     Lines       87227    87463     +236     
     Branches     9260     9294      +34     
   ==========================================
   + Hits        72638    72819     +181     
   - Misses      11448    11488      +40     
   - Partials     3141     3156      +15     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/libcloud/pull/1667?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [libcloud/container/drivers/kubernetes.py](https://codecov.io/gh/apache/libcloud/pull/1667/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-bGliY2xvdWQvY29udGFpbmVyL2RyaXZlcnMva3ViZXJuZXRlcy5weQ==) | `68.75% <67.20%> (-6.56%)` | :arrow_down: |
   | [libcloud/container/base.py](https://codecov.io/gh/apache/libcloud/pull/1667/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-bGliY2xvdWQvY29udGFpbmVyL2Jhc2UucHk=) | `89.23% <100.00%> (+0.16%)` | :arrow_up: |
   | [libcloud/test/container/test\_kubernetes.py](https://codecov.io/gh/apache/libcloud/pull/1667/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-bGliY2xvdWQvdGVzdC9jb250YWluZXIvdGVzdF9rdWJlcm5ldGVzLnB5) | `98.52% <100.00%> (+1.86%)` | :arrow_up: |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/libcloud/pull/1667?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/libcloud/pull/1667?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [8c4f229...a05aa53](https://codecov.io/gh/apache/libcloud/pull/1667?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@libcloud.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [libcloud] Kami commented on a change in pull request #1667: Update Kubernetes driver

Posted by GitBox <gi...@apache.org>.
Kami commented on a change in pull request #1667:
URL: https://github.com/apache/libcloud/pull/1667#discussion_r834163866



##########
File path: libcloud/container/drivers/kubernetes.py
##########
@@ -30,20 +33,178 @@
 from libcloud.container.providers import Provider
 from libcloud.container.types import ContainerState
 
-__all__ = ["KubernetesContainerDriver"]
+from libcloud.compute.types import NodeState
+from libcloud.compute.base import Node
+from libcloud.compute.base import NodeSize
+from libcloud.compute.base import NodeImage
+from libcloud.common.exceptions import BaseHTTPError
+
+__all__ = [
+    "KubernetesContainerDriver",
+    "to_n_bytes",
+    "to_memory_str",
+    "to_cpu_str",
+    "to_n_cpus",
+]
 
 
 ROOT_URL = "/api/"
 
 
+K8S_UNIT_MAP = OrderedDict(
+    {
+        "K": 1000,
+        "Ki": 1024,
+        "M": 1000 * 1000,
+        "Mi": 1024 * 1024,
+        "G": 1000 * 1000 * 1000,
+        "Gi": 1024 * 1024 * 1024,
+    }
+)
+
+
+def to_n_bytes(memory_str: str) -> int:
+    """Convert memory string to number of bytes
+    (e.g. '1234Mi'-> 1293942784)
+    """
+    if memory_str.startswith("0"):
+        return 0
+    if memory_str.isnumeric():
+        return int(memory_str)
+    for unit, multiplier in K8S_UNIT_MAP.items():
+        if memory_str.endswith(unit):
+            return int(memory_str.strip(unit)) * multiplier
+
+
+def to_memory_str(n_bytes: int, unit: Optional[str] = None) -> str:
+    """Convert number of bytes to k8s memory string
+    (e.g. 1293942784 -> '1234Mi')
+    """
+    if n_bytes == 0:
+        return "0K"
+    n_bytes = int(n_bytes)
+    memory_str = None
+    if unit is None:
+        for unit, multiplier in reversed(K8S_UNIT_MAP.items()):
+            converted_n_bytes_float = n_bytes / multiplier
+            converted_n_bytes = n_bytes // multiplier
+            memory_str = f"{converted_n_bytes}{unit}"
+            if converted_n_bytes_float % 1 == 0:
+                break
+    elif K8S_UNIT_MAP.get(unit):
+        memory_str = f"{n_bytes // K8S_UNIT_MAP[unit]}{unit}"
+    return memory_str
+
+
+def to_cpu_str(n_cpus: Union[int, float]) -> str:
+    """Convert number of cpus to cpu string
+    (e.g. 0.5 -> '500m')
+    """
+    if n_cpus == 0:
+        return "0"
+    millicores = n_cpus * 1000
+    if millicores % 1 == 0:
+        return f"{int(millicores)}m"
+    microcores = n_cpus * 1000000
+    if microcores % 1 == 0:
+        return f"{int(microcores)}u"
+    nanocores = n_cpus * 1000000000
+    return f"{int(nanocores)}n"
+
+
+def to_n_cpus(cpu_str: str) -> Union[int, float]:
+    """Convert cpu string to number of cpus
+    (e.g. '500m' -> 0.5, '2000000000n' -> 2)
+    """
+    if cpu_str.endswith("n"):
+        return int(cpu_str.strip("n")) / 1000000000
+    elif cpu_str.endswith("u"):
+        return int(cpu_str.strip("u")) / 1000000
+    elif cpu_str.endswith("m"):
+        return int(cpu_str.strip("m")) / 1000
+    elif cpu_str.isnumeric():
+        return int(cpu_str)
+    else:
+        return 0
+
+
+def sum_resources(self, *resource_dicts):
+    total_cpu = 0
+    total_memory = 0
+    for rd in resource_dicts:
+        total_cpu += to_n_cpus(rd.get("cpu", "0m"))
+        total_memory += to_n_bytes(rd.get("memory", "0K"))
+    return {"cpu": to_cpu_str(total_cpu), "memory": to_memory_str(total_memory)}
+
+
+class KubernetesDeployment:
+    def __init__(
+        self,
+        id: str,
+        name: str,
+        namespace: str,
+        created_at: str,
+        replicas: int,
+        selector: Dict[str, Any],
+        extra: Optional[Dict[str, Any]] = None,

Review comment:
       Thanks for including type annotations everywhere :+1: 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@libcloud.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org