Skip to content

Commit

Permalink
Merge pull request #1 from volcano-sh/master
Browse files Browse the repository at this point in the history
sync in 10th Dec. 2019
  • Loading branch information
jiangkaihua authored Dec 10, 2019
2 parents 0564a5f + cbe3c00 commit 5ca4c6b
Show file tree
Hide file tree
Showing 127 changed files with 2,886 additions and 2,743 deletions.
11 changes: 2 additions & 9 deletions Gopkg.lock

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

4 changes: 0 additions & 4 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ required = [
"k8s.io/code-generator/cmd/defaulter-gen",
]

[[constraint]]
branch = "master"
name = "github.com/golang/glog"

[[constraint]]
name = "github.com/onsi/ginkgo"
version = "1.7.0"
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ generate-code:
./hack/update-gencode.sh

unit-test:
go clean -testcache
go list ./... | grep -v e2e | xargs go test -v -race

e2e-test-kind:
Expand All @@ -84,7 +85,7 @@ clean:
rm -rf _output/
rm -f *.log

verify: generate-code
verify:
hack/verify-gofmt.sh
hack/verify-golint.sh
hack/verify-gencode.sh
Expand Down
42 changes: 21 additions & 21 deletions cmd/admission/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ limitations under the License.
package options

import (
"flag"
"fmt"

"github.com/golang/glog"
"github.com/spf13/pflag"

"k8s.io/api/admissionregistration/v1beta1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
admissionregistrationv1beta1 "k8s.io/client-go/kubernetes/typed/admissionregistration/v1beta1"
"k8s.io/klog"
)

const (
Expand Down Expand Up @@ -58,27 +58,27 @@ func NewConfig() *Config {
}

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

const (
Expand Down Expand Up @@ -235,13 +235,13 @@ func registerMutateWebhook(client admissionregistrationv1beta1.MutatingWebhookCo
return err
}
if err == nil && existing != nil {
glog.Infof("Updating MutatingWebhookConfiguration %v", hook)
klog.Infof("Updating MutatingWebhookConfiguration %v", hook)
existing.Webhooks = hook.Webhooks
if _, err := client.Update(existing); err != nil {
return err
}
} else {
glog.Infof("Creating MutatingWebhookConfiguration %v", hook)
klog.Infof("Creating MutatingWebhookConfiguration %v", hook)
if _, err := client.Create(&hook); err != nil {
return err
}
Expand All @@ -259,12 +259,12 @@ func registerValidateWebhook(client admissionregistrationv1beta1.ValidatingWebho
}
if err == nil && existing != nil {
existing.Webhooks = hook.Webhooks
glog.Infof("Updating ValidatingWebhookConfiguration %v", hook)
klog.Infof("Updating ValidatingWebhookConfiguration %v", hook)
if _, err := client.Update(existing); err != nil {
return err
}
} else {
glog.Infof("Creating ValidatingWebhookConfiguration %v", hook)
klog.Infof("Creating ValidatingWebhookConfiguration %v", hook)
if _, err := client.Create(&hook); err != nil {
return err
}
Expand Down
14 changes: 7 additions & 7 deletions cmd/admission/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ package app
import (
"crypto/tls"

"github.com/golang/glog"

"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/klog"

"volcano.sh/volcano/cmd/admission/app/options"
"volcano.sh/volcano/pkg/client/clientset/versioned"
)
Expand All @@ -31,7 +31,7 @@ import (
func GetClient(restConfig *rest.Config) *kubernetes.Clientset {
clientset, err := kubernetes.NewForConfig(restConfig)
if err != nil {
glog.Fatal(err)
klog.Fatal(err)
}
return clientset
}
Expand All @@ -40,7 +40,7 @@ func GetClient(restConfig *rest.Config) *kubernetes.Clientset {
func GetVolcanoClient(restConfig *rest.Config) *versioned.Clientset {
clientset, err := versioned.NewForConfig(restConfig)
if err != nil {
glog.Fatal(err)
klog.Fatal(err)
}
return clientset
}
Expand All @@ -52,7 +52,7 @@ func ConfigTLS(config *options.Config, restConfig *rest.Config) *tls.Config {
if len(config.CertFile) != 0 && len(config.KeyFile) != 0 {
sCert, err := tls.LoadX509KeyPair(config.CertFile, config.KeyFile)
if err != nil {
glog.Fatal(err)
klog.Fatal(err)
}

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

return &tls.Config{
Certificates: []tls.Certificate{sCert},
}
}

glog.Fatal("tls: failed to find any tls config data")
klog.Fatal("tls: failed to find any tls config data")
return &tls.Config{}
}
33 changes: 23 additions & 10 deletions cmd/admission/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,21 @@ limitations under the License.
package main

import (
"flag"
"io/ioutil"
"net/http"
"os"
"os/signal"
"runtime"
"strconv"
"syscall"
"time"

"github.com/golang/glog"
"github.com/spf13/pflag"

"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apiserver/pkg/util/flag"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/klog"

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

var logFlushFreq = pflag.Duration("log-flush-frequency", 5*time.Second, "Maximum number of seconds between log flushes")

func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
klog.InitFlags(nil)

config := options.NewConfig()
config.AddFlags()
flag.Parse()
config.AddFlags(pflag.CommandLine)

flag.InitFlags()

if config.PrintVersion {
version.PrintVersionAndExit()
}

go wait.Until(klog.Flush, *logFlushFreq, wait.NeverStop)
defer klog.Flush()

http.HandleFunc(admission.AdmitJobPath, serveJobs)
http.HandleFunc(admission.MutateJobPath, serveMutateJobs)

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

restConfig, err := clientcmd.BuildConfigFromFlags(config.Master, config.Kubeconfig)
if err != nil {
glog.Fatalf("Unable to build k8s config: %v", err)
klog.Fatalf("Unable to build k8s config: %v", err)
}

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

caBundle, err := ioutil.ReadFile(config.CaCertFile)
if err != nil {
glog.Fatalf("Unable to read cacert file: %v", err)
klog.Fatalf("Unable to read cacert file: %v", err)
}

err = options.RegisterWebhooks(config, app.GetClient(restConfig), caBundle)
if err != nil {
glog.Fatalf("Unable to register webhook configs: %v", err)
klog.Fatalf("Unable to register webhook configs: %v", err)
}

stopChannel := make(chan os.Signal)
Expand All @@ -89,15 +102,15 @@ func main() {
go func() {
err = server.ListenAndServeTLS("", "")
if err != nil && err != http.ErrServerClosed {
glog.Fatalf("ListenAndServeTLS for admission webhook failed: %v", err)
klog.Fatalf("ListenAndServeTLS for admission webhook failed: %v", err)
close(webhookServeError)
}
}()

select {
case <-stopChannel:
if err := server.Close(); err != nil {
glog.Fatalf("Close admission server failed: %v", err)
klog.Fatalf("Close admission server failed: %v", err)
}
return
case <-webhookServeError:
Expand Down
34 changes: 27 additions & 7 deletions cmd/cli/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,40 @@ import (
)

func buildQueueCmd() *cobra.Command {
jobCmd := &cobra.Command{
queueCmd := &cobra.Command{
Use: "queue",
Short: "Queue Operations",
}

jobRunCmd := &cobra.Command{
queueCreateCmd := &cobra.Command{
Use: "create",
Short: "creates queue",
Run: func(cmd *cobra.Command, args []string) {
checkError(cmd, queue.CreateQueue())
},
}
queue.InitRunFlags(jobRunCmd)
jobCmd.AddCommand(jobRunCmd)
queue.InitCreateFlags(queueCreateCmd)
queueCmd.AddCommand(queueCreateCmd)

queueDeleteCmd := &cobra.Command{
Use: "delete",
Short: "delete queue",
Run: func(cmd *cobra.Command, args []string) {
checkError(cmd, queue.DeleteQueue())
},
}
queue.InitDeleteFlags(queueDeleteCmd)
queueCmd.AddCommand(queueDeleteCmd)

queueOperateCmd := &cobra.Command{
Use: "operate queue",
Short: "operate queue",
Run: func(cmd *cobra.Command, args []string) {
checkError(cmd, queue.OperateQueue())
},
}
queue.InitOperateFlags(queueOperateCmd)
queueCmd.AddCommand(queueOperateCmd)

queueListCmd := &cobra.Command{
Use: "list",
Expand All @@ -46,7 +66,7 @@ func buildQueueCmd() *cobra.Command {
},
}
queue.InitListFlags(queueListCmd)
jobCmd.AddCommand(queueListCmd)
queueCmd.AddCommand(queueListCmd)

queueGetCmd := &cobra.Command{
Use: "get",
Expand All @@ -56,7 +76,7 @@ func buildQueueCmd() *cobra.Command {
},
}
queue.InitGetFlags(queueGetCmd)
jobCmd.AddCommand(queueGetCmd)
queueCmd.AddCommand(queueGetCmd)

return jobCmd
return queueCmd
}
Loading

0 comments on commit 5ca4c6b

Please sign in to comment.