-
Notifications
You must be signed in to change notification settings - Fork 0
/
interactwithcluster.go
34 lines (31 loc) · 1.01 KB
/
interactwithcluster.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
package pools
import (
"encoding/json"
"github.com/mohammedzee1000/openshift-cluster-pool/pkg/clusters"
"github.com/mohammedzee1000/openshift-cluster-pool/pkg/database"
"github.com/mohammedzee1000/openshift-cluster-pool/pkg/generic"
"time"
)
//Gets when a cluster will expire in conjunction with a pool config
func (p Pool) ExpiresOn(c *clusters.Cluster) time.Time {
var t time.Time
if c.State == clusters.ClusterSuccess {
t = c.CreatedOn.Add(p.UnusedClusterTimeout.Duration)
} else if c.State == clusters.ClusterUsed {
t = c.ActivatedOn.Add(time.Duration(p.UsedClusterTimeout.Duration) * time.Hour)
}
return t
}
func (p Pool) GetClusters(ctx *generic.Context) (*clusters.ClusterList, error) {
clusterlist := clusters.NewClusterList()
d := database.GetMultipleWithPrefixFromKVDB(ctx, clusters.GetClusterPoolKey(p.Name))
for _, item := range d {
var cl clusters.Cluster
err := json.Unmarshal([]byte(item), &cl)
if err != nil {
return nil, err
}
clusterlist.Append(&cl)
}
return clusterlist, nil
}