mock.go 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. package kubecost
  2. import (
  3. "fmt"
  4. "time"
  5. )
  6. const gb = 1024 * 1024 * 1024
  7. const day = 24 * time.Hour
  8. var disk = PVKey{}
  9. // NewMockUnitAllocation creates an *Allocation with all of its float64 values set to 1 and generic properties if not provided in arg
  10. func NewMockUnitAllocation(name string, start time.Time, resolution time.Duration, props *AllocationProperties) *Allocation {
  11. if name == "" {
  12. name = "cluster1/namespace1/pod1/container1"
  13. }
  14. properties := &AllocationProperties{}
  15. if props == nil {
  16. properties.Cluster = "cluster1"
  17. properties.Node = "node1"
  18. properties.Namespace = "namespace1"
  19. properties.ControllerKind = "deployment"
  20. properties.Controller = "deployment1"
  21. properties.Pod = "pod1"
  22. properties.Container = "container1"
  23. } else {
  24. properties = props
  25. }
  26. end := start.Add(resolution)
  27. alloc := &Allocation{
  28. Name: name,
  29. Properties: properties,
  30. Window: NewWindow(&start, &end).Clone(),
  31. Start: start,
  32. End: end,
  33. CPUCoreHours: 1,
  34. CPUCost: 1,
  35. CPUCoreRequestAverage: 1,
  36. CPUCoreUsageAverage: 1,
  37. GPUHours: 1,
  38. GPUCost: 1,
  39. NetworkCost: 1,
  40. LoadBalancerCost: 1,
  41. PVs: PVAllocations{
  42. disk: {
  43. ByteHours: 1,
  44. Cost: 1,
  45. },
  46. },
  47. RAMByteHours: 1,
  48. RAMCost: 1,
  49. RAMBytesRequestAverage: 1,
  50. RAMBytesUsageAverage: 1,
  51. RawAllocationOnly: &RawAllocationOnlyData{
  52. CPUCoreUsageMax: 1,
  53. RAMBytesUsageMax: 1,
  54. },
  55. }
  56. // If idle allocation, remove non-idle costs, but maintain total cost
  57. if alloc.IsIdle() {
  58. alloc.PVs = nil
  59. alloc.NetworkCost = 0.0
  60. alloc.LoadBalancerCost = 0.0
  61. alloc.CPUCoreHours += 1.0
  62. alloc.CPUCost += 1.0
  63. alloc.RAMByteHours += 1.0
  64. alloc.RAMCost += 1.0
  65. }
  66. return alloc
  67. }
  68. // GenerateMockAllocationSetClusterIdle creates generic allocation set which includes an idle set broken down by cluster
  69. func GenerateMockAllocationSetClusterIdle(start time.Time) *AllocationSet {
  70. // Cluster Idle allocations
  71. a1i := NewMockUnitAllocation(fmt.Sprintf("cluster1/%s", IdleSuffix), start, day, &AllocationProperties{
  72. Cluster: "cluster1",
  73. })
  74. a1i.CPUCost = 5.0
  75. a1i.RAMCost = 15.0
  76. a1i.GPUCost = 0.0
  77. a2i := NewMockUnitAllocation(fmt.Sprintf("cluster2/%s", IdleSuffix), start, day, &AllocationProperties{
  78. Cluster: "cluster2",
  79. })
  80. a2i.CPUCost = 5.0
  81. a2i.RAMCost = 5.0
  82. a2i.GPUCost = 0.0
  83. as := GenerateMockAllocationSet(start)
  84. as.Insert(a1i)
  85. as.Insert(a2i)
  86. return as
  87. }
  88. // GenerateMockAllocationSetNodeIdle creates generic allocation set which includes an idle set broken down by node
  89. func GenerateMockAllocationSetNodeIdle(start time.Time) *AllocationSet {
  90. // Node Idle allocations
  91. a11i := NewMockUnitAllocation(fmt.Sprintf("c1nodes/%s", IdleSuffix), start, day, &AllocationProperties{
  92. Cluster: "cluster1",
  93. Node: "c1nodes",
  94. ProviderID: "c1nodes",
  95. })
  96. a11i.CPUCost = 5.0
  97. a11i.RAMCost = 15.0
  98. a11i.GPUCost = 0.0
  99. a21i := NewMockUnitAllocation(fmt.Sprintf("node1/%s", IdleSuffix), start, day, &AllocationProperties{
  100. Cluster: "cluster2",
  101. Node: "node1",
  102. ProviderID: "node1",
  103. })
  104. a21i.CPUCost = 1.666667
  105. a21i.RAMCost = 1.666667
  106. a21i.GPUCost = 0.0
  107. a22i := NewMockUnitAllocation(fmt.Sprintf("node2/%s", IdleSuffix), start, day, &AllocationProperties{
  108. Cluster: "cluster2",
  109. Node: "node2",
  110. ProviderID: "node2",
  111. })
  112. a22i.CPUCost = 1.666667
  113. a22i.RAMCost = 1.666667
  114. a22i.GPUCost = 0.0
  115. a23i := NewMockUnitAllocation(fmt.Sprintf("node3/%s", IdleSuffix), start, day, &AllocationProperties{
  116. Cluster: "cluster2",
  117. Node: "node3",
  118. ProviderID: "node3",
  119. Namespace: "",
  120. })
  121. a23i.CPUCost = 1.666667
  122. a23i.RAMCost = 1.666667
  123. a23i.GPUCost = 0.0
  124. as := GenerateMockAllocationSet(start)
  125. as.Insert(a11i)
  126. as.Insert(a21i)
  127. as.Insert(a22i)
  128. as.Insert(a23i)
  129. return as
  130. }
  131. // GenerateMockAllocationSet creates generic allocation set without idle allocations
  132. func GenerateMockAllocationSet(start time.Time) *AllocationSet {
  133. // Active allocations
  134. a1111 := NewMockUnitAllocation("cluster1/namespace1/pod1/container1", start, day, &AllocationProperties{
  135. Cluster: "cluster1",
  136. Namespace: "namespace1",
  137. Pod: "pod1",
  138. Container: "container1",
  139. ProviderID: "c1nodes",
  140. })
  141. a1111.RAMCost = 11.00
  142. a11abc2 := NewMockUnitAllocation("cluster1/namespace1/pod-abc/container2", start, day, &AllocationProperties{
  143. Cluster: "cluster1",
  144. Namespace: "namespace1",
  145. Pod: "pod-abc",
  146. Container: "container2",
  147. ProviderID: "c1nodes",
  148. })
  149. a11def3 := NewMockUnitAllocation("cluster1/namespace1/pod-def/container3", start, day, &AllocationProperties{
  150. Cluster: "cluster1",
  151. Namespace: "namespace1",
  152. Pod: "pod-def",
  153. Container: "container3",
  154. ProviderID: "c1nodes",
  155. })
  156. a12ghi4 := NewMockUnitAllocation("cluster1/namespace2/pod-ghi/container4", start, day, &AllocationProperties{
  157. Cluster: "cluster1",
  158. Namespace: "namespace2",
  159. Pod: "pod-ghi",
  160. Container: "container4",
  161. ProviderID: "c1nodes",
  162. })
  163. a12ghi5 := NewMockUnitAllocation("cluster1/namespace2/pod-ghi/container5", start, day, &AllocationProperties{
  164. Cluster: "cluster1",
  165. Namespace: "namespace2",
  166. Pod: "pod-ghi",
  167. Container: "container5",
  168. ProviderID: "c1nodes",
  169. })
  170. a12jkl6 := NewMockUnitAllocation("cluster1/namespace2/pod-jkl/container6", start, day, &AllocationProperties{
  171. Cluster: "cluster1",
  172. Namespace: "namespace2",
  173. Pod: "pod-jkl",
  174. Container: "container6",
  175. ProviderID: "c1nodes",
  176. })
  177. a22mno4 := NewMockUnitAllocation("cluster2/namespace2/pod-mno/container4", start, day, &AllocationProperties{
  178. Cluster: "cluster2",
  179. Namespace: "namespace2",
  180. Pod: "pod-mno",
  181. Container: "container4",
  182. ProviderID: "node1",
  183. })
  184. a22mno5 := NewMockUnitAllocation("cluster2/namespace2/pod-mno/container5", start, day, &AllocationProperties{
  185. Cluster: "cluster2",
  186. Namespace: "namespace2",
  187. Pod: "pod-mno",
  188. Container: "container5",
  189. ProviderID: "node1",
  190. })
  191. a22pqr6 := NewMockUnitAllocation("cluster2/namespace2/pod-pqr/container6", start, day, &AllocationProperties{
  192. Cluster: "cluster2",
  193. Namespace: "namespace2",
  194. Pod: "pod-pqr",
  195. Container: "container6",
  196. ProviderID: "node2",
  197. })
  198. a23stu7 := NewMockUnitAllocation("cluster2/namespace3/pod-stu/container7", start, day, &AllocationProperties{
  199. Cluster: "cluster2",
  200. Namespace: "namespace3",
  201. Pod: "pod-stu",
  202. Container: "container7",
  203. ProviderID: "node2",
  204. })
  205. a23vwx8 := NewMockUnitAllocation("cluster2/namespace3/pod-vwx/container8", start, day, &AllocationProperties{
  206. Cluster: "cluster2",
  207. Namespace: "namespace3",
  208. Pod: "pod-vwx",
  209. Container: "container8",
  210. ProviderID: "node3",
  211. })
  212. a23vwx9 := NewMockUnitAllocation("cluster2/namespace3/pod-vwx/container9", start, day, &AllocationProperties{
  213. Cluster: "cluster2",
  214. Namespace: "namespace3",
  215. Pod: "pod-vwx",
  216. Container: "container9",
  217. ProviderID: "node3",
  218. })
  219. // Controllers
  220. a11abc2.Properties.ControllerKind = "deployment"
  221. a11abc2.Properties.Controller = "deployment1"
  222. a11def3.Properties.ControllerKind = "deployment"
  223. a11def3.Properties.Controller = "deployment1"
  224. a12ghi4.Properties.ControllerKind = "deployment"
  225. a12ghi4.Properties.Controller = "deployment2"
  226. a12ghi5.Properties.ControllerKind = "deployment"
  227. a12ghi5.Properties.Controller = "deployment2"
  228. a22mno4.Properties.ControllerKind = "deployment"
  229. a22mno4.Properties.Controller = "deployment2"
  230. a22mno5.Properties.ControllerKind = "deployment"
  231. a22mno5.Properties.Controller = "deployment2"
  232. a23stu7.Properties.ControllerKind = "deployment"
  233. a23stu7.Properties.Controller = "deployment3"
  234. a12jkl6.Properties.ControllerKind = "daemonset"
  235. a12jkl6.Properties.Controller = "daemonset1"
  236. a22pqr6.Properties.ControllerKind = "daemonset"
  237. a22pqr6.Properties.Controller = "daemonset1"
  238. a23vwx8.Properties.ControllerKind = "statefulset"
  239. a23vwx8.Properties.Controller = "statefulset1"
  240. a23vwx9.Properties.ControllerKind = "statefulset"
  241. a23vwx9.Properties.Controller = "statefulset1"
  242. // Labels
  243. a1111.Properties.Labels = map[string]string{"app": "app1", "env": "env1"}
  244. a12ghi4.Properties.Labels = map[string]string{"app": "app2", "env": "env2"}
  245. a12ghi5.Properties.Labels = map[string]string{"app": "app2", "env": "env2"}
  246. a22mno4.Properties.Labels = map[string]string{"app": "app2"}
  247. a22mno5.Properties.Labels = map[string]string{"app": "app2"}
  248. //Annotations
  249. a23stu7.Properties.Annotations = map[string]string{"team": "team1"}
  250. a23vwx8.Properties.Annotations = map[string]string{"team": "team2"}
  251. a23vwx9.Properties.Annotations = map[string]string{"team": "team1"}
  252. // Services
  253. a12jkl6.Properties.Services = []string{"service1"}
  254. a22pqr6.Properties.Services = []string{"service1"}
  255. return NewAllocationSet(start, start.Add(day),
  256. // cluster 1, namespace1
  257. a1111, a11abc2, a11def3,
  258. // cluster 1, namespace 2
  259. a12ghi4, a12ghi5, a12jkl6,
  260. // cluster 2, namespace 2
  261. a22mno4, a22mno5, a22pqr6,
  262. // cluster 2, namespace 3
  263. a23stu7, a23vwx8, a23vwx9,
  264. )
  265. }
  266. // GenerateMockAllocationSetWithAssetProperties with no idle and connections to Assets in properties
  267. func GenerateMockAllocationSetWithAssetProperties(start time.Time) *AllocationSet {
  268. as := GenerateMockAllocationSet(start)
  269. disk1 := PVKey{
  270. Cluster: "cluster2",
  271. Name: "disk1",
  272. }
  273. disk2 := PVKey{
  274. Cluster: "cluster2",
  275. Name: "disk2",
  276. }
  277. for _, a := range as.allocations {
  278. // add reconcilable pvs to pod-mno
  279. if a.Properties.Pod == "pod-mno" {
  280. a.PVs = a.PVs.Add(PVAllocations{
  281. disk1: {
  282. Cost: 2.5,
  283. ByteHours: 2.5 * gb,
  284. },
  285. disk2: {
  286. Cost: 5,
  287. ByteHours: 5 * gb,
  288. },
  289. })
  290. }
  291. // add loadBalancer service to allocations
  292. if a.Name == "cluster2/namespace2/pod-mno/container4" {
  293. a.Properties.Services = append(a.Properties.Services, "loadBalancer1")
  294. }
  295. if a.Name == "cluster2/namespace2/pod-mno/container5" {
  296. a.Properties.Services = append(a.Properties.Services, "loadBalancer2")
  297. }
  298. if a.Name == "cluster2/namespace2/pod-pqr/container6" {
  299. a.Properties.Services = append(a.Properties.Services, "loadBalancer1")
  300. a.Properties.Services = append(a.Properties.Services, "loadBalancer2")
  301. }
  302. }
  303. return as
  304. }
  305. // GenerateMockAssetSets creates generic AssetSets
  306. func GenerateMockAssetSets(start, end time.Time) []*AssetSet {
  307. var assetSets []*AssetSet
  308. // Create an AssetSet representing cluster costs for two clusters (cluster1
  309. // and cluster2). Include Nodes and Disks for both, even though only
  310. // Nodes will be counted. Whereas in practice, Assets should be aggregated
  311. // by type, here we will provide multiple Nodes for one of the clusters to
  312. // make sure the function still holds.
  313. // NOTE: we're re-using GenerateMockAllocationSet so this has to line up with
  314. // the allocated node costs from that function. See table above.
  315. // | Hierarchy | Cost | CPU | RAM | GPU | Adjustment |
  316. // +-----------------------------------------+------+------+------+------+------------+
  317. // cluster1:
  318. // nodes 100.00 55.00 44.00 11.00 -10.00
  319. // +-----------------------------------------+------+------+------+------+------------+
  320. // cluster1 subtotal (adjusted) 100.00 50.00 40.00 10.00 0.00
  321. // +-----------------------------------------+------+------+------+------+------------+
  322. // cluster1 allocated 48.00 6.00 16.00 6.00 0.00
  323. // +-----------------------------------------+------+------+------+------+------------+
  324. // cluster1 idle 72.00 44.00 24.00 4.00 0.00
  325. // +-----------------------------------------+------+------+------+------+------------+
  326. // cluster2:
  327. // node1 35.00 20.00 15.00 0.00 0.00
  328. // node2 35.00 20.00 15.00 0.00 0.00
  329. // node3 30.00 10.00 10.00 10.00 0.00
  330. // (disks should not matter for idle)
  331. // +-----------------------------------------+------+------+------+------+------------+
  332. // cluster2 subtotal 100.00 50.00 40.00 10.00 0.00
  333. // +-----------------------------------------+------+------+------+------+------------+
  334. // cluster2 allocated 28.00 6.00 6.00 6.00 0.00
  335. // +-----------------------------------------+------+------+------+------+------------+
  336. // cluster2 idle 82.00 44.00 34.00 4.00 0.00
  337. // +-----------------------------------------+------+------+------+------+------------+
  338. cluster1Nodes := NewNode("c1nodes", "cluster1", "c1nodes", start, end, NewWindow(&start, &end))
  339. cluster1Nodes.CPUCost = 55.0
  340. cluster1Nodes.RAMCost = 44.0
  341. cluster1Nodes.GPUCost = 11.0
  342. cluster1Nodes.adjustment = -10.00
  343. cluster1Nodes.CPUCoreHours = 8
  344. cluster1Nodes.RAMByteHours = 6
  345. cluster1Nodes.GPUHours = 24
  346. cluster2Node1 := NewNode("node1", "cluster2", "node1", start, end, NewWindow(&start, &end))
  347. cluster2Node1.CPUCost = 20.0
  348. cluster2Node1.RAMCost = 15.0
  349. cluster2Node1.GPUCost = 0.0
  350. cluster2Node1.CPUCoreHours = 4
  351. cluster2Node1.RAMByteHours = 3
  352. cluster2Node1.GPUHours = 0
  353. cluster2Node2 := NewNode("node2", "cluster2", "node2", start, end, NewWindow(&start, &end))
  354. cluster2Node2.CPUCost = 20.0
  355. cluster2Node2.RAMCost = 15.0
  356. cluster2Node2.GPUCost = 0.0
  357. cluster2Node2.CPUCoreHours = 3
  358. cluster2Node2.RAMByteHours = 2
  359. cluster2Node2.GPUHours = 0
  360. cluster2Node3 := NewNode("node3", "cluster2", "node3", start, end, NewWindow(&start, &end))
  361. cluster2Node3.CPUCost = 10.0
  362. cluster2Node3.RAMCost = 10.0
  363. cluster2Node3.GPUCost = 10.0
  364. cluster2Node3.CPUCoreHours = 2
  365. cluster2Node3.RAMByteHours = 2
  366. cluster2Node3.GPUHours = 24
  367. // Add PVs
  368. cluster2Disk1 := NewDisk("disk1", "cluster2", "disk1", start, end, NewWindow(&start, &end))
  369. cluster2Disk1.Cost = 5.0
  370. cluster2Disk1.adjustment = 1.0
  371. cluster2Disk1.ByteHours = 5 * gb
  372. cluster2Disk2 := NewDisk("disk2", "cluster2", "disk2", start, end, NewWindow(&start, &end))
  373. cluster2Disk2.Cost = 10.0
  374. cluster2Disk2.adjustment = 3.0
  375. cluster2Disk2.ByteHours = 10 * gb
  376. cluster2Node1Disk := NewDisk("node1", "cluster2", "node1", start, end, NewWindow(&start, &end))
  377. cluster2Node1Disk.Cost = 1.0
  378. cluster2Node1Disk.ByteHours = 5 * gb
  379. // Add Attached Disks
  380. cluster2Node2Disk := NewDisk("node2", "cluster2", "node2", start, end, NewWindow(&start, &end))
  381. cluster2Node2Disk.Cost = 2.0
  382. cluster2Node2Disk.ByteHours = 5 * gb
  383. cluster2Node3Disk := NewDisk("node3", "cluster2", "node3", start, end, NewWindow(&start, &end))
  384. cluster2Node3Disk.Cost = 3.0
  385. cluster2Node3Disk.ByteHours = 5 * gb
  386. // Add Cluster Management
  387. cluster1ClusterManagement := NewClusterManagement("", "cluster1", NewWindow(&start, &end))
  388. cluster1ClusterManagement.Cost = 2.0
  389. cluster2ClusterManagement := NewClusterManagement("", "cluster2", NewWindow(&start, &end))
  390. cluster2ClusterManagement.Cost = 2.0
  391. // Add Networks
  392. c1Network := NewNetwork("", "cluster1", "c1nodes", start, end, NewWindow(&start, &end))
  393. c1Network.Cost = 3.0
  394. node1Network := NewNetwork("node1", "cluster2", "node1", start, end, NewWindow(&start, &end))
  395. node1Network.Cost = 4.0
  396. node2Network := NewNetwork("node2", "cluster2", "node2", start, end, NewWindow(&start, &end))
  397. node2Network.Cost = 5.0
  398. node3Network := NewNetwork("node3", "cluster2", "node3", start, end, NewWindow(&start, &end))
  399. node3Network.Cost = 2.0
  400. // Add LoadBalancers
  401. cluster2LoadBalancer1 := NewLoadBalancer("namespace2/loadBalancer1", "cluster2", "lb1", start, end, NewWindow(&start, &end))
  402. cluster2LoadBalancer1.Cost = 10.0
  403. cluster2LoadBalancer2 := NewLoadBalancer("namespace2/loadBalancer2", "cluster2", "lb2", start, end, NewWindow(&start, &end))
  404. cluster2LoadBalancer2.Cost = 15.0
  405. assetSet1 := NewAssetSet(start, end, cluster1Nodes, cluster2Node1, cluster2Node2, cluster2Node3, cluster2Disk1,
  406. cluster2Disk2, cluster2Node1Disk, cluster2Node2Disk, cluster2Node3Disk, cluster1ClusterManagement,
  407. cluster2ClusterManagement, c1Network, node1Network, node2Network, node3Network, cluster2LoadBalancer1, cluster2LoadBalancer2)
  408. assetSets = append(assetSets, assetSet1)
  409. // NOTE: we're re-using GenerateMockAllocationSet so this has to line up with
  410. // the allocated node costs from that function. See table above.
  411. // | Hierarchy | Cost | CPU | RAM | GPU | Adjustment |
  412. // +-----------------------------------------+------+------+------+------+------------+
  413. // cluster1:
  414. // nodes 100.00 5.00 4.00 1.00 90.00
  415. // +-----------------------------------------+------+------+------+------+------------+
  416. // cluster1 subtotal (adjusted) 100.00 50.00 40.00 10.00 0.00
  417. // +-----------------------------------------+------+------+------+------+------------+
  418. // cluster1 allocated 48.00 6.00 16.00 6.00 0.00
  419. // +-----------------------------------------+------+------+------+------+------------+
  420. // cluster1 idle 72.00 44.00 24.00 4.00 0.00
  421. // +-----------------------------------------+------+------+------+------+------------+
  422. // cluster2:
  423. // node1 35.00 20.00 15.00 0.00 0.00
  424. // node2 35.00 20.00 15.00 0.00 0.00
  425. // node3 30.00 10.00 10.00 10.00 0.00
  426. // (disks should not matter for idle)
  427. // +-----------------------------------------+------+------+------+------+------------+
  428. // cluster2 subtotal 100.00 50.00 40.00 10.00 0.00
  429. // +-----------------------------------------+------+------+------+------+------------+
  430. // cluster2 allocated 28.00 6.00 6.00 6.00 0.00
  431. // +-----------------------------------------+------+------+------+------+------------+
  432. // cluster2 idle 82.00 44.00 34.00 4.00 0.00
  433. // +-----------------------------------------+------+------+------+------+------------+
  434. cluster1Nodes = NewNode("", "cluster1", "c1nodes", start, end, NewWindow(&start, &end))
  435. cluster1Nodes.CPUCost = 5.0
  436. cluster1Nodes.RAMCost = 4.0
  437. cluster1Nodes.GPUCost = 1.0
  438. cluster1Nodes.adjustment = 90.00
  439. cluster1Nodes.CPUCoreHours = 8
  440. cluster1Nodes.RAMByteHours = 6
  441. cluster1Nodes.GPUHours = 24
  442. cluster2Node1 = NewNode("node1", "cluster2", "node1", start, end, NewWindow(&start, &end))
  443. cluster2Node1.CPUCost = 20.0
  444. cluster2Node1.RAMCost = 15.0
  445. cluster2Node1.GPUCost = 0.0
  446. cluster2Node1.CPUCoreHours = 4
  447. cluster2Node1.RAMByteHours = 3
  448. cluster2Node1.GPUHours = 0
  449. cluster2Node2 = NewNode("node2", "cluster2", "node2", start, end, NewWindow(&start, &end))
  450. cluster2Node2.CPUCost = 20.0
  451. cluster2Node2.RAMCost = 15.0
  452. cluster2Node2.GPUCost = 0.0
  453. cluster2Node2.CPUCoreHours = 3
  454. cluster2Node2.RAMByteHours = 2
  455. cluster2Node2.GPUHours = 0
  456. cluster2Node3 = NewNode("node3", "cluster2", "node3", start, end, NewWindow(&start, &end))
  457. cluster2Node3.CPUCost = 10.0
  458. cluster2Node3.RAMCost = 10.0
  459. cluster2Node3.GPUCost = 10.0
  460. cluster2Node3.CPUCoreHours = 2
  461. cluster2Node3.RAMByteHours = 2
  462. cluster2Node3.GPUHours = 24
  463. // Add PVs
  464. cluster2Disk1 = NewDisk("disk1", "cluster2", "disk1", start, end, NewWindow(&start, &end))
  465. cluster2Disk1.Cost = 5.0
  466. cluster2Disk1.adjustment = 1.0
  467. cluster2Disk1.ByteHours = 5 * gb
  468. cluster2Disk2 = NewDisk("disk2", "cluster2", "disk2", start, end, NewWindow(&start, &end))
  469. cluster2Disk2.Cost = 12.0
  470. cluster2Disk2.adjustment = 4.0
  471. cluster2Disk2.ByteHours = 20 * gb
  472. assetSet2 := NewAssetSet(start, end, cluster1Nodes, cluster2Node1, cluster2Node2, cluster2Node3, cluster2Disk1,
  473. cluster2Disk2, cluster2Node1Disk, cluster2Node2Disk, cluster2Node3Disk, cluster1ClusterManagement,
  474. cluster2ClusterManagement, c1Network, node1Network, node2Network, node3Network, cluster2LoadBalancer1, cluster2LoadBalancer2)
  475. assetSets = append(assetSets, assetSet2)
  476. return assetSets
  477. }
  478. // GenerateMockAssetSet generates the following topology:
  479. //
  480. // | Asset | Cost | Adj |
  481. // +------------------------------+------+------+
  482. // cluster1:
  483. // node1: 6.00 1.00
  484. // node2: 4.00 1.50
  485. // node3: 7.00 -0.50
  486. // disk1: 2.50 0.00
  487. // disk2: 1.50 0.00
  488. // clusterManagement1: 3.00 0.00
  489. // +------------------------------+------+------+
  490. // cluster1 subtotal 24.00 2.00
  491. // +------------------------------+------+------+
  492. // cluster2:
  493. // node4: 12.00 -1.00
  494. // disk3: 2.50 0.00
  495. // disk4: 1.50 0.00
  496. // clusterManagement2: 0.00 0.00
  497. // +------------------------------+------+------+
  498. // cluster2 subtotal 16.00 -1.00
  499. // +------------------------------+------+------+
  500. // cluster3:
  501. // node5: 17.00 2.00
  502. // +------------------------------+------+------+
  503. // cluster3 subtotal 17.00 2.00
  504. // +------------------------------+------+------+
  505. // total 57.00 3.00
  506. // +------------------------------+------+------+
  507. func GenerateMockAssetSet(start time.Time) *AssetSet {
  508. end := start.Add(day)
  509. window := NewWindow(&start, &end)
  510. hours := window.Duration().Hours()
  511. node1 := NewNode("node1", "cluster1", "gcp-node1", *window.Clone().start, *window.Clone().end, window.Clone())
  512. node1.CPUCost = 4.0
  513. node1.RAMCost = 4.0
  514. node1.GPUCost = 2.0
  515. node1.Discount = 0.5
  516. node1.CPUCoreHours = 2.0 * hours
  517. node1.RAMByteHours = 4.0 * gb * hours
  518. node1.GPUHours = 1.0 * hours
  519. node1.SetAdjustment(1.0)
  520. node1.SetLabels(map[string]string{"test": "test"})
  521. node2 := NewNode("node2", "cluster1", "gcp-node2", *window.Clone().start, *window.Clone().end, window.Clone())
  522. node2.CPUCost = 4.0
  523. node2.RAMCost = 4.0
  524. node2.GPUCost = 0.0
  525. node2.Discount = 0.5
  526. node2.CPUCoreHours = 2.0 * hours
  527. node2.RAMByteHours = 4.0 * gb * hours
  528. node2.GPUHours = 0.0 * hours
  529. node2.SetAdjustment(1.5)
  530. node3 := NewNode("node3", "cluster1", "gcp-node3", *window.Clone().start, *window.Clone().end, window.Clone())
  531. node3.CPUCost = 4.0
  532. node3.RAMCost = 4.0
  533. node3.GPUCost = 3.0
  534. node3.Discount = 0.5
  535. node3.CPUCoreHours = 2.0 * hours
  536. node3.RAMByteHours = 4.0 * gb * hours
  537. node3.GPUHours = 2.0 * hours
  538. node3.SetAdjustment(-0.5)
  539. node4 := NewNode("node4", "cluster2", "gcp-node4", *window.Clone().start, *window.Clone().end, window.Clone())
  540. node4.CPUCost = 10.0
  541. node4.RAMCost = 6.0
  542. node4.GPUCost = 0.0
  543. node4.Discount = 0.25
  544. node4.CPUCoreHours = 4.0 * hours
  545. node4.RAMByteHours = 12.0 * gb * hours
  546. node4.GPUHours = 0.0 * hours
  547. node4.SetAdjustment(-1.0)
  548. node5 := NewNode("node5", "cluster3", "aws-node5", *window.Clone().start, *window.Clone().end, window.Clone())
  549. node5.CPUCost = 10.0
  550. node5.RAMCost = 7.0
  551. node5.GPUCost = 0.0
  552. node5.Discount = 0.0
  553. node5.CPUCoreHours = 8.0 * hours
  554. node5.RAMByteHours = 24.0 * gb * hours
  555. node5.GPUHours = 0.0 * hours
  556. node5.SetAdjustment(2.0)
  557. disk1 := NewDisk("disk1", "cluster1", "gcp-disk1", *window.Clone().start, *window.Clone().end, window.Clone())
  558. disk1.Cost = 2.5
  559. disk1.ByteHours = 100 * gb * hours
  560. disk2 := NewDisk("disk2", "cluster1", "gcp-disk2", *window.Clone().start, *window.Clone().end, window.Clone())
  561. disk2.Cost = 1.5
  562. disk2.ByteHours = 60 * gb * hours
  563. disk3 := NewDisk("disk3", "cluster2", "gcp-disk3", *window.Clone().start, *window.Clone().end, window.Clone())
  564. disk3.Cost = 2.5
  565. disk3.ByteHours = 100 * gb * hours
  566. disk4 := NewDisk("disk4", "cluster2", "gcp-disk4", *window.Clone().start, *window.Clone().end, window.Clone())
  567. disk4.Cost = 1.5
  568. disk4.ByteHours = 100 * gb * hours
  569. cm1 := NewClusterManagement("gcp", "cluster1", window.Clone())
  570. cm1.Cost = 3.0
  571. cm2 := NewClusterManagement("gcp", "cluster2", window.Clone())
  572. cm2.Cost = 0.0
  573. return NewAssetSet(
  574. start, end,
  575. // cluster 1
  576. node1, node2, node3, disk1, disk2, cm1,
  577. // cluster 2
  578. node4, disk3, disk4, cm2,
  579. // cluster 3
  580. node5,
  581. )
  582. }