-
Notifications
You must be signed in to change notification settings - Fork 88
Hostpath snapshot implementation #94
Conversation
|
Looks like two errors from the unit tests: 1. go fmt 2. Seems one of the API calls did not pass. |
| return &csi.ValidateVolumeCapabilitiesResponse{Supported: true, Message: ""}, nil | ||
| } | ||
|
|
||
| func (cs *controllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequest) (*csi.CreateSnapshotResponse, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add a lot of comments to this function to explain what the algorithm is and what tools it needs from the container?
| createAt := time.Now().UnixNano() | ||
| volPath := hostPathVolume.VolPath | ||
| file := snapshotRoot + snapshotID + ".tgz" | ||
| args := []string{"czf", file, "-C", volPath, "."} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool idea.
pkg/hostpath/controllerserver.go
Outdated
| } | ||
|
|
||
| glog.V(4).Infof("create volume snapshot %s", file) | ||
| hostPathSna := hostPathSnapshot{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is Sna? Is that Snapshot? Maybe call it just snap or snapshot since it is a local variable.
pkg/hostpath/hostpath.go
Outdated
| } | ||
|
|
||
| type hostPathSnapshot struct { | ||
| SnaName string `json:"snaName"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove all Sna prefixes since they are part of the hostPathSnapshot object. So, SnaID being just Id would be the id of the snapshot. and so one.
| glog.V(4).Infof("deleting volume %s", snapshotID) | ||
| path := snapshotRoot + snapshotID + ".tgz" | ||
| os.RemoveAll(path) | ||
| delete(hostPathVolumeSnapshots, snapshotID) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should check first if it is there. If it is not, then it should return that the snapshot id is not found.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not think so. from the spec, we can see this for DeleteSnapshot,
This operation MUST be idempotent. If a snapshot corresponding to the specified snapshot_id does not exist or the artifacts associated with the snapshot do not exist anymore, the Plugin MUST reply 0 OK.
I think we can just do the delete operation like deleteVolume and we do not need check whether the snapshot exists.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, great point.
pkg/hostpath/controllerserver.go
Outdated
|
|
||
| func (cs *controllerServer) ListSnapshots(ctx context.Context, req *csi.ListSnapshotsRequest) (*csi.ListSnapshotsResponse, error) { | ||
| // Check arguments | ||
| if len(req.GetSnapshotId()) == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is optional. It is only used to get the snapshot information about a single snapshot id. it should not be checked if it was passed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, we should return a list of all the snapshots in the system that:
- Match the source volume id
- Match the snapshot id
- Match Anything (meaning all of the snapshots)
8080b3e to
07864ee
Compare
|
@lpabon test has been fixed by kubernetes-csi/csi-test#81 |
|
@wackxu Seems there is one more csi-sanity issue: I'll take a look to see if we are using the latest from csi-sanity |
|
Can you fix the typo in the title s/Hostpaht/hostpath. |
|
@xing-yang Done |
|
@lpabon Yes, I see we are using the latest from csi-sanity, and there is a bug when csi-sanity switch to CSI 0.3.0. And we should first merge kubernetes-csi/csi-test#81. then test will pass. |
| goto result | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't there be duplicate snapshot entries where both, snapshotId and sourceVolumeId are given?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually it won't as it'll goto result once process this block. You can skip above comment
| } | ||
|
|
||
| rsp := &csi.ListSnapshotsResponse{ | ||
| Entries: entries, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It shouldn't return more than MaxEntries entries.
pkg/hostpath/controllerserver.go
Outdated
| } | ||
|
|
||
| // case 2: SourceVolumeId is not empty, return snapshots that match the source volume id. | ||
| if len(req.SourceVolumeId) != 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can it be consistent to be req.GetSourceVolumeId()?
| Id: exSnap.Id, | ||
| SourceVolumeId: exSnap.VolID, | ||
| CreatedAt: exSnap.CreateAt, | ||
| Status: exSnap.Status, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to return SizeBytes.
| SourceVolumeId: snapshot.VolID, | ||
| CreatedAt: snapshot.CreateAt, | ||
| Status: snapshot.Status, | ||
| }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SizeBytes is missing.
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: wackxu If they are not already assigned, you can assign the PR to them by writing The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
10a8abd to
ce10084
Compare
|
@lpabon @sarjeet2013 @xing-yang Sorry for the delay, update, PTAL |
|
@lpabon @xing-yang I think we should merge this asap, since external-snapshotter is merged and it is easy for us to test the external-snapshotter if we merge this. |
pkg/hostpath/controllerserver.go
Outdated
| snapshot.VolID = volumeID | ||
| snapshot.Path = file | ||
| snapshot.CreateAt = createAt | ||
| snapshot.SizeBytes = fileInfo.Size() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be the size of the original volume, not how much space is used.
For example, "hostPathVol.VolSize = capacity" in CreateVolume. We should do the same thing here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for clarify this, Updated
|
@xing-yang: changing LGTM is restricted to assignees, and only kubernetes-csi/drivers repo collaborators may be assigned issues. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
xing-yang
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
kindly ping @lpabon for approval |
pkg/hostpath/controllerserver.go
Outdated
| }, nil | ||
| } | ||
|
|
||
| func covertSnapshot(snap hostPathSnapshot) *csi.ListSnapshotsResponse { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean * convertSnapshot*?
pkg/hostpath/controllerserver.go
Outdated
| } | ||
|
|
||
| var nextToken string | ||
| if n := startingToken + int32(i); n < ulenSnapshots { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not directly use j as next token?
|
LGTM. few minor comments but not a blocker to merge. |
|
@sarjeet2013 Thanks for your review, Updated |
I am working with @xing-yang about Move Snapshot APIs in-tree, and we have test the implementation of host path volume snapshot. so push this code.