-
Notifications
You must be signed in to change notification settings - Fork 0
/
cluster.go
65 lines (52 loc) · 1.55 KB
/
cluster.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package entities
import (
"encoding/json"
"time"
"github.com/google/uuid"
"github.com/gosimple/slug"
)
const (
DefaultClusterName = "default"
)
type ClusterStatus string
const (
ClusterStatusCreating ClusterStatus = "creating"
ClusterStatusCreated ClusterStatus = "created"
ClusterStatusRemoving ClusterStatus = "removing"
)
type Cluster struct {
ID string `json:"id"`
Name string `json:"name"`
DefaultInstanceType string `json:"default_instance_type"`
InfrastructureJSON string `json:"infrastructure_json"`
DevEnvs map[string]*DevEnv `json:"dev_envs"`
IsDefault bool `json:"is_default"`
Status ClusterStatus `json:"status"`
CreatedAtTimestamp int64 `json:"created_at_timestamp"`
}
func NewCluster(
clusterName string,
defaultInstanceType string,
isDefaultCluster bool,
) *Cluster {
return &Cluster{
ID: uuid.NewString(),
Name: clusterName,
DefaultInstanceType: defaultInstanceType,
DevEnvs: map[string]*DevEnv{},
IsDefault: isDefaultCluster,
Status: ClusterStatusCreating,
CreatedAtTimestamp: time.Now().Unix(),
}
}
func (c *Cluster) GetNameSlug() string {
return slug.Make(c.Name)
}
func (c *Cluster) SetInfrastructureJSON(infrastructure interface{}) error {
infrastructureJSON, err := json.Marshal(infrastructure)
if err != nil {
return err
}
c.InfrastructureJSON = string(infrastructureJSON)
return nil
}