diff --git a/deployment/clusterObjectModel/mainParser/layout.py b/deployment/clusterObjectModel/mainParser/layout.py index d6c399f2d4..245ba4b661 100644 --- a/deployment/clusterObjectModel/mainParser/layout.py +++ b/deployment/clusterObjectModel/mainParser/layout.py @@ -32,6 +32,13 @@ def __init__(self, layout_configuration): def validation_pre(self): # TODO + + # validate unique hostname + host_list = [host["hostname"] for host in self.layout_configuration["machine-list"]] + duplicate_host_list = set([host for host in host_list if host_list.count(host) > 1]) + if duplicate_host_list: + return False, "duplicate hostname [{}] in kubernetes-configuration".format(", ".join(duplicate_host_list)) + return True, None diff --git a/deployment/clusterObjectModel/test/data/configuration-duplicate-hostname/kubernetes-configuration.yaml b/deployment/clusterObjectModel/test/data/configuration-duplicate-hostname/kubernetes-configuration.yaml new file mode 100644 index 0000000000..97a0ca4470 --- /dev/null +++ b/deployment/clusterObjectModel/test/data/configuration-duplicate-hostname/kubernetes-configuration.yaml @@ -0,0 +1,49 @@ +# Copyright (c) Microsoft Corporation +# All rights reserved. +# +# MIT License +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +# documentation files (the "Software"), to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and +# to permit persons to whom the Software is furnished to do so, subject to the following conditions: +# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +# BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +kubernetes: + # Find the namesever in /etc/resolv.conf + cluster-dns: 127.0.0.1 + # To support k8s ha, you should set an lb address here. + # If deploy k8s with single master node, please set master IP address here + load-balance-ip: 10.0.0.1 + + # specify an IP range not in the same network segment with the host machine. + service-cluster-ip-range: 169.254.0.0/16 + # According to the etcdversion, you should fill a corresponding backend name. + # If you are not familiar with etcd, please don't change it. + storage-backend: etcd3 + # The docker registry used in the k8s deployment. If you can access to gcr, we suggest to use gcr. + docker-registry: gcr.io/google_containers + # http://gcr.io/google_containers/hyperkube. Or the tag in your registry. + hyperkube-version: v1.9.9 + # http://gcr.io/google_containers/etcd. Or the tag in your registry. + # If you are not familiar with etcd, please don't change it. + etcd-version: 3.2.17 + # http://gcr.io/google_containers/kube-apiserver. Or the tag in your registry. + apiserver-version: v1.9.9 + # http://gcr.io/google_containers/kube-scheduler. Or the tag in your registry. + kube-scheduler-version: v1.9.9 + # http://gcr.io/google_containers/kube-controller-manager + kube-controller-manager-version: v1.9.9 + # http://gcr.io/google_containers/kubernetes-dashboard-amd64 + dashboard-version: v1.8.3 + # The path to storage etcd data. + etcd-data-path: "/var/etcd" + + + diff --git a/deployment/clusterObjectModel/test/data/configuration-duplicate-hostname/layout.yaml b/deployment/clusterObjectModel/test/data/configuration-duplicate-hostname/layout.yaml new file mode 100644 index 0000000000..7b44e47aec --- /dev/null +++ b/deployment/clusterObjectModel/test/data/configuration-duplicate-hostname/layout.yaml @@ -0,0 +1,122 @@ +# Copyright (c) Microsoft Corporation +# All rights reserved. +# +# MIT License +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +# documentation files (the "Software"), to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and +# to permit persons to whom the Software is furnished to do so, subject to the following conditions: +# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +# BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +kubernetes: + api-servers-url: http://10.0.0.1:8080 + dashboard-host: 10.0.0.1 + +# If corresponding values aren't be set in the machine list, the default value will be filled in. +default-machine-properties: + # Account with root permission + username: username + password: password + sshport: 22 + + +machine-sku: + + NC24R: + mem: 224 + gpu: + # type: gpu{type} + type: teslak80 + count: 4 + cpu: + vcore: 24 + #dataFolder: "/mnt" + #Note: Up to now, the only supported os version is Ubuntu16.04. Please do not change it here. + os: ubuntu16.04 + + D8SV3: + mem: 32 + cpu: + vcore: 8 + #dataFolder: "/mnt" + #Note: Up to now, the only supported os version is Ubuntu16.04. Pls don't change it here. + os: ubuntu16.04 + + + +machine-list: + + - hostname: hostname1 (echo `hostname`) + hostip: 10.0.0.1 + machine-type: D8SV3 + etcdid: etcdid1 + #sshport: PORT (Optional) + #username: username (Optional) + #password: password (Optional) + k8s-role: master + dashboard: "true" + zkid: "1" + pai-master: "true" + + + - hostname: hostname2 + hostip: 10.0.0.2 + machine-type: D8SV3 + etcdid: etcdid2 + #sshport: PORT (Optional) + #username: username (Optional) + #password: password (Optional) + k8s-role: master + + + - hostname: hostname3 + hostip: 10.0.0.3 + machine-type: D8SV3 + etcdid: etcdid3 + #sshport: PORT (Optional) + #username: username (Optional) + #password: password (Optional) + k8s-role: master + + + - hostname: hostname2 + hostip: 10.0.0.4 + machine-type: NC24R + #sshport: PORT (Optional) + #username: username (Optional) + #password: password (Optional) + k8s-role: worker + pai-worker: "true" + + + - hostname: hostname5 + hostip: 10.0.0.5 + machine-type: NC24R + #sshport: PORT (Optional) + #username: username (Optional) + #password: password (Optional) + k8s-role: worker + pai-worker: "true" + + + - hostname: hostname3 + hostip: 10.0.0.6 + machine-type: NC24R + #sshport: PORT (Optional) + #username: username (Optional) + #password: password (Optional) + k8s-role: worker + pai-worker: "true" + + + + + + diff --git a/deployment/clusterObjectModel/test/data/configuration-duplicate-hostname/services-configuration.yaml b/deployment/clusterObjectModel/test/data/configuration-duplicate-hostname/services-configuration.yaml new file mode 100644 index 0000000000..1f22976baf --- /dev/null +++ b/deployment/clusterObjectModel/test/data/configuration-duplicate-hostname/services-configuration.yaml @@ -0,0 +1,22 @@ +# Copyright (c) Microsoft Corporation +# All rights reserved. +# +# MIT License +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated +# documentation files (the "Software"), to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and +# to permit persons to whom the Software is furnished to do so, subject to the following conditions: +# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +# BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + +rest-server: + default-pai-admin-username: your_default_pai_admin_username + default-pai-admin-password: your_default_pai_admin_password + diff --git a/deployment/clusterObjectModel/test/data/configuration-none-overwrite/layout.yaml b/deployment/clusterObjectModel/test/data/configuration-none-overwrite/layout.yaml index 6c946fce5c..bb3fd8e95f 100644 --- a/deployment/clusterObjectModel/test/data/configuration-none-overwrite/layout.yaml +++ b/deployment/clusterObjectModel/test/data/configuration-none-overwrite/layout.yaml @@ -53,7 +53,7 @@ machine-sku: machine-list: - - hostname: hostname (echo `hostname`) + - hostname: hostname1 (echo `hostname`) hostip: 10.0.0.1 machine-type: D8SV3 etcdid: etcdid1 @@ -66,7 +66,7 @@ machine-list: pai-master: "true" - - hostname: hostname + - hostname: hostname2 hostip: 10.0.0.2 machine-type: D8SV3 etcdid: etcdid2 @@ -76,7 +76,7 @@ machine-list: k8s-role: master - - hostname: hostname + - hostname: hostname3 hostip: 10.0.0.3 machine-type: D8SV3 etcdid: etcdid3 @@ -86,7 +86,7 @@ machine-list: k8s-role: master - - hostname: hostname + - hostname: hostname4 hostip: 10.0.0.4 machine-type: NC24R #sshport: PORT (Optional) @@ -96,7 +96,7 @@ machine-list: pai-worker: "true" - - hostname: hostname + - hostname: hostname5 hostip: 10.0.0.5 machine-type: NC24R #sshport: PORT (Optional) @@ -106,7 +106,7 @@ machine-list: pai-worker: "true" - - hostname: hostname + - hostname: hostname6 hostip: 10.0.0.6 machine-type: NC24R #sshport: PORT (Optional) diff --git a/deployment/clusterObjectModel/test/data/configuration-overwrite/layout.yaml b/deployment/clusterObjectModel/test/data/configuration-overwrite/layout.yaml index 6c946fce5c..bb3fd8e95f 100644 --- a/deployment/clusterObjectModel/test/data/configuration-overwrite/layout.yaml +++ b/deployment/clusterObjectModel/test/data/configuration-overwrite/layout.yaml @@ -53,7 +53,7 @@ machine-sku: machine-list: - - hostname: hostname (echo `hostname`) + - hostname: hostname1 (echo `hostname`) hostip: 10.0.0.1 machine-type: D8SV3 etcdid: etcdid1 @@ -66,7 +66,7 @@ machine-list: pai-master: "true" - - hostname: hostname + - hostname: hostname2 hostip: 10.0.0.2 machine-type: D8SV3 etcdid: etcdid2 @@ -76,7 +76,7 @@ machine-list: k8s-role: master - - hostname: hostname + - hostname: hostname3 hostip: 10.0.0.3 machine-type: D8SV3 etcdid: etcdid3 @@ -86,7 +86,7 @@ machine-list: k8s-role: master - - hostname: hostname + - hostname: hostname4 hostip: 10.0.0.4 machine-type: NC24R #sshport: PORT (Optional) @@ -96,7 +96,7 @@ machine-list: pai-worker: "true" - - hostname: hostname + - hostname: hostname5 hostip: 10.0.0.5 machine-type: NC24R #sshport: PORT (Optional) @@ -106,7 +106,7 @@ machine-list: pai-worker: "true" - - hostname: hostname + - hostname: hostname6 hostip: 10.0.0.6 machine-type: NC24R #sshport: PORT (Optional) diff --git a/deployment/clusterObjectModel/test/test_cluster_object_model.py b/deployment/clusterObjectModel/test/test_cluster_object_model.py index b390cd4df4..a443b20994 100644 --- a/deployment/clusterObjectModel/test/test_cluster_object_model.py +++ b/deployment/clusterObjectModel/test/test_cluster_object_model.py @@ -68,12 +68,10 @@ def test_cluster_object_model_cfg_overwrite(self): com_handler.kubernetes_config() + def test_cluster_object_model_cfg_duplicate_hostname(self): - - - - - - - - + duplicate_hostname_path = "data/configuration-duplicate-hostname/" + com_handler = cluster_object_model.cluster_object_model(duplicate_hostname_path) + with self.assertRaises(SystemExit) as cm: + com_handler.kubernetes_config() + self.assertEqual(cm.exception.code, 1)