Skip to content

Commit

Permalink
Merge pull request #6168 from sbueringer/pr-doc-json-log-change
Browse files Browse the repository at this point in the history
📖 book: document component-base/logs change in migration doc
  • Loading branch information
k8s-ci-robot authored Feb 24, 2022
2 parents 73ff976 + 942f57c commit fbc39a0
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion docs/book/src/developer/providers/v1.1-to-v1.2.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,43 @@ in ClusterAPI are kept in sync with the versions used by `sigs.k8s.io/controller

### Other

-
- Logging:
- To align with the upstream Kubernetes community CAPI now configures logging via `component-base/logs`.
This provides advantages like support for the JSON logging format (via `--logging-format=json`) and automatic
deprecation of klog flags aligned to the upstream Kubernetes deprecation period.
<details>
<summary>View <code>main.go</code> diff</summary>

```diff
var (
...
+ logOptions = logs.NewOptions()
)

func init() {
- klog.InitFlags(nil)

func InitFlags(fs *pflag.FlagSet) {
+ logs.AddFlags(fs, logs.SkipLoggingConfigurationFlags())
+ logOptions.AddFlags(fs)

func main() {
...
pflag.Parse()

+ if err := logOptions.ValidateAndApply(); err != nil {
+ setupLog.Error(err, "unable to start manager")
+ os.Exit(1)
+ }
+
+ // Set the Klog format, as the Serialize format shouldn't be used anymore.
+ // This makes sure that the logs are formatted correctly, i.e.:
+ // * JSON logging format: msg isn't serialized twice
+ // * text logging format: values are formatted with their .String() func.
+ ctrl.SetLogger(klogr.NewWithOptions(klogr.WithFormat(klogr.FormatKlog)))
- ctrl.SetLogger(klogr.New())
```
</details>

This change has been introduced in CAPI in the following PRs: [#6072](https://github.com/kubernetes-sigs/cluster-api/pull/6072), [#6190](https://github.com/kubernetes-sigs/cluster-api/pull/6190).</br>
**Note**: This change is not mandatory for providers, but highly recommended.

0 comments on commit fbc39a0

Please sign in to comment.