mock.go 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  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. Node: "c1nodes",
  141. })
  142. a1111.RAMCost = 11.00
  143. a11abc2 := NewMockUnitAllocation("cluster1/namespace1/pod-abc/container2", start, day, &AllocationProperties{
  144. Cluster: "cluster1",
  145. Namespace: "namespace1",
  146. Pod: "pod-abc",
  147. Container: "container2",
  148. ProviderID: "c1nodes",
  149. Node: "c1nodes",
  150. })
  151. a11def3 := NewMockUnitAllocation("cluster1/namespace1/pod-def/container3", start, day, &AllocationProperties{
  152. Cluster: "cluster1",
  153. Namespace: "namespace1",
  154. Pod: "pod-def",
  155. Container: "container3",
  156. ProviderID: "c1nodes",
  157. Node: "c1nodes",
  158. })
  159. a12ghi4 := NewMockUnitAllocation("cluster1/namespace2/pod-ghi/container4", start, day, &AllocationProperties{
  160. Cluster: "cluster1",
  161. Namespace: "namespace2",
  162. Pod: "pod-ghi",
  163. Container: "container4",
  164. ProviderID: "c1nodes",
  165. Node: "c1nodes",
  166. })
  167. a12ghi5 := NewMockUnitAllocation("cluster1/namespace2/pod-ghi/container5", start, day, &AllocationProperties{
  168. Cluster: "cluster1",
  169. Namespace: "namespace2",
  170. Pod: "pod-ghi",
  171. Container: "container5",
  172. ProviderID: "c1nodes",
  173. Node: "c1nodes",
  174. })
  175. a12jkl6 := NewMockUnitAllocation("cluster1/namespace2/pod-jkl/container6", start, day, &AllocationProperties{
  176. Cluster: "cluster1",
  177. Namespace: "namespace2",
  178. Pod: "pod-jkl",
  179. Container: "container6",
  180. ProviderID: "c1nodes",
  181. Node: "c1nodes",
  182. })
  183. a22mno4 := NewMockUnitAllocation("cluster2/namespace2/pod-mno/container4", start, day, &AllocationProperties{
  184. Cluster: "cluster2",
  185. Namespace: "namespace2",
  186. Pod: "pod-mno",
  187. Container: "container4",
  188. ProviderID: "node1",
  189. Node: "node1",
  190. })
  191. a22mno5 := NewMockUnitAllocation("cluster2/namespace2/pod-mno/container5", start, day, &AllocationProperties{
  192. Cluster: "cluster2",
  193. Namespace: "namespace2",
  194. Pod: "pod-mno",
  195. Container: "container5",
  196. ProviderID: "node1",
  197. Node: "node1",
  198. })
  199. a22pqr6 := NewMockUnitAllocation("cluster2/namespace2/pod-pqr/container6", start, day, &AllocationProperties{
  200. Cluster: "cluster2",
  201. Namespace: "namespace2",
  202. Pod: "pod-pqr",
  203. Container: "container6",
  204. ProviderID: "node2",
  205. Node: "node2",
  206. })
  207. a23stu7 := NewMockUnitAllocation("cluster2/namespace3/pod-stu/container7", start, day, &AllocationProperties{
  208. Cluster: "cluster2",
  209. Namespace: "namespace3",
  210. Pod: "pod-stu",
  211. Container: "container7",
  212. ProviderID: "node2",
  213. Node: "node2",
  214. })
  215. a23vwx8 := NewMockUnitAllocation("cluster2/namespace3/pod-vwx/container8", start, day, &AllocationProperties{
  216. Cluster: "cluster2",
  217. Namespace: "namespace3",
  218. Pod: "pod-vwx",
  219. Container: "container8",
  220. ProviderID: "node3",
  221. Node: "node3",
  222. })
  223. a23vwx9 := NewMockUnitAllocation("cluster2/namespace3/pod-vwx/container9", start, day, &AllocationProperties{
  224. Cluster: "cluster2",
  225. Namespace: "namespace3",
  226. Pod: "pod-vwx",
  227. Container: "container9",
  228. ProviderID: "node3",
  229. Node: "node3",
  230. })
  231. // Controllers
  232. a11abc2.Properties.ControllerKind = "deployment"
  233. a11abc2.Properties.Controller = "deployment1"
  234. a11def3.Properties.ControllerKind = "deployment"
  235. a11def3.Properties.Controller = "deployment1"
  236. a12ghi4.Properties.ControllerKind = "deployment"
  237. a12ghi4.Properties.Controller = "deployment2"
  238. a12ghi5.Properties.ControllerKind = "deployment"
  239. a12ghi5.Properties.Controller = "deployment2"
  240. a22mno4.Properties.ControllerKind = "deployment"
  241. a22mno4.Properties.Controller = "deployment2"
  242. a22mno5.Properties.ControllerKind = "deployment"
  243. a22mno5.Properties.Controller = "deployment2"
  244. a23stu7.Properties.ControllerKind = "deployment"
  245. a23stu7.Properties.Controller = "deployment3"
  246. a12jkl6.Properties.ControllerKind = "daemonset"
  247. a12jkl6.Properties.Controller = "daemonset1"
  248. a22pqr6.Properties.ControllerKind = "daemonset"
  249. a22pqr6.Properties.Controller = "daemonset1"
  250. a23vwx8.Properties.ControllerKind = "statefulset"
  251. a23vwx8.Properties.Controller = "statefulset1"
  252. a23vwx9.Properties.ControllerKind = "statefulset"
  253. a23vwx9.Properties.Controller = "statefulset1"
  254. // Labels
  255. a1111.Properties.Labels = map[string]string{"app": "app1", "env": "env1"}
  256. a12ghi4.Properties.Labels = map[string]string{"app": "app2", "env": "env2"}
  257. a12ghi5.Properties.Labels = map[string]string{"app": "app2", "env": "env2"}
  258. a22mno4.Properties.Labels = map[string]string{"app": "app2"}
  259. a22mno5.Properties.Labels = map[string]string{"app": "app2"}
  260. //Annotations
  261. a23stu7.Properties.Annotations = map[string]string{"team": "team1"}
  262. a23vwx8.Properties.Annotations = map[string]string{"team": "team2"}
  263. a23vwx9.Properties.Annotations = map[string]string{"team": "team1"}
  264. // Services
  265. a12jkl6.Properties.Services = []string{"service1"}
  266. a22pqr6.Properties.Services = []string{"service1"}
  267. return NewAllocationSet(start, start.Add(day),
  268. // cluster 1, namespace1
  269. a1111, a11abc2, a11def3,
  270. // cluster 1, namespace 2
  271. a12ghi4, a12ghi5, a12jkl6,
  272. // cluster 2, namespace 2
  273. a22mno4, a22mno5, a22pqr6,
  274. // cluster 2, namespace 3
  275. a23stu7, a23vwx8, a23vwx9,
  276. )
  277. }
  278. // GenerateMockAllocationSetWithAssetProperties with no idle and connections to Assets in properties
  279. func GenerateMockAllocationSetWithAssetProperties(start time.Time) *AllocationSet {
  280. as := GenerateMockAllocationSet(start)
  281. disk1 := PVKey{
  282. Cluster: "cluster2",
  283. Name: "disk1",
  284. }
  285. disk2 := PVKey{
  286. Cluster: "cluster2",
  287. Name: "disk2",
  288. }
  289. for _, a := range as.allocations {
  290. // add reconcilable pvs to pod-mno
  291. if a.Properties.Pod == "pod-mno" {
  292. a.PVs = a.PVs.Add(PVAllocations{
  293. disk1: {
  294. Cost: 2.5,
  295. ByteHours: 2.5 * gb,
  296. },
  297. disk2: {
  298. Cost: 5,
  299. ByteHours: 5 * gb,
  300. },
  301. })
  302. }
  303. // add loadBalancer service to allocations
  304. if a.Name == "cluster2/namespace2/pod-mno/container4" {
  305. a.Properties.Services = append(a.Properties.Services, "loadBalancer1")
  306. }
  307. if a.Name == "cluster2/namespace2/pod-mno/container5" {
  308. a.Properties.Services = append(a.Properties.Services, "loadBalancer2")
  309. }
  310. if a.Name == "cluster2/namespace2/pod-pqr/container6" {
  311. a.Properties.Services = append(a.Properties.Services, "loadBalancer1")
  312. a.Properties.Services = append(a.Properties.Services, "loadBalancer2")
  313. }
  314. }
  315. return as
  316. }
  317. // GenerateMockAssetSets creates generic AssetSets
  318. func GenerateMockAssetSets(start, end time.Time) []*AssetSet {
  319. var assetSets []*AssetSet
  320. // Create an AssetSet representing cluster costs for two clusters (cluster1
  321. // and cluster2). Include Nodes and Disks for both, even though only
  322. // Nodes will be counted. Whereas in practice, Assets should be aggregated
  323. // by type, here we will provide multiple Nodes for one of the clusters to
  324. // make sure the function still holds.
  325. // NOTE: we're re-using GenerateMockAllocationSet so this has to line up with
  326. // the allocated node costs from that function. See table above.
  327. // | Hierarchy | Cost | CPU | RAM | GPU | Adjustment |
  328. // +-----------------------------------------+------+------+------+------+------------+
  329. // cluster1:
  330. // nodes 100.00 55.00 44.00 11.00 -10.00
  331. // +-----------------------------------------+------+------+------+------+------------+
  332. // cluster1 subtotal (adjusted) 100.00 50.00 40.00 10.00 0.00
  333. // +-----------------------------------------+------+------+------+------+------------+
  334. // cluster1 allocated 48.00 6.00 16.00 6.00 0.00
  335. // +-----------------------------------------+------+------+------+------+------------+
  336. // cluster1 idle 72.00 44.00 24.00 4.00 0.00
  337. // +-----------------------------------------+------+------+------+------+------------+
  338. // cluster2:
  339. // node1 35.00 20.00 15.00 0.00 0.00
  340. // node2 35.00 20.00 15.00 0.00 0.00
  341. // node3 30.00 10.00 10.00 10.00 0.00
  342. // (disks should not matter for idle)
  343. // +-----------------------------------------+------+------+------+------+------------+
  344. // cluster2 subtotal 100.00 50.00 40.00 10.00 0.00
  345. // +-----------------------------------------+------+------+------+------+------------+
  346. // cluster2 allocated 28.00 6.00 6.00 6.00 0.00
  347. // +-----------------------------------------+------+------+------+------+------------+
  348. // cluster2 idle 82.00 44.00 34.00 4.00 0.00
  349. // +-----------------------------------------+------+------+------+------+------------+
  350. cluster1Nodes := NewNode("c1nodes", "cluster1", "c1nodes", start, end, NewWindow(&start, &end))
  351. cluster1Nodes.CPUCost = 55.0
  352. cluster1Nodes.RAMCost = 44.0
  353. cluster1Nodes.GPUCost = 11.0
  354. cluster1Nodes.adjustment = -10.00
  355. cluster1Nodes.CPUCoreHours = 8
  356. cluster1Nodes.RAMByteHours = 6
  357. cluster1Nodes.GPUHours = 24
  358. cluster2Node1 := NewNode("node1", "cluster2", "node1", start, end, NewWindow(&start, &end))
  359. cluster2Node1.CPUCost = 20.0
  360. cluster2Node1.RAMCost = 15.0
  361. cluster2Node1.GPUCost = 0.0
  362. cluster2Node1.CPUCoreHours = 4
  363. cluster2Node1.RAMByteHours = 3
  364. cluster2Node1.GPUHours = 0
  365. cluster2Node2 := NewNode("node2", "cluster2", "node2", start, end, NewWindow(&start, &end))
  366. cluster2Node2.CPUCost = 20.0
  367. cluster2Node2.RAMCost = 15.0
  368. cluster2Node2.GPUCost = 0.0
  369. cluster2Node2.CPUCoreHours = 3
  370. cluster2Node2.RAMByteHours = 2
  371. cluster2Node2.GPUHours = 0
  372. cluster2Node3 := NewNode("node3", "cluster2", "node3", start, end, NewWindow(&start, &end))
  373. cluster2Node3.CPUCost = 10.0
  374. cluster2Node3.RAMCost = 10.0
  375. cluster2Node3.GPUCost = 10.0
  376. cluster2Node3.CPUCoreHours = 2
  377. cluster2Node3.RAMByteHours = 2
  378. cluster2Node3.GPUHours = 24
  379. // Add PVs
  380. cluster2Disk1 := NewDisk("disk1", "cluster2", "disk1", start, end, NewWindow(&start, &end))
  381. cluster2Disk1.Cost = 5.0
  382. cluster2Disk1.adjustment = 1.0
  383. cluster2Disk1.ByteHours = 5 * gb
  384. cluster2Disk2 := NewDisk("disk2", "cluster2", "disk2", start, end, NewWindow(&start, &end))
  385. cluster2Disk2.Cost = 10.0
  386. cluster2Disk2.adjustment = 3.0
  387. cluster2Disk2.ByteHours = 10 * gb
  388. cluster2Node1Disk := NewDisk("node1", "cluster2", "node1", start, end, NewWindow(&start, &end))
  389. cluster2Node1Disk.Cost = 1.0
  390. cluster2Node1Disk.ByteHours = 5 * gb
  391. // Add Attached Disks
  392. cluster2Node2Disk := NewDisk("node2", "cluster2", "node2", start, end, NewWindow(&start, &end))
  393. cluster2Node2Disk.Cost = 2.0
  394. cluster2Node2Disk.ByteHours = 5 * gb
  395. cluster2Node3Disk := NewDisk("node3", "cluster2", "node3", start, end, NewWindow(&start, &end))
  396. cluster2Node3Disk.Cost = 3.0
  397. cluster2Node3Disk.ByteHours = 5 * gb
  398. // Add Cluster Management
  399. cluster1ClusterManagement := NewClusterManagement("", "cluster1", NewWindow(&start, &end))
  400. cluster1ClusterManagement.Cost = 2.0
  401. cluster2ClusterManagement := NewClusterManagement("", "cluster2", NewWindow(&start, &end))
  402. cluster2ClusterManagement.Cost = 2.0
  403. // Add Networks
  404. c1Network := NewNetwork("", "cluster1", "c1nodes", start, end, NewWindow(&start, &end))
  405. c1Network.Cost = 3.0
  406. node1Network := NewNetwork("node1", "cluster2", "node1", start, end, NewWindow(&start, &end))
  407. node1Network.Cost = 4.0
  408. node2Network := NewNetwork("node2", "cluster2", "node2", start, end, NewWindow(&start, &end))
  409. node2Network.Cost = 5.0
  410. node3Network := NewNetwork("node3", "cluster2", "node3", start, end, NewWindow(&start, &end))
  411. node3Network.Cost = 2.0
  412. // Add LoadBalancers
  413. cluster2LoadBalancer1 := NewLoadBalancer("namespace2/loadBalancer1", "cluster2", "lb1", start, end, NewWindow(&start, &end))
  414. cluster2LoadBalancer1.Cost = 10.0
  415. cluster2LoadBalancer2 := NewLoadBalancer("namespace2/loadBalancer2", "cluster2", "lb2", start, end, NewWindow(&start, &end))
  416. cluster2LoadBalancer2.Cost = 15.0
  417. assetSet1 := NewAssetSet(start, end, cluster1Nodes, cluster2Node1, cluster2Node2, cluster2Node3, cluster2Disk1,
  418. cluster2Disk2, cluster2Node1Disk, cluster2Node2Disk, cluster2Node3Disk, cluster1ClusterManagement,
  419. cluster2ClusterManagement, c1Network, node1Network, node2Network, node3Network, cluster2LoadBalancer1, cluster2LoadBalancer2)
  420. assetSets = append(assetSets, assetSet1)
  421. // NOTE: we're re-using GenerateMockAllocationSet so this has to line up with
  422. // the allocated node costs from that function. See table above.
  423. // | Hierarchy | Cost | CPU | RAM | GPU | Adjustment |
  424. // +-----------------------------------------+------+------+------+------+------------+
  425. // cluster1:
  426. // nodes 100.00 5.00 4.00 1.00 90.00
  427. // +-----------------------------------------+------+------+------+------+------------+
  428. // cluster1 subtotal (adjusted) 100.00 50.00 40.00 10.00 0.00
  429. // +-----------------------------------------+------+------+------+------+------------+
  430. // cluster1 allocated 48.00 6.00 16.00 6.00 0.00
  431. // +-----------------------------------------+------+------+------+------+------------+
  432. // cluster1 idle 72.00 44.00 24.00 4.00 0.00
  433. // +-----------------------------------------+------+------+------+------+------------+
  434. // cluster2:
  435. // node1 35.00 20.00 15.00 0.00 0.00
  436. // node2 35.00 20.00 15.00 0.00 0.00
  437. // node3 30.00 10.00 10.00 10.00 0.00
  438. // (disks should not matter for idle)
  439. // +-----------------------------------------+------+------+------+------+------------+
  440. // cluster2 subtotal 100.00 50.00 40.00 10.00 0.00
  441. // +-----------------------------------------+------+------+------+------+------------+
  442. // cluster2 allocated 28.00 6.00 6.00 6.00 0.00
  443. // +-----------------------------------------+------+------+------+------+------------+
  444. // cluster2 idle 82.00 44.00 34.00 4.00 0.00
  445. // +-----------------------------------------+------+------+------+------+------------+
  446. cluster1Nodes = NewNode("", "cluster1", "c1nodes", start, end, NewWindow(&start, &end))
  447. cluster1Nodes.CPUCost = 5.0
  448. cluster1Nodes.RAMCost = 4.0
  449. cluster1Nodes.GPUCost = 1.0
  450. cluster1Nodes.adjustment = 90.00
  451. cluster1Nodes.CPUCoreHours = 8
  452. cluster1Nodes.RAMByteHours = 6
  453. cluster1Nodes.GPUHours = 24
  454. cluster2Node1 = NewNode("node1", "cluster2", "node1", start, end, NewWindow(&start, &end))
  455. cluster2Node1.CPUCost = 20.0
  456. cluster2Node1.RAMCost = 15.0
  457. cluster2Node1.GPUCost = 0.0
  458. cluster2Node1.CPUCoreHours = 4
  459. cluster2Node1.RAMByteHours = 3
  460. cluster2Node1.GPUHours = 0
  461. cluster2Node2 = NewNode("node2", "cluster2", "node2", start, end, NewWindow(&start, &end))
  462. cluster2Node2.CPUCost = 20.0
  463. cluster2Node2.RAMCost = 15.0
  464. cluster2Node2.GPUCost = 0.0
  465. cluster2Node2.CPUCoreHours = 3
  466. cluster2Node2.RAMByteHours = 2
  467. cluster2Node2.GPUHours = 0
  468. cluster2Node3 = NewNode("node3", "cluster2", "node3", start, end, NewWindow(&start, &end))
  469. cluster2Node3.CPUCost = 10.0
  470. cluster2Node3.RAMCost = 10.0
  471. cluster2Node3.GPUCost = 10.0
  472. cluster2Node3.CPUCoreHours = 2
  473. cluster2Node3.RAMByteHours = 2
  474. cluster2Node3.GPUHours = 24
  475. // Add PVs
  476. cluster2Disk1 = NewDisk("disk1", "cluster2", "disk1", start, end, NewWindow(&start, &end))
  477. cluster2Disk1.Cost = 5.0
  478. cluster2Disk1.adjustment = 1.0
  479. cluster2Disk1.ByteHours = 5 * gb
  480. cluster2Disk2 = NewDisk("disk2", "cluster2", "disk2", start, end, NewWindow(&start, &end))
  481. cluster2Disk2.Cost = 12.0
  482. cluster2Disk2.adjustment = 4.0
  483. cluster2Disk2.ByteHours = 20 * gb
  484. assetSet2 := NewAssetSet(start, end, cluster1Nodes, cluster2Node1, cluster2Node2, cluster2Node3, cluster2Disk1,
  485. cluster2Disk2, cluster2Node1Disk, cluster2Node2Disk, cluster2Node3Disk, cluster1ClusterManagement,
  486. cluster2ClusterManagement, c1Network, node1Network, node2Network, node3Network, cluster2LoadBalancer1, cluster2LoadBalancer2)
  487. assetSets = append(assetSets, assetSet2)
  488. return assetSets
  489. }
  490. // GenerateMockAssetSet generates the following topology:
  491. //
  492. // | Asset | Cost | Adj |
  493. // +------------------------------+------+------+
  494. // cluster1:
  495. // node1: 6.00 1.00
  496. // node2: 4.00 1.50
  497. // node3: 7.00 -0.50
  498. // disk1: 2.50 0.00
  499. // disk2: 1.50 0.00
  500. // clusterManagement1: 3.00 0.00
  501. // +------------------------------+------+------+
  502. // cluster1 subtotal 24.00 2.00
  503. // +------------------------------+------+------+
  504. // cluster2:
  505. // node4: 12.00 -1.00
  506. // disk3: 2.50 0.00
  507. // disk4: 1.50 0.00
  508. // clusterManagement2: 0.00 0.00
  509. // +------------------------------+------+------+
  510. // cluster2 subtotal 16.00 -1.00
  511. // +------------------------------+------+------+
  512. // cluster3:
  513. // node5: 17.00 2.00
  514. // +------------------------------+------+------+
  515. // cluster3 subtotal 17.00 2.00
  516. // +------------------------------+------+------+
  517. // total 57.00 3.00
  518. // +------------------------------+------+------+
  519. func GenerateMockAssetSet(start time.Time) *AssetSet {
  520. end := start.Add(day)
  521. window := NewWindow(&start, &end)
  522. hours := window.Duration().Hours()
  523. node1 := NewNode("node1", "cluster1", "gcp-node1", *window.Clone().start, *window.Clone().end, window.Clone())
  524. node1.CPUCost = 4.0
  525. node1.RAMCost = 4.0
  526. node1.GPUCost = 2.0
  527. node1.Discount = 0.5
  528. node1.CPUCoreHours = 2.0 * hours
  529. node1.RAMByteHours = 4.0 * gb * hours
  530. node1.GPUHours = 1.0 * hours
  531. node1.SetAdjustment(1.0)
  532. node1.SetLabels(map[string]string{"test": "test"})
  533. node2 := NewNode("node2", "cluster1", "gcp-node2", *window.Clone().start, *window.Clone().end, window.Clone())
  534. node2.CPUCost = 4.0
  535. node2.RAMCost = 4.0
  536. node2.GPUCost = 0.0
  537. node2.Discount = 0.5
  538. node2.CPUCoreHours = 2.0 * hours
  539. node2.RAMByteHours = 4.0 * gb * hours
  540. node2.GPUHours = 0.0 * hours
  541. node2.SetAdjustment(1.5)
  542. node3 := NewNode("node3", "cluster1", "gcp-node3", *window.Clone().start, *window.Clone().end, window.Clone())
  543. node3.CPUCost = 4.0
  544. node3.RAMCost = 4.0
  545. node3.GPUCost = 3.0
  546. node3.Discount = 0.5
  547. node3.CPUCoreHours = 2.0 * hours
  548. node3.RAMByteHours = 4.0 * gb * hours
  549. node3.GPUHours = 2.0 * hours
  550. node3.SetAdjustment(-0.5)
  551. node4 := NewNode("node4", "cluster2", "gcp-node4", *window.Clone().start, *window.Clone().end, window.Clone())
  552. node4.CPUCost = 10.0
  553. node4.RAMCost = 6.0
  554. node4.GPUCost = 0.0
  555. node4.Discount = 0.25
  556. node4.CPUCoreHours = 4.0 * hours
  557. node4.RAMByteHours = 12.0 * gb * hours
  558. node4.GPUHours = 0.0 * hours
  559. node4.SetAdjustment(-1.0)
  560. node5 := NewNode("node5", "cluster3", "aws-node5", *window.Clone().start, *window.Clone().end, window.Clone())
  561. node5.CPUCost = 10.0
  562. node5.RAMCost = 7.0
  563. node5.GPUCost = 0.0
  564. node5.Discount = 0.0
  565. node5.CPUCoreHours = 8.0 * hours
  566. node5.RAMByteHours = 24.0 * gb * hours
  567. node5.GPUHours = 0.0 * hours
  568. node5.SetAdjustment(2.0)
  569. disk1 := NewDisk("disk1", "cluster1", "gcp-disk1", *window.Clone().start, *window.Clone().end, window.Clone())
  570. disk1.Cost = 2.5
  571. disk1.ByteHours = 100 * gb * hours
  572. disk2 := NewDisk("disk2", "cluster1", "gcp-disk2", *window.Clone().start, *window.Clone().end, window.Clone())
  573. disk2.Cost = 1.5
  574. disk2.ByteHours = 60 * gb * hours
  575. disk3 := NewDisk("disk3", "cluster2", "gcp-disk3", *window.Clone().start, *window.Clone().end, window.Clone())
  576. disk3.Cost = 2.5
  577. disk3.ByteHours = 100 * gb * hours
  578. disk4 := NewDisk("disk4", "cluster2", "gcp-disk4", *window.Clone().start, *window.Clone().end, window.Clone())
  579. disk4.Cost = 1.5
  580. disk4.ByteHours = 100 * gb * hours
  581. cm1 := NewClusterManagement("gcp", "cluster1", window.Clone())
  582. cm1.Cost = 3.0
  583. cm2 := NewClusterManagement("gcp", "cluster2", window.Clone())
  584. cm2.Cost = 0.0
  585. return NewAssetSet(
  586. start, end,
  587. // cluster 1
  588. node1, node2, node3, disk1, disk2, cm1,
  589. // cluster 2
  590. node4, disk3, disk4, cm2,
  591. // cluster 3
  592. node5,
  593. )
  594. }