diff --git a/deployment/clusterObjectModel/test/data/configuration-template-generate/services-configuration.yaml b/deployment/clusterObjectModel/test/data/configuration-template-generate/services-configuration.yaml index 1923505712..a6a81a47df 100644 --- a/deployment/clusterObjectModel/test/data/configuration-template-generate/services-configuration.yaml +++ b/deployment/clusterObjectModel/test/data/configuration-template-generate/services-configuration.yaml @@ -100,3 +100,8 @@ pylon: # port of pylon port: 80 +hivedscheduler: + config: | + physicalCluster: none + virtualClusters: none + diff --git a/src/hivedscheduler/config/hivedscheduler.py b/src/hivedscheduler/config/hivedscheduler.py new file mode 100644 index 0000000000..6a63071bb7 --- /dev/null +++ b/src/hivedscheduler/config/hivedscheduler.py @@ -0,0 +1,36 @@ +# 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. + + +class Hivedscheduler: + def __init__(self, cluster_conf, service_conf, default_service_conf): + self.cluster_conf = cluster_conf + self.service_conf = service_conf + self.default_service_conf = default_service_conf + + def validation_pre(self): + if 'config' not in self.service_conf: + self.service_conf['config'] = '' + # return False, 'hived scheduler config is missing' + return True, None + + def run(self): + self.service_conf['config'] = self.service_conf['config'].replace('\n', '\n ') + return self.service_conf + + def validation_post(self, conf): + return True, None diff --git a/src/hivedscheduler/deploy/delete.sh b/src/hivedscheduler/deploy/delete.sh new file mode 100644 index 0000000000..7f2397ac01 --- /dev/null +++ b/src/hivedscheduler/deploy/delete.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +# 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. + +pushd $(dirname "$0") > /dev/null + +/bin/bash stop.sh || exit $? + +popd > /dev/null diff --git a/src/hivedscheduler/deploy/hivedscheduler-config.yaml.template b/src/hivedscheduler/deploy/hivedscheduler-config.yaml.template new file mode 100644 index 0000000000..77f7e80056 --- /dev/null +++ b/src/hivedscheduler/deploy/hivedscheduler-config.yaml.template @@ -0,0 +1,62 @@ +# 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. + +apiVersion: v1 +kind: ConfigMap +metadata: + name: hivedscheduler-config + namespace: default +data: + config.yaml: | + apiVersion: kubescheduler.config.k8s.io/v1alpha1 + kind: KubeSchedulerConfiguration + schedulerName: hivedscheduler + algorithmSource: + policy: + configMap: + name: hivedscheduler-config + namespace: default + leaderElection: + leaderElect: true + lockObjectName: hivedscheduler + lockObjectNamespace: default + policy.cfg : | + { + "kind": "Policy", + "apiVersion": "v1", + "extenders": [ + { + "urlPrefix": "http://localhost:9096/v1/extender", + "filterVerb": "filter", + "preemptVerb": "preempt", + "bindVerb": "bind", + "enableHttps": false, + "httpTimeout": 5000000000, + "nodeCacheCapable": true, + "ignorable": false, + "managedResources": [ + { + "name": "hivedscheduler.microsoft.com/pod-scheduling-enable", + "ignoredByScheduler": true + } + ] + } + ] + } + hivedscheduler.yaml: | + kubeApiServerAddress: "{{ cluster_cfg['layout']['kubernetes']['api-servers-url'] }}" + {{ cluster_cfg['hivedscheduler']['config'] }} diff --git a/src/hivedscheduler/deploy/hivedscheduler.yaml.template b/src/hivedscheduler/deploy/hivedscheduler.yaml.template new file mode 100644 index 0000000000..f506ad3a54 --- /dev/null +++ b/src/hivedscheduler/deploy/hivedscheduler.yaml.template @@ -0,0 +1,61 @@ +# 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. + +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: hivedscheduler-sts + namespace: default +spec: + serviceName: hivedscheduler + selector: + matchLabels: + app: hivedscheduler + replicas: 1 + template: + metadata: + labels: + app: hivedscheduler + spec: + serviceAccountName: hivedscheduler-account + containers: + - name: defaultscheduler + image: gcr.io/google_containers/kube-scheduler:v1.14.2 + command: [ + "/usr/local/bin/kube-scheduler", + "--master={{ cluster_cfg['layout']['kubernetes']['api-servers-url'] }}", + "--config=/hivedscheduler-config/config.yaml", + "-v=4"] + volumeMounts: + - name: hivedscheduler-config + mountPath: /hivedscheduler-config + - name: hivedscheduler + image: hivedscheduler/hivedscheduler:v0.1.0 + command: [ + "bash", "-c", + "cp /hivedscheduler-config/hivedscheduler.yaml . && + ./start.sh"] + env: + - name: KUBE_APISERVER_ADDRESS + value: "{{ cluster_cfg['layout']['kubernetes']['api-servers-url'] }}" + volumeMounts: + - name: hivedscheduler-config + mountPath: /hivedscheduler-config + volumes: + - name: hivedscheduler-config + configMap: + name: hivedscheduler-config diff --git a/src/hivedscheduler/deploy/rbac.yaml b/src/hivedscheduler/deploy/rbac.yaml new file mode 100644 index 0000000000..e85918df7f --- /dev/null +++ b/src/hivedscheduler/deploy/rbac.yaml @@ -0,0 +1,36 @@ +# 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. + +apiVersion: v1 +kind: ServiceAccount +metadata: + name: hivedscheduler-account + namespace: default +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: hivedscheduler-role-binding + namespace: default +subjects: + - kind: ServiceAccount + name: hivedscheduler-account + namespace: default +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: cluster-admin diff --git a/src/hivedscheduler/deploy/refresh.sh b/src/hivedscheduler/deploy/refresh.sh new file mode 100644 index 0000000000..86c1891ac0 --- /dev/null +++ b/src/hivedscheduler/deploy/refresh.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +# 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. + + +pushd $(dirname "$0") > /dev/null + +popd > /dev/null diff --git a/src/hivedscheduler/deploy/service.yaml b/src/hivedscheduler/deploy/service.yaml new file mode 100644 index 0000000000..ee85c42a05 --- /dev/null +++ b/src/hivedscheduler/deploy/service.yaml @@ -0,0 +1,37 @@ +# 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. + +cluster-type: + - k8s + +prerequisite: + - cluster-configuration + - k8s-frameworkcontroller + - drivers + +template-list: + - hivedscheduler.yaml + - hivedscheduler-config.yaml + +start-script: start.sh +stop-script: stop.sh +delete-script: delete.sh +refresh-script: refresh.sh +upgraded-script: upgraded.sh + +deploy-rules: + - in: pai-master \ No newline at end of file diff --git a/src/hivedscheduler/deploy/start.sh b/src/hivedscheduler/deploy/start.sh new file mode 100644 index 0000000000..eb1b0afea5 --- /dev/null +++ b/src/hivedscheduler/deploy/start.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +# 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. + +pushd $(dirname "$0") > /dev/null + +kubectl apply --overwrite=true -f https://raw.githubusercontent.com/NVIDIA/k8s-device-plugin/1.0.0-beta/nvidia-device-plugin.yml || exit $? + +kubectl apply --overwrite=true -f configmap.yaml || exit $? +kubectl apply --overwrite=true -f rbac.yaml || exit $? +kubectl apply --overwrite=true -f hivedscheduler.yaml || exit $? + +sleep 10 +# Wait until the service is ready. +PYTHONPATH="../../../deployment" python -m k8sPaiLibrary.monitorTool.check_pod_ready_status -w -k app -v hivedscheduler || exit $? + +popd > /dev/null \ No newline at end of file diff --git a/src/hivedscheduler/deploy/stop.sh b/src/hivedscheduler/deploy/stop.sh new file mode 100644 index 0000000000..7d3f2d4753 --- /dev/null +++ b/src/hivedscheduler/deploy/stop.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +# 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. + +pushd $(dirname "$0") > /dev/null + +APISERVER=$(kubectl config view | grep server | cut -f 2- -d ":" | tr -d " ") + +until ! kubectl get sts | grep -q "hivedscheduler-sts"; do + echo 'Trying to stop hivedscheduler ...' + curl -X DELETE $APISERVER/apis/apps/v1/namespaces/default/statefulsets/hivedscheduler-sts \ + -H "Content-Type: application/json" \ + -d '{"kind":"DeleteOptions","apiVersion":"v1","propagationPolicy":"Foreground"}' > /dev/null 2>&1 + sleep 5 +done + +if kubectl get configmap | grep -q "hivedscheduler-config"; then + kubectl delete configmap hivedscheduler-config || exit $? +fi + +if kubectl get serviceaccount | grep -q "hivedscheduler-account"; then + kubectl delete serviceaccount hivedscheduler-account || exit $? +fi + +if kubectl get clusterrolebinding | grep -q "hivedscheduler-role-binding"; then + kubectl delete clusterrolebinding hivedscheduler-role-binding || exit $? +fi + +until ! kubectl get ds --namespace=kube-system | grep -q "nvidia-device-plugin-daemonset"; do + echo 'Trying to stop nvidia device plugin ...' + curl -X DELETE $APISERVER/apis/apps/v1/namespaces/kube-system/daemonsets/nvidia-device-plugin-daemonset \ + -H "Content-Type: application/json" \ + -d '{"kind":"DeleteOptions","apiVersion":"v1","propagationPolicy":"Foreground"}' > /dev/null 2>&1 + sleep 5 +done + +popd > /dev/null diff --git a/src/k8s-frameworkcontroller/deploy/service.yaml b/src/k8s-frameworkcontroller/deploy/service.yaml index 420c47978e..9f5fabac19 100644 --- a/src/k8s-frameworkcontroller/deploy/service.yaml +++ b/src/k8s-frameworkcontroller/deploy/service.yaml @@ -15,6 +15,8 @@ # 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. +cluster-type: + - k8s prerequisite: - cluster-configuration