-
Notifications
You must be signed in to change notification settings - Fork 1.3k
buildctl: fix tlsdir handling logic for cert-manager.io #5950
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
Conversation
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.
PTAL CI errors, look related
cmd/buildctl/common/common.go
Outdated
@@ -18,6 +18,30 @@ import ( | |||
"go.opentelemetry.io/otel/trace" | |||
) | |||
|
|||
// ResolveTLSFilesFromDir scans a TLS directory for known cert/key filenames. | |||
func ResolveTLSFilesFromDir(tlsDir string) (caCert, cert, key string, err 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.
Keep this helper function private as seems to be only used internally.
cmd/buildctl/common/common.go
Outdated
return fpath, nil | ||
} | ||
} | ||
return "", errors.Errorf("directory did not contain one of the needed files: %s or %s", either, or) |
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.
Might be better to capture actual error if the error was not IsNotExist()
. Eg. could be that the file exists but is returning eperm.
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.
Done.
cmd/buildctl/common/common_test.go
Outdated
caOut, certOut, keyOut, err := resolveTLSFilesFromDir(dir) | ||
require.Equal(t, ca, caOut) | ||
require.Empty(t, cert, certOut) | ||
require.Empty(t, key, keyOut) |
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.
There is a typo here, should be:
require.Equal(t, cert, certOut)
require.Equal(t, key, keyOut)
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.
Fixed.
`tldir` flag handling now properly handles the old logic and the new logic for cert-manager.io without failing. Improved error message when files are missing. Co-authored-by: Gleb Nebolyubov <gleb.nebo@gmail.com> Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
|
||
// resolveTLSFilesFromDir scans a TLS directory for known cert/key filenames. | ||
func resolveTLSFilesFromDir(tlsDir string) (caCert, cert, key string, err error) { | ||
oneOf := func(either, or string) (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.
nit: simpler if just func(names ...string)
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.
It made the error message more difficult to write because then I'd have to check the number of arguments for the correct pattern of "X, Y, or Z" or just "X" or "X or Y". Since it's only ever called with two parameters, I just did it this way.
tldir
flag handling now properly handles the old logic and the newlogic for cert-manager.io without failing.
Improved error message when files are missing.
Fixes #5931.
Replaces #5935.
Co-authored-by: Gleb Nebolyubov gleb.nebo@gmail.com
Signed-off-by: Jonathan A. Sternberg jonathan.sternberg@docker.com