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


Python pykube.HTTPClient方法代碼示例

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


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

示例1: main

# 需要導入模塊: import pykube [as 別名]
# 或者: from pykube import HTTPClient [as 別名]
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--seconds', type=int, default=3600, help='Delete all finished jobs older than ..')
    parser.add_argument('--timeout-seconds', type=int, default=-1, help='Kill all jobs older than ..')
    parser.add_argument('--dry-run', action='store_true', help='Dry run mode')
    parser.add_argument('--namespace', type=str, default=None, help='Only search for completed jobs in a single namespace')
    args = parser.parse_args()

    try:
        config = pykube.KubeConfig.from_service_account()
    except FileNotFoundError:
        # local testing
        config = pykube.KubeConfig.from_file(os.path.expanduser('~/.kube/config'))
    api = pykube.HTTPClient(config)

    namespace = args.namespace or pykube.all

    for job in pykube.Job.objects(api, namespace=namespace):
        delete_if_expired(args.dry_run, job, job_expired(args.seconds, args.timeout_seconds, job))

    for pod in pykube.Pod.objects(api, namespace=namespace):
        delete_if_expired(args.dry_run, pod, pod_expired(args.seconds, pod)) 
開發者ID:hjacobs,項目名稱:kube-job-cleaner,代碼行數:24,代碼來源:cleaner.py

示例2: test_no_auth_with_no_user

# 需要導入模塊: import pykube [as 別名]
# 或者: from pykube import HTTPClient [as 別名]
def test_no_auth_with_no_user(self):
        config = {
            "clusters": [
                {
                    "name": "no-auth-cluster",
                    "cluster": {
                        "server": "http://localhost:8080",
                    }
                }
            ],
            "contexts": [
                {
                    "name": "no-auth-cluster",
                    "context": {
                        "cluster": "no-auth-cluster"
                    }
                }
            ],
            "current-context": "no-auth-cluster"
        }
        client = pykube.HTTPClient(pykube.KubeConfig(doc=config))
        self.ensure_no_auth(client) 
開發者ID:kelproject,項目名稱:pykube,代碼行數:24,代碼來源:test_httpclient.py

示例3: test_build_session_bearer_token

# 需要導入模塊: import pykube [as 別名]
# 或者: from pykube import HTTPClient [as 別名]
def test_build_session_bearer_token(self):
        """Test that HTTPClient correctly parses the token
        """
        self.config.update({
            'users': [
                {
                    'name': 'test-user',
                    'user': {
                        'token': 'test'
                    },
                },
            ]
        })
        _log.info('Built config: %s', self.config)

        client = pykube.HTTPClient(pykube.KubeConfig(doc=self.config))
        _log.debug('Checking headers %s', client.session.headers)
        self.assertIn('Authorization', client.session.headers)
        self.assertEqual(client.session.headers['Authorization'], 'Bearer test') 
開發者ID:kelproject,項目名稱:pykube,代碼行數:21,代碼來源:test_httpclient.py

示例4: pod_killer

# 需要導入模塊: import pykube [as 別名]
# 或者: from pykube import HTTPClient [as 別名]
def pod_killer(namespace, name, logger, timeout=30):
    try:
        logger.info(f"=== Pod killing happens in {timeout}s.")
        await asyncio.sleep(timeout)
        logger.info(f"=== Pod killing happens NOW!")

        api = pykube.HTTPClient(pykube.KubeConfig.from_env())
        pod = pykube.Pod.objects(api, namespace=namespace).get_by_name(name)
        pod.delete()
        api.session.close()

    except asyncio.CancelledError:
        logger.info(f"=== Pod killing is cancelled!")

    finally:
        if namespace in tasks and name in tasks[namespace]:
            del tasks[namespace][name] 
開發者ID:zalando-incubator,項目名稱:kopf,代碼行數:19,代碼來源:example.py

示例5: create_pod

# 需要導入模塊: import pykube [as 別名]
# 或者: from pykube import HTTPClient [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

示例6: get_kube_api

# 需要導入模塊: import pykube [as 別名]
# 或者: from pykube import HTTPClient [as 別名]
def get_kube_api():
    try:
        config = pykube.KubeConfig.from_service_account()
    except FileNotFoundError:
        # local testing
        config = pykube.KubeConfig.from_file(os.path.expanduser('~/.kube/config'))
    api = pykube.HTTPClient(config)
    return api 
開發者ID:amelbakry,項目名稱:kube-schedule-scaler,代碼行數:10,代碼來源:deployment-script.py

示例7: get_kube_api

# 需要導入模塊: import pykube [as 別名]
# 或者: from pykube import HTTPClient [as 別名]
def get_kube_api():
    """ Initiating the API from Service Account or when running locally from ~/.kube/config """
    try:
        config = pykube.KubeConfig.from_service_account()
    except FileNotFoundError:
        # local testing
        config = pykube.KubeConfig.from_file(os.path.expanduser('~/.kube/config'))
    api = pykube.HTTPClient(config)
    return api 
開發者ID:amelbakry,項目名稱:kube-schedule-scaler,代碼行數:11,代碼來源:schedule_scaling.py

示例8: __init__

# 需要導入模塊: import pykube [as 別名]
# 或者: from pykube import HTTPClient [as 別名]
def __init__(
        self, name: str, api: HTTPClient, labels: dict = None, spec: dict = None
    ):
        self.name = name
        self.api = api
        self.labels = labels or {}
        self.spec = spec or {} 
開發者ID:hjacobs,項目名稱:kube-web-view,代碼行數:9,代碼來源:cluster_discovery.py

示例9: refresh

# 需要導入模塊: import pykube [as 別名]
# 或者: from pykube import HTTPClient [as 別名]
def refresh(self):
        try:
            response = self._session.get(
                urljoin(self._url, "/kubernetes-clusters"), timeout=10
            )
            response.raise_for_status()
            clusters = []
            for row in response.json()["items"]:
                # only consider "ready" clusters
                if row.get("lifecycle_status", "ready") == "ready":
                    config = KubeConfig.from_url(row["api_server_url"])
                    client = HTTPClient(config)
                    client.session.auth = OAuth2BearerTokenAuth(
                        self._oauth2_bearer_token_path
                    )
                    labels = {}
                    for key in (
                        "id",
                        "channel",
                        "environment",
                        "infrastructure_account",
                        "region",
                    ):
                        if key in row:
                            labels[key.replace("_", "-")] = row[key]
                    clusters.append(Cluster(row["alias"], client, labels, row))
            self._clusters = clusters
            self._last_cache_refresh = time.time()
        except Exception:
            logger.exception(f"Failed to refresh from cluster registry {self._url}") 
開發者ID:hjacobs,項目名稱:kube-web-view,代碼行數:32,代碼來源:cluster_discovery.py

示例10: get_clusters

# 需要導入模塊: import pykube [as 別名]
# 或者: from pykube import HTTPClient [as 別名]
def get_clusters(self):
        # Kubernetes Python client expects "vintage" string path
        config_file = str(self._path) if self._path else None
        config = KubeConfig.from_file(config_file)
        for context in config.contexts:
            if self._contexts and context not in self._contexts:
                # filter out
                continue
            # create a new KubeConfig with new "current context"
            context_config = KubeConfig(config.doc, context)
            client = HTTPClient(context_config)
            cluster = Cluster(context, client)
            yield cluster 
開發者ID:hjacobs,項目名稱:kube-web-view,代碼行數:15,代碼來源:cluster_discovery.py

示例11: __init__

# 需要導入模塊: import pykube [as 別名]
# 或者: from pykube import HTTPClient [as 別名]
def __init__(self, opts: Namespace) -> None:
        self.api = pykube.HTTPClient(pykube.KubeConfig.from_file(opts.kube_config_file)) 
開發者ID:DistributedSystemsGroup,項目名稱:zoe,代碼行數:4,代碼來源:api_client.py

示例12: kube_client

# 需要導入模塊: import pykube [as 別名]
# 或者: from pykube import HTTPClient [as 別名]
def kube_client(self):
        return pykube.HTTPClient(self.kube_config) 
開發者ID:miracle2k,項目名稱:k8s-snapshots,代碼行數:4,代碼來源:context.py

示例13: __init__

# 需要導入模塊: import pykube [as 別名]
# 或者: from pykube import HTTPClient [as 別名]
def __init__(self, client_factory: Optional[ClientFactory] = None):
        """

        Parameters
        ----------
        client_factory
            Used in threaded operations to create a local
            :any:`pykube.HTTPClient` instance.
        """
        # Used for threaded operations
        self.client_factory = client_factory 
開發者ID:miracle2k,項目名稱:k8s-snapshots,代碼行數:13,代碼來源:kube.py

示例14: fx_mock_context_kube_client

# 需要導入模塊: import pykube [as 別名]
# 或者: from pykube import HTTPClient [as 別名]
def fx_mock_context_kube_client():
    def _fake_client(self: Context):
        return MagicMock(
            spec=pykube.HTTPClient,
            config=self.load_kube_config()
        )
    with mock.patch(
        'k8s_snapshots.context.Context.kube_client',
        _fake_client,
    ) as _mock:
        yield _mock 
開發者ID:miracle2k,項目名稱:k8s-snapshots,代碼行數:13,代碼來源:kube.py

示例15: fx_kube_config

# 需要導入模塊: import pykube [as 別名]
# 或者: from pykube import HTTPClient [as 別名]
def fx_kube_config(request: FixtureRequest) -> pykube.KubeConfig:
    """
    Minimal fake pykube.HTTPClient config fixture.
    """
    return KUBE_CONFIG 
開發者ID:miracle2k,項目名稱:k8s-snapshots,代碼行數:7,代碼來源:kube.py


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