-
Notifications
You must be signed in to change notification settings - Fork 42
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
RFC-0030 - Add support to Diego for file based service bindings #100
base: main
Are you sure you want to change the base?
RFC-0030 - Add support to Diego for file based service bindings #100
Conversation
2c59134
to
2f5337e
Compare
Remove ioutil.ReadFile in favor of os.ReadFile. Remove MkdirAll in favor of Mkdir.
2f5337e
to
fa28a86
Compare
return nil | ||
} | ||
|
||
func (h *ServiceBindingRootHandler) RemoveDir(logger lager.Logger, container executor.Container) 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.
I do not see this function covered with tests, or am i wrong?
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.
Hello here it is the test for RemoveDir
https://github.com/cloudfoundry/executor/pull/100/files#diff-5e39d32f309883624104dc2056437db4a3d782ea689020c000a3848675ca80d8R81
depot/containerstore/storenode.go
Outdated
@@ -33,6 +33,7 @@ const ContainerMissingMessage = "missing garden container" | |||
const VolmanMountFailed = "failed to mount volume" | |||
const BindMountCleanupFailed = "failed to cleanup bindmount artifacts" | |||
const CredDirFailed = "failed to create credentials directory" | |||
const VolumeMountedFileFailed = "failed to create service binding root" |
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 think the future of this feature will be used for more things than just service bindings.
❓ Can you change this error message to be less specific to service bindings and more generic about volume mounted files?
depot/containerstore/storenode.go
Outdated
@@ -242,7 +247,19 @@ func (n *storeNode) Create(logger lager.Logger, traceID string) error { | |||
n.complete(logger, traceID, true, CredDirFailed, true) | |||
return err | |||
} | |||
|
|||
if len(n.info.VolumeMountedFiles) > 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.
❓ should this use info
instead of n.info
like everything else in this function?
return nil, err | ||
} | ||
|
||
logger.Info("creating-dir - volume-mounted-files") |
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.
❓ Is "volume-mounted-files" meant to be hard coded? Or should it be "h.volumeMountPath"?
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.
Or maybe "h.containerMountPath"?
It("validates the content of the redis username file", func() { | ||
_, err := handler.CreateDir(logger, container) | ||
Expect(err).To(Succeed()) | ||
|
||
usernameFilePath := filepath.Join(tmpdir, fakeContainerUUID, "redis", "username") | ||
Expect(usernameFilePath).To(BeAnExistingFile()) | ||
|
||
content, err := os.ReadFile(usernameFilePath) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(string(content)).To(Equal("username")) | ||
}) | ||
|
||
It("validates the content of the redis password file", func() { | ||
_, err := handler.CreateDir(logger, container) | ||
Expect(err).To(Succeed()) | ||
|
||
usernameFilePath := filepath.Join(tmpdir, fakeContainerUUID, "redis", "password") | ||
Expect(usernameFilePath).To(BeAnExistingFile()) | ||
|
||
content, err := os.ReadFile(usernameFilePath) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(string(content)).To(Equal("password")) | ||
}) | ||
|
||
It("validates the content of the httpd username file", func() { | ||
_, err := handler.CreateDir(logger, container) | ||
Expect(err).To(Succeed()) | ||
|
||
usernameFilePath := filepath.Join(tmpdir, fakeContainerUUID, "httpd", "username") | ||
Expect(usernameFilePath).To(BeAnExistingFile()) | ||
|
||
content, err := os.ReadFile(usernameFilePath) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(string(content)).To(Equal("username")) | ||
}) | ||
|
||
It("validates the content of the httpd password file", func() { | ||
_, err := handler.CreateDir(logger, container) | ||
Expect(err).To(Succeed()) | ||
|
||
usernameFilePath := filepath.Join(tmpdir, fakeContainerUUID, "httpd", "password") | ||
Expect(usernameFilePath).To(BeAnExistingFile()) | ||
|
||
content, err := os.ReadFile(usernameFilePath) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(string(content)).To(Equal("password")) | ||
}) |
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 are all basically the same test. Can you DRY this up by turning these into table tests?
It("removes volume-mounted-files directory", func() { | ||
err := handler.RemoveDir(logger, container) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
volumeMountedFiles := filepath.Join(tmpdir, fakeContainerUUID) | ||
Eventually(volumeMountedFiles).ShouldNot(BeADirectory()) | ||
}) | ||
|
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 under a Describe for "RemoveDir" not "CreateDir".
|
||
It("returns an error", func() { | ||
_, err := handler.CreateDir(logger, executor.Container{Guid: "fake_guid"}) | ||
Expect(err).To(HaveOccurred()) |
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 you add another expect on a more specific error?
if err != nil { | ||
logger.Error("failed-to-remove-volume-mounted-files-directory", err, lager.Data{"directory": path}) | ||
} |
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 you add a test for this?
}, nil | ||
} | ||
|
||
func (h *VolumeMountedFilesHandler) volumeMountedFilesForServices( |
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.
All of these errors are untested. I understand that it can be hard to test file actions and to force them to fail, but is there a way to force a least one failure, so that you can test what happens to CreateDir when this function returns an error?
err := fmt.Errorf("failed to extract volume-mounted-files directory. format is: /serviceName/fileName") | ||
logger.Error(" volume-mounted-files directory is required", err, lager.Data{"dirName": "is empty"}) | ||
|
||
continue |
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 do some errors only log instead of bubble up? Why would you continue in these cases?
Hello @ameowlia, all comments were addressed. |
Summary
This PR is continuation for the RFC-0030
Backward Compatibility
Breaking Change? No
This feature is the first PoC for RFC-0030.
Since the CAPI implementation for RFC-0030 is not done yet, the PR doesn't need to be applied immediately.