123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- package priorities
- import (
- "fmt"
- "os"
- _ "github.com/go-sql-driver/mysql"
- client "github.com/influxdata/influxdb1-client/v2"
- "gopkg.in/yaml.v2"
- "k8s.io/klog"
- )
- var (
- customResourcePriority = &CustomAllocationPriority{"CustomResourceAllocation", customResourceScorer}
-
-
-
-
-
-
- CustomRequestedPriorityMap = customResourcePriority.PriorityMap
- )
- type Config struct {
- Server struct {
- Port string `yaml:"port"`
- Host string `yaml:"host"`
- } `yaml:"server"`
- Database struct {
- Type string `yaml: "type"`
- Name string `yaml:"name"`
- Username string `yaml:"username"`
- Password string `yaml:"password"`
- } `yaml:"database"`
- }
- type System struct {
- ID int `json:"id"`
- Uuid string `json:"uuid"`
- numSockets int `json:"num_sockets"`
- numCores int `json:"num_cores`
- }
- var nodes = map[string]string{
- "kube-01": "c4766d29-4dc1-11ea-9d98-0242ac110002",
- "kube-02": "c4766d29-4dc1-11ea-9d98-0242ac110002",
- "kube-03": "c4766d29-4dc1-11ea-9d98-0242ac110002",
- "kube-04": "c4766d29-4dc1-11ea-9d98-0242ac110002",
- "kube-05": "c4766d29-4dc1-11ea-9d98-0242ac110002",
- "kube-06": "c4766d29-4dc1-11ea-9d98-0242ac110002",
- "kube-07": "c4766d29-4dc1-11ea-9d98-0242ac110002",
- "kube-08": "c4766d29-4dc1-11ea-9d98-0242ac110002",
- }
- func readFile(cfg *Config, file string) {
- f, err := os.Open("/etc/kubernetes/scheduler-monitoringDB.yaml")
- if err != nil {
- panic(err.Error())
- }
- defer f.Close()
- decoder := yaml.NewDecoder(f)
- err = decoder.Decode(&cfg)
- if err != nil {
- panic(err.Error())
- }
- }
- func customResourceScorer(nodeName string) int64 {
-
-
-
- var cfg Config
- readFile(&cfg, "/etc/kubernetes/scheduler-monitoringDB.yaml")
-
-
-
-
-
-
-
-
- c, err := client.NewHTTPClient(client.HTTPConfig{
- Addr: "http://" + cfg.Server.Host + ":" + cfg.Server.Port + "",
- })
- if err != nil {
- klog.Infof("Error while creating InfluxDB client: %v ", err.Error())
- } else {
- klog.Infof("Connected Successfully to InfluxDB")
- }
-
- defer c.Close()
-
- curr_uuid, ok := nodes[nodeName]
- if ok {
- command := fmt.Sprintf("SELECT ipc from system_metrics where uuid = '%s' order by time desc limit 1", curr_uuid)
- q := client.NewQuery(command, "evolve", "")
- if response, err := c.Query(q); err == nil && response.Error() == nil {
- klog.Infof("%v", response.Results)
- }
- } else {
- klog.Infof("Error finding the uuid: %v", ok)
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- res := customRequestedScore(nodeName)
- klog.Infof("Node name %s, has score %d\n", nodeName, res)
- return res
- }
- func customRequestedScore(nodeName string) int64 {
- if nodeName == "kube-01" {
- return 10
- }
- return 0
- }
|