Skip to content

Commit 97f5c2c

Browse files
committed
Initial commit for kubernetes scheduler simulator
1 parent afc309d commit 97f5c2c

File tree

5,035 files changed

+1395727
-0
lines changed

Some content is hidden

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

5,035 files changed

+1395727
-0
lines changed

.gitignore

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.idea
2+
.vscode
3+
4+
.DS_Store
5+
*.tgz
6+
*.tar
7+
*.log
8+
9+
__pycache__
10+
.ipynb_checkpoints
11+
bin/*
12+
kubeconfig
13+
configmap-simon.yaml
14+
15+
data
16+
logs
17+
experiments
18+
example/snapshot
19+
config/cluster-config/

Makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
OUTPUT_DIR=./bin
2+
BINARY_NAME=simon
3+
LINUX_BINARY_NAME=simon_linux
4+
5+
.PHONY: local_build
6+
local_build:
7+
GOARCH=amd64 GOOS=darwin go build -v -o $(OUTPUT_DIR)/$(BINARY_NAME) ./cmd
8+
9+
.PHONY: linux_build
10+
linux_build:
11+
GOARCH=amd64 GOOS=linux go build -v -o $(OUTPUT_DIR)/$(LINUX_BINARY_NAME) ./cmd
12+
chmod +x $(OUTPUT_DIR)/$(LINUX_BINARY_NAME)

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
## Environment Setup
2+
3+
Please ensure that Go is installed. `go mod vendor` will install the dependencies required for the simulator, and `make` will generate the compiled binary fils in the `bin` directory.
4+
5+
```bash
6+
$ go mod vendor
7+
$ make local_build
8+
$ make linux_build
9+
```
10+
11+
## QuickStart Example
12+
13+
```bash
14+
$ LOGLEVEL=DEBUG bin/simon apply --extended-resources "gpu" -s example/test-scheduler-config.yaml -f example/test-cluster-config.yaml
15+
```
16+
17+
## Acknowledge
18+
19+
Our simulator is developed based on [Alibaba's open-simulator](https://github.com/alibaba/open-simulator), a simulator used for cluster capacity planning.
20+
The GPU-related plugin has been incorporated into its main branch.

cmd/apply/apply.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package apply
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
applypkg "github.com/hkust-adsl/kubernetes-scheduler-simulator/pkg/apply"
8+
log "github.com/sirupsen/logrus"
9+
"github.com/spf13/cobra"
10+
)
11+
12+
var options = applypkg.Options{}
13+
14+
var ApplyCmd = &cobra.Command{
15+
Use: "apply",
16+
Short: "Make a reasonable cluster capacity planning based on application resource requirements",
17+
Run: func(cmd *cobra.Command, args []string) {
18+
applier := applypkg.NewApplier(options)
19+
if err := applier.Run(); err != nil {
20+
fmt.Printf("apply error: %s", err.Error())
21+
os.Exit(1)
22+
}
23+
},
24+
}
25+
26+
func init() {
27+
ApplyCmd.Flags().StringVarP(&options.SimonConfig, "simon-config", "f", options.SimonConfig, "path to the cluster kube-config file used to connect cluster, one of both kube-config and cluster-config must exist.")
28+
ApplyCmd.Flags().StringVarP(&options.DefaultSchedulerConfigFile, "default-scheduler-config", "s", options.DefaultSchedulerConfigFile, "path to JSON or YAML file containing scheduler configuration.")
29+
ApplyCmd.Flags().BoolVar(&options.UseGreed, "use-greed", false, "use greedy algorithm when queue pods")
30+
ApplyCmd.Flags().BoolVarP(&options.Interactive, "interactive", "i", false, "interactive mode")
31+
ApplyCmd.Flags().StringSliceVarP(&options.ExtendedResources, "extended-resources", "e", nil, "show extended resources when reporting, e.g. open-local, gpu")
32+
33+
if err := ApplyCmd.MarkFlagRequired("simon-config"); err != nil {
34+
log.Fatal("failed to init ApplyCmd on simon-config flag")
35+
}
36+
}

cmd/debug/debug.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package debug
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/spf13/cobra"
8+
)
9+
10+
var options = Options{}
11+
12+
// DebugCmd is only for debug
13+
var DebugCmd = &cobra.Command{
14+
Use: "debug",
15+
Short: "debug alpha feature",
16+
Run: func(cmd *cobra.Command, args []string) {
17+
if err := run(&options); err != nil {
18+
fmt.Printf("debug error: %s", err.Error())
19+
os.Exit(1)
20+
}
21+
},
22+
}
23+
24+
func init() {
25+
options.AddFlags(DebugCmd.Flags())
26+
if err := DebugCmd.MarkFlagRequired("filepath"); err != nil {
27+
fmt.Printf("debug init error: %s", err.Error())
28+
os.Exit(1)
29+
}
30+
}
31+
32+
func run(opt *Options) error {
33+
return nil
34+
}

cmd/debug/options.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package debug
2+
3+
import (
4+
"github.com/spf13/pflag"
5+
)
6+
7+
// Options is the combined set of options for all operating modes.
8+
type Options struct {
9+
Kubeconfig string
10+
}
11+
12+
// AddFlags will add the flag to the pflag.FlagSet
13+
func (options *Options) AddFlags(fs *pflag.FlagSet) {
14+
fs.StringVar(&options.Kubeconfig, "kubeconfig", options.Kubeconfig, "Path to the kubeconfig file to use for the analysis.")
15+
}

cmd/doc/generate_markdown.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package doc
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/spf13/cobra"
8+
"github.com/spf13/cobra/doc"
9+
)
10+
11+
type GenerateDoc struct {
12+
DocCmd *cobra.Command
13+
outputDir string
14+
}
15+
16+
var GenDoc = &GenerateDoc{}
17+
18+
func init() {
19+
GenDoc.DocCmd = &cobra.Command{
20+
Use: "gen-doc",
21+
Short: "Generate markdown document for your project",
22+
Args: cobra.NoArgs,
23+
SilenceErrors: true,
24+
SilenceUsage: true,
25+
RunE: func(cmd *cobra.Command, args []string) error {
26+
return GenDoc.generateDocument()
27+
},
28+
}
29+
30+
GenDoc.DocCmd.Flags().StringVarP(&GenDoc.outputDir, "output-directory", "d", "./docs/commandline", "assign a directory to store documents")
31+
}
32+
33+
func (c *GenerateDoc) generateDocument() error {
34+
if _, err := os.Stat(c.outputDir); err != nil {
35+
return fmt.Errorf("Invalid output directory(%s) ", c.outputDir)
36+
}
37+
return doc.GenMarkdownTree(c.DocCmd.Parent(), c.outputDir)
38+
}

cmd/main.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/hkust-adsl/kubernetes-scheduler-simulator/cmd/simon"
8+
)
9+
10+
func main() {
11+
cmd := simon.NewSimonCommand()
12+
if err := cmd.Execute(); err != nil {
13+
fmt.Printf("start with error: %s", err.Error())
14+
os.Exit(1)
15+
}
16+
}

cmd/simon/simon.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package simon
2+
3+
import (
4+
goflag "flag"
5+
log "github.com/sirupsen/logrus"
6+
"github.com/spf13/cobra"
7+
cliflag "k8s.io/component-base/cli/flag"
8+
"os"
9+
10+
"github.com/hkust-adsl/kubernetes-scheduler-simulator/cmd/apply"
11+
"github.com/hkust-adsl/kubernetes-scheduler-simulator/cmd/doc"
12+
"github.com/hkust-adsl/kubernetes-scheduler-simulator/cmd/version"
13+
)
14+
15+
const (
16+
EnvLogLevel = "LOGLEVEL"
17+
LogPanic = "PANIC"
18+
LogFatal = "FATAL"
19+
LogError = "ERROR"
20+
LogWarn = "WARN"
21+
LogInfo = "INFO"
22+
LogDebug = "DEBUG"
23+
LogTrace = "TRACE"
24+
)
25+
26+
func NewSimonCommand() *cobra.Command {
27+
simonCmd := &cobra.Command{
28+
Use: "simon",
29+
Short: "Simon is a simulator, which will simulate a cluster and simulate workload scheduling.",
30+
}
31+
32+
simonCmd.AddCommand(
33+
version.VersionCmd,
34+
apply.ApplyCmd,
35+
doc.GenDoc.DocCmd,
36+
)
37+
simonCmd.SetGlobalNormalizationFunc(cliflag.WordSepNormalizeFunc)
38+
simonCmd.Flags().AddGoFlagSet(goflag.CommandLine)
39+
simonCmd.DisableAutoGenTag = true
40+
41+
return simonCmd
42+
}
43+
44+
func init() {
45+
logLevel := os.Getenv(EnvLogLevel)
46+
switch logLevel {
47+
case LogPanic:
48+
log.SetLevel(log.PanicLevel)
49+
case LogFatal:
50+
log.SetLevel(log.FatalLevel)
51+
case LogError:
52+
log.SetLevel(log.ErrorLevel)
53+
case LogWarn:
54+
log.SetLevel(log.WarnLevel)
55+
case LogInfo:
56+
log.SetLevel(log.InfoLevel)
57+
case LogDebug:
58+
log.SetLevel(log.DebugLevel)
59+
case LogTrace:
60+
log.SetLevel(log.TraceLevel)
61+
default:
62+
log.SetLevel(log.InfoLevel)
63+
}
64+
}

cmd/version/version.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package version
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/spf13/cobra"
7+
)
8+
9+
var (
10+
// VERSION is version of CSI Pangu Driver
11+
VERSION = ""
12+
// COMMITID is commit ID of code
13+
COMMITID = ""
14+
)
15+
16+
var VersionCmd = &cobra.Command{
17+
Use: "version",
18+
Short: "Print the version of simon",
19+
Run: func(cmd *cobra.Command, args []string) {
20+
fmt.Printf("Version: %s\n", VERSION)
21+
fmt.Printf("Commit: %s\n", COMMITID)
22+
},
23+
}

0 commit comments

Comments
 (0)