Skip to content

Commit eebf1e5

Browse files
author
mada 00483107
committed
Merge branch 'add_kube_batch' into 'master'
[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
2 parents 2d78703 + ee82fd2 commit eebf1e5

File tree

161 files changed

+2990
-3747
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

161 files changed

+2990
-3747
lines changed

Gopkg.lock

+11-58
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ required = [
3636
branch = "master"
3737
name = "github.com/golang/glog"
3838

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

4343
[[constraint]]
4444
name = "github.com/onsi/ginkgo"

Makefile

+55-29
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,68 @@ BIN_DIR=_output/bin
22
CHART_DIR=_output/chart
33
IMAGE_DIR=_output/image
44
IMAGE=volcano
5-
TAG=0.1
5+
REL_OSARCH="linux/amd64"
6+
TAG=v0.4.2
67
VERSION?=${TAG}
7-
CHART_VERSION?=${VERSION}
8+
RELEASE_VER?=${TAG}
9+
IMAGE_PREFIX=kubesigs/vk
10+
LD_FLAGS=" \
11+
-X '${REPO_PATH}/pkg/version.GitSHA=${GitSHA}' \
12+
-X '${REPO_PATH}/pkg/version.Built=${Date}' \
13+
-X '${REPO_PATH}/pkg/version.Version=${RELEASE_VER}'"
814

915
.EXPORT_ALL_VARIABLES:
1016

11-
all: controllers scheduler cli admission
17+
all: kube-batch vk-controllers vk-admission vkctl
1218

13-
init:
14-
mkdir -p ${BIN_DIR}
15-
mkdir -p ${CHART_DIR}
16-
mkdir -p ${IMAGE_DIR}
17-
18-
controllers:
19-
go build -o ${BIN_DIR}/vk-controllers ./cmd/controllers
19+
kube-batch: init
20+
go build -ldflags ${LD_FLAGS} -o=${BIN_DIR}/kube-batch ./cmd/kube-batch
2021

21-
scheduler:
22-
go build -o ${BIN_DIR}/vk-scheduler ./cmd/scheduler
22+
vk-controllers: init
23+
go build -ldflags ${LD_FLAGS} -o=${BIN_DIR}/vk-controllers ./cmd/controllers
2324

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

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

30-
release:
31-
CGO_ENABLED=0 go build -o ${BIN_DIR}/rel/vk-controllers ./cmd/controllers
32-
CGO_ENABLED=0 go build -o ${BIN_DIR}/rel/vk-scheduler ./cmd/scheduler
33-
CGO_ENABLED=0 go build -o ${BIN_DIR}/rel/vk-admission ./cmd/admission
31+
init:
32+
mkdir -p ${BIN_DIR}
33+
mkdir -p ${CHART_DIR}
34+
mkdir -p ${IMAGE_DIR}
3435

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

47+
images: rel_bins
48+
#Build kube-batch images
49+
cp ${BIN_DIR}/${REL_OSARCH}/kube-batch ./deployment/images/
50+
docker build ./deployment/images -t kubesigs/kube-batch:${RELEASE_VER}
51+
rm -f ./deployment/images/kube-batch
52+
#Build job controller and admission images
53+
for name in controllers admission; do\
54+
cp ${BIN_DIR}/${REL_OSARCH}/vk-$$name ./deployment/images/$$name/; \
55+
docker build --no-cache -t $(IMAGE_PREFIX)-$$name:$(RELEASE_VER) ./deployment/images/$$name; \
56+
rm deployment/images/$$name/vk-$$name; \
57+
done
58+
59+
docker: images
60+
61+
generate-deepcopy: init
62+
go build -o ${BIN_DIR}/deepcopy-gen ./cmd/deepcopy-gen/
63+
${BIN_DIR}/deepcopy-gen -i ./pkg/apis/scheduling/v1alpha1/ -O zz_generated.deepcopy --go-header-file hack/boilerplate/boilerplate.generatego.txt
64+
${BIN_DIR}/deepcopy-gen -i ./pkg/apis/batch/v1alpha1/ -O zz_generated.deepcopy --go-header-file hack/boilerplate/boilerplate.generatego.txt
65+
${BIN_DIR}/deepcopy-gen -i ./pkg/apis/bus/v1alpha1/ -O zz_generated.deepcopy --go-header-file hack/boilerplate/boilerplate.generatego.txt
66+
4267
generate-code:
4368
./hack/update-gencode.sh
4469

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

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

66-
package: docker chart cli
67-
for name in controllers scheduler admission; do \
68-
docker save $(IMAGE)-$$name:$(TAG) > ${IMAGE_DIR}/$(IMAGE)-$$name.$(TAG).tar; \
91+
package: clean images chart vkctl
92+
docker save kubesigs/kube-batch:${RELEASE_VER} > ${IMAGE_DIR}/kube-batch.$(RELEASE_VER).tar;
93+
for name in controllers admission; do \
94+
docker save $(IMAGE_PREFIX)-$$name:$(RELEASE_VER) > ${IMAGE_DIR}/$(IMAGE)-$$name.$(RELEASE_VER).tar; \
6995
done
7096
gzip ${IMAGE_DIR}/*.tar
7197
tar -zcvf _output/Volcano-package-${VERSION}.tgz -C _output/ ./bin/vkctl ./chart ./image
+27-11
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,31 @@ import (
2323
"github.com/spf13/pflag"
2424
)
2525

26+
const (
27+
defaultSchedulerName = "kube-batch"
28+
defaultSchedulerPeriod = time.Second
29+
defaultQueue = "default"
30+
defaultListenAddress = ":8080"
31+
)
32+
2633
// ServerOption is the main context object for the controller manager.
2734
type ServerOption struct {
2835
Master string
2936
Kubeconfig string
3037
SchedulerName string
3138
SchedulerConf string
32-
SchedulePeriod string
39+
SchedulePeriod time.Duration
3340
EnableLeaderElection bool
3441
LockObjectNamespace string
3542
DefaultQueue string
3643
PrintVersion bool
3744
ListenAddress string
45+
EnablePriorityClass bool
3846
}
3947

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

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

7182
return nil
7283
}
84+
85+
// RegisterOptions registers options
86+
func (s *ServerOption) RegisterOptions() {
87+
ServerOpts = s
88+
}
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
Copyright 2019 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package options
18+
19+
import (
20+
"reflect"
21+
"testing"
22+
"time"
23+
24+
"github.com/spf13/pflag"
25+
)
26+
27+
func TestAddFlags(t *testing.T) {
28+
fs := pflag.NewFlagSet("addflagstest", pflag.ContinueOnError)
29+
s := NewServerOption()
30+
s.AddFlags(fs)
31+
32+
args := []string{
33+
"--schedule-period=5m",
34+
"--priority-class=false",
35+
}
36+
fs.Parse(args)
37+
38+
// This is a snapshot of expected options parsed by args.
39+
expected := &ServerOption{
40+
SchedulerName: defaultSchedulerName,
41+
SchedulePeriod: 5 * time.Minute,
42+
DefaultQueue: defaultQueue,
43+
ListenAddress: defaultListenAddress,
44+
}
45+
46+
if !reflect.DeepEqual(expected, s) {
47+
t.Errorf("Got different run options than expected.\nGot: %+v\nExpected: %+v\n", s, expected)
48+
}
49+
}

0 commit comments

Comments
 (0)