Skip to content

Commit 942f57c

Browse files
committed
book: document component-base/logs change in migration doc
Signed-off-by: Stefan Büringer buringerst@vmware.com
1 parent 73ff976 commit 942f57c

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

docs/book/src/developer/providers/v1.1-to-v1.2.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,43 @@ in ClusterAPI are kept in sync with the versions used by `sigs.k8s.io/controller
3434

3535
### Other
3636

37-
-
37+
- Logging:
38+
- To align with the upstream Kubernetes community CAPI now configures logging via `component-base/logs`.
39+
This provides advantages like support for the JSON logging format (via `--logging-format=json`) and automatic
40+
deprecation of klog flags aligned to the upstream Kubernetes deprecation period.
41+
<details>
42+
<summary>View <code>main.go</code> diff</summary>
43+
44+
```diff
45+
var (
46+
...
47+
+ logOptions = logs.NewOptions()
48+
)
49+
50+
func init() {
51+
- klog.InitFlags(nil)
52+
53+
func InitFlags(fs *pflag.FlagSet) {
54+
+ logs.AddFlags(fs, logs.SkipLoggingConfigurationFlags())
55+
+ logOptions.AddFlags(fs)
56+
57+
func main() {
58+
...
59+
pflag.Parse()
60+
61+
+ if err := logOptions.ValidateAndApply(); err != nil {
62+
+ setupLog.Error(err, "unable to start manager")
63+
+ os.Exit(1)
64+
+ }
65+
+
66+
+ // Set the Klog format, as the Serialize format shouldn't be used anymore.
67+
+ // This makes sure that the logs are formatted correctly, i.e.:
68+
+ // * JSON logging format: msg isn't serialized twice
69+
+ // * text logging format: values are formatted with their .String() func.
70+
+ ctrl.SetLogger(klogr.NewWithOptions(klogr.WithFormat(klogr.FormatKlog)))
71+
- ctrl.SetLogger(klogr.New())
72+
```
73+
</details>
74+
75+
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>
76+
**Note**: This change is not mandatory for providers, but highly recommended.

0 commit comments

Comments
 (0)