Skip to content
This repository was archived by the owner on Oct 3, 2020. It is now read-only.

Add PodDisruptionBudget object #11

Merged
merged 1 commit into from
Mar 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pykube/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
PersistentVolume,
PersistentVolumeClaim,
Pod,
PodDisruptionBudget,
PodSecurityPolicy,
ReplicationController,
ReplicaSet,
Expand Down
4 changes: 3 additions & 1 deletion pykube/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,15 @@ def from_service_account(cls, path="/var/run/secrets/kubernetes.io/serviceaccoun
return self

@classmethod
def from_file(cls, filename, **kwargs):
def from_file(cls, filename=None, **kwargs):
"""
Creates an instance of the KubeConfig class from a kubeconfig file.

:Parameters:
- `filename`: The full path to the configuration file
"""
if not filename:
filename = os.getenv('KUBECONFIG', '~/.kube/config')
filename = os.path.expanduser(filename)
if not os.path.isfile(filename):
raise exceptions.PyKubeError("Configuration file {} not found".format(filename))
Expand Down
7 changes: 7 additions & 0 deletions pykube/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,3 +464,10 @@ class PodSecurityPolicy(APIObject):
version = "extensions/v1beta1"
endpoint = "podsecuritypolicies"
kind = "PodSecurityPolicy"


class PodDisruptionBudget(APIObject):

version = "policy/v1beta1"
endpoint = "poddisruptionbudgets"
kind = "PodDisruptionBudget"
31 changes: 31 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import pytest

from pathlib import Path
from unittest.mock import MagicMock

from pykube import config, exceptions

Expand Down Expand Up @@ -46,6 +47,36 @@ def test_from_url():
assert 'users' not in cfg.doc


@pytest.fixture
def kubeconfig(tmpdir):
kubeconfig = tmpdir.join('kubeconfig')
kubeconfig.write('''
apiVersion: v1
clusters:
- cluster: {server: 'https://localhost:9443'}
name: test
contexts:
- context: {cluster: test, user: test}
name: test
current-context: test
kind: Config
preferences: {}
users:
- name: test
user: {token: testtoken}
''')
return kubeconfig


def test_from_default_kubeconfig(monkeypatch, kubeconfig):
mock = MagicMock()
mock.return_value = str(kubeconfig)
monkeypatch.setattr('os.path.expanduser', mock)
cfg = config.KubeConfig.from_file()
mock.assert_called_with('~/.kube/config')
assert cfg.doc['clusters'][0]['cluster'] == {'server': 'https://localhost:9443'}


class TestConfig(TestCase):

def setUp(self):
Expand Down