/
deployment.go
138 lines (118 loc) · 3.04 KB
/
deployment.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
//
// Last.Backend LLC CONFIDENTIAL
// __________________
//
// [2014] - [2018] Last.Backend LLC
// All Rights Reserved.
//
// NOTICE: All information contained herein is, and remains
// the property of Last.Backend LLC and its suppliers,
// if any. The intellectual and technical concepts contained
// herein are proprietary to Last.Backend LLC
// and its suppliers and may be covered by Russian Federation and Foreign Patents,
// patents in process, and are protected by trade secret or copyright law.
// Dissemination of this information or reproduction of this material
// is strictly forbidden unless prior written permission is obtained
// from Last.Backend LLC.
//
package types
import "fmt"
type DeploymentMap struct {
Runtime
Items map[string]*Deployment
}
type DeploymentList struct {
Runtime
Items []*Deployment
}
type Deployment struct {
Runtime
// Deployment Meta
Meta DeploymentMeta `json:"meta"`
// Deployment status
Status DeploymentStatus `json:"status"`
// Deployment spec
Spec DeploymentSpec `json:"spec"`
}
type DeploymentMeta struct {
Meta
// Version
Version int `json:"version"`
// Namespace id
Namespace string `json:"namespace"`
// Service id
Service string `json:"service"`
// Endpoint
Endpoint string `json:"endpoint"`
// Self Link
Status string `json:"status"`
}
type DeploymentSpec struct {
Replicas int `json:"replicas"`
State SpecState `json:"state"`
Selector SpecSelector `json:"selector"`
Template SpecTemplate `json:"template"`
}
type DeploymentStatus struct {
State string `json:"state"`
Message string `json:"message"`
}
type DeploymentReplicas struct {
Total int `json:"total"`
Provision int `json:"provision"`
Pulling int `json:"pulling"`
Created int `json:"created"`
Started int `json:"started"`
Stopped int `json:"stopped"`
Errored int `json:"errored"`
}
type DeploymentOptions struct {
Replicas int `json:"replicas"`
}
func (d *Deployment) SelfLink() string {
if d.Meta.SelfLink == "" {
d.Meta.SelfLink = d.CreateSelfLink(d.Meta.Namespace, d.Meta.Service, d.Meta.Name)
}
return d.Meta.SelfLink
}
func (d *Deployment) CreateSelfLink(namespace, service, name string) string {
return fmt.Sprintf("%s:%s:%s", namespace, service, name)
}
func (d *Deployment) ServiceLink() string {
return fmt.Sprintf("%s:%s", d.Meta.Namespace, d.Meta.Service)
}
func (d *DeploymentStatus) SetProvision() {
d.State = StateProvision
d.Message = ""
}
func (d *DeploymentStatus) SetReady() {
d.State = StateReady
d.Message = ""
}
func (d *DeploymentStatus) SetCancel() {
d.State = StateCancel
d.Message = ""
}
func (d *DeploymentStatus) SetDestroy() {
d.State = StateDestroy
d.Message = ""
}
type DeploymentUpdateOptions struct {
// Number of replicas
Replicas *int
// Deployment status for update
Status *struct {
State string
Message string
}
}
func NewDeploymentList() *DeploymentList {
dm := new(DeploymentList)
dm.Items = make([]*Deployment, 0)
return dm
}
func NewDeploymentMap() *DeploymentMap {
dm := new(DeploymentMap)
dm.Items = make(map[string]*Deployment)
return dm
}