Skip to content

Conversation

@Kristina-Pianykh
Copy link
Contributor

@Kristina-Pianykh Kristina-Pianykh commented Aug 31, 2025

This PR introduces a new configuration option in the Helm chart to control the logging mode (development/production) of the k6-operator-controller-manager.

The issue and the proposed solution are laid out in #638.
Closes #638.

TL;DR: Currently, the manager's logs are in the console format, which can be difficult to parse for structured logging platforms like Datadog or Loki. This change makes the logging mode configurable, allowing users to switch to a production-mode logger.

The change is backward compatible (the default logger remains in the development mode by default as it’s currently configured).

To benefit from the production-mode logger:

k6-operator:
  manager:
    replicas: 1
    serviceAccount:
      create: true
      name: k6-operator-controller
    ...
    logging:
      development: false

Test

  • To check the final manifests after templating (override the default logger to set it to production mode):
IMG_NAME=k6operator IMG_TAG=foo make manifests helm
IMG_TAG=foo helm template k6-operator ./charts/k6-operator -f ./charts/k6-operator/values.yaml --set manager.image.tag=$IMG_TAG --set manager.logging.development=false
  • To check the default behavior (development-mode logger):
kind create cluster --name k6-test
kind load docker-image k6operator:foo --name k6-test
IMG_NAME=k6operator IMG_TAG=foo make deploy
kubectl logs -n k6-operator-system $(kubectl get pods -n k6-operator-system \
  -l control-plane=controller-manager \
  -o jsonpath="{.items[0].metadata.name}") | head -n 10

Output (development-mode logging, console formatting, as expected):

2025-08-31T16:19:06Z	INFO	setup	starting manager
2025-08-31T16:19:06Z	INFO	controller-runtime.metrics	Starting metrics server
2025-08-31T16:19:06Z	INFO	controller-runtime.metrics	Serving metrics server	{"bindAddress": ":8080", "secure": false}
2025-08-31T16:19:06Z	INFO	starting server	{"name": "health probe", "addr": "[::]:8081"}
I0831 16:19:06.969169       1 leaderelection.go:257] attempting to acquire leader lease k6-operator-system/fcdfce80.io...
I0831 16:19:07.176597       1 leaderelection.go:271] successfully acquired lease k6-operator-system/fcdfce80.io
2025-08-31T16:19:07Z	DEBUG	events	k6-operator-controller-manager-54bc86d7db-xm69v_bf5e5a34-b65b-4a07-a8bc-6681266b22a1 became leader	{"type": "Normal", "object": {"kind":"Lease","namespace":"k6-operator-system","name":"fcdfce80.io","uid":"9004a3f9-27ee-4434-be9c-055100855876","apiVersion":"coordination.k8s.io/v1","resourceVersion":"692"}, "reason": "LeaderElection"}
2025-08-31T16:19:07Z	INFO	Starting EventSource	{"controller": "testrun", "controllerGroup": "k6.io", "controllerKind": "TestRun", "source": "kind source: *v1.Pod"}
2025-08-31T16:19:07Z	INFO	Starting EventSource	{"controller": "privateloadzone", "controllerGroup": "k6.io", "controllerKind": "PrivateLoadZone", "source": "kind source: *v1alpha1.PrivateLoadZone"}
2025-08-31T16:19:07Z	INFO	Starting EventSource	{"controller": "testrun", "controllerGroup": "k6.io", "controllerKind": "TestRun", "source": "kind source: *v1alpha1.TestRun"}
  • I also installed the updated k6-operator by referencing it locally in a minimal setup:
❯ tree -L 3 .
.
├── Chart.lock
├── Chart.yaml
├── charts
│   ├── k6-operator
│   │   ├── Chart.yaml
│   │   ├── README.md
│   │   ├── README.md.gotmpl
│   │   ├── samples
│   │   ├── templates
│   │   ├── values.schema.json
│   │   └── values.yaml
│   └── k6-operator-3.16.0.tgz
└── values.yaml

Chart.yaml:

apiVersion: v2
name: k6-test
version: 0.1.0
dependencies:
  - name: k6-operator
    version: ">=0.0.0"
    repository: "file://charts/k6-operator"

values.yaml:

k6-operator:
  manager:
    logging:
      development: false
kind create cluster --name k6-test
helm install k6-test ./ \                                            
  --namespace k6-operator-system \      
  -f values.yaml
kubectl logs -n k6-operator-system $(kubectl get pods -n k6-operator-system \
  -l control-plane=controller-manager \
  -o jsonpath="{.items[0].metadata.name}")

Output (the default logger is overriden with the production logger):

{"level":"info","ts":"2025-08-31T15:27:23Z","logger":"setup","msg":"starting manager"}
{"level":"info","ts":"2025-08-31T15:27:23Z","msg":"starting server","name":"health probe","addr":"[::]:8081"}
{"level":"info","ts":"2025-08-31T15:27:23Z","logger":"controller-runtime.metrics","msg":"Starting metrics server"}
{"level":"info","ts":"2025-08-31T15:27:23Z","logger":"controller-runtime.metrics","msg":"Serving metrics server","bindAddress":":8443","secure":false}
{"level":"info","ts":"2025-08-31T15:27:23Z","msg":"Starting EventSource","controller":"testrun","controllerGroup":"k6.io","controllerKind":"TestRun","source":"kind source: *v1.Pod"}
{"level":"info","ts":"2025-08-31T15:27:23Z","msg":"Starting EventSource","controller":"testrun","controllerGroup":"k6.io","controllerKind":"TestRun","source":"kind source: *v1alpha1.TestRun"}

@CLAassistant
Copy link

CLAassistant commented Aug 31, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
Collaborator

@yorugac yorugac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Kristina-Pianykh, the changes seem to work fine 🙌 I have just one small request to move the logic out to the helper file: please see my coment.

- --leader-elect
{{- end }}
- --metrics-bind-address=:8443
- --zap-devel={{ if hasKey .Values.manager.logging "development" }}{{ .Values.manager.logging.development | toString }}{{ else }}true{{ end }}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to move this out into _helpers.tpl, to simplify readability a bit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the review @yorugac , much appreciated!
I've moved it to the helpers template in 8a05509 and rebased.

@Kristina-Pianykh Kristina-Pianykh force-pushed the feat/configurable-logging branch from ad4c4d5 to 3375e25 Compare September 11, 2025 14:37
Copy link
Collaborator

@yorugac yorugac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update, @Kristina-Pianykh! LGTM 🙌

@yorugac yorugac merged commit 4977b9c into grafana:main Sep 12, 2025
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow configuration of controller manager's logger via Helm chart

3 participants