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

RFC-0030 - Add support to Diego for file based service bindings #100

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

dimitardimitrov13
Copy link

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.

return nil
}

func (h *ServiceBindingRootHandler) RemoveDir(logger lager.Logger, container executor.Container) error {

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?

Copy link
Author

Choose a reason for hiding this comment

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

@@ -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"
Copy link
Member

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?

@@ -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 {
Copy link
Member

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

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"?

Copy link
Member

Choose a reason for hiding this comment

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

Or maybe "h.containerMountPath"?

Comment on lines 91 to 137
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"))
})
Copy link
Member

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?

Comment on lines 139 to 146
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())
})

Copy link
Member

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

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?

Comment on lines 133 to 135
if err != nil {
logger.Error("failed-to-remove-volume-mounted-files-directory", err, lager.Data{"directory": path})
}
Copy link
Member

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

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

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?

@dimitardimitrov13
Copy link
Author

Hello @ameowlia, all comments were addressed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

3 participants