Skip to content

Conversation

jsternberg
Copy link
Collaborator

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.

Fixes #5931.
Replaces #5935.

Co-authored-by: Gleb Nebolyubov gleb.nebo@gmail.com
Signed-off-by: Jonathan A. Sternberg jonathan.sternberg@docker.com

Copy link
Member

@tonistiigi tonistiigi left a 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

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

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.

return fpath, nil
}
}
return "", errors.Errorf("directory did not contain one of the needed files: %s or %s", either, or)
Copy link
Member

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

caOut, certOut, keyOut, err := resolveTLSFilesFromDir(dir)
require.Equal(t, ca, caOut)
require.Empty(t, cert, certOut)
require.Empty(t, key, keyOut)
Copy link
Contributor

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)

Copy link
Collaborator Author

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

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)

Copy link
Collaborator Author

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.

@tonistiigi tonistiigi merged commit 2e531e7 into moby:master Apr 29, 2025
111 checks passed
@jsternberg jsternberg deleted the fix-tlsdir branch April 29, 2025 15:28
@thompson-shaun thompson-shaun added this to the v0.21.1 milestone Apr 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

#5886 broke tlsdir option
4 participants