Skip to content

Commit

Permalink
Merge pull request #3454 from SataQiu/fix-0508
Browse files Browse the repository at this point in the history
bugfix and code refactor around klog
  • Loading branch information
volcano-sh-bot authored May 24, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents 0dc370d + 3cc9960 commit aa7c8b8
Showing 11 changed files with 42 additions and 139 deletions.
23 changes: 4 additions & 19 deletions cmd/cli/vcancel/main.go
Original file line number Diff line number Diff line change
@@ -16,30 +16,16 @@ limitations under the License.
package main

import (
"fmt"
"os"
"time"

"github.com/spf13/cobra"
"github.com/spf13/pflag"

"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/klog/v2"
"k8s.io/component-base/cli"

"volcano.sh/volcano/cmd/cli/util"
"volcano.sh/volcano/pkg/cli/vcancel"
)

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

func main() {
// flag.InitFlags()
klog.InitFlags(nil)

// The default klog flush interval is 30 seconds, which is frighteningly long.
go wait.Until(klog.Flush, *logFlushFreq, wait.NeverStop)
defer klog.Flush()

rootCmd := cobra.Command{
Use: "vcancel",
Short: "cancel a job",
@@ -51,8 +37,7 @@ func main() {

jobCancelCmd := &rootCmd
vcancel.InitCancelFlags(jobCancelCmd)
if err := rootCmd.Execute(); err != nil {
fmt.Printf("Failed to execute vcancel: %v\n", err)
os.Exit(-2)
}

code := cli.Run(&rootCmd)
os.Exit(code)
}
21 changes: 3 additions & 18 deletions cmd/cli/vcctl.go
Original file line number Diff line number Diff line change
@@ -18,28 +18,15 @@ package main
import (
"fmt"
"os"
"time"

"github.com/spf13/cobra"
"github.com/spf13/pflag"
"k8s.io/apimachinery/pkg/util/wait"
_ "k8s.io/client-go/plugin/pkg/client/auth/oidc"
"k8s.io/klog/v2"
"k8s.io/component-base/cli"

"volcano.sh/volcano/pkg/version"
)

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

func main() {
// flag.InitFlags()

klog.InitFlags(nil)

// The default klog flush interval is 30 seconds, which is frighteningly long.
go wait.Until(klog.Flush, *logFlushFreq, wait.NeverStop)
defer klog.Flush()

rootCmd := cobra.Command{
Use: "vcctl",
}
@@ -51,10 +38,8 @@ func main() {
rootCmd.AddCommand(buildQueueCmd())
rootCmd.AddCommand(versionCommand())

if err := rootCmd.Execute(); err != nil {
fmt.Printf("Failed to execute command: %v\n", err)
os.Exit(2)
}
code := cli.Run(&rootCmd)
os.Exit(code)
}

func checkError(cmd *cobra.Command, err error) {
23 changes: 4 additions & 19 deletions cmd/cli/vjobs/main.go
Original file line number Diff line number Diff line change
@@ -16,30 +16,16 @@ limitations under the License.
package main

import (
"fmt"
"os"
"time"

"github.com/spf13/cobra"
"github.com/spf13/pflag"

"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/klog/v2"
"k8s.io/component-base/cli"

"volcano.sh/volcano/cmd/cli/util"
"volcano.sh/volcano/pkg/cli/vjobs"
)

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

func main() {
// flag.InitFlags()
klog.InitFlags(nil)

// The default klog flush interval is 30 seconds, which is frighteningly long.
go wait.Until(klog.Flush, *logFlushFreq, wait.NeverStop)
defer klog.Flush()

rootCmd := cobra.Command{
Use: "vjobs",
Short: "view job information",
@@ -51,8 +37,7 @@ func main() {

jobViewCmd := &rootCmd
vjobs.InitViewFlags(jobViewCmd)
if err := rootCmd.Execute(); err != nil {
fmt.Printf("Failed to execute vjobs: %v\n", err)
os.Exit(-2)
}

code := cli.Run(&rootCmd)
os.Exit(code)
}
23 changes: 4 additions & 19 deletions cmd/cli/vqueues/main.go
Original file line number Diff line number Diff line change
@@ -16,30 +16,16 @@ limitations under the License.
package main

import (
"fmt"
"os"
"time"

"github.com/spf13/cobra"
"github.com/spf13/pflag"

"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/klog/v2"
"k8s.io/component-base/cli"

"volcano.sh/volcano/cmd/cli/util"
"volcano.sh/volcano/pkg/cli/vqueues"
)

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

func main() {
// flag.InitFlags()
klog.InitFlags(nil)

// The default klog flush interval is 30 seconds, which is frighteningly long.
go wait.Until(klog.Flush, *logFlushFreq, wait.NeverStop)
defer klog.Flush()

rootCmd := cobra.Command{
Use: "vqueues",
Short: "view queue information",
@@ -51,8 +37,7 @@ func main() {

jobGetCmd := &rootCmd
vqueues.InitGetFlags(jobGetCmd)
if err := rootCmd.Execute(); err != nil {
fmt.Printf("Failed to execute vqueues: %v\n", err)
os.Exit(-2)
}

code := cli.Run(&rootCmd)
os.Exit(code)
}
23 changes: 4 additions & 19 deletions cmd/cli/vresume/main.go
Original file line number Diff line number Diff line change
@@ -16,30 +16,16 @@ limitations under the License.
package main

import (
"fmt"
"os"
"time"

"github.com/spf13/cobra"
"github.com/spf13/pflag"

"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/klog/v2"
"k8s.io/component-base/cli"

"volcano.sh/volcano/cmd/cli/util"
"volcano.sh/volcano/pkg/cli/vresume"
)

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

func main() {
// flag.InitFlags()
klog.InitFlags(nil)

// The default klog flush interval is 30 seconds, which is frighteningly long.
go wait.Until(klog.Flush, *logFlushFreq, wait.NeverStop)
defer klog.Flush()

rootCmd := cobra.Command{
Use: "vresume",
Short: "resume a job",
@@ -51,8 +37,7 @@ func main() {

jobResumeCmd := &rootCmd
vresume.InitResumeFlags(jobResumeCmd)
if err := rootCmd.Execute(); err != nil {
fmt.Printf("Failed to execute vresume: %v\n", err)
os.Exit(-2)
}

code := cli.Run(&rootCmd)
os.Exit(code)
}
23 changes: 4 additions & 19 deletions cmd/cli/vsub/main.go
Original file line number Diff line number Diff line change
@@ -16,30 +16,16 @@ limitations under the License.
package main

import (
"fmt"
"os"
"time"

"github.com/spf13/cobra"
"github.com/spf13/pflag"

"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/klog/v2"
"k8s.io/component-base/cli"

"volcano.sh/volcano/cmd/cli/util"
"volcano.sh/volcano/pkg/cli/vsub"
)

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

func main() {
// flag.InitFlags()
klog.InitFlags(nil)

// The default klog flush interval is 30 seconds, which is frighteningly long.
go wait.Until(klog.Flush, *logFlushFreq, wait.NeverStop)
defer klog.Flush()

rootCmd := cobra.Command{
Use: "vsub",
Short: "submit a job",
@@ -51,8 +37,7 @@ func main() {

jobSubCmd := &rootCmd
vsub.InitRunFlags(jobSubCmd)
if err := rootCmd.Execute(); err != nil {
fmt.Printf("Failed to execute vsub: %v\n", err)
os.Exit(-2)
}

code := cli.Run(&rootCmd)
os.Exit(code)
}
23 changes: 4 additions & 19 deletions cmd/cli/vsuspend/main.go
Original file line number Diff line number Diff line change
@@ -16,30 +16,16 @@ limitations under the License.
package main

import (
"fmt"
"os"
"time"

"github.com/spf13/cobra"
"github.com/spf13/pflag"

"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/klog/v2"
"k8s.io/component-base/cli"

"volcano.sh/volcano/cmd/cli/util"
"volcano.sh/volcano/pkg/cli/vsuspend"
)

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

func main() {
// flag.InitFlags()
klog.InitFlags(nil)

// The default klog flush interval is 30 seconds, which is frighteningly long.
go wait.Until(klog.Flush, *logFlushFreq, wait.NeverStop)
defer klog.Flush()

rootCmd := cobra.Command{
Use: "vsuspend",
Short: "suspend a job",
@@ -51,8 +37,7 @@ func main() {

jobSuspendCmd := &rootCmd
vsuspend.InitSuspendFlags(jobSuspendCmd)
if err := rootCmd.Execute(); err != nil {
fmt.Printf("Failed to execute vsuspend: %v\n", err)
os.Exit(-2)
}

code := cli.Run(&rootCmd)
os.Exit(code)
}
4 changes: 1 addition & 3 deletions cmd/controller-manager/main.go
Original file line number Diff line number Diff line change
@@ -23,7 +23,6 @@ import (

"github.com/spf13/pflag"
_ "go.uber.org/automaxprocs"
"k8s.io/apimachinery/pkg/util/wait"
cliflag "k8s.io/component-base/cli/flag"
componentbaseoptions "k8s.io/component-base/config/options"
"k8s.io/klog/v2"
@@ -70,8 +69,7 @@ func main() {
}
}

// The default klog flush interval is 30 seconds, which is frighteningly long.
go wait.Until(klog.Flush, *logFlushFreq, wait.NeverStop)
klog.StartFlushDaemon(*logFlushFreq)
defer klog.Flush()

if err := app.Run(s); err != nil {
3 changes: 1 addition & 2 deletions cmd/scheduler/main.go
Original file line number Diff line number Diff line change
@@ -23,7 +23,6 @@ import (

"github.com/spf13/pflag"
_ "go.uber.org/automaxprocs"
"k8s.io/apimachinery/pkg/util/wait"
cliflag "k8s.io/component-base/cli/flag"
componentbaseoptions "k8s.io/component-base/config/options"
"k8s.io/klog/v2"
@@ -70,7 +69,7 @@ func main() {
}
}

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

if err := app.Run(s); err != nil {
3 changes: 1 addition & 2 deletions cmd/webhook-manager/main.go
Original file line number Diff line number Diff line change
@@ -24,7 +24,6 @@ import (
"github.com/spf13/pflag"
_ "go.uber.org/automaxprocs"

"k8s.io/apimachinery/pkg/util/wait"
cliflag "k8s.io/component-base/cli/flag"
"k8s.io/klog/v2"

@@ -51,7 +50,7 @@ func main() {

cliflag.InitFlags()

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

if err := config.CheckPortOrDie(); err != nil {
Loading

0 comments on commit aa7c8b8

Please sign in to comment.