diff --git a/Makefile b/Makefile index f998d1fcc5..a3756fc623 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,24 @@ +# Copyright 2019 The Volcano Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + BIN_DIR=_output/bin RELEASE_DIR=_output/release REL_OSARCH=linux/amd64 REPO_PATH=volcano.sh/volcano IMAGE_PREFIX=volcanosh/vc -TAG=latest +# If tag not explicitly set in users default to the git sha. +TAG ?= $(shell git rev-parse --verify HEAD) RELEASE_VER=v0.1 GitSHA=`git rev-parse HEAD` Date=`date "+%Y-%m-%d %H:%M:%S"` diff --git a/README.md b/README.md index b52a2c7455..ecf9458015 100644 --- a/README.md +++ b/README.md @@ -66,19 +66,16 @@ You can watch industry experts talking about Volcano in different International - Kubernetes 1.12+ with CRD support -### Install with YAML files -Install volcano k8s resources +You can try volcano by one the following two ways. -``` -kubectl apply -f https://raw.githubusercontent.com/volcano-sh/volcano/master/installer/volcano-development.yaml -``` -Install `default-queue` for volcano scheduler, note that the crd resources should be ready before this. +### Install with YAML files -``` -kubectl apply -f https://raw.githubusercontent.com/volcano-sh/volcano/master/installer/helm/chart/volcano/templates/default-queue.yaml +Install volcano on a existing Kubernetes cluster. +``` +kubectl apply -f https://raw.githubusercontent.com/volcano-sh/volcano/master/installer/volcano-development.yaml ``` Enjoy! Volcano will create the following resources in `volcano-system` namespace. @@ -109,6 +106,14 @@ job.batch/volcano-admission-init 1/1 48s 96s ``` +### Install from code + +If you have no kubernetes cluster, try one click install from code base: + +```bash +./hack/local-up-volcano.sh +``` + ## Community, discussion, contribution, and support diff --git a/hack/lib/install.sh b/hack/lib/install.sh new file mode 100644 index 0000000000..13418acd84 --- /dev/null +++ b/hack/lib/install.sh @@ -0,0 +1,67 @@ +#!/bin/bash + +# Copyright 2019 The Volcano Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# spin up cluster with kind command +function kind-up-cluster { + check-kind + echo "Running kind: [kind create cluster ${CLUSTER_CONTEXT} ${KIND_OPT}]" + kind create cluster ${CLUSTER_CONTEXT} ${KIND_OPT} + + echo "Loading docker images into kind cluster" + kind load docker-image ${IMAGE_PREFIX}-controllers:${TAG} ${CLUSTER_CONTEXT} + kind load docker-image ${IMAGE_PREFIX}-scheduler:${TAG} ${CLUSTER_CONTEXT} + kind load docker-image ${IMAGE_PREFIX}-admission:${TAG} ${CLUSTER_CONTEXT} +} + + +# check if kubectl installed +function check-prerequisites { + echo "checking prerequisites" + which kubectl >/dev/null 2>&1 + if [[ $? -ne 0 ]]; then + echo "kubectl not installed, exiting." + exit 1 + else + echo -n "found kubectl, " && kubectl version --short --client + fi +} + +# check if kind installed +function check-kind { + echo "checking kind" + which kind >/dev/null 2>&1 + if [[ $? -ne 0 ]]; then + echo "installing kind ." + GO111MODULE="on" go get sigs.k8s.io/kind@v0.4.0 + else + echo -n "found kind, version: " && kind version + fi +} + +# install helm if not installed +function install-helm { + echo "checking helm" + which helm >/dev/null 2>&1 + if [[ $? -ne 0 ]]; then + echo "Install helm via script" + HELM_TEMP_DIR=`mktemp -d` + curl https://raw.githubusercontent.com/helm/helm/master/scripts/get > ${HELM_TEMP_DIR}/get_helm.sh + #TODO: There are some issue with helm's latest version, remove '--version' when it get fixed. + chmod 700 ${HELM_TEMP_DIR}/get_helm.sh && ${HELM_TEMP_DIR}/get_helm.sh --version v2.13.0 + else + echo -n "found helm, version: " && helm version + fi +} diff --git a/hack/local-up-volcano.sh b/hack/local-up-volcano.sh new file mode 100755 index 0000000000..dd7a9f85af --- /dev/null +++ b/hack/local-up-volcano.sh @@ -0,0 +1,102 @@ +#!/bin/bash + +# Copyright 2019 The Volcano Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +VK_ROOT=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/.. +CLUSTER_NAME=${CLUSTER_NAME:-volcano} +CLUSTER_CONTEXT="--name ${CLUSTER_NAME}" +KIND_OPT=${KIND_OPT:-} +INSTALL_MODE=${INSTALL_MODE:-"kind"} +IMAGE_PREFIX=volcanosh/vc +TAG=${TAG:-`git rev-parse --verify HEAD`} +RELEASE_DIR=_output/release +RELEASE_FOLDER=${VK_ROOT}/${RELEASE_DIR} +YAML_FILENAME=volcano-${TAG}.yaml + + +# prepare deploy yaml and docker images +function prepare { + echo "Preparing..." + install-helm + echo "Generating valcano deploy yaml" + make generate-yaml + + echo "Building docker images" + make images +} + + +function install-volcano { + # TODO: add a graceful way waiting for all crd ready + kubectl apply -f ${RELEASE_FOLDER}/${YAML_FILENAME} +} + +function uninstall-volcano { + kubectl delete -f ${VK_ROOT}/installer/helm/chart/volcano/templates/default-queue.yaml + kubectl delete -f ${RELEASE_FOLDER}/${YAML_FILENAME} +} + +# clean up +function cleanup { + uninstall-volcano + + if [ "${INSTALL_MODE}" == "kind" ]; then + echo "Running kind: [kind delete cluster ${CLUSTER_CONTEXT}]" + kind delete cluster ${CLUSTER_CONTEXT} + fi +} + +echo $* | grep -E -q "\-\-help|\-h" +if [[ $? -eq 0 ]]; then + echo "Customize the kind-cluster name: + + export CLUSTER_NAME= # default: volcano + +Customize kind options other than --name: + + export KIND_OPT= + +Using existing kubernetes cluster rather than starting a kind custer: + + export INSTALL_MODE=existing + +Cleanup all installation: + + ./hack/local-up-volcano.sh -q +" + exit 0 +fi + + +echo $* | grep -E -q "\-\-quit|\-q" +if [[ $? -eq 0 ]]; then + cleanup + exit 0 +fi + +source "${VK_ROOT}/hack/lib/install.sh" + +check-prerequisites + +prepare + +if [ "${INSTALL_MODE}" == "kind" ]; then + kind-up-cluster + export KUBECONFIG="$(kind get kubeconfig-path ${CLUSTER_CONTEXT})" +fi + +install-volcano + + diff --git a/hack/run-e2e-kind.sh b/hack/run-e2e-kind.sh index 8073e69d4a..b6b972011f 100755 --- a/hack/run-e2e-kind.sh +++ b/hack/run-e2e-kind.sh @@ -15,29 +15,10 @@ export CLUSTER_CONTEXT="--name ${CLUSTER_NAME}" export KIND_OPT=${KIND_OPT:=" --config ${VK_ROOT}/hack/e2e-kind-config.yaml"} -# check if kind installed -function check-prerequisites { - echo "checking prerequisites" - which kind >/dev/null 2>&1 - if [[ $? -ne 0 ]]; then - echo "kind not installed, exiting." - exit 1 - else - echo -n "found kind, version: " && kind version - fi - - which kubectl >/dev/null 2>&1 - if [[ $? -ne 0 ]]; then - echo "kubectl not installed, exiting." - exit 1 - else - echo -n "found kubectl, " && kubectl version --short --client - fi -} - # spin up cluster with kind command function kind-up-cluster { check-prerequisites + check-kind echo "Running kind: [kind create cluster ${CLUSTER_CONTEXT} ${KIND_OPT}]" kind create cluster ${CLUSTER_CONTEXT} ${KIND_OPT} } @@ -47,20 +28,13 @@ function install-volcano { kubectl create serviceaccount --namespace kube-system tiller kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller - echo "Install helm via script and waiting tiller becomes ready" - HELM_TEMP_DIR=`mktemp -d` - curl https://raw.githubusercontent.com/helm/helm/master/scripts/get > ${HELM_TEMP_DIR}/get_helm.sh - #TODO: There are some issue with helm's latest version, remove '--version' when it get fixed. - chmod 700 ${HELM_TEMP_DIR}/get_helm.sh && ${HELM_TEMP_DIR}/get_helm.sh --version v2.13.0 + install-helm helm init --service-account tiller --kubeconfig ${KUBECONFIG} --wait echo "Pulling required docker images" docker pull ${MPI_EXAMPLE_IMAGE} echo "Loading docker images into kind cluster" - kind load docker-image ${IMAGE_PREFIX}-controllers:${TAG} ${CLUSTER_CONTEXT} - kind load docker-image ${IMAGE_PREFIX}-scheduler:${TAG} ${CLUSTER_CONTEXT} - kind load docker-image ${IMAGE_PREFIX}-admission:${TAG} ${CLUSTER_CONTEXT} kind load docker-image ${MPI_EXAMPLE_IMAGE} ${CLUSTER_CONTEXT} echo "Install volcano chart" @@ -115,7 +89,9 @@ if [[ $CLEANUP_CLUSTER -eq 1 ]]; then trap cleanup EXIT fi +source "${VK_ROOT}/hack/lib/install.sh" +check-prerequisites kind-up-cluster export KUBECONFIG="$(kind get kubeconfig-path ${CLUSTER_CONTEXT})" diff --git a/pkg/scheduler/cache/cache.go b/pkg/scheduler/cache/cache.go index 12a4d0fd42..20cf9c9e10 100644 --- a/pkg/scheduler/cache/cache.go +++ b/pkg/scheduler/cache/cache.go @@ -23,8 +23,9 @@ import ( "github.com/golang/glog" - v1 "k8s.io/api/core/v1" + "k8s.io/api/core/v1" "k8s.io/api/scheduling/v1beta1" + apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" utilruntime "k8s.io/apimachinery/pkg/util/runtime" @@ -45,6 +46,7 @@ import ( "volcano.sh/volcano/cmd/scheduler/app/options" "volcano.sh/volcano/pkg/apis/scheduling/v1alpha1" + "volcano.sh/volcano/pkg/apis/scheduling/v1alpha2" kbver "volcano.sh/volcano/pkg/client/clientset/versioned" "volcano.sh/volcano/pkg/client/clientset/versioned/scheme" kbschema "volcano.sh/volcano/pkg/client/clientset/versioned/scheme" @@ -258,6 +260,19 @@ func newSchedulerCache(config *rest.Config, schedulerName string, defaultQueue s panic(fmt.Sprintf("failed init eventClient, with err: %v", err)) } + // create default queue + defaultQue := v1alpha2.Queue{ + ObjectMeta: metav1.ObjectMeta{ + Name: defaultQueue, + }, + Spec: v1alpha2.QueueSpec{ + Weight: 1, + }, + } + if _, err := kbClient.SchedulingV1alpha2().Queues().Create(&defaultQue); err != nil && !apierrors.IsAlreadyExists(err) { + panic(fmt.Sprintf("failed init default queue, with err: %v", err)) + } + sc := &SchedulerCache{ Jobs: make(map[kbapi.JobID]*kbapi.JobInfo), Nodes: make(map[string]*kbapi.NodeInfo),