-
Notifications
You must be signed in to change notification settings - Fork 386
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 Controller #7
Add Snapshot Controller #7
Conversation
pkg/connection/connection.go
Outdated
} | ||
|
||
// Create VolumeSnapshotData in the database | ||
snapshotData := &crdv1.VolumeSnapshotData{ |
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 feel it is better to create VolumeSnapshotData object in the controller, not in connection code.
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.
Sure.
pkg/controller/util.go
Outdated
return true, nil | ||
} | ||
|
||
func GenSnapshotStatus(snapshotCon *crdv1.VolumeSnapshotCondition) *crdv1.VolumeSnapshotCondition { |
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 the purpose of this function?
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 makes a copy of of the Condition. Probably not needed. We can use DeepCopy.
cmd/csi-snapshotter/main.go
Outdated
}, | ||
} | ||
|
||
key, err := cache.DeletionHandlingMetaNamespaceKeyFunc(vs) |
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.
remove this part?
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.
Sure.
cmd/csi-snapshotter/main.go
Outdated
// wait until CRD gets processed | ||
err = WaitForSnapshotResource(crdClient) | ||
if err != nil { | ||
panic(err) |
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 use panic instead of os.Exist like below?
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.
Will change it.
pkg/connection/connection.go
Outdated
Name: snapDataName, | ||
}, | ||
Spec: crdv1.VolumeSnapshotDataSpec{ | ||
VolumeSnapshotRef: &v1.ObjectReference{ |
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 volumesnapshotRef should be the existing one, instead of creating a new one?
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.
Sure. I'll check it here.
0020694
to
9b48753
Compare
e3c46ae
to
fdfad5e
Compare
pkg/connection/connection.go
Outdated
|
||
req := csi.CreateSnapshotRequest{ | ||
SourceVolumeId: volume.Spec.CSI.VolumeHandle, | ||
Name: snapshot.Name, |
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.
should use snapshot.UID? Different namespaces might have the same snapshot name which will cause problem 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.
Good catch. Yes, it should be snapshot.UID. Will fix it.
pkg/connection/connection.go
Outdated
} | ||
|
||
return rsp.Entries[0].Snapshot.Status, nil | ||
return rsp.Entries[0].Snapshot.Status, rsp.Entries[0].Snapshot.CreatedAt, nil |
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 thought this rsp.Entries[0].Snapshot.CreatedAt is when snapshot is cut, not when it is ready or something else.
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.
Yes. In ConvertSnapshotStatus in controller/util.go, this timestamp is used to set CreatedAt (when snapshot is cut). For AvailableAt and timestamp in VolumeError, the current time is used.
40c9790
to
d3b1d87
Compare
e87f318
to
0573211
Compare
bc02d60
to
3841a99
Compare
3e881ed
to
325fda7
Compare
pkg/connection/connection.go
Outdated
SourceVolumeId: volume.Spec.CSI.VolumeHandle, | ||
Name: snapshotName, | ||
Parameters: parameters, | ||
CreateSnapshotSecrets: nil, |
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.
As you know, some storage providers need secrets to create the snapshot.
Do you have any plan to implement this?
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.
@sngchlko Thanks for the feedback! Yes, this should be fixed.
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.
@sngchlko It's fixed here: xing-yang@dd820b5
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.
Fixed.
This PR adds changes to support restoring a volume from a snapshot. Note: Mark it WIP until the DataSource addition in core API (kubernetes/kubernetes#67087) and snapshot API/controller changes (kubernetes-csi/external-snapshotter#7) are merged.
325fda7
to
7fa276f
Compare
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
cmd/csi-snapshotter/main.go
Outdated
os.Exit(1) | ||
} | ||
|
||
glog.V(2).Infof("Start NewCSISnapshotController with snapshotter %s", *snapshotter) |
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 be added after, but it would be nice to log the options.
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.
Sure.
pkg/controller/csi_handler.go
Outdated
|
||
func (handler *csiHandler) CreateSnapshot(snapshot *crdv1.VolumeSnapshot, volume *v1.PersistentVolume, parameters map[string]string) (string, string, int64, *csi.SnapshotStatus, error) { | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), handler.timeout) |
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.
nice
content.Spec.VolumeSnapshotRef.Name == snapshot.Name && | ||
content.Spec.VolumeSnapshotRef.Namespace == snapshot.Namespace && | ||
content.Spec.VolumeSnapshotRef.UID == snapshot.UID { | ||
found = true |
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.
do we need check whether the snapshotClass is same?
Namespace: snapshot.Namespace, | ||
Name: snapshot.Name, | ||
UID: snapshot.UID, | ||
APIVersion: "v1alpha1", |
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 should be snapshot.storage.k8s.io/v1alpha1
glog.V(4).Infof("error is already set in snapshot, do not retry to create: %s", snapshot.Status.Error.Message) | ||
return snapshot, nil | ||
} | ||
class, err := ctrl.GetClassFromVolumeSnapshot(snapshot) |
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 may update snapshot when the snapshot do not set VolumeSnapshotClassName field and use the default snapshot class , in this case, the follow update will always be version conflict, so we`d better return the snapshot from the function.
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.
Will fix it. Thanks
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.
good point. I am thinking maybe we should use two functions here instead of one to make it more clear.
if len(className) > 0 {
// call GetClassFromVolumeSnapshot()
} else {
// call SetDefaultClass()
}
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.
sure
This commit splits GetClassFromVolumeSnapshot to two functions, GetSnapshotClass and SetDefaultSnapshotClass.
Change VolumeSnapshotClassName to a pointer to string
if err == nil { | ||
// The volume snapshot still exists in informer cache, the event must have | ||
// been add/update/sync | ||
if ctrl.shouldProcessSnapshot(snapshot) { |
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.
here shouldProcessSnapshot might update the snapshot, then this function should return the new version of the snapshot so that the following updateSnapshot can use the new version
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.
Fixed.
Also rename shouldProcessSnapshot to checkAndUpdateSnapshotClass.
Addressed all review comments. |
return nil | ||
} | ||
snapshotClone := snapshot.DeepCopy() | ||
if snapshot.Status.Error == nil { |
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.
remove this line to allow new discovered error to show up.
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.
Done
lgtm-ish, I went through the code and tests and it looks usable. IMO, it's good for alpha, it needs serious testing. |
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
/approve
/test all |
This PR adds changes to support restoring a volume from a snapshot. Note: The DataSource addition in core API (kubernetes/kubernetes#67087) and snapshot API/controller changes (kubernetes-csi/external-snapshotter#7) are merged.
This PR adds external snapshot controller and main package under cmd.
Which issue(s) this PR fixes:
Fixes #
kubernetes/enhancements#177