當前位置: 首頁>>代碼示例>>Python>>正文


Python pykube.Pod方法代碼示例

本文整理匯總了Python中pykube.Pod方法的典型用法代碼示例。如果您正苦於以下問題:Python pykube.Pod方法的具體用法?Python pykube.Pod怎麽用?Python pykube.Pod使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pykube的用法示例。


在下文中一共展示了pykube.Pod方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: single_pod_table_with_labels

# 需要導入模塊: import pykube [as 別名]
# 或者: from pykube import Pod [as 別名]
def single_pod_table_with_labels():
    table = Table(
        Pod,
        {
            "kind": "Table",
            "columnDefinitions": [{"name": "Name"}, {"name": "Status"}],
            "rows": [
                {
                    "cells": ["myname", "ImagePullBackOff"],
                    "object": {"metadata": {"labels": {"label1": "labelval1"}}},
                }
            ],
            "clusters": ["c1"],
        },
    )
    return table 
開發者ID:hjacobs,項目名稱:kube-web-view,代碼行數:18,代碼來源:test_table.py

示例2: test_merge_cluster_tables_completely_different

# 需要導入模塊: import pykube [as 別名]
# 或者: from pykube import Pod [as 別名]
def test_merge_cluster_tables_completely_different():
    table1 = Table(
        Pod,
        {
            "kind": "Table",
            "columnDefinitions": [{"name": "A"}],
            "rows": [{"cells": ["a"]}],
            "clusters": ["c1"],
        },
    )
    table2 = Table(
        Pod,
        {
            "kind": "Table",
            "columnDefinitions": [{"name": "B"}],
            "rows": [{"cells": ["b"]}],
            "clusters": ["c1"],
        },
    )
    table = merge_cluster_tables(table1, table2)
    assert len(table.obj["clusters"]) == 2
    assert table.columns == [{"name": "A"}, {"name": "B"}]
    assert table.rows == [{"cells": ["a", None]}, {"cells": [None, "b"]}] 
開發者ID:hjacobs,項目名稱:kube-web-view,代碼行數:25,代碼來源:test_table.py

示例3: test_add_label_columns_performance

# 需要導入模塊: import pykube [as 別名]
# 或者: from pykube import Pod [as 別名]
def test_add_label_columns_performance(capsys):
    def _add_label_cols():
        table = Table(
            Pod,
            {
                "kind": "Table",
                "columnDefinitions": [{"name": "A"}, {"name": "C"}, {"name": "E"}],
                "rows": [
                    {
                        "cells": ["a", "c", "e"],
                        "object": {"metadata": {"labels": {"foo": "bar"}}},
                    }
                ]
                * 100,
                "clusters": ["c1"],
            },
        )
        add_label_columns(table, "*")

    with capsys.disabled():
        print("add_label_columns", timeit.timeit(_add_label_cols, number=1000)) 
開發者ID:hjacobs,項目名稱:kube-web-view,代碼行數:23,代碼來源:test_table.py

示例4: test_marge_cluster_tables_performance

# 需要導入模塊: import pykube [as 別名]
# 或者: from pykube import Pod [as 別名]
def test_marge_cluster_tables_performance(capsys):
    def merge_tables():
        table1 = Table(
            Pod,
            {
                "kind": "Table",
                "columnDefinitions": [{"name": "A"}, {"name": "C"}, {"name": "E"}],
                "rows": [{"cells": ["a", "c", "e"]}] * 100,
                "clusters": ["c1"],
            },
        )
        table2 = Table(
            Pod,
            {
                "kind": "Table",
                "columnDefinitions": [{"name": "B"}, {"name": "D"}],
                "rows": [{"cells": ["b", "d"]}] * 100,
                "clusters": ["c1"],
            },
        )
        merge_cluster_tables(table1, table2)

    with capsys.disabled():
        print("merge_cluster_tables", timeit.timeit(merge_tables, number=1000)) 
開發者ID:hjacobs,項目名稱:kube-web-view,代碼行數:26,代碼來源:test_table.py

示例5: test_tainted_scale_set

# 需要導入模塊: import pykube [as 別名]
# 或者: from pykube import Pod [as 別名]
def test_tainted_scale_set(self):
        region = 'test'

        mock_client, monitor_client, resource_client = _default_mock_clients(region)

        instance_type = 'Standard_NC24'
        resource_group = 'test-resource-group'
        scale_set = AzureScaleSet(region, resource_group, 'test-scale-set', instance_type, 0, 'Succeeded', no_schedule_taints={'gpu': 'yes'})

        virtual_scale_set = AzureVirtualScaleSet(region, resource_group, AzureWrapper(mock_client, monitor_client, resource_client), instance_type, True, [scale_set], [])

        dir_path = os.path.dirname(os.path.realpath(__file__))
        with open(os.path.join(dir_path, 'data/busybox.yaml'), 'r') as f:
            dummy_pod = yaml.load(f.read())
        pod = KubePod(pykube.Pod(None, dummy_pod))

        self.assertFalse(virtual_scale_set.is_taints_tolerated(pod))

        dummy_pod['spec']['tolerations'] = [{'key': 'gpu', 'operator': 'Exists'}]
        pod = KubePod(pykube.Pod(None, dummy_pod))
        self.assertTrue(virtual_scale_set.is_taints_tolerated(pod)) 
開發者ID:openai,項目名稱:kubernetes-ec2-autoscaler,代碼行數:23,代碼來源:test_azure.py

示例6: test_timed_out_group

# 需要導入模塊: import pykube [as 別名]
# 或者: from pykube import Pod [as 別名]
def test_timed_out_group(self):
        with mock.patch('autoscaler.autoscaling_groups.AutoScalingGroup.is_timed_out') as is_timed_out:
            with mock.patch('autoscaler.autoscaling_groups.AutoScalingGroup.scale') as scale:
                is_timed_out.return_value = True
                scale.return_value = utils.CompletedFuture(None)

                pod = KubePod(pykube.Pod(self.api, self.dummy_pod))
                selectors_hash = utils.selectors_to_hash(pod.selectors)
                asgs = self.cluster.autoscaling_groups.get_all_groups([])
                self.cluster.fulfill_pending(asgs, selectors_hash, [pod])

                scale.assert_not_called()

                response = self.asg_client.describe_auto_scaling_groups()
                self.assertEqual(len(response['AutoScalingGroups']), 1)
                self.assertEqual(response['AutoScalingGroups'][0]['DesiredCapacity'], 0) 
開發者ID:openai,項目名稱:kubernetes-ec2-autoscaler,代碼行數:18,代碼來源:test_cluster.py

示例7: test_scale_down_launch_grace_period

# 需要導入模塊: import pykube [as 別名]
# 或者: from pykube import Pod [as 別名]
def test_scale_down_launch_grace_period(self):
        """
        kube node with daemonset and no pod + launch grace period --> noop
        """
        node = self._spin_up_node()
        all_nodes = [node]
        managed_nodes = [n for n in all_nodes if node.is_managed()]
        running_insts_map = self.cluster.get_running_instances_map(managed_nodes, [])
        pods_to_schedule = {}
        asgs = self.cluster.autoscaling_groups.get_all_groups(all_nodes)

        ds_pod = KubePod(pykube.Pod(self.api, self.dummy_ds_pod))
        running_or_pending_assigned_pods = [ds_pod]

        self.cluster.idle_threshold = -1
        self.cluster.type_idle_threshold = -1
        self.cluster.LAUNCH_HOUR_THRESHOLD['aws'] = 60*30
        self.cluster.maintain(
            managed_nodes, running_insts_map,
            pods_to_schedule, running_or_pending_assigned_pods, asgs)

        response = self.asg_client.describe_auto_scaling_groups()
        self.assertEqual(len(response['AutoScalingGroups']), 1)
        self.assertEqual(response['AutoScalingGroups'][0]['DesiredCapacity'], 1)
        node.cordon.assert_not_called() 
開發者ID:openai,項目名稱:kubernetes-ec2-autoscaler,代碼行數:27,代碼來源:test_cluster.py

示例8: test_scale_down_grace_period

# 需要導入模塊: import pykube [as 別名]
# 或者: from pykube import Pod [as 別名]
def test_scale_down_grace_period(self):
        """
        kube node with daemonset and no pod + grace period --> noop
        """
        node = self._spin_up_node()
        all_nodes = [node]
        managed_nodes = [n for n in all_nodes if node.is_managed()]
        running_insts_map = self.cluster.get_running_instances_map(managed_nodes, [])
        pods_to_schedule = {}
        asgs = self.cluster.autoscaling_groups.get_all_groups(all_nodes)

        # kube node with daemonset and no pod --> cordon
        ds_pod = KubePod(pykube.Pod(self.api, self.dummy_ds_pod))
        running_or_pending_assigned_pods = [ds_pod]

        self.cluster.maintain(
            managed_nodes, running_insts_map,
            pods_to_schedule, running_or_pending_assigned_pods, asgs)

        response = self.asg_client.describe_auto_scaling_groups()
        self.assertEqual(len(response['AutoScalingGroups']), 1)
        self.assertEqual(response['AutoScalingGroups'][0]['DesiredCapacity'], 1)
        node.cordon.assert_not_called() 
開發者ID:openai,項目名稱:kubernetes-ec2-autoscaler,代碼行數:25,代碼來源:test_cluster.py

示例9: test_pods_reacted

# 需要導入模塊: import pykube [as 別名]
# 或者: from pykube import Pod [as 別名]
def test_pods_reacted():

    example_py = os.path.join(os.path.dirname(__file__), 'example.py')
    with kopf.testing.KopfRunner(['run', '--standalone', '--verbose', example_py], timeout=60) as runner:
        name = _create_pod()
        time.sleep(5)  # give it some time to react
        _delete_pod(name)
        time.sleep(1)  # give it some time to react

    assert runner.exception is None
    assert runner.exit_code == 0

    assert f'[default/{name}] Creation event:' in runner.stdout
    assert f'[default/{name}] === Pod killing happens in 30s.' in runner.stdout
    assert f'[default/{name}] Deletion event:' in runner.stdout
    assert f'[default/{name}] === Pod killing is cancelled!' in runner.stdout 
開發者ID:zalando-incubator,項目名稱:kopf,代碼行數:18,代碼來源:test_example_10.py

示例10: create_pod

# 需要導入模塊: import pykube [as 別名]
# 或者: from pykube import Pod [as 別名]
def create_pod(**kwargs):

    # Render the pod yaml with some spec fields used in the template.
    pod_data = yaml.safe_load(f"""
        apiVersion: v1
        kind: Pod
        spec:
          containers:
          - name: the-only-one
            image: busybox
            command: ["sh", "-x", "-c", "sleep 1"]
    """)

    # Make it our child: assign the namespace, name, labels, owner references, etc.
    kopf.adopt(pod_data)
    kopf.label(pod_data, {'application': 'kopf-example-10'})

    # Actually create an object by requesting the Kubernetes API.
    api = pykube.HTTPClient(pykube.KubeConfig.from_env())
    pod = pykube.Pod(api, pod_data)
    pod.create()
    api.session.close() 
開發者ID:zalando-incubator,項目名稱:kopf,代碼行數:24,代碼來源:example.py

示例11: single_pod_table

# 需要導入模塊: import pykube [as 別名]
# 或者: from pykube import Pod [as 別名]
def single_pod_table():
    table = Table(
        Pod,
        {
            "kind": "Table",
            "columnDefinitions": [{"name": "Name"}, {"name": "Status"}],
            "rows": [{"cells": ["myname", "ImagePullBackOff"]}],
            "clusters": ["c1"],
        },
    )
    return table 
開發者ID:hjacobs,項目名稱:kube-web-view,代碼行數:13,代碼來源:test_table.py

示例12: two_pod_table

# 需要導入模塊: import pykube [as 別名]
# 或者: from pykube import Pod [as 別名]
def two_pod_table():
    table = Table(
        Pod,
        {
            "kind": "Table",
            "columnDefinitions": [{"name": "Name"}, {"name": "Status"}],
            "rows": [
                {"cells": ["pod-a", "Running"]},
                {"cells": ["pod-b", "Completed"]},
            ],
            "clusters": ["c2"],
        },
    )
    return table 
開發者ID:hjacobs,項目名稱:kube-web-view,代碼行數:16,代碼來源:test_table.py

示例13: test_add_label_columns

# 需要導入模塊: import pykube [as 別名]
# 或者: from pykube import Pod [as 別名]
def test_add_label_columns():
    table = Table(
        Pod,
        {
            "kind": "Table",
            "columnDefinitions": [],
            "rows": [{"cells": [], "object": {"metadata": {}}}],
        },
    )
    add_label_columns(table, "foo, bar")
    assert table.columns == [
        {"name": "Foo", "description": "foo label", "label": "foo"},
        {"name": "Bar", "description": "bar label", "label": "bar"},
    ] 
開發者ID:hjacobs,項目名稱:kube-web-view,代碼行數:16,代碼來源:test_table.py

示例14: test_add_label_columns_empty

# 需要導入模塊: import pykube [as 別名]
# 或者: from pykube import Pod [as 別名]
def test_add_label_columns_empty():
    table = Table(Pod, {"kind": "Table", "columnDefinitions": [], "rows": []})
    add_label_columns(table, ", ")
    assert table.columns == [] 
開發者ID:hjacobs,項目名稱:kube-web-view,代碼行數:6,代碼來源:test_table.py

示例15: test_merge_cluster_tables_new_columns

# 需要導入模塊: import pykube [as 別名]
# 或者: from pykube import Pod [as 別名]
def test_merge_cluster_tables_new_columns():
    table1 = Table(
        Pod,
        {
            "kind": "Table",
            "columnDefinitions": [{"name": "Name"}, {"name": "Status"}],
            "rows": [{"cells": ["myname", "ImagePullBackOff"]}],
            "clusters": ["c1"],
        },
    )
    table2 = Table(
        Pod,
        {
            "kind": "Table",
            "columnDefinitions": [
                {"name": "Name"},
                {"name": "FooCol"},
                {"name": "Status"},
            ],
            "rows": [{"cells": ["myname", "foo", "ImagePullBackOff"]}],
            "clusters": ["c1"],
        },
    )
    table = merge_cluster_tables(table1, table2)
    assert len(table.obj["clusters"]) == 2
    assert table.columns == [{"name": "Name"}, {"name": "Status"}, {"name": "FooCol"}]
    assert table.rows == [
        {"cells": ["myname", "ImagePullBackOff", None]},
        {"cells": ["myname", "ImagePullBackOff", "foo"]},
    ] 
開發者ID:hjacobs,項目名稱:kube-web-view,代碼行數:32,代碼來源:test_table.py


注:本文中的pykube.Pod方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。