|
4 | 4 | package main |
5 | 5 |
|
6 | 6 | import ( |
| 7 | + "bufio" |
7 | 8 | "bytes" |
8 | 9 | "crypto/x509" |
9 | 10 | "encoding/pem" |
@@ -97,6 +98,7 @@ type Config struct { |
97 | 98 | GoogleDriveImpersonateSubject string `split_words:"true"` |
98 | 99 | GoogleDriveEndpoint string `split_words:"true"` |
99 | 100 | GoogleDriveTokenURL string `split_words:"true"` |
| 101 | + Timezone string `envconfig:"TZ"` |
100 | 102 | source string |
101 | 103 | additionalEnvVars map[string]string |
102 | 104 | } |
@@ -322,3 +324,81 @@ func (c *Config) resolve() (reset func() error, warnings []string, err error) { |
322 | 324 | } |
323 | 325 | return |
324 | 326 | } |
| 327 | + |
| 328 | +func mountedPaths(path string) (map[string]struct{}, error) { |
| 329 | + file, err := os.Open(path) |
| 330 | + if err != nil { |
| 331 | + return nil, err |
| 332 | + } |
| 333 | + defer func() { _ = file.Close() }() |
| 334 | + |
| 335 | + mounts := make(map[string]struct{}) |
| 336 | + scanner := bufio.NewScanner(file) |
| 337 | + |
| 338 | + for scanner.Scan() { |
| 339 | + line := scanner.Text() |
| 340 | + parts := strings.SplitN(line, " - ", 2) |
| 341 | + fields := strings.Fields(parts[0]) |
| 342 | + if len(fields) < 5 { |
| 343 | + continue |
| 344 | + } |
| 345 | + mounts[fields[4]] = struct{}{} |
| 346 | + } |
| 347 | + |
| 348 | + if err := scanner.Err(); err != nil { |
| 349 | + return nil, err |
| 350 | + } |
| 351 | + |
| 352 | + return mounts, nil |
| 353 | +} |
| 354 | + |
| 355 | +func (c *Config) timezoneDeprecationWarnings() ([]string, error) { |
| 356 | + mounts, err := mountedPaths("/proc/self/mountinfo") |
| 357 | + if err != nil { |
| 358 | + return nil, errwrap.Wrap(err, "error reading mount info") |
| 359 | + } |
| 360 | + |
| 361 | + deprecatedMounts := []string{ |
| 362 | + "/etc/timezone", |
| 363 | + "/etc/localtime", |
| 364 | + "/usr/share/zoneinfo", |
| 365 | + } |
| 366 | + |
| 367 | + var found []string |
| 368 | + for _, mnt := range deprecatedMounts { |
| 369 | + if _, ok := mounts[mnt]; ok { |
| 370 | + found = append(found, mnt) |
| 371 | + } |
| 372 | + } |
| 373 | + |
| 374 | + if len(found) == 0 { |
| 375 | + return nil, nil |
| 376 | + } |
| 377 | + |
| 378 | + var warnings []string |
| 379 | + |
| 380 | + // Primary deprecation message (compressed) |
| 381 | + warnings = append(warnings, |
| 382 | + fmt.Sprintf( |
| 383 | + "Deprecated timezone bind mounts detected: %s. Support for these will be removed in a future version.", |
| 384 | + strings.Join(found, ", "), |
| 385 | + ), |
| 386 | + ) |
| 387 | + |
| 388 | + // Guidance based on TZ usage |
| 389 | + if c.Timezone == "" { |
| 390 | + warnings = append(warnings, |
| 391 | + "Set the container timezone using the `TZ` environment variable instead.", |
| 392 | + "Refer to the documentation for migration details.", |
| 393 | + ) |
| 394 | + } else { |
| 395 | + warnings = append(warnings, |
| 396 | + fmt.Sprintf( |
| 397 | + "`TZ=%s` is set, but deprecated timezone bind mounts are still present. Remove the bind mounts after confirming timezone handling works as expected.", |
| 398 | + c.Timezone, |
| 399 | + ), |
| 400 | + ) |
| 401 | + } |
| 402 | + |
| 403 | + return warnings, nil |
| 404 | +} |
0 commit comments