Skip to content

Commit

Permalink
config: minor fixes on driver logging config
Browse files Browse the repository at this point in the history
Since `nomad` is the default value for `Driver` users may be able to
specify just `Options` in the task `config`, so we need to check if no
value are set.
  • Loading branch information
lgfa29 committed Feb 8, 2024
1 parent 3b3cf3a commit 79fa570
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

IMPROVEMENTS:

* build: Updated to Go 1.21.5 [[GH-303](https://github.com/hashicorp/nomad-driver-podman/pull/303)]
* build: Updated to Go 1.21.5 [[GH-303](https://github.com/hashicorp/nomad-driver-podman/pull/303)]
* config: Add `logging` options to the plugin configuration [[GH-285](https://github.com/hashicorp/nomad-driver-podman/pull/285)]

## 0.5.1 (August 14, 2023)

Expand Down
5 changes: 5 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ type TaskLoggingConfig struct {
Options hclutils.MapStrStr `codec:"options"`
}

// Empty returns true if the logging configuration is not set.
func (l *TaskLoggingConfig) Empty() bool {
return l.Driver == "" && len(l.Options) == 0
}

// VolumeConfig is the drivers volume specific configuration
type VolumeConfig struct {
Enabled bool `codec:"enabled"`
Expand Down
8 changes: 3 additions & 5 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,9 +502,9 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive
createOpts.ContainerBasicConfig.Labels = driverConfig.Labels

// Logging
if driverConfig.Logging.Driver != "" {
if !driverConfig.Logging.Empty() {
switch driverConfig.Logging.Driver {
case LOG_DRIVER_NOMAD:
case "", LOG_DRIVER_NOMAD:
if !d.config.DisableLogCollection {
createOpts.LogConfiguration.Driver = "k8s-file"
createOpts.ContainerBasicConfig.LogConfiguration.Path = cfg.StdoutPath
Expand All @@ -518,9 +518,7 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive
} else {
d.logger.Trace("no podman log driver provided, defaulting to plugin config")
switch d.config.Logging.Driver {
case "": // The default is nomad
fallthrough
case LOG_DRIVER_NOMAD:
case "", LOG_DRIVER_NOMAD:
if !d.config.DisableLogCollection {
createOpts.LogConfiguration.Driver = "k8s-file"
createOpts.ContainerBasicConfig.LogConfiguration.Path = cfg.StdoutPath
Expand Down

0 comments on commit 79fa570

Please sign in to comment.