Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Snapshot APIs #6

Merged
merged 2 commits into from
Aug 14, 2018
Merged

Conversation

xing-yang
Copy link
Collaborator

@xing-yang xing-yang commented Jul 12, 2018

This PR adds snapshot APIs as CRD and adds generated files.
The design doc is kubernetes/community#2335

@xing-yang xing-yang changed the title Snapshot apis Add Snapshot APIs Jul 12, 2018
// VolumeSnapshotConditionUploading means the snapshot is cut and the application
// can resume accessing data if ConditionStatus is True. It corresponds
// to "Uploading" in GCE PD or "Pending" in AWS and ConditionStatus is True.
// This condition type is not applicable in OpenStack Cinder.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe make this comment a little more generic. "Uploading" condition is only applicable to the volume plugins which support uploading snapshots to Cloud storage. For example, it corresponds to snapshot "UPLOADING" status in GCE and ...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't see the change?

Copy link

@liggitt liggitt Jul 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"VolumeSnapshotConditionUploading means the snapshot is cut" doesn't seem like a correct condition to monitor to determine if creation has completed (means the snapshot is cut and the application can resume accessing data), for a few reasons:

  • it appears to only apply to some volume plugins... if they don't upload data, this condition would never be true
  • it is transient... once uploaded, this condition would no longer be true
  • it is not necessarily mutually exclusive with "Creating"... a plugin could conceivably start streaming an upload while it was still in the process of creating the snapshot

Copy link
Collaborator

@jingxu97 jingxu97 Jul 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • it appears to only apply to some volume plugins... if they don't upload data, this condition would never be true

that's right

  • it is transient... once uploaded, this condition would no longer be true

right. Snapshot creation goes through a few phases: e.g., in GCE PD, we have CREATING, UPLOADING, and READY. Both creating and uploading are transient. Once that phase passes, the condition is no longer true.

  • it is not necessarily mutually exclusive with "Creating"... a plugin could conceivably start streaming an upload while it was still in the process of creating the snapshot

I think they are mutually exclusive. After the snapshot is cut, it is no longer in "creating" phase, and either go to "uploading" phase, or directly move to "ready" phase if no uploading is performed.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read the updated condition guideline again, and have the following thoughts.

Condition should be considered as observations that users cared about instead of state-machine phases. For snapshot, user cares about whether snapshot is created successfully or not first. These can be represented by "ready" and "failed" conditions. The other condition user cares about is when the snapshot is taken (or cut). Because some plugins support uploading which might take a long time. User needs to know when the snapshot is taken (usually in a second) so that application can be resumed. So we could add another condition "snapshotTaken" (or just "Taken") condition. So now we have three conditions "snapshotTaken", "snapshotReady" and "snapshotFailed"

During the snapshot creation, we might see the following conditions at different times.

  1. First when user create VolumeSnapshot object, there is no condition yet. (means controller is working on it, but there is no observed state available yet)
  2. The volume plugin starts to create the snapshot. When the snapshot is taken (cut), controller will get a response and add "SnapshotTaken" condition to true. If snapshot is failed, it will be set to false. If there is no uploading phase, Ready condition will also be true right after snapshot is taken.
  3. If there is an uploading phase, the controller will add "Ready" condition to true after uploading finishes. If uploading failed, the condition is set to false.

Please let me know if you have any feedback/comment about it. Thanks!

// to "Uploading" in GCE PD or "Pending" in AWS and ConditionStatus is True.
// This condition type is not applicable in OpenStack Cinder.
VolumeSnapshotConditionUploading VolumeSnapshotConditionType = "Uploading"
// VolumeSnapshotConditionReady is added when the snapshot has been successfully created and is ready to be used.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change "is added" to "means"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

VolumeSnapshotConditionError VolumeSnapshotConditionType = "Error"
)

// VolumeSnapshotCondition describes the state of a volume snapshot at a certain point.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove at a certain point.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


// Spec represents the desired state of the snapshot
// +optional
Spec VolumeSnapshotSpec `json:"spec" protobuf:"bytes,2,opt,name=spec"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Spec should be required

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PersistentVolumeClaimSpec is optional in PersistentVolumeClaim API object. Should we be consistent with that?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed with @liggitt and we think it should be required also for PersistentVolumeClaimSpec.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

type VolumeSnapshotSpec struct {
// PersistentVolumeClaimName is the name of the PVC being snapshotted
// +optional
PersistentVolumeClaimName string `json:"persistentVolumeClaimName" protobuf:"bytes,1,opt,name=persistentVolumeClaimName"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is also a required field

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think by leaving this one optional, we can support static binding?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, I think you are right

metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`

// Spec represents the desired state of the snapshot
// +optional
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spec should be required?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that PersistentVolumeSpec is an optional field in PersistentVolume. So we should probably be consistent with that?

// +optional
metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`

Items []VolumeSnapshotData `json:"items" protobuf:"bytes,2,rep,name=items"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to add comments to all fields?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

// VolumeSnapshotRef is part of bi-directional binding between VolumeSnapshot
// and VolumeSnapshotData
// +optional
VolumeSnapshotRef *core_v1.ObjectReference `json:"volumeSnapshotRef" protobuf:"bytes,2,opt,name=volumeSnapshotRef"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also required field?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that ClaimRef is an optional field in PersistentVolumeSpec. It becomes non-nil when bound. I'll add a comment here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok.

// PersistentVolumeRef represents the PersistentVolume that the snapshot has been
// taken from
// +optional
PersistentVolumeRef *core_v1.ObjectReference `json:"persistentVolumeRef" protobuf:"bytes,3,opt,name=persistentVolumeRef"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

required field?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, this becomes non-nil when bound.

// Required.
SnapshotHandle string `json:"snapshotHandle"`

// Timestamp when the point-in-time snapshot is taken on the storage
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is not very clear that which time is used here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This timestamp will be generated by the CSI driver after the snapshot is cut. I'll add this to the comment.

@jingxu97
Copy link
Collaborator

cc @liggitt

@jingxu97
Copy link
Collaborator

cc @saad-ali


const (
// VolumeSnapshotDataResourcePlural is "volumesnapshotdatas"
VolumeSnapshotDataResourcePlural = "volumesnapshotdatas"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"datas" is not a correct plural

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have a suggestion for this? "data" is a plural itself. How do we differentiate between singular and plural if they are the same?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like "volumesnapshotdatas" will be generated automatically for clientset when generating code for the CRD. So unless if we rename VolumeSnapshotData to something else, it will be "volumesnapshotdatas".

Copy link

@liggitt liggitt Jul 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like "volumesnapshotdatas" will be generated automatically for clientset when generating code for the CRD. So unless if we rename VolumeSnapshotData to something else, it will be "volumesnapshotdatas".

That's correct, and is a gap in the client generator. This has also been reported by others (see https://kubernetes.slack.com/archives/C0EG7JC6T/p1528416072000218). However, we shouldn't accept an incorrect API because of that... it would be better to participate in improving the generator to allow specifying the plural (or rename the VolumeSnapshotData type)

// VolumeSnapshotConditionType is the type of VolumeSnapshot conditions
type VolumeSnapshotConditionType string

// These are valid conditions of a volume snapshot.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would recommend reviewing the updated condition guidelines in https://github.com/kubernetes/community/pull/2350/files

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed VolumeSnapshotConditionType to "Created", "Available", and "Error" following today's discussion during the snapshot design meeting.

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// VolumeSnapshotData represents the actual "on-disk" snapshot object
type VolumeSnapshotData struct {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the relationship between VolumeSnapshot and VolumeSnapshotData 1:1 or 1:*?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is 1:1

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed VolumeSnapshotData to VolumeSnapshotContent.

@jingxu97
Copy link
Collaborator

cc @thockin

@xing-yang xing-yang force-pushed the snapshot_apis branch 4 times, most recently from 3c74892 to c14d975 Compare July 16, 2018 19:30
// addKnownTypes adds the set of types defined in this package to the supplied scheme.
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&SnapshotClass{},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be consistent with all the objects, I think they should all start with either "Snapshot" or "VolumeSnapshot", but not a mix.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, will change to VolumeSnapshotClass.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// VolumeSnapshotContent represents the actual "on-disk" snapshot object
type VolumeSnapshotContent struct {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know we had some discussion on this in the last call. Wouldn't VolumeSnapshotClaim or VolumeSnapshotRequest as the user-facing object and VolumeSnapshot as the storage backend representation be better names? These names follow the PersistentVolumeClaim-PersistentVolume convention and can be pluralized.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, PersistentVolumeClaim does not follow the name pattern as all other user-facing objects. For example, we don't use PodClaim to represent user's pod. We think we should have named PVC and PV as PersistentVolume (user) and PersistentVolumeContent (system admin) at the first place. So instead of following the wrong pattern, we decided to use VolumeSnapshot to represent the user's snapshot.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PVCs don't follow other user-facing objects because other objects don't follow the dual-object model where we have a request and a response or a user-facing representation and an internal representation, but I agree with you that it's better not to follow the wrong pattern and have the more straightforward name (i.e., VolumeSnapshot) exposed to the users.

Copy link

@garthy garthy Jul 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK I'm late to to conversation so don't really have much right to input. I would prefer sticking to the PVC/PV pattern even if you belive it is wrong as it exists now. I personally don't belive it is incorrect as @kangarlou says nothing else follows the request response pattern. It will make users familiar with the PVC/PV pattern pick it up easier. All through reading it I was trying to map it to PVC/PV model.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry to reply late. Yes, naming is hard. But since we have been using these names for a while, we decided to continue use these names. The relationship between snapshot and its content is very similar to pvc/pv.

CreatedAt int64 `json:"createdAt,omitempty" protobuf:"varint,3,opt,name=createdAt"`
}

// GetObjectKind is required to satisfy Object interface
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the following is not need, so can remove these lines.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. I'll take a look. Thanks.

// +optional
AvailableAt *metav1.Time `json:"availableAt" protobuf:"bytes,2,opt,name=availableAt"`
// Bound is set to true only if the snapshot is ready to use (e.g., finish uploading if
// there is an uplaoding phase) and also VolumeSnapshot andn its VolumeSnapshotContent
Copy link
Collaborator Author

@xing-yang xing-yang Aug 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/uplaoding/uploading

s/andn/and

@@ -93,15 +88,17 @@ type VolumeSnapshotList struct {

// VolumeSnapshotSpec is the desired state of the volume snapshot
type VolumeSnapshotSpec struct {
// PersistentVolumeClaimName is the name of the PVC being snapshotted
// PersistentVolumeClaimName is the name of the PVC being snapshotted.
// If not specified, user can create SnapshotContent and bind it with VolumeSnapshot manually.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/SnapshotContent/VolumeSnapshotContent

// +optional
AvailableAt *metav1.Time `json:"availableAt" protobuf:"bytes,2,opt,name=availableAt"`
// Bound is set to true only if the snapshot is ready to use (e.g., finish uploading if
// there is an uploading phase) and also VolumeSnapshot andn its VolumeSnapshotContent
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/andn/and

This PR adds generated files under pkg/client and vendor folder.
This PR adds snapshot APIs as CRD.
Copy link
Member

@lpabon lpabon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

Copy link
Member

@saad-ali saad-ali left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
/approve

// Represents the source from CSI volume snapshot
type CSIVolumeSnapshotSource struct {
// Driver is the name of the driver to use for this snapshot.
// Required.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add:

    // This MUST be the same name returned by the CSI GetPluginName() call for
    // that driver.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`

// Spec represents the desired state of the snapshot data
Spec VolumeSnapshotContentSpec `json:"spec" protobuf:"bytes,2,opt,name=spec"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No status in VolumeSnapshotContent? No way to know if the object is bound or not?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had status in VolumeSnapshotContent earlier on but decided to drop it because it is exactly the same as status in VolumeSnapshot. Now we just use "Ready" in VolumsSnapshotStatus to let user know it is bound and snapshot is ready for use.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 14, 2018
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: saad-ali, xing-yang

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 14, 2018
@saad-ali saad-ali added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Aug 14, 2018
@k8s-ci-robot k8s-ci-robot merged commit cc19fd3 into kubernetes-csi:master Aug 14, 2018
@xing-yang xing-yang deleted the snapshot_apis branch April 8, 2019 02:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants