mock.go 24 KB

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