Skip to content

Commit 36f6489

Browse files
committed
Fix loading certificates
1 parent 71be7e6 commit 36f6489

File tree

4 files changed

+22
-10
lines changed

4 files changed

+22
-10
lines changed

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,8 @@ resource "kubernetes_deployment" "hello_world" {
3838
```
3939

4040
This ensures all pod events will be sent during initialization and startup.
41+
42+
## Custom Certificates
43+
44+
- [`SSL_CERT_FILE`](https://go.dev/src/crypto/x509/root_unix.go#L19): Specifies the path to an SSL certificate.
45+
- [`SSL_CERT_DIR`](https://go.dev/src/crypto/x509/root_unix.go#L25): Identifies which directory to check for SSL certificate files.

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ require (
3232
github.com/armon/go-radix v1.0.0 // indirect
3333
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
3434
github.com/beorn7/perks v1.0.1 // indirect
35+
github.com/breml/rootcerts v0.2.11 // indirect
3536
github.com/cenkalti/backoff/v4 v4.2.0 // indirect
3637
github.com/cespare/xxhash/v2 v2.2.0 // indirect
3738
github.com/charmbracelet/lipgloss v0.7.1 // indirect

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ github.com/bep/debounce v1.2.1 h1:v67fRdBA9UQu2NhLFXrSg0Brw7CexQekrBwDMM8bzeY=
114114
github.com/bep/godartsass v0.16.0 h1:nTpenrZBQjVSjLkCw3AgnYmBB2czauTJa4BLLv448qg=
115115
github.com/bep/golibsass v1.1.0 h1:pjtXr00IJZZaOdfryNa9wARTB3Q0BmxC3/V1KNcgyTw=
116116
github.com/bool64/shared v0.1.5 h1:fp3eUhBsrSjNCQPcSdQqZxxh9bBwrYiZ+zOKFkM0/2E=
117+
github.com/breml/rootcerts v0.2.11 h1:njUAtoyZ6HUXPAPk63tGz0BEZk1/6gyfqK5fTzksHkM=
118+
github.com/breml/rootcerts v0.2.11/go.mod h1:S/PKh+4d1HUn4HQovEB8hPJZO6pUZYrIhmXBhsegfXw=
117119
github.com/bytecodealliance/wasmtime-go/v3 v3.0.2 h1:3uZCA/BLTIu+DqCfguByNMJa2HVHpXvjfy0Dy7g6fuA=
118120
github.com/cenkalti/backoff/v4 v4.2.0 h1:HN5dHm3WBOgndBH6E8V0q2jIYIR3s9yglV8k/+MN3u4=
119121
github.com/cenkalti/backoff/v4 v4.2.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=

logger.go

+14-10
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ import (
1818
"k8s.io/client-go/informers"
1919
"k8s.io/client-go/kubernetes"
2020
"k8s.io/client-go/tools/cache"
21+
22+
// *Never* remove this. Certificates are not bundled as part
23+
// of the container, so this is necessary for all connections
24+
// to not be insecure.
25+
_ "github.com/breml/rootcerts"
2126
)
2227

2328
type podEventLoggerOptions struct {
@@ -137,18 +142,17 @@ func (p *podEventLogger) init() error {
137142
p.mutex.Lock()
138143
defer p.mutex.Unlock()
139144
tokens, ok := p.podToAgentTokens[pod.Name]
145+
if !ok {
146+
return
147+
}
140148
delete(p.podToAgentTokens, pod.Name)
141-
if ok {
142-
for _, token := range tokens {
143-
p.sendLog(pod.Name, token, agentsdk.StartupLog{
144-
CreatedAt: time.Now(),
145-
Output: fmt.Sprintf("🗑️ %s: %s", newColor(color.Bold).Sprint("Deleted pod"), pod.Name),
146-
Level: codersdk.LogLevelError,
147-
})
148-
}
149-
149+
for _, token := range tokens {
150+
p.sendLog(pod.Name, token, agentsdk.StartupLog{
151+
CreatedAt: time.Now(),
152+
Output: fmt.Sprintf("🗑️ %s: %s", newColor(color.Bold).Sprint("Deleted pod"), pod.Name),
153+
Level: codersdk.LogLevelError,
154+
})
150155
}
151-
152156
p.logger.Info(p.ctx, "unregistered agent pod", slog.F("pod", pod.Name))
153157
},
154158
})

0 commit comments

Comments
 (0)