Skip to content

Commit 496111e

Browse files
committed
more docs.
1 parent 94f46da commit 496111e

4 files changed

Lines changed: 12 additions & 5 deletions

File tree

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ hcloud-cloud-controller-manager
88
*.tgz
99
hack/.*
1010
coverage/
11-
.vscode

hcloud/runtime_credentials.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func newRuntimeCredentials() (*runtimeCredentials, error) {
4949
credentials.robotUserPath = files.RobotUser
5050
credentials.robotPassPath = files.RobotPassword
5151

52-
if !files.HasAny() {
52+
if !files.HasAnyFilePaths() {
5353
return credentials, nil
5454
}
5555

@@ -115,6 +115,7 @@ func (c *runtimeCredentials) watch() {
115115
select {
116116
case event, ok := <-c.watcher.Events:
117117
if !ok {
118+
// !ok means the watcher closed the events channel.
118119
return
119120
}
120121
if !shouldReload(event) {
@@ -129,6 +130,7 @@ func (c *runtimeCredentials) watch() {
129130
debounceTimer.Reset(credentialsReloadDebounce)
130131
case err, ok := <-c.watcher.Errors:
131132
if !ok {
133+
// !ok means the watcher closed the errors channel.
132134
return
133135
}
134136
klog.ErrorS(err, "watching mounted credential files")

internal/config/runtime_credentials.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,22 @@ import (
1010
"github.com/hetznercloud/hcloud-go/v2/hcloud/exp/kit/envutil"
1111
)
1212

13+
// RuntimeCredentialFiles contains file-backed credential sources that can be
14+
// watched for runtime reloads.
1315
type RuntimeCredentialFiles struct {
1416
HCloudToken string
1517
RobotUser string
1618
RobotPassword string
1719
}
1820

19-
func (f RuntimeCredentialFiles) HasAny() bool {
21+
// HasAnyFilePaths reports whether any runtime credential file path is
22+
// configured.
23+
func (f RuntimeCredentialFiles) HasAnyFilePaths() bool {
2024
return f.HCloudToken != "" || f.RobotUser != "" || f.RobotPassword != ""
2125
}
2226

27+
// Directories returns the unique parent directories of the configured
28+
// credential files.
2329
func (f RuntimeCredentialFiles) Directories() []string {
2430
return uniqueDirectories(f.HCloudToken, f.RobotUser, f.RobotPassword)
2531
}

internal/config/runtime_credentials_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
func TestRuntimeCredentialFilesHelpers(t *testing.T) {
1414
files := RuntimeCredentialFiles{}
15-
assert.False(t, files.HasAny())
15+
assert.False(t, files.HasAnyFilePaths())
1616
assert.Empty(t, files.Directories())
1717

1818
files = RuntimeCredentialFiles{
@@ -21,7 +21,7 @@ func TestRuntimeCredentialFilesHelpers(t *testing.T) {
2121
RobotPassword: "/tmp/two/password",
2222
}
2323

24-
assert.True(t, files.HasAny())
24+
assert.True(t, files.HasAnyFilePaths())
2525
assert.ElementsMatch(t, []string{"/tmp/one", "/tmp/two"}, files.Directories())
2626
}
2727

0 commit comments

Comments
 (0)