Skip to content

Commit

Permalink
wip: rework dump flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Travis Raines committed Jan 26, 2021
1 parent 546a81c commit c742ec1
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
11 changes: 7 additions & 4 deletions cli/ingress-controller/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ type cliConfig struct {
EnableReverseSync bool

// Logging
LogLevel string
LogFormat string
LogSensitiveConfig bool
LogLevel string
LogFormat string
DumpConfig string

// k8s connection details
APIServerHost string
Expand Down Expand Up @@ -199,6 +199,9 @@ trace, debug, info, warn, error, fatal and panic.`)
flags.String("log-format", "text",
`Format of logs of the controller. Allowed values are
text and json.`)
flags.String("dump-config", "",
`Dump generated configuration to filesystem when set to "enabled".
When set to "sensitive", dumps will include certificate+key pairs and credentials.`)

// k8s connection details
flags.String("apiserver-host", "",
Expand Down Expand Up @@ -311,7 +314,7 @@ func parseFlags() (cliConfig, error) {
// Logging
config.LogLevel = viper.GetString("log-level")
config.LogFormat = viper.GetString("log-format")
config.LogSensitiveConfig = viper.GetBool("log-sensitive-config")
config.DumpConfig = viper.GetString("dump-config")

// k8s connection details
config.APIServerHost = viper.GetString("apiserver-host")
Expand Down
4 changes: 2 additions & 2 deletions cli/ingress-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ func controllerConfigFromCLIConfig(cliConfig cliConfig) controller.Configuration
UpdateStatusOnShutdown: cliConfig.UpdateStatusOnShutdown,
ElectionID: cliConfig.ElectionID,

LogSensitiveConfig: cliConfig.LogSensitiveConfig,
LogLevel: cliConfig.LogLevel,
DumpConfig: cliConfig.DumpConfig,
LogLevel: cliConfig.LogLevel,
}
}

Expand Down
6 changes: 3 additions & 3 deletions internal/ingress/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ type Configuration struct {

EnableKnativeIngressSupport bool

Logger logrus.FieldLogger
LogSensitiveConfig bool
LogLevel string
Logger logrus.FieldLogger
LogLevel string
DumpConfig string
}

// sync collects all the pieces required to assemble the configuration file and
Expand Down
6 changes: 3 additions & 3 deletions internal/ingress/controller/kong.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ func (n *KongController) OnUpdate(ctx context.Context, state *kongstate.KongStat
err = n.onUpdateDBMode(targetContent)
}
var target []byte
if n.cfg.LogSensitiveConfig {
if n.cfg.DumpConfig == "enabled" {
target, _ = json.Marshal(targetContent)
} else {
} else if n.cfg.DumpConfig == "sensitive" {
sanitizedState := state.SanitizedCopy()
target, _ = json.Marshal(n.toDeckContent(ctx, sanitizedState))
}
if err != nil {
if n.cfg.LogLevel == "debug" {
if len(target) > 0 {
_ = ioutil.WriteFile(filepath.Join(n.tmpDir, "target.json"), target, 0600)
_ = ioutil.WriteFile(filepath.Join(n.tmpDir, "last_good.json"), n.lastConfig, 0600)
}
Expand Down

0 comments on commit c742ec1

Please sign in to comment.