infrastructure.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package priorities
  2. import (
  3. "os"
  4. client "github.com/influxdata/influxdb1-client/v2"
  5. "gopkg.in/yaml.v2"
  6. "k8s.io/klog"
  7. )
  8. type scorerInput struct {
  9. metricName string
  10. metrics map[string]float64
  11. }
  12. type Config struct {
  13. Server struct {
  14. Port string `yaml:"port"`
  15. Host string `yaml:"host"`
  16. } `yaml:"server"`
  17. Database struct {
  18. Type string `yaml:"type"`
  19. Name string `yaml:"name"`
  20. Username string `yaml:"username"`
  21. Password string `yaml:"password"`
  22. } `yaml:"database"`
  23. MonitoringSpecs struct {
  24. TimeInterval float32 `yaml:"interval"`
  25. } `yaml:"monitoring"`
  26. }
  27. var nodes = map[string]string{
  28. "kube-01": "e77467ad-636e-4e7e-8bc9-53e46ae51da1",
  29. "kube-02": "e77467ad-636e-4e7e-8bc9-53e46ae51da1",
  30. "kube-03": "e77467ad-636e-4e7e-8bc9-53e46ae51da1",
  31. "kube-04": "e77467ad-636e-4e7e-8bc9-53e46ae51da1",
  32. "kube-05": "c4766d29-4dc1-11ea-9d98-0242ac110002",
  33. "kube-06": "c4766d29-4dc1-11ea-9d98-0242ac110002",
  34. "kube-07": "c4766d29-4dc1-11ea-9d98-0242ac110002",
  35. "kube-08": "c4766d29-4dc1-11ea-9d98-0242ac110002",
  36. }
  37. var sockets = map[string]int{
  38. "kube-01": 1,
  39. "kube-02": 0,
  40. "kube-03": 0,
  41. "kube-04": 1,
  42. "kube-05": 0,
  43. "kube-06": 1,
  44. "kube-07": 0,
  45. "kube-08": 1,
  46. }
  47. var cores = map[string][]int{
  48. "kube-01": []int{20, 21, 22, 23},
  49. "kube-02": []int{2, 3, 4, 5, 6, 7, 8, 9},
  50. "kube-03": []int{40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55},
  51. "kube-04": []int{24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75},
  52. "kube-05": []int{0, 1, 2, 3},
  53. "kube-06": []int{12, 13, 14, 15, 16, 17, 18, 19},
  54. "kube-07": []int{4, 5, 6, 7, 8, 9, 10, 11, 24, 25, 26, 27, 28, 29, 30, 31},
  55. "kube-08": []int{20, 21, 22, 23, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47},
  56. }
  57. func readFile(cfg *Config, file string) error {
  58. f, err := os.Open(file)
  59. if err != nil {
  60. klog.Infof("Config file for scheduler not found. Error: %v", err)
  61. return err
  62. }
  63. defer f.Close()
  64. decoder := yaml.NewDecoder(f)
  65. err = decoder.Decode(&cfg)
  66. if err != nil {
  67. klog.Infof("Unable to decode the config file. Error: %v", err)
  68. return err
  69. }
  70. return nil
  71. }
  72. func connectToInfluxDB(cfg Config) (client.Client, error) {
  73. c, err := client.NewHTTPClient(client.HTTPConfig{
  74. Addr: "http://" + cfg.Server.Host + ":" + cfg.Server.Port + "",
  75. })
  76. if err != nil {
  77. klog.Infof("Error while connecting to InfluxDB: %v ", err.Error())
  78. return nil, err
  79. }
  80. klog.Infof("Connected Successfully to InfluxDB")
  81. return c, nil
  82. }