-
Notifications
You must be signed in to change notification settings - Fork 217
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
Conversation
51639b6
to
a93049e
Compare
/assign @fengzixu @pohly @xing-yang |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: fengzixu 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 |
pkg/state/snapshot.go
Outdated
return filepath.Join(dataRoot, fmt.Sprintf("%s%s", snapshotID, snapshotExt)) | ||
} | ||
|
||
func (hps *HostPathDriverState) loadSnapshotsFromFile(snapshotFilePath string) 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.
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.
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.
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
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.
"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.
pkg/state/snapshot.go
Outdated
// Lock before acting on global state. A production-quality | ||
// driver might use more fine-grained locking. | ||
hps.SnapshotsFileRWLock.Lock() | ||
defer hps.SnapshotsFileRWLock.Unlock() |
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.
Locking should be entirely in the gRPC layer, not here.
pkg/state/types.go
Outdated
// backed by a Pod volume. | ||
dataRoot = "/csi-data-dir" | ||
volumesDataDir = "/csi-volumes-data" | ||
volumesDataFilePath = path.Join(volumesDataDir, "volumes.json") |
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.
These paths must be configurable for unit testing and when running the driver manually as non-root outside of a container.
ba026be
to
e0b0fd9
Compare
@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. |
@fengzixu: The following tests failed, say
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. |
return snapshot, nil | ||
} | ||
|
||
func (hps *HostPathDriverState) DeleteSnapshot(snapshotId string) 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.
Create/Delete snapshot method doesn't implement "file operation"
assert.EqualValues(t, testSnapshots, snapshots) | ||
} | ||
|
||
// func TestLoadStateFromFile(t *testing.T) { |
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.
Test should be uncommented after https://github.com/kubernetes-csi/csi-driver-host-path/pull/276/files#r615995654
// 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) { |
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.
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.
What type of PR is this?
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?: