infrastructure.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 links = map[string][]float32{
  38. "e77467ad-636e-4e7e-8bc9-53e46ae51da1": []float32{3, 10.4},
  39. "c4766d29-4dc1-11ea-9d98-0242ac110002": []float32{2, 9.6},
  40. }
  41. var sockets = map[string]int{
  42. "kube-01": 1,
  43. "kube-02": 0,
  44. "kube-03": 0,
  45. "kube-04": 1,
  46. "kube-05": 0,
  47. "kube-06": 1,
  48. "kube-07": 0,
  49. "kube-08": 1,
  50. }
  51. var cores = map[string][]int{
  52. "kube-01": []int{20, 21, 22, 23},
  53. "kube-02": []int{2, 3, 4, 5, 6, 7, 8, 9},
  54. "kube-03": []int{40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55},
  55. "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},
  56. "kube-05": []int{0, 1, 2, 3},
  57. "kube-06": []int{12, 13, 14, 15, 16, 17, 18, 19},
  58. "kube-07": []int{4, 5, 6, 7, 8, 9, 10, 11, 24, 25, 26, 27, 28, 29, 30, 31},
  59. "kube-08": []int{20, 21, 22, 23, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47},
  60. }
  61. func readFile(cfg *Config, file string) error {
  62. f, err := os.Open(file)
  63. if err != nil {
  64. klog.Infof("Config file for scheduler not found. Error: %v", err)
  65. return err
  66. }
  67. defer f.Close()
  68. decoder := yaml.NewDecoder(f)
  69. err = decoder.Decode(&cfg)
  70. if err != nil {
  71. klog.Infof("Unable to decode the config file. Error: %v", err)
  72. return err
  73. }
  74. return nil
  75. }
  76. func connectToInfluxDB(cfg Config) (client.Client, error) {
  77. c, err := client.NewHTTPClient(client.HTTPConfig{
  78. Addr: "http://" + cfg.Server.Host + ":" + cfg.Server.Port + "",
  79. })
  80. if err != nil {
  81. klog.Infof("Error while connecting to InfluxDB: %v ", err.Error())
  82. return nil, err
  83. }
  84. klog.Infof("Connected Successfully to InfluxDB")
  85. return c, nil
  86. }