Skip to content

Commit 5ca4c6b

Browse files
authored
Merge pull request #1 from volcano-sh/master
sync in 10th Dec. 2019
2 parents 0564a5f + cbe3c00 commit 5ca4c6b

127 files changed

Lines changed: 2886 additions & 2743 deletions

File tree

Some content is hidden

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

Gopkg.lock

Lines changed: 2 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ required = [
3232
"k8s.io/code-generator/cmd/defaulter-gen",
3333
]
3434

35-
[[constraint]]
36-
branch = "master"
37-
name = "github.com/golang/glog"
38-
3935
[[constraint]]
4036
name = "github.com/onsi/ginkgo"
4137
version = "1.7.0"

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ generate-code:
6868
./hack/update-gencode.sh
6969

7070
unit-test:
71+
go clean -testcache
7172
go list ./... | grep -v e2e | xargs go test -v -race
7273

7374
e2e-test-kind:
@@ -84,7 +85,7 @@ clean:
8485
rm -rf _output/
8586
rm -f *.log
8687

87-
verify: generate-code
88+
verify:
8889
hack/verify-gofmt.sh
8990
hack/verify-golint.sh
9091
hack/verify-gencode.sh

cmd/admission/app/options/options.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ limitations under the License.
1717
package options
1818

1919
import (
20-
"flag"
2120
"fmt"
2221

23-
"github.com/golang/glog"
22+
"github.com/spf13/pflag"
2423

2524
"k8s.io/api/admissionregistration/v1beta1"
2625
apierrors "k8s.io/apimachinery/pkg/api/errors"
2726
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2827
"k8s.io/client-go/kubernetes"
2928
admissionregistrationv1beta1 "k8s.io/client-go/kubernetes/typed/admissionregistration/v1beta1"
29+
"k8s.io/klog"
3030
)
3131

3232
const (
@@ -58,27 +58,27 @@ func NewConfig() *Config {
5858
}
5959

6060
// AddFlags add flags
61-
func (c *Config) AddFlags() {
62-
flag.StringVar(&c.Master, "master", c.Master, "The address of the Kubernetes API server (overrides any value in kubeconfig)")
63-
flag.StringVar(&c.Kubeconfig, "kubeconfig", c.Kubeconfig, "Path to kubeconfig file with authorization and master location information.")
64-
flag.StringVar(&c.CertFile, "tls-cert-file", c.CertFile, ""+
61+
func (c *Config) AddFlags(fs *pflag.FlagSet) {
62+
fs.StringVar(&c.Master, "master", c.Master, "The address of the Kubernetes API server (overrides any value in kubeconfig)")
63+
fs.StringVar(&c.Kubeconfig, "kubeconfig", c.Kubeconfig, "Path to kubeconfig file with authorization and master location information.")
64+
fs.StringVar(&c.CertFile, "tls-cert-file", c.CertFile, ""+
6565
"File containing the default x509 Certificate for HTTPS. (CA cert, if any, concatenated "+
6666
"after server cert).")
67-
flag.StringVar(&c.KeyFile, "tls-private-key-file", c.KeyFile, "File containing the default x509 private key matching --tls-cert-file.")
68-
flag.StringVar(&c.CaCertFile, "ca-cert-file", c.CaCertFile, "File containing the x509 Certificate for HTTPS.")
69-
flag.IntVar(&c.Port, "port", 443, "the port used by admission-controller-server.")
70-
flag.StringVar(&c.MutateWebhookConfigName, "mutate-webhook-config-name", "",
67+
fs.StringVar(&c.KeyFile, "tls-private-key-file", c.KeyFile, "File containing the default x509 private key matching --tls-cert-file.")
68+
fs.StringVar(&c.CaCertFile, "ca-cert-file", c.CaCertFile, "File containing the x509 Certificate for HTTPS.")
69+
fs.IntVar(&c.Port, "port", 443, "the port used by admission-controller-server.")
70+
fs.StringVar(&c.MutateWebhookConfigName, "mutate-webhook-config-name", "",
7171
"Name of the mutatingwebhookconfiguration resource in Kubernetes [Deprecated]: it will be generated when not specified.")
72-
flag.StringVar(&c.MutateWebhookName, "mutate-webhook-name", "",
72+
fs.StringVar(&c.MutateWebhookName, "mutate-webhook-name", "",
7373
"Name of the webhook entry in the webhook config. [Deprecated]: it will be generated when not specified")
74-
flag.StringVar(&c.ValidateWebhookConfigName, "validate-webhook-config-name", "",
74+
fs.StringVar(&c.ValidateWebhookConfigName, "validate-webhook-config-name", "",
7575
"Name of the mutatingwebhookconfiguration resource in Kubernetes. [Deprecated]: it will be generated when not specified")
76-
flag.StringVar(&c.ValidateWebhookName, "validate-webhook-name", "",
76+
fs.StringVar(&c.ValidateWebhookName, "validate-webhook-name", "",
7777
"Name of the webhook entry in the webhook config. [Deprecated]: it will be generated when not specified")
78-
flag.BoolVar(&c.PrintVersion, "version", false, "Show version and quit")
79-
flag.StringVar(&c.AdmissionServiceNamespace, "webhook-namespace", "default", "The namespace of this webhook")
80-
flag.StringVar(&c.AdmissionServiceName, "webhook-service-name", "admission-service", "The name of this admission service")
81-
flag.StringVar(&c.SchedulerName, "scheduler-name", defaultSchedulerName, "Volcano will handle pods whose .spec.SchedulerName is same as scheduler-name")
78+
fs.BoolVar(&c.PrintVersion, "version", false, "Show version and quit")
79+
fs.StringVar(&c.AdmissionServiceNamespace, "webhook-namespace", "default", "The namespace of this webhook")
80+
fs.StringVar(&c.AdmissionServiceName, "webhook-service-name", "admission-service", "The name of this admission service")
81+
fs.StringVar(&c.SchedulerName, "scheduler-name", defaultSchedulerName, "Volcano will handle pods whose .spec.SchedulerName is same as scheduler-name")
8282
}
8383

8484
const (
@@ -235,13 +235,13 @@ func registerMutateWebhook(client admissionregistrationv1beta1.MutatingWebhookCo
235235
return err
236236
}
237237
if err == nil && existing != nil {
238-
glog.Infof("Updating MutatingWebhookConfiguration %v", hook)
238+
klog.Infof("Updating MutatingWebhookConfiguration %v", hook)
239239
existing.Webhooks = hook.Webhooks
240240
if _, err := client.Update(existing); err != nil {
241241
return err
242242
}
243243
} else {
244-
glog.Infof("Creating MutatingWebhookConfiguration %v", hook)
244+
klog.Infof("Creating MutatingWebhookConfiguration %v", hook)
245245
if _, err := client.Create(&hook); err != nil {
246246
return err
247247
}
@@ -259,12 +259,12 @@ func registerValidateWebhook(client admissionregistrationv1beta1.ValidatingWebho
259259
}
260260
if err == nil && existing != nil {
261261
existing.Webhooks = hook.Webhooks
262-
glog.Infof("Updating ValidatingWebhookConfiguration %v", hook)
262+
klog.Infof("Updating ValidatingWebhookConfiguration %v", hook)
263263
if _, err := client.Update(existing); err != nil {
264264
return err
265265
}
266266
} else {
267-
glog.Infof("Creating ValidatingWebhookConfiguration %v", hook)
267+
klog.Infof("Creating ValidatingWebhookConfiguration %v", hook)
268268
if _, err := client.Create(&hook); err != nil {
269269
return err
270270
}

cmd/admission/app/server.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ package app
1919
import (
2020
"crypto/tls"
2121

22-
"github.com/golang/glog"
23-
2422
"k8s.io/client-go/kubernetes"
2523
"k8s.io/client-go/rest"
24+
"k8s.io/klog"
25+
2626
"volcano.sh/volcano/cmd/admission/app/options"
2727
"volcano.sh/volcano/pkg/client/clientset/versioned"
2828
)
@@ -31,7 +31,7 @@ import (
3131
func GetClient(restConfig *rest.Config) *kubernetes.Clientset {
3232
clientset, err := kubernetes.NewForConfig(restConfig)
3333
if err != nil {
34-
glog.Fatal(err)
34+
klog.Fatal(err)
3535
}
3636
return clientset
3737
}
@@ -40,7 +40,7 @@ func GetClient(restConfig *rest.Config) *kubernetes.Clientset {
4040
func GetVolcanoClient(restConfig *rest.Config) *versioned.Clientset {
4141
clientset, err := versioned.NewForConfig(restConfig)
4242
if err != nil {
43-
glog.Fatal(err)
43+
klog.Fatal(err)
4444
}
4545
return clientset
4646
}
@@ -52,7 +52,7 @@ func ConfigTLS(config *options.Config, restConfig *rest.Config) *tls.Config {
5252
if len(config.CertFile) != 0 && len(config.KeyFile) != 0 {
5353
sCert, err := tls.LoadX509KeyPair(config.CertFile, config.KeyFile)
5454
if err != nil {
55-
glog.Fatal(err)
55+
klog.Fatal(err)
5656
}
5757

5858
return &tls.Config{
@@ -63,14 +63,14 @@ func ConfigTLS(config *options.Config, restConfig *rest.Config) *tls.Config {
6363
if len(restConfig.CertData) != 0 && len(restConfig.KeyData) != 0 {
6464
sCert, err := tls.X509KeyPair(restConfig.CertData, restConfig.KeyData)
6565
if err != nil {
66-
glog.Fatal(err)
66+
klog.Fatal(err)
6767
}
6868

6969
return &tls.Config{
7070
Certificates: []tls.Certificate{sCert},
7171
}
7272
}
7373

74-
glog.Fatal("tls: failed to find any tls config data")
74+
klog.Fatal("tls: failed to find any tls config data")
7575
return &tls.Config{}
7676
}

cmd/admission/main.go

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,21 @@ limitations under the License.
1616
package main
1717

1818
import (
19-
"flag"
2019
"io/ioutil"
2120
"net/http"
2221
"os"
2322
"os/signal"
23+
"runtime"
2424
"strconv"
2525
"syscall"
26+
"time"
2627

27-
"github.com/golang/glog"
28+
"github.com/spf13/pflag"
2829

30+
"k8s.io/apimachinery/pkg/util/wait"
31+
"k8s.io/apiserver/pkg/util/flag"
2932
"k8s.io/client-go/tools/clientcmd"
33+
"k8s.io/klog"
3034

3135
"volcano.sh/volcano/cmd/admission/app"
3236
"volcano.sh/volcano/cmd/admission/app/options"
@@ -42,26 +46,35 @@ func serveMutateJobs(w http.ResponseWriter, r *http.Request) {
4246
admission.Serve(w, r, admission.MutateJobs)
4347
}
4448

49+
var logFlushFreq = pflag.Duration("log-flush-frequency", 5*time.Second, "Maximum number of seconds between log flushes")
50+
4551
func main() {
52+
runtime.GOMAXPROCS(runtime.NumCPU())
53+
klog.InitFlags(nil)
54+
4655
config := options.NewConfig()
47-
config.AddFlags()
48-
flag.Parse()
56+
config.AddFlags(pflag.CommandLine)
57+
58+
flag.InitFlags()
4959

5060
if config.PrintVersion {
5161
version.PrintVersionAndExit()
5262
}
5363

64+
go wait.Until(klog.Flush, *logFlushFreq, wait.NeverStop)
65+
defer klog.Flush()
66+
5467
http.HandleFunc(admission.AdmitJobPath, serveJobs)
5568
http.HandleFunc(admission.MutateJobPath, serveMutateJobs)
5669

5770
if err := config.CheckPortOrDie(); err != nil {
58-
glog.Fatalf("Configured port is invalid: %v", err)
71+
klog.Fatalf("Configured port is invalid: %v", err)
5972
}
6073
addr := ":" + strconv.Itoa(config.Port)
6174

6275
restConfig, err := clientcmd.BuildConfigFromFlags(config.Master, config.Kubeconfig)
6376
if err != nil {
64-
glog.Fatalf("Unable to build k8s config: %v", err)
77+
klog.Fatalf("Unable to build k8s config: %v", err)
6578
}
6679

6780
admission.VolcanoClientSet = app.GetVolcanoClient(restConfig)
@@ -70,12 +83,12 @@ func main() {
7083

7184
caBundle, err := ioutil.ReadFile(config.CaCertFile)
7285
if err != nil {
73-
glog.Fatalf("Unable to read cacert file: %v", err)
86+
klog.Fatalf("Unable to read cacert file: %v", err)
7487
}
7588

7689
err = options.RegisterWebhooks(config, app.GetClient(restConfig), caBundle)
7790
if err != nil {
78-
glog.Fatalf("Unable to register webhook configs: %v", err)
91+
klog.Fatalf("Unable to register webhook configs: %v", err)
7992
}
8093

8194
stopChannel := make(chan os.Signal)
@@ -89,15 +102,15 @@ func main() {
89102
go func() {
90103
err = server.ListenAndServeTLS("", "")
91104
if err != nil && err != http.ErrServerClosed {
92-
glog.Fatalf("ListenAndServeTLS for admission webhook failed: %v", err)
105+
klog.Fatalf("ListenAndServeTLS for admission webhook failed: %v", err)
93106
close(webhookServeError)
94107
}
95108
}()
96109

97110
select {
98111
case <-stopChannel:
99112
if err := server.Close(); err != nil {
100-
glog.Fatalf("Close admission server failed: %v", err)
113+
klog.Fatalf("Close admission server failed: %v", err)
101114
}
102115
return
103116
case <-webhookServeError:

cmd/cli/queue.go

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,40 @@ import (
2323
)
2424

2525
func buildQueueCmd() *cobra.Command {
26-
jobCmd := &cobra.Command{
26+
queueCmd := &cobra.Command{
2727
Use: "queue",
2828
Short: "Queue Operations",
2929
}
3030

31-
jobRunCmd := &cobra.Command{
31+
queueCreateCmd := &cobra.Command{
3232
Use: "create",
3333
Short: "creates queue",
3434
Run: func(cmd *cobra.Command, args []string) {
3535
checkError(cmd, queue.CreateQueue())
3636
},
3737
}
38-
queue.InitRunFlags(jobRunCmd)
39-
jobCmd.AddCommand(jobRunCmd)
38+
queue.InitCreateFlags(queueCreateCmd)
39+
queueCmd.AddCommand(queueCreateCmd)
40+
41+
queueDeleteCmd := &cobra.Command{
42+
Use: "delete",
43+
Short: "delete queue",
44+
Run: func(cmd *cobra.Command, args []string) {
45+
checkError(cmd, queue.DeleteQueue())
46+
},
47+
}
48+
queue.InitDeleteFlags(queueDeleteCmd)
49+
queueCmd.AddCommand(queueDeleteCmd)
50+
51+
queueOperateCmd := &cobra.Command{
52+
Use: "operate queue",
53+
Short: "operate queue",
54+
Run: func(cmd *cobra.Command, args []string) {
55+
checkError(cmd, queue.OperateQueue())
56+
},
57+
}
58+
queue.InitOperateFlags(queueOperateCmd)
59+
queueCmd.AddCommand(queueOperateCmd)
4060

4161
queueListCmd := &cobra.Command{
4262
Use: "list",
@@ -46,7 +66,7 @@ func buildQueueCmd() *cobra.Command {
4666
},
4767
}
4868
queue.InitListFlags(queueListCmd)
49-
jobCmd.AddCommand(queueListCmd)
69+
queueCmd.AddCommand(queueListCmd)
5070

5171
queueGetCmd := &cobra.Command{
5272
Use: "get",
@@ -56,7 +76,7 @@ func buildQueueCmd() *cobra.Command {
5676
},
5777
}
5878
queue.InitGetFlags(queueGetCmd)
59-
jobCmd.AddCommand(queueGetCmd)
79+
queueCmd.AddCommand(queueGetCmd)
6080

61-
return jobCmd
81+
return queueCmd
6282
}

0 commit comments

Comments
 (0)