-
Notifications
You must be signed in to change notification settings - Fork 124
/
volume.go
156 lines (132 loc) · 3.41 KB
/
volume.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
//
// 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"
"time"
)
const (
KindVolumeHostDir = "dir"
)
// swagger:ignore
// swagger:model types_volume
type Volume struct {
Runtime
// Volume meta
Meta VolumeMeta `json:"meta" yaml:"meta"`
// Volume spec
Spec VolumeSpec `json:"spec" yaml:"spec"`
// Volume status
Status VolumeStatus `json:"status" yaml:"status"`
}
// swagger:ignore
// swagger:model types_volume_map
type VolumeMap struct {
Runtime
Items map[string]*Volume
}
// swagger:ignore
// swagger:model types_volume_list
type VolumeList struct {
Runtime
Items []*Volume
}
// swagger:ignore
// swagger:model types_volume_meta
type VolumeMeta struct {
Meta
Node string `json:"node"`
Namespace string `json:"namespace"`
}
// swagger:model types_volume_spec
type VolumeSpec struct {
Type string `json:"type"`
Selector SpecSelector `json:"selector"`
Capacity SpecVolumeCapacity `json:"capacity"`
State VolumeSpecState `json:"state"`
HostPath string `json:"host_path"`
AccessMode string `json:"access_mode"`
Updated time.Time `json:"updated"`
}
// swagger:model types_volume_spec_state
type VolumeSpecState struct {
Destroy bool `json:"destroy"`
}
// swagger:ignore
// swagger:model types_volume_create
type VolumeCreateOptions struct {
}
// swagger:ignore
// swagger:model types_volume_update
type VolumeUpdateOptions struct {
}
type VolumeStatus struct {
// volume state
State string `json:"state" yaml:"state"`
// volume status
Status VolumeState `json:"status" yaml:"status"`
// volume status message
Message string `json:"message" yaml:"message"`
}
// swagger:ignore
// swagger:model types_volume_status
type VolumeState struct {
Type string `json:"type" yaml:"type"`
// Volume root path
Path string `json:"path" yaml:"path"`
// Volume state ready
Ready bool `json:"ready" yaml:"ready"`
}
func (vs *VolumeStatus) SetReady () {
vs.Status.Ready = true
vs.State = StateReady
vs.Message = EmptyString
}
func (vs *VolumeStatus) SetDestroyed () {
vs.Status.Ready = false
vs.State = StateDestroyed
vs.Message = EmptyString
}
func (vs *VolumeStatus) SetError (err error) {
vs.Status.Ready = false
vs.State = StateError
vs.Message = err.Error()
}
func (v *Volume) SelfLink() string {
if v.Meta.SelfLink == "" {
v.Meta.SelfLink = v.CreateSelfLink(v.Meta.Namespace, v.Meta.Name)
}
return v.Meta.SelfLink
}
func (v *Volume) CreateSelfLink(namespace, name string) string {
return fmt.Sprintf("%s:%s", namespace, name)
}
func NewVolumeList() *VolumeList {
dm := new(VolumeList)
dm.Items = make([]*Volume, 0)
return dm
}
func NewVolumeMap() *VolumeMap {
dm := new(VolumeMap)
dm.Items = make(map[string]*Volume)
return dm
}
func NewVolumeStatus() *VolumeStatus {
status := VolumeStatus{}
return &status
}