-
Notifications
You must be signed in to change notification settings - Fork 2
/
common.go
39 lines (33 loc) · 1.09 KB
/
common.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package hpa
import (
"github.com/kubeservice-stack/basa/src/backend/resources/dataselector"
)
// The code below allows to perform complex data section on []autoscaling.v1.HorizontalPodAutoscaler
type HPACell HPA
func (self HPACell) GetProperty(name dataselector.PropertyName) dataselector.ComparableValue {
switch name {
case dataselector.NameProperty:
return dataselector.StdComparableString(self.ObjectMeta.Name)
case dataselector.CreationTimestampProperty:
return dataselector.StdComparableTime(self.ObjectMeta.CreationTimestamp.Time)
case dataselector.NamespaceProperty:
return dataselector.StdComparableString(self.ObjectMeta.Namespace)
default:
// if name is not supported then just return a constant dummy value, sort will have no effect.
return nil
}
}
func toCells(std []*HPA) []dataselector.DataCell {
cells := make([]dataselector.DataCell, len(std))
for i := range std {
cells[i] = HPACell(*std[i])
}
return cells
}
func fromCells(cells []dataselector.DataCell) []HPA {
std := make([]HPA, len(cells))
for i := range std {
std[i] = HPA(cells[i].(HPACell))
}
return std
}