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

initial implementation of refactor host-path-driver #276

Closed

Conversation

fengzixu
Copy link
Contributor

What type of PR is this?

/kind bug

What this PR does / why we need it:

For fixing bugs that are mentioned in the issues below

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

Fixing bug of host-path-csi-driver which may causes it's failed to start up.

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Apr 18, 2021
@k8s-ci-robot k8s-ci-robot requested review from msau42 and pohly April 18, 2021 04:19
@k8s-ci-robot k8s-ci-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Apr 18, 2021
@fengzixu fengzixu force-pushed the fix-bug-listing-volume branch from 51639b6 to a93049e Compare April 18, 2021 04:25
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 18, 2021
@fengzixu fengzixu changed the title WIPL initial implementation of refactor host-path-driver [WIP]:initial implementation of refactor host-path-driver Apr 18, 2021
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 18, 2021
@fengzixu
Copy link
Contributor Author

/assign @fengzixu @pohly @xing-yang

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: fengzixu
To complete the pull request process, please ask for approval from pohly after the PR has been reviewed.

The full list of commands accepted by this bot can be found 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

return filepath.Join(dataRoot, fmt.Sprintf("%s%s", snapshotID, snapshotExt))
}

func (hps *HostPathDriverState) loadSnapshotsFromFile(snapshotFilePath string) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of loadSnapshotsFromFile and loadVolumesFromFile and many different files, a single loadFromFile and saveToFile with one state file that contains multiple volumes and snapshots is enough.

loadFromFile then only needs to be called once during startup when constructing HostPathDriverState. saveToFile needs to be called after each change to the in-memory struct.

Don't worry about failure scenarios when writing that file fails, just check and return the error.

This is not a high-quality implementation and should come with a warning that a real driver may have to be more careful about not loosing state, but for this driver it is sufficient.

Copy link
Contributor Author

@fengzixu fengzixu Apr 19, 2021

Choose a reason for hiding this comment

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

Instead of loadSnapshotsFromFile and loadVolumesFromFile a single loadFromFile and saveToFile

I agree this point. Let me improve it. But I don't think aggregate all of logic into the single state.go file is good idea. I want this refractory change can give a better experience for the new contributor of this project. It is easy for them to understand" What state package did".

loadFromFile then only needs to be called once during startup when constructing HostPathDriverState. saveToFile needs to be called after each change to the in-memory struct.

Sure

Copy link
Contributor

Choose a reason for hiding this comment

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

"The state package manages the internal state of the driver on a node. It ensures that the driver can be stopped and restarted".

It should be that simple. All additional logic for managing snapshots and volumes should be where it resides at the moment.

// Lock before acting on global state. A production-quality
// driver might use more fine-grained locking.
hps.SnapshotsFileRWLock.Lock()
defer hps.SnapshotsFileRWLock.Unlock()
Copy link
Contributor

Choose a reason for hiding this comment

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

Locking should be entirely in the gRPC layer, not here.

// backed by a Pod volume.
dataRoot = "/csi-data-dir"
volumesDataDir = "/csi-volumes-data"
volumesDataFilePath = path.Join(volumesDataDir, "volumes.json")
Copy link
Contributor

Choose a reason for hiding this comment

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

These paths must be configurable for unit testing and when running the driver manually as non-root outside of a container.

@fengzixu fengzixu force-pushed the fix-bug-listing-volume branch from ba026be to e0b0fd9 Compare April 19, 2021 16:11
@fengzixu fengzixu changed the title [WIP]:initial implementation of refactor host-path-driver initial implementation of refactor host-path-driver Apr 19, 2021
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 19, 2021
@k8s-ci-robot
Copy link
Contributor

@fengzixu: PR needs rebase.

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.

@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Apr 19, 2021
@k8s-ci-robot
Copy link
Contributor

@fengzixu: The following tests failed, say /retest to rerun all failed tests:

Test name Commit Details Rerun command
pull-kubernetes-csi-csi-driver-host-path-1-19-on-kubernetes-1-19 e0b0fd9 link /test pull-kubernetes-csi-csi-driver-host-path-1-19-on-kubernetes-1-19
pull-kubernetes-csi-csi-driver-host-path-1-20-on-kubernetes-1-20 e0b0fd9 link /test pull-kubernetes-csi-csi-driver-host-path-1-20-on-kubernetes-1-20
pull-kubernetes-csi-csi-driver-host-path-unit e0b0fd9 link /test pull-kubernetes-csi-csi-driver-host-path-unit
pull-kubernetes-csi-csi-driver-host-path-1-18-on-kubernetes-1-18 e0b0fd9 link /test pull-kubernetes-csi-csi-driver-host-path-1-18-on-kubernetes-1-18

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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. I understand the commands that are listed here.

@fengzixu fengzixu requested a review from pohly April 19, 2021 16:18
return snapshot, nil
}

func (hps *HostPathDriverState) DeleteSnapshot(snapshotId string) error {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Create/Delete snapshot method doesn't implement "file operation"

assert.EqualValues(t, testSnapshots, snapshots)
}

// func TestLoadStateFromFile(t *testing.T) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

// adds the volume to the list.
//
// It returns the volume path or err if one occurs. That error is suitable as result of a gRPC call.
func (hps *HostPathDriverState) CreateVolume(volID, name string, cap int64, volAccessType AccessType, ephemeral bool, kind string, maxVolumeSize int64, capacity Capacity) (hpv *HostPathVolume, finalErr error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The "state" package should not implement the complete logic for creating and manipulating volumes and snapshots. That mixes state management with CSI driver logic.

HostPathDriverState.AddVolume should just take a Volume struct and then have a few lines of code which update the update the map and store the entire struct in a state file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. release-note Denotes a PR that will be considered when it comes time to generate release notes. 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.

4 participants