forked from kubernetes-retired/external-storage
/
types.go
398 lines (340 loc) · 14.7 KB
/
types.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package v1
import (
"encoding/json"
core_v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
)
const (
// VolumeSnapshotDataResourcePlural is "volumesnapshotdatas"
VolumeSnapshotDataResourcePlural = "volumesnapshotdatas"
// VolumeSnapshotResourcePlural is "volumesnapshots"
VolumeSnapshotResourcePlural = "volumesnapshots"
)
// VolumeSnapshotStatus is the status of the VolumeSnapshot
type VolumeSnapshotStatus struct {
// The time the snapshot was successfully created
// +optional
CreationTimestamp metav1.Time `json:"creationTimestamp" protobuf:"bytes,1,opt,name=creationTimestamp"`
// Represent the latest available observations about the volume snapshot
Conditions []VolumeSnapshotCondition `json:"conditions" protobuf:"bytes,2,rep,name=conditions"`
}
// VolumeSnapshotConditionType is the type of VolumeSnapshot conditions
type VolumeSnapshotConditionType string
// These are valid conditions of a volume snapshot.
const (
// VolumeSnapshotConditionPending means the snapshot is cut and the application
// can resume accessing data if core_v1.ConditionStatus is True. It corresponds
// to "Uploading" in GCE PD or "Pending" in AWS and core_v1.ConditionStatus is True.
// It also corresponds to "Creating" in OpenStack Cinder and core_v1.ConditionStatus
// is Unknown.
VolumeSnapshotConditionPending VolumeSnapshotConditionType = "Pending"
// VolumeSnapshotConditionReady is added when the snapshot has been successfully created and is ready to be used.
VolumeSnapshotConditionReady VolumeSnapshotConditionType = "Ready"
// VolumeSnapshotConditionError means an error occurred during snapshot creation.
VolumeSnapshotConditionError VolumeSnapshotConditionType = "Error"
)
// VolumeSnapshotCondition describes the state of a volume snapshot at a certain point.
type VolumeSnapshotCondition struct {
// Type of replication controller condition.
Type VolumeSnapshotConditionType `json:"type" protobuf:"bytes,1,opt,name=type,casttype=VolumeSnapshotConditionType"`
// Status of the condition, one of True, False, Unknown.
Status core_v1.ConditionStatus `json:"status" protobuf:"bytes,2,opt,name=status,casttype=ConditionStatus"`
// The last time the condition transitioned from one status to another.
// +optional
LastTransitionTime metav1.Time `json:"lastTransitionTime" protobuf:"bytes,3,opt,name=lastTransitionTime"`
// The reason for the condition's last transition.
// +optional
Reason string `json:"reason" protobuf:"bytes,4,opt,name=reason"`
// A human readable message indicating details about the transition.
// +optional
Message string `json:"message" protobuf:"bytes,5,opt,name=message"`
}
// +genclient=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// VolumeSnapshot is the volume snapshot object accessible to the user. Upon succesful creation of the actual
// snapshot by the volume provider it is bound to the corresponding VolumeSnapshotData through
// the VolumeSnapshotSpec
type VolumeSnapshot struct {
metav1.TypeMeta `json:",inline"`
Metadata metav1.ObjectMeta `json:"metadata"`
// Spec represents the desired state of the snapshot
// +optional
Spec VolumeSnapshotSpec `json:"spec" protobuf:"bytes,2,opt,name=spec"`
// Status represents the latest observer state of the snapshot
// +optional
Status VolumeSnapshotStatus `json:"status" protobuf:"bytes,3,opt,name=status"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// VolumeSnapshotList is a list of VolumeSnapshot objects
type VolumeSnapshotList struct {
metav1.TypeMeta `json:",inline"`
Metadata metav1.ListMeta `json:"metadata"`
Items []VolumeSnapshot `json:"items"`
}
// VolumeSnapshotSpec is the desired state of the volume snapshot
type VolumeSnapshotSpec struct {
// PersistentVolumeClaimName is the name of the PVC being snapshotted
// +optional
PersistentVolumeClaimName string `json:"persistentVolumeClaimName" protobuf:"bytes,1,opt,name=persistentVolumeClaimName"`
// SnapshotDataName binds the VolumeSnapshot object with the VolumeSnapshotData
// +optional
SnapshotDataName string `json:"snapshotDataName" protobuf:"bytes,2,opt,name=snapshotDataName"`
}
// VolumeSnapshotDataStatus is the actual state of the volume snapshot
type VolumeSnapshotDataStatus struct {
// The time the snapshot was successfully created
// +optional
CreationTimestamp metav1.Time `json:"creationTimestamp" protobuf:"bytes,1,opt,name=creationTimestamp"`
// Representes the lates available observations about the volume snapshot
Conditions []VolumeSnapshotDataCondition `json:"conditions" protobuf:"bytes,2,rep,name=conditions"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// VolumeSnapshotDataList is a list of VolumeSnapshotData objects
type VolumeSnapshotDataList struct {
metav1.TypeMeta `json:",inline"`
Metadata metav1.ListMeta `json:"metadata"`
Items []VolumeSnapshotData `json:"items"`
}
// VolumeSnapshotDataConditionType is the type of the VolumeSnapshotData condition
type VolumeSnapshotDataConditionType string
// These are valid conditions of a volume snapshot.
const (
// VolumeSnapshotDataReady is added when the on-disk snapshot has been successfully created.
VolumeSnapshotDataConditionReady VolumeSnapshotDataConditionType = "Ready"
// VolumeSnapshotDataPending is added when the on-disk snapshot has been successfully created but is not available to use.
VolumeSnapshotDataConditionPending VolumeSnapshotDataConditionType = "Pending"
// VolumeSnapshotDataError is added but the on-disk snapshot is failed to created
VolumeSnapshotDataConditionError VolumeSnapshotDataConditionType = "Error"
)
// VolumeSnapshotDataCondition describes the state of a volume snapshot at a certain point.
type VolumeSnapshotDataCondition struct {
// Type of volume snapshot condition.
Type VolumeSnapshotDataConditionType `json:"type" protobuf:"bytes,1,opt,name=type,casttype=VolumeSnapshotDataConditionType"`
// Status of the condition, one of True, False, Unknown.
Status core_v1.ConditionStatus `json:"status" protobuf:"bytes,2,opt,name=status,casttype=ConditionStatus"`
// The last time the condition transitioned from one status to another.
// +optional
LastTransitionTime metav1.Time `json:"lastTransitionTime" protobuf:"bytes,3,opt,name=lastTransitionTime"`
// The reason for the condition's last transition.
// +optional
Reason string `json:"reason" protobuf:"bytes,4,opt,name=reason"`
// A human readable message indicating details about the transition.
// +optional
Message string `json:"message" protobuf:"bytes,5,opt,name=message"`
}
// +genclient=true
// +nonNamespaced=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// VolumeSnapshotData represents the actual "on-disk" snapshot object
type VolumeSnapshotData struct {
metav1.TypeMeta `json:",inline"`
// +optional
Metadata metav1.ObjectMeta `json:"metadata"`
// Spec represents the desired state of the snapshot
// +optional
Spec VolumeSnapshotDataSpec `json:"spec" protobuf:"bytes,2,opt,name=spec"`
// Status represents the latest observed state of the snapshot
// +optional
Status VolumeSnapshotDataStatus `json:"status" protobuf:"bytes,3,opt,name=status"`
}
// VolumeSnapshotDataSpec is the spec of the volume snapshot data
type VolumeSnapshotDataSpec struct {
// Source represents the location and type of the volume snapshot
VolumeSnapshotDataSource `json:",inline" protobuf:"bytes,1,opt,name=volumeSnapshotDataSource"`
// VolumeSnapshotRef is part of bi-directional binding between VolumeSnapshot
// and VolumeSnapshotData
// +optional
VolumeSnapshotRef *core_v1.ObjectReference `json:"volumeSnapshotRef" protobuf:"bytes,2,opt,name=volumeSnapshotRef"`
// PersistentVolumeRef represents the PersistentVolume that the snapshot has been
// taken from
// +optional
PersistentVolumeRef *core_v1.ObjectReference `json:"persistentVolumeRef" protobuf:"bytes,3,opt,name=persistentVolumeRef"`
}
// HostPathVolumeSnapshotSource is HostPath volume snapshot source
type HostPathVolumeSnapshotSource struct {
// Path represents a tar file that stores the HostPath volume source
Path string `json:"snapshot"`
}
// GlusterVolumeSnapshotSource is Gluster volume snapshot source
type GlusterVolumeSnapshotSource struct {
// UniqueID represents a snapshot resource.
SnapshotID string `json:"snapshotId"`
}
// AWSElasticBlockStoreVolumeSnapshotSource is AWS EBS volume snapshot source
type AWSElasticBlockStoreVolumeSnapshotSource struct {
// Unique id of the persistent disk snapshot resource. Used to identify the disk snapshot in AWS
SnapshotID string `json:"snapshotId"`
// Original volume file system type. The volume created from the snapshot would be pre-formatted
// using the same file system, so it has to be saved along with the AWS snapshot ID
// +optional
FSType string `json:"fsType"`
}
// CinderVolumeSnapshotSource is Cinder volume snapshot source
type CinderVolumeSnapshotSource struct {
// Unique id of the cinder volume snapshot resource. Used to identify the snapshot in OpenStack
SnapshotID string `json:"snapshotId"`
}
// GCEPersistentDiskSnapshotSource is GCE PD volume snapshot source
type GCEPersistentDiskSnapshotSource struct {
// Unique id of the persistent disk snapshot resource. Used to identify the disk snapshot in GCE
SnapshotName string `json:"snapshotId"`
}
// VolumeSnapshotDataSource represents the actual location and type of the snapshot. Only one of its members may be specified.
type VolumeSnapshotDataSource struct {
// HostPath represents a directory on the host.
// Provisioned by a developer or tester.
// This is useful for single-node development and testing only!
// On-host storage is not supported in any way and WILL NOT WORK in a multi-node cluster.
// More info: https://kubernetes.io/docs/concepts/storage/volumes#hostpath
// +optional
HostPath *HostPathVolumeSnapshotSource `json:"hostPath,omitempty"`
// AWSElasticBlockStore represents an AWS Disk resource that is attached to a
// kubelet's host machine and then exposed to the pod.
// More info: https://kubernetes.io/docs/concepts/storage/volumes#awselasticblockstore
// +optional
//GlusterSnapshotSource represents a gluster snapshot resource
GlusterSnapshotVolume *GlusterVolumeSnapshotSource `json:"glusterSnapshotVolume,omitempty"`
// +optional
AWSElasticBlockStore *AWSElasticBlockStoreVolumeSnapshotSource `json:"awsElasticBlockStore,omitempty"`
// GCEPersistentDiskSnapshotSource represents an GCE PD snapshot resource
// +optional
GCEPersistentDiskSnapshot *GCEPersistentDiskSnapshotSource `json:"gcePersistentDisk,omitempty"`
// CinderVolumeSnapshotSource represents Cinder snapshot resource
// +optional
CinderSnapshot *CinderVolumeSnapshotSource `json:"cinderVolume,omitempty"`
}
// GetSupportedVolumeFromPVSpec gets supported volume from PV spec
func GetSupportedVolumeFromPVSpec(spec *core_v1.PersistentVolumeSpec) string {
if spec.HostPath != nil {
return "hostPath"
}
if spec.AWSElasticBlockStore != nil {
return "aws_ebs"
}
if spec.GCEPersistentDisk != nil {
return "gce-pd"
}
if spec.Cinder != nil {
return "cinder"
}
if spec.Glusterfs != nil {
return "glusterfs"
}
return ""
}
// GetSupportedVolumeFromSnapshotDataSpec gets supported volume from snapshot data spec
func GetSupportedVolumeFromSnapshotDataSpec(spec *VolumeSnapshotDataSpec) string {
if spec.HostPath != nil {
return "hostPath"
}
if spec.AWSElasticBlockStore != nil {
return "aws_ebs"
}
if spec.GCEPersistentDiskSnapshot != nil {
return "gce-pd"
}
if spec.CinderSnapshot != nil {
return "cinder"
}
if spec.GlusterSnapshotVolume != nil {
return "glusterfs"
}
return ""
}
// GetObjectKind is required to satisfy Object interface
func (v *VolumeSnapshotData) GetObjectKind() schema.ObjectKind {
return &v.TypeMeta
}
// GetObjectMeta is required to satisfy ObjectMetaAccessor interface
func (v *VolumeSnapshotData) GetObjectMeta() metav1.Object {
return &v.Metadata
}
// GetObjectKind is required to satisfy Object interface
func (vd *VolumeSnapshotDataList) GetObjectKind() schema.ObjectKind {
return &vd.TypeMeta
}
// GetListMeta is required to satisfy ListMetaAccessor interface
func (vd *VolumeSnapshotDataList) GetListMeta() metav1.ListInterface {
return &vd.Metadata
}
// GetObjectKind is required to satisfy Object interface
func (v *VolumeSnapshot) GetObjectKind() schema.ObjectKind {
return &v.TypeMeta
}
// GetObjectMeta is required to satisfy ObjectMetaAccessor interface
func (v *VolumeSnapshot) GetObjectMeta() metav1.Object {
return &v.Metadata
}
// GetObjectKind is required to satisfy Object interface
func (vd *VolumeSnapshotList) GetObjectKind() schema.ObjectKind {
return &vd.TypeMeta
}
// GetListMeta is required to satisfy ListMetaAccessor interface
func (vd *VolumeSnapshotList) GetListMeta() metav1.ListInterface {
return &vd.Metadata
}
// VolumeSnapshotDataListCopy is a VolumeSnapshotDataList type
type VolumeSnapshotDataListCopy VolumeSnapshotDataList
// VolumeSnapshotDataCopy is a VolumeSnapshotData type
type VolumeSnapshotDataCopy VolumeSnapshotData
// VolumeSnapshotListCopy is a VolumeSnapshotList type
type VolumeSnapshotListCopy VolumeSnapshotList
// VolumeSnapshotCopy is a VolumeSnapshot type
type VolumeSnapshotCopy VolumeSnapshot
// UnmarshalJSON unmarshalls json data
func (v *VolumeSnapshot) UnmarshalJSON(data []byte) error {
tmp := VolumeSnapshotCopy{}
err := json.Unmarshal(data, &tmp)
if err != nil {
return err
}
tmp2 := VolumeSnapshot(tmp)
*v = tmp2
return nil
}
// UnmarshalJSON unmarshals json data
func (vd *VolumeSnapshotList) UnmarshalJSON(data []byte) error {
tmp := VolumeSnapshotListCopy{}
err := json.Unmarshal(data, &tmp)
if err != nil {
return err
}
tmp2 := VolumeSnapshotList(tmp)
*vd = tmp2
return nil
}
// UnmarshalJSON unmarshals json data
func (v *VolumeSnapshotData) UnmarshalJSON(data []byte) error {
tmp := VolumeSnapshotDataCopy{}
err := json.Unmarshal(data, &tmp)
if err != nil {
return err
}
tmp2 := VolumeSnapshotData(tmp)
*v = tmp2
return nil
}
// UnmarshalJSON unmarshals json data
func (vd *VolumeSnapshotDataList) UnmarshalJSON(data []byte) error {
tmp := VolumeSnapshotDataListCopy{}
err := json.Unmarshal(data, &tmp)
if err != nil {
return err
}
tmp2 := VolumeSnapshotDataList(tmp)
*vd = tmp2
return nil
}