-
Notifications
You must be signed in to change notification settings - Fork 199
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
Porter explain warns for docker host access #1868
Porter explain warns for docker host access #1868
Conversation
3d2d7d7
to
665493c
Compare
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 also add a test case for the warning that should appear when the bundle requires the docker extension? Here's where we have a similar test already:
porter/pkg/porter/explain_test.go
Line 123 in 6dab64a
func TestExplain_generateTable(t *testing.T) { |
pkg/porter/explain.go
Outdated
|
||
// Check whether the bundle requires docker mixin and warn for host access. | ||
var requireDocker bool = false | ||
for _, mixin := range bun.Mixins { |
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.
Using the docker mixin isn't the problem we need to warn about. What we are looking for is when a bundle declares that it requires docker host access:
https://porter.sh/author-bundles/#required
required:
- docker # this says inject the docker socket into the bundle
The preferred way to check for that is with bun.SupportsX
, like bun.SupportsFileParameters
, which checks if a CNAB required extension is defined on the bundle. There should be a function named bun.SupportsDocker
but I guess that function never made.
It should look like this:
func SupportsParameterSources(b bundle.Bundle) bool { |
which should be added to https://github.com/getporter/porter/blob/main/pkg/cnab/extensions/docker.go
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 just realized that I didn't stumble upon this one since the directory of pkg/cnab/extensions
doesn't exist on release/v1
branch but only exists on main
branch. Does this mean that the PR for this particular issue should be made upon the main
branch?
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.
Oops, sorry I shouldn't have linked to the main branch. This PR should target release/v1 but the code that I wanted to show you as an example moved a bit:
porter/pkg/cnab/parameter_sources.go
Lines 204 to 206 in a93a44a
func (b ExtendedBundle) SupportsParameterSources() bool { | |
return b.SupportsExtension(ParameterSourcesExtensionKey) | |
} |
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.
Edited, thank you so much for the guidance, Carolyn! 😄
@carolynvs Also I found this particular TODO line while working on this issue. Does this mean that we have to address this before https://github.com/getporter/porter/blob/release/v1/pkg/cnab/file_parameter.go#L39-L42 |
Wait why can't my link for line of code on GitHub be rendered as a snippet like yours 🤔 |
d7e8c5f
to
9a21508
Compare
oof, that is a good question. If we removed that and relied 100% on if the bundle says that it supports file parameters, then old bundles would stop working in porter v1.0.0. I don't really see a good reason to do that, and it's just a single line to keep around to keep old bundles working. We should just remove that todo and not remove that line of code. |
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 looks great! I just had some small suggestions. Once the unit tests are passing (there's a build failure in the tests), this is ready to go! 🚀
pkg/porter/explain.go
Outdated
fmt.Fprintf(p.Out, "porter install%s%s%s\n", bundleReferenceFlag, requiredParameterFlags, credentialFlags) | ||
porterInstallCommand := fmt.Sprintf("porter install%s%s%s", bundleReferenceFlag, requiredParameterFlags, credentialFlags) | ||
|
||
// Check whether the bundle requires docker mixin and add flag for host access for install command. |
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 comment is a bit misleading since we aren't checking for the docker mixin, but if the bundle requires the docker socket to be mounted into the bundle.
pkg/porter/explain_test.go
Outdated
err = p.printBundleExplain(opts, pb, b) | ||
assert.NoError(t, err) | ||
gotOutput := p.TestConfig.TestContext.GetOutput() | ||
expected, err := ioutil.ReadFile("testdata/explain/expected-table-output-docker.txt") |
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.
We have a test helper that makes it easier to compare command output with the contents of a file and keep it in sync when the command output changes.
import "get.porter.sh/porter/pkg/test"
test.CompareGoldenFile(t, "testdata/explain/expected-table-output-docker.txt", gotOutput)
If you run mage updateTestFiles
it will find any tests whose output has changed and updates the testdata file automatically so the test passes.
We aren't using that new helper function everywhere in Porter yet, but I'd like new tests to use it so they are easier to maintain.
93fc135
to
cc5b376
Compare
…is docker as one of the required mixins in the bundle Signed-off-by: joshuabezaleel <[email protected]>
Signed-off-by: joshuabezaleel <[email protected]>
Signed-off-by: joshuabezaleel <[email protected]>
Signed-off-by: joshuabezaleel <[email protected]>
Signed-off-by: joshuabezaleel <[email protected]>
Signed-off-by: joshuabezaleel <[email protected]>
Signed-off-by: joshuabezaleel <[email protected]>
Signed-off-by: joshuabezaleel <[email protected]>
Signed-off-by: joshuabezaleel <[email protected]>
da29fba
to
b794ac2
Compare
@carolynvs Sorry for the failing test, my bad. Should be all green by now. Thank you Carolyn! 😄 |
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 love all the improvements to porter explain! It really makes it a much better experience for new users and helping them learn how to use bundles. 👍
I really hope the |
What does this change
When the bundle has docker as one of the required mixins,
porter explain
command warns for the host access in advance and also include--allow-docker-host-access
flag for the installation command at the end.I attached the screenshot for running the
![image](https://user-images.githubusercontent.com/7043511/150789019-cc7f6fa0-f225-4ddd-a090-5e2f6770550c.png)
porter explain
command for thetabbycat-demo
bundle withdocker
added as one of the required mixins and also for thewhalesay
bundle.What issue does it fix
Closes #1830
Checklist
Reviewer Checklist