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

Commit

Permalink
#9 add PodDisruptionBudget
Browse files Browse the repository at this point in the history
  • Loading branch information
hjacobs committed Mar 3, 2019
1 parent c4962c9 commit 87061f3
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
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

0 comments on commit 87061f3

Please sign in to comment.