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 Controller #7

Merged
merged 30 commits into from
Aug 30, 2018

Conversation

xing-yang
Copy link
Collaborator

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

This PR adds external snapshot controller and main package under cmd.

Which issue(s) this PR fixes:
Fixes #
kubernetes/enhancements#177

@xing-yang xing-yang changed the title Add Snapshot Controller WIP Add Snapshot Controller Jul 12, 2018
}

// Create VolumeSnapshotData in the database
snapshotData := &crdv1.VolumeSnapshotData{
Copy link
Collaborator

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.

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.

return true, nil
}

func GenSnapshotStatus(snapshotCon *crdv1.VolumeSnapshotCondition) *crdv1.VolumeSnapshotCondition {
Copy link
Collaborator

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?

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 makes a copy of of the Condition. Probably not needed. We can use DeepCopy.

},
}

key, err := cache.DeletionHandlingMetaNamespaceKeyFunc(vs)
Copy link
Collaborator

Choose a reason for hiding this comment

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

remove this part?

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.

// wait until CRD gets processed
err = WaitForSnapshotResource(crdClient)
if err != nil {
panic(err)
Copy link
Collaborator

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will change it.

Name: snapDataName,
},
Spec: crdv1.VolumeSnapshotDataSpec{
VolumeSnapshotRef: &v1.ObjectReference{
Copy link
Collaborator

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?

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 check it here.

@xing-yang xing-yang force-pushed the snapshot_controller branch 2 times, most recently from 0020694 to 9b48753 Compare July 14, 2018 18:53
@xing-yang xing-yang force-pushed the snapshot_controller branch 3 times, most recently from e3c46ae to fdfad5e Compare July 23, 2018 20:34
@xing-yang xing-yang changed the title WIP Add Snapshot Controller Add Snapshot Controller Jul 25, 2018

req := csi.CreateSnapshotRequest{
SourceVolumeId: volume.Spec.CSI.VolumeHandle,
Name: snapshot.Name,
Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

}

return rsp.Entries[0].Snapshot.Status, nil
return rsp.Entries[0].Snapshot.Status, rsp.Entries[0].Snapshot.CreatedAt, nil
Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

SourceVolumeId: volume.Spec.CSI.VolumeHandle,
Name: snapshotName,
Parameters: parameters,
CreateSnapshotSecrets: nil,
Copy link

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

xing-yang added a commit to xing-yang/external-provisioner that referenced this pull request Aug 10, 2018
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.
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

os.Exit(1)
}

glog.V(2).Infof("Start NewCSISnapshotController with snapshotter %s", *snapshotter)
Copy link
Member

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.

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.


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)
Copy link
Member

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
Copy link
Contributor

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",
Copy link
Contributor

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)
Copy link
Contributor

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will fix it. Thanks

Copy link
Collaborator

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()
}

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

if err == nil {
// The volume snapshot still exists in informer cache, the event must have
// been add/update/sync
if ctrl.shouldProcessSnapshot(snapshot) {
Copy link
Collaborator

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

Copy link
Collaborator Author

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.
@xing-yang
Copy link
Collaborator Author

Addressed all review comments.

return nil
}
snapshotClone := snapshot.DeepCopy()
if snapshot.Status.Error == nil {
Copy link
Collaborator

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.

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

@jsafrane
Copy link
Contributor

lgtm-ish, I went through the code and tests and it looks usable. IMO, it's good for alpha, it needs serious testing.

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

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

/test all

@jingxu97 jingxu97 added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Aug 30, 2018
@k8s-ci-robot k8s-ci-robot merged commit 234c01b into kubernetes-csi:master Aug 30, 2018
xing-yang added a commit to xing-yang/external-provisioner that referenced this pull request Aug 30, 2018
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.
@xing-yang xing-yang deleted the snapshot_controller 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. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants