|
| 1 | +/* |
| 2 | +Copyright 2018 The Kubernetes Authors. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package v1alpha1 |
| 18 | + |
| 19 | +import ( |
| 20 | + core_v1 "k8s.io/api/core/v1" |
| 21 | + storage "k8s.io/api/storage/v1beta1" |
| 22 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 23 | +) |
| 24 | + |
| 25 | +const ( |
| 26 | + // VolumeSnapshotContentResourcePlural is "volumesnapshotcontents" |
| 27 | + VolumeSnapshotContentResourcePlural = "volumesnapshotcontents" |
| 28 | + // VolumeSnapshotResourcePlural is "volumesnapshots" |
| 29 | + VolumeSnapshotResourcePlural = "volumesnapshots" |
| 30 | + // VolumeSnapshotClassResourcePlural is "volumesnapshotclasses" |
| 31 | + VolumeSnapshotClassResourcePlural = "volumesnapshotclasses" |
| 32 | +) |
| 33 | + |
| 34 | +// +genclient |
| 35 | +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 36 | + |
| 37 | +// VolumeSnapshot is a user's request for taking a snapshot. Upon successful creation of the actual |
| 38 | +// snapshot by the volume provider it is bound to the corresponding VolumeSnapshotContent. |
| 39 | +// Only the VolumeSnapshot object is accessible to the user in the namespace. |
| 40 | +type VolumeSnapshot struct { |
| 41 | + metav1.TypeMeta `json:",inline"` |
| 42 | + // Standard object's metadata. |
| 43 | + // More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata |
| 44 | + // +optional |
| 45 | + metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` |
| 46 | + |
| 47 | + // Spec defines the desired characteristics of a snapshot requested by a user. |
| 48 | + Spec VolumeSnapshotSpec `json:"spec" protobuf:"bytes,2,opt,name=spec"` |
| 49 | + |
| 50 | + // Status represents the latest observed state of the snapshot |
| 51 | + // +optional |
| 52 | + Status VolumeSnapshotStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"` |
| 53 | +} |
| 54 | + |
| 55 | +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 56 | + |
| 57 | +// VolumeSnapshotList is a list of VolumeSnapshot objects |
| 58 | +type VolumeSnapshotList struct { |
| 59 | + metav1.TypeMeta `json:",inline"` |
| 60 | + // +optional |
| 61 | + metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` |
| 62 | + |
| 63 | + // Items is the list of VolumeSnapshots |
| 64 | + Items []VolumeSnapshot `json:"items" protobuf:"bytes,2,rep,name=items"` |
| 65 | +} |
| 66 | + |
| 67 | +// VolumeSnapshotSpec describes the common attributes of a volume snapshot |
| 68 | +type VolumeSnapshotSpec struct { |
| 69 | + // Source has the information about where the snapshot is created from. |
| 70 | + // In Alpha version, only PersistentVolumeClaim is supported as the source. |
| 71 | + // If not specified, user can create VolumeSnapshotContent and bind it with VolumeSnapshot manually. |
| 72 | + // +optional |
| 73 | + Source *TypedLocalObjectReference `json:"source" protobuf:"bytes,1,opt,name=source"` |
| 74 | + |
| 75 | + // SnapshotContentName binds the VolumeSnapshot object with the VolumeSnapshotContent |
| 76 | + // +optional |
| 77 | + SnapshotContentName string `json:"snapshotContentName" protobuf:"bytes,2,opt,name=snapshotContentName"` |
| 78 | + |
| 79 | + // Name of the VolumeSnapshotClass used by the VolumeSnapshot. If not specified, a default snapshot class will |
| 80 | + // be used if it is available. |
| 81 | + // +optional |
| 82 | + VolumeSnapshotClassName string `json:"snapshotClassName" protobuf:"bytes,3,opt,name=snapshotClassName"` |
| 83 | +} |
| 84 | + |
| 85 | +// VolumeSnapshotStatus is the status of the VolumeSnapshot |
| 86 | +type VolumeSnapshotStatus struct { |
| 87 | + // CreationTime is the time the snapshot was successfully created. If it is set, |
| 88 | + // it means the snapshot was created; Otherwise the snapshot was not created. |
| 89 | + // +optional |
| 90 | + CreationTime *metav1.Time `json:"createdAt" protobuf:"bytes,1,opt,name=createdAt"` |
| 91 | + |
| 92 | + // Ready is set to true only if the snapshot is ready to use (e.g., finish uploading if |
| 93 | + // there is an uploading phase) and also VolumeSnapshot and its VolumeSnapshotContent |
| 94 | + // bind correctly with each other. If any of the above condition is not true, Ready is |
| 95 | + // set to false |
| 96 | + // +optional |
| 97 | + Ready bool `json:"ready" protobuf:"varint,2,opt,name=ready"` |
| 98 | + |
| 99 | + // The last error encountered during create snapshot operation, if any. |
| 100 | + // This field must only be set by the entity completing the create snapshot |
| 101 | + // operation, i.e. the external-snapshotter. |
| 102 | + // +optional |
| 103 | + Error *storage.VolumeError |
| 104 | +} |
| 105 | + |
| 106 | +// TypedLocalObjectReference contains enough information to let you locate the typed referenced object inside the same namespace. |
| 107 | +// TODO: After TypedLocalObjectReference is merged into the in-tree core API, this will be replaced. |
| 108 | +type TypedLocalObjectReference struct { |
| 109 | + // Name of the referent. |
| 110 | + // +optional |
| 111 | + Name string `json:"name,omitempty" protobuf:"bytes,1,opt,name=name"` |
| 112 | + // Kind of the referent. |
| 113 | + // +optional |
| 114 | + Kind string `json:"kind,omitempty" protobuf:"bytes,2,opt,name=kind"` |
| 115 | +} |
| 116 | + |
| 117 | +// +genclient |
| 118 | +// +genclient:nonNamespaced |
| 119 | +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 120 | + |
| 121 | +// VolumeSnapshotClass describes the parameters used by storage system when |
| 122 | +// provisioning VolumeSnapshots from PVCs. |
| 123 | +// The name of a VolumeSnapshotClass object is significant, and is how users can request a particular class. |
| 124 | +type VolumeSnapshotClass struct { |
| 125 | + metav1.TypeMeta `json:",inline"` |
| 126 | + // Standard object's metadata. |
| 127 | + // More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata |
| 128 | + // +optional |
| 129 | + metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` |
| 130 | + |
| 131 | + // Snapshotter is the driver expected to handle this VolumeSnapshotClass. |
| 132 | + Snapshotter string `json:"snapshotter" protobuf:"bytes,2,opt,name=snapshotter"` |
| 133 | + |
| 134 | + // Parameters holds parameters for the snapshotter. |
| 135 | + // These values are opaque to the system and are passed directly |
| 136 | + // to the snapshotter. |
| 137 | + // +optional |
| 138 | + Parameters map[string]string `json:"parameters,omitempty" protobuf:"bytes,3,rep,name=parameters"` |
| 139 | +} |
| 140 | + |
| 141 | +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 142 | + |
| 143 | +// VolumeSnapshotClassList is a collection of snapshot classes. |
| 144 | +type VolumeSnapshotClassList struct { |
| 145 | + metav1.TypeMeta `json:",inline"` |
| 146 | + // Standard list metadata |
| 147 | + // More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata |
| 148 | + // +optional |
| 149 | + metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` |
| 150 | + |
| 151 | + // Items is the list of VolumeSnapshotClasses |
| 152 | + Items []VolumeSnapshotClass `json:"items" protobuf:"bytes,2,rep,name=items"` |
| 153 | +} |
| 154 | + |
| 155 | +// +genclient |
| 156 | +// +genclient:nonNamespaced |
| 157 | +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 158 | + |
| 159 | +// VolumeSnapshotContent represents the actual "on-disk" snapshot object |
| 160 | +type VolumeSnapshotContent struct { |
| 161 | + metav1.TypeMeta `json:",inline"` |
| 162 | + // Standard object's metadata. |
| 163 | + // More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata |
| 164 | + // +optional |
| 165 | + metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` |
| 166 | + |
| 167 | + // Spec represents the desired state of the snapshot data |
| 168 | + Spec VolumeSnapshotContentSpec `json:"spec" protobuf:"bytes,2,opt,name=spec"` |
| 169 | +} |
| 170 | + |
| 171 | +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 172 | + |
| 173 | +// VolumeSnapshotContentList is a list of VolumeSnapshotContent objects |
| 174 | +type VolumeSnapshotContentList struct { |
| 175 | + metav1.TypeMeta `json:",inline"` |
| 176 | + // +optional |
| 177 | + metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` |
| 178 | + |
| 179 | + // Items is the list of VolumeSnapshotContents |
| 180 | + Items []VolumeSnapshotContent `json:"items" protobuf:"bytes,2,rep,name=items"` |
| 181 | +} |
| 182 | + |
| 183 | +// VolumeSnapshotContentSpec is the spec of the volume snapshot data |
| 184 | +type VolumeSnapshotContentSpec struct { |
| 185 | + // Source represents the location and type of the volume snapshot |
| 186 | + VolumeSnapshotSource `json:",inline" protobuf:"bytes,1,opt,name=volumeSnapshotSource"` |
| 187 | + |
| 188 | + // VolumeSnapshotRef is part of bi-directional binding between VolumeSnapshot |
| 189 | + // and VolumeSnapshotContent. It becomes non-nil when bound. |
| 190 | + // +optional |
| 191 | + VolumeSnapshotRef *core_v1.ObjectReference `json:"volumeSnapshotRef" protobuf:"bytes,2,opt,name=volumeSnapshotRef"` |
| 192 | + |
| 193 | + // PersistentVolumeRef represents the PersistentVolume that the snapshot has been |
| 194 | + // taken from. It becomes non-nil when VolumeSnapshot and VolumeSnapshotContent are bound. |
| 195 | + // +optional |
| 196 | + PersistentVolumeRef *core_v1.ObjectReference `json:"persistentVolumeRef" protobuf:"bytes,3,opt,name=persistentVolumeRef"` |
| 197 | +} |
| 198 | + |
| 199 | +// VolumeSnapshotSource represents the actual location and type of the snapshot. Only one of its members may be specified. |
| 200 | +type VolumeSnapshotSource struct { |
| 201 | + // CSI (Container Storage Interface) represents storage that handled by an external CSI Volume Driver (Alpha feature). |
| 202 | + // +optional |
| 203 | + CSI *CSIVolumeSnapshotSource `json:"csiVolumeSnapshotSource,omitempty"` |
| 204 | +} |
| 205 | + |
| 206 | +// Represents the source from CSI volume snapshot |
| 207 | +type CSIVolumeSnapshotSource struct { |
| 208 | + // Driver is the name of the driver to use for this snapshot. |
| 209 | + // Required. |
| 210 | + Driver string `json:"driver"` |
| 211 | + |
| 212 | + // SnapshotHandle is the unique snapshot id returned by the CSI volume |
| 213 | + // plugin’s CreateSnapshot to refer to the snapshot on all subsequent calls. |
| 214 | + // Required. |
| 215 | + SnapshotHandle string `json:"snapshotHandle"` |
| 216 | + |
| 217 | + // Timestamp when the point-in-time snapshot is taken on the storage |
| 218 | + // system. This timestamp will be generated by the CSI volume driver after |
| 219 | + // the snapshot is cut. The format of this field should be a Unix nanoseconds |
| 220 | + // time encoded as an int64. On Unix, the command `date +%s%N` returns |
| 221 | + // the current time in nanoseconds since 1970-01-01 00:00:00 UTC. |
| 222 | + // This field is REQUIRED. |
| 223 | + CreatedAt int64 `json:"createdAt,omitempty" protobuf:"varint,3,opt,name=createdAt"` |
| 224 | +} |
0 commit comments