Skip to content

Commit

Permalink
Merge branch 'add_kube_batch' into 'master'
Browse files Browse the repository at this point in the history
[Issue volcano-sh#59] add kube-batch framework into volcano

## run command 
> dep ensure -v
>
> bash -x hack/update-gencode.sh

## make images

![image](/uploads/4ee5da2a4d4c1a533e881ddb70224f1a/image.png)

## make all

![image](/uploads/46f1cfe764f952d16e7bfdb035d064bc/image.png)

## make package

![image](/uploads/04a0499e33a2fbab10a3455e3154f47c/image.png)

## bash -x hack/run-e2e-kind.sh

all errors are caused by controller. check it later.

![image](/uploads/035735357867d778467017091b89e0a8/image.png)

Issues info:
Issue ID: 59
Title: add kube-batch framework into volcano
Issue url: CBU-PaaS/Community/volcano/volcano#59


See merge request CBU-PaaS/Community/volcano/volcano!96
  • Loading branch information
mada 00483107 committed Apr 18, 2019
2 parents 2d78703 + ee82fd2 commit eebf1e5
Show file tree
Hide file tree
Showing 161 changed files with 2,990 additions and 3,747 deletions.
69 changes: 11 additions & 58 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ required = [
branch = "master"
name = "github.com/golang/glog"

[[constraint]]
name = "github.com/kubernetes-sigs/kube-batch"
version = "0.4.1"
#[[constraint]]
# name = "volcano.sh/volcano"
# version = "0.4.1"

[[constraint]]
name = "github.com/onsi/ginkgo"
Expand Down
84 changes: 55 additions & 29 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,68 @@ BIN_DIR=_output/bin
CHART_DIR=_output/chart
IMAGE_DIR=_output/image
IMAGE=volcano
TAG=0.1
REL_OSARCH="linux/amd64"
TAG=v0.4.2
VERSION?=${TAG}
CHART_VERSION?=${VERSION}
RELEASE_VER?=${TAG}
IMAGE_PREFIX=kubesigs/vk
LD_FLAGS=" \
-X '${REPO_PATH}/pkg/version.GitSHA=${GitSHA}' \
-X '${REPO_PATH}/pkg/version.Built=${Date}' \
-X '${REPO_PATH}/pkg/version.Version=${RELEASE_VER}'"

.EXPORT_ALL_VARIABLES:

all: controllers scheduler cli admission
all: kube-batch vk-controllers vk-admission vkctl

init:
mkdir -p ${BIN_DIR}
mkdir -p ${CHART_DIR}
mkdir -p ${IMAGE_DIR}

controllers:
go build -o ${BIN_DIR}/vk-controllers ./cmd/controllers
kube-batch: init
go build -ldflags ${LD_FLAGS} -o=${BIN_DIR}/kube-batch ./cmd/kube-batch

scheduler:
go build -o ${BIN_DIR}/vk-scheduler ./cmd/scheduler
vk-controllers: init
go build -ldflags ${LD_FLAGS} -o=${BIN_DIR}/vk-controllers ./cmd/controllers

cli:
go build -o ${BIN_DIR}/vkctl ./cmd/cli
vk-admission: init
go build -ldflags ${LD_FLAGS} -o=${BIN_DIR}/vk-admission ./cmd/admission

admission:
go build -o ${BIN_DIR}/vk-admission ./cmd/admission
vkctl: init
go build -ldflags ${LD_FLAGS} -o=${BIN_DIR}/vkctl ./cmd/cli

release:
CGO_ENABLED=0 go build -o ${BIN_DIR}/rel/vk-controllers ./cmd/controllers
CGO_ENABLED=0 go build -o ${BIN_DIR}/rel/vk-scheduler ./cmd/scheduler
CGO_ENABLED=0 go build -o ${BIN_DIR}/rel/vk-admission ./cmd/admission
init:
mkdir -p ${BIN_DIR}
mkdir -p ${CHART_DIR}
mkdir -p ${IMAGE_DIR}

docker: release
for name in controllers scheduler admission; do\
cp ${BIN_DIR}/rel/vk-$$name ./installer/dockerfile/$$name/; \
docker build --no-cache -t $(IMAGE)-$$name:$(TAG) ./installer/dockerfile/$$name; \
rm installer/dockerfile/$$name/vk-$$name; \
rel_bins:
go get github.com/mitchellh/gox
#Build kube-batch binary
CGO_ENABLED=0 gox -osarch=${REL_OSARCH} -ldflags ${LD_FLAGS} \
-output=${BIN_DIR}/{{.OS}}/{{.Arch}}/kube-batch ./cmd/kube-batch
#Build job controller & job admission
#TODO: Add version support in job controller and admission to make LD_FLAGS work
for name in controllers admission; do\
CGO_ENABLED=0 gox -osarch=${REL_OSARCH} -ldflags ${LD_FLAGS} -output ${BIN_DIR}/{{.OS}}/{{.Arch}}/vk-$$name ./cmd/$$name; \
done

images: rel_bins
#Build kube-batch images
cp ${BIN_DIR}/${REL_OSARCH}/kube-batch ./deployment/images/
docker build ./deployment/images -t kubesigs/kube-batch:${RELEASE_VER}
rm -f ./deployment/images/kube-batch
#Build job controller and admission images
for name in controllers admission; do\
cp ${BIN_DIR}/${REL_OSARCH}/vk-$$name ./deployment/images/$$name/; \
docker build --no-cache -t $(IMAGE_PREFIX)-$$name:$(RELEASE_VER) ./deployment/images/$$name; \
rm deployment/images/$$name/vk-$$name; \
done

docker: images

generate-deepcopy: init
go build -o ${BIN_DIR}/deepcopy-gen ./cmd/deepcopy-gen/
${BIN_DIR}/deepcopy-gen -i ./pkg/apis/scheduling/v1alpha1/ -O zz_generated.deepcopy --go-header-file hack/boilerplate/boilerplate.generatego.txt
${BIN_DIR}/deepcopy-gen -i ./pkg/apis/batch/v1alpha1/ -O zz_generated.deepcopy --go-header-file hack/boilerplate/boilerplate.generatego.txt
${BIN_DIR}/deepcopy-gen -i ./pkg/apis/bus/v1alpha1/ -O zz_generated.deepcopy --go-header-file hack/boilerplate/boilerplate.generatego.txt

generate-code:
./hack/update-gencode.sh

Expand All @@ -61,11 +86,12 @@ verify: generate-code
hack/verify-gencode.sh

chart: init
helm package installer/chart/volcano --version=${CHART_VERSION} --destination=${CHART_DIR}
helm package ./deployment/volcano --version=${VERSION} --destination=${CHART_DIR}

package: docker chart cli
for name in controllers scheduler admission; do \
docker save $(IMAGE)-$$name:$(TAG) > ${IMAGE_DIR}/$(IMAGE)-$$name.$(TAG).tar; \
package: clean images chart vkctl
docker save kubesigs/kube-batch:${RELEASE_VER} > ${IMAGE_DIR}/kube-batch.$(RELEASE_VER).tar;
for name in controllers admission; do \
docker save $(IMAGE_PREFIX)-$$name:$(RELEASE_VER) > ${IMAGE_DIR}/$(IMAGE)-$$name.$(RELEASE_VER).tar; \
done
gzip ${IMAGE_DIR}/*.tar
tar -zcvf _output/Volcano-package-${VERSION}.tgz -C _output/ ./bin/vkctl ./chart ./image
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,31 @@ import (
"github.com/spf13/pflag"
)

const (
defaultSchedulerName = "kube-batch"
defaultSchedulerPeriod = time.Second
defaultQueue = "default"
defaultListenAddress = ":8080"
)

// ServerOption is the main context object for the controller manager.
type ServerOption struct {
Master string
Kubeconfig string
SchedulerName string
SchedulerConf string
SchedulePeriod string
SchedulePeriod time.Duration
EnableLeaderElection bool
LockObjectNamespace string
DefaultQueue string
PrintVersion bool
ListenAddress string
EnablePriorityClass bool
}

// ServerOpts server options
var ServerOpts *ServerOption

// NewServerOption creates a new CMServer with a default config.
func NewServerOption() *ServerOption {
s := ServerOption{}
Expand All @@ -47,26 +58,31 @@ func NewServerOption() *ServerOption {
func (s *ServerOption) AddFlags(fs *pflag.FlagSet) {
fs.StringVar(&s.Master, "master", s.Master, "The address of the Kubernetes API server (overrides any value in kubeconfig)")
fs.StringVar(&s.Kubeconfig, "kubeconfig", s.Kubeconfig, "Path to kubeconfig file with authorization and master location information")
// kube-batch will ignore pods with scheduler names other than specified with the option
fs.StringVar(&s.SchedulerName, "scheduler-name", "kube-batch", "kube-batch will handle pods with the scheduler-name")
// volcano will ignore pods with scheduler names other than specified with the option
fs.StringVar(&s.SchedulerName, "scheduler-name", defaultSchedulerName, "volcano will handle pods whose .spec.SchedulerName is same as scheduler-name")
fs.StringVar(&s.SchedulerConf, "scheduler-conf", "", "The absolute path of scheduler configuration file")
fs.StringVar(&s.SchedulePeriod, "schedule-period", "1s", "The period between each scheduling cycle")
fs.StringVar(&s.DefaultQueue, "default-queue", "default", "The default queue name of the job")
fs.DurationVar(&s.SchedulePeriod, "schedule-period", defaultSchedulerPeriod, "The period between each scheduling cycle")
fs.StringVar(&s.DefaultQueue, "default-queue", defaultQueue, "The default queue name of the job")
fs.BoolVar(&s.EnableLeaderElection, "leader-elect", s.EnableLeaderElection,
"Start a leader election client and gain leadership before "+
"executing the main loop. Enable this when running replicated kube-batch for high availability")
"executing the main loop. Enable this when running replicated volcano for high availability")
fs.BoolVar(&s.PrintVersion, "version", false, "Show version and quit")
fs.StringVar(&s.LockObjectNamespace, "lock-object-namespace", s.LockObjectNamespace, "Define the namespace of the lock object")
fs.StringVar(&s.ListenAddress, "listen-address", ":8080", "The address to listen on for HTTP requests.")
fs.StringVar(&s.LockObjectNamespace, "lock-object-namespace", s.LockObjectNamespace, "Define the namespace of the lock object that is used for leader election")
fs.StringVar(&s.ListenAddress, "listen-address", defaultListenAddress, "The address to listen on for HTTP requests.")
fs.BoolVar(&s.EnablePriorityClass, "priority-class", true,
"Enable PriorityClass to provide the capacity of preemption at pod group level; to disable it, set it false")
}

// CheckOptionOrDie check lock-object-namespace when LeaderElection is enabled
func (s *ServerOption) CheckOptionOrDie() error {
if s.EnableLeaderElection && s.LockObjectNamespace == "" {
return fmt.Errorf("lock-object-namespace must not be nil when LeaderElection is enabled")
}
if _, err := time.ParseDuration(s.SchedulePeriod); err != nil {
return fmt.Errorf("failed to parse --schedule-period: %v", err)
}

return nil
}

// RegisterOptions registers options
func (s *ServerOption) RegisterOptions() {
ServerOpts = s
}
49 changes: 49 additions & 0 deletions cmd/kube-batch/app/options/options_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
Copyright 2019 The Kubernetes 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.
*/

package options

import (
"reflect"
"testing"
"time"

"github.com/spf13/pflag"
)

func TestAddFlags(t *testing.T) {
fs := pflag.NewFlagSet("addflagstest", pflag.ContinueOnError)
s := NewServerOption()
s.AddFlags(fs)

args := []string{
"--schedule-period=5m",
"--priority-class=false",
}
fs.Parse(args)

// This is a snapshot of expected options parsed by args.
expected := &ServerOption{
SchedulerName: defaultSchedulerName,
SchedulePeriod: 5 * time.Minute,
DefaultQueue: defaultQueue,
ListenAddress: defaultListenAddress,
}

if !reflect.DeepEqual(expected, s) {
t.Errorf("Got different run options than expected.\nGot: %+v\nExpected: %+v\n", s, expected)
}
}
Loading

0 comments on commit eebf1e5

Please sign in to comment.