diff --git a/README.md b/README.md index c85f68c42..537131157 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Build Status](https://travis-ci.org/kubernetes-client/python-base.svg?branch=master)](https://travis-ci.org/kubernetes-client/python-base) -This is the utility part of the [python client](https://github.com/kubernetes-incubator/client-python). It has been added to the main +This is the utility part of the [python client](https://github.com/kubernetes-client/python). It has been added to the main repo using git submodules. This structure allow other developers to create their own kubernetes client and still use standard kubernetes python utilities. For more information refer to [clients-library-structure](https://github.com/kubernetes-client/community/blob/master/design-docs/clients-library-structure.md). @@ -10,4 +10,4 @@ For more information refer to [clients-library-structure](https://github.com/kub # Development Any changes to utilites in this repo should be send as a PR to this repo. After the PR is merged, developers should create another PR in the main repo to update -the submodule. See [this document](https://github.com/kubernetes-incubator/client-python/blob/master/devel/submodules.md) for more guidelines. +the submodule. See [this document](https://github.com/kubernetes-client/python/blob/master/devel/submodules.md) for more guidelines. diff --git a/config/kube_config.py b/config/kube_config.py index c09900980..58c96255d 100644 --- a/config/kube_config.py +++ b/config/kube_config.py @@ -399,6 +399,7 @@ class ConfigNode(object): raise ConfigException( 'Invalid kube-config file. Expected %s to be a list' % self.name) + result = None for v in self.value: if 'name' not in v: raise ConfigException( @@ -406,7 +407,15 @@ class ConfigNode(object): 'Expected all values in %s list to have \'name\' key' % self.name) if v['name'] == name: - return ConfigNode('%s[name=%s]' % (self.name, name), v) + if result is None: + result = v + else: + raise ConfigException( + 'Invalid kube-config file. ' + 'Expected only one object with name %s in %s list' + % (name, self.name)) + if result is not None: + return ConfigNode('%s[name=%s]' % (self.name, name), result) if safe: return None raise ConfigException( diff --git a/config/kube_config_test.py b/config/kube_config_test.py index c98dff02d..4ffca9fa6 100644 --- a/config/kube_config_test.py +++ b/config/kube_config_test.py @@ -193,7 +193,11 @@ class TestConfigNode(BaseTestCase): "with_names": [{"name": "test_name", "value": "test_value"}, {"name": "test_name2", "value": {"key1", "test"}}, - {"name": "test_name3", "value": [1, 2, 3]}]} + {"name": "test_name3", "value": [1, 2, 3]}], + "with_names_dup": [{"name": "test_name", "value": "test_value"}, + {"name": "test_name", + "value": {"key1", "test"}}, + {"name": "test_name3", "value": [1, 2, 3]}]} def setUp(self): super(TestConfigNode, self).setUp() @@ -201,7 +205,7 @@ class TestConfigNode(BaseTestCase): def test_normal_map_array_operations(self): self.assertEqual("test", self.node['key1']) - self.assertEqual(4, len(self.node)) + self.assertEqual(5, len(self.node)) self.assertEqual("test_obj/key2", self.node['key2'].name) self.assertEqual(["a", "b", "c"], self.node['key2'].value) @@ -248,6 +252,11 @@ class TestConfigNode(BaseTestCase): lambda: self.node['with_names'].get_with_name('no-name'), "Expected object with name no-name in test_obj/with_names list") + def test_get_with_name_on_duplicate_name(self): + self.expect_exception( + lambda: self.node['with_names_dup'].get_with_name('test_name'), + "Expected only one object with name test_name in test_obj/with_names_dup list") + class FakeConfig: diff --git a/run_tox.sh b/run_tox.sh index 94e515803..557337855 100755 --- a/run_tox.sh +++ b/run_tox.sh @@ -34,8 +34,8 @@ SCRIPT_ROOT=`pwd` popd > /dev/null cd "${TMP_DIR}" -git clone https://github.com/kubernetes-incubator/client-python.git -cd client-python +git clone https://github.com/kubernetes-client/python.git +cd python git config user.email "kubernetes-client@k8s.com" git config user.name "kubenetes client" git rm -rf kubernetes/base