|
4 | 4 | package config |
5 | 5 |
|
6 | 6 | import ( |
| 7 | + "context" |
7 | 8 | "crypto/tls" |
8 | 9 | "crypto/x509" |
9 | 10 | "errors" |
10 | 11 | "fmt" |
11 | 12 | "io/fs" |
12 | 13 | "os" |
| 14 | + "sigs.k8s.io/controller-runtime/pkg/certwatcher" |
13 | 15 | "time" |
14 | 16 |
|
15 | 17 | "github.com/go-logr/logr" |
@@ -207,26 +209,31 @@ func Load() (*Config, string, error) { |
207 | 209 |
|
208 | 210 | // ValidateConfig validates the cli and file configs together. |
209 | 211 | func ValidateConfig(config *Config) error { |
210 | | - scrapeConfigsPresent := (config.PromConfig != nil && len(config.PromConfig.ScrapeConfigs) > 0) |
| 212 | + scrapeConfigsPresent := config.PromConfig != nil && len(config.PromConfig.ScrapeConfigs) > 0 |
211 | 213 | if !(config.PrometheusCR.Enabled || scrapeConfigsPresent) { |
212 | 214 | return fmt.Errorf("at least one scrape config must be defined, or Prometheus CR watching must be enabled") |
213 | 215 | } |
214 | 216 | return nil |
215 | 217 | } |
216 | 218 |
|
217 | | -func (c HTTPSServerConfig) NewTLSConfig() (*tls.Config, error) { |
218 | | - cert, err := tls.LoadX509KeyPair(c.TLSCertFilePath, c.TLSKeyFilePath) |
| 219 | +func (c HTTPSServerConfig) NewTLSConfig(ctx context.Context) (*tls.Config, error) { |
| 220 | + tlsConfig := &tls.Config{ |
| 221 | + MinVersion: tls.VersionTLS13, |
| 222 | + } |
| 223 | + |
| 224 | + certWatcher, err := certwatcher.New(c.TLSCertFilePath, c.TLSKeyFilePath) |
219 | 225 | if err != nil { |
220 | 226 | return nil, err |
221 | 227 | } |
222 | | - tlsConfig := &tls.Config{ |
223 | | - Certificates: []tls.Certificate{cert}, |
224 | | - ClientAuth: tls.NoClientCert, |
225 | | - MinVersion: tls.VersionTLS12, |
226 | | - } |
| 228 | + tlsConfig.GetCertificate = certWatcher.GetCertificate |
| 229 | + go func() { |
| 230 | + _ = certWatcher.Start(ctx) |
| 231 | + }() |
| 232 | + |
227 | 233 | if c.CAFilePath == "" { |
228 | 234 | return tlsConfig, nil |
229 | 235 | } |
| 236 | + |
230 | 237 | caCert, err := os.ReadFile(c.CAFilePath) |
231 | 238 | caCertPool := x509.NewCertPool() |
232 | 239 | if err != nil { |
|
0 commit comments