Skip to content

Commit d3a31fe

Browse files
committed
Default logger to production mode
Switch "Development: false" in both cmd/main.go and cmd/operator/main.go so the controller emits structured JSON logs by default. Add $(ARGS) to the run and run-operator Makefile targets so dev logging can be restored with: make run ARGS="--zap-devel". As part of ESS SEC-APP-REQ-1 (Secure Application Development), we need to ensure that proper input and output sanitization is implemented. While working on the OpenStack Lightspeed Operator, I noticed that this is also missing from the OpenStack Operator. There may be other places requiring changes to complete the ESS, I did not performed a complete analysis of this repository. Signed-off-by: Lucas Alvares Gomes <lucasagomes@gmail.com>
1 parent b243f21 commit d3a31fe

4 files changed

Lines changed: 13 additions & 12 deletions

File tree

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ run: export ENABLE_WEBHOOKS?=false
240240
run: manifests generate fmt vet ## Run a controller from your host.
241241
/bin/bash hack/clean_local_webhook.sh
242242
source hack/export_related_images.sh && \
243-
go run ./cmd/main.go -metrics-bind-address ":$(METRICS_PORT)" -health-probe-bind-address ":$(HEALTH_PORT)" -pprof-bind-address ":$(PPROF_PORT)"
243+
go run ./cmd/main.go -metrics-bind-address ":$(METRICS_PORT)" -health-probe-bind-address ":$(HEALTH_PORT)" -pprof-bind-address ":$(PPROF_PORT)" $(ARGS)
244244

245245
.PHONY: run-operator
246246
run-operator: export METRICS_PORT?=8080
@@ -252,7 +252,7 @@ run-operator: export OPERATOR_IMAGE_URL=${IMG}
252252
run-operator: manifests generate fmt vet ## Run a controller from your host.
253253
source hack/export_related_images.sh && \
254254
source hack/export_operator_related_images.sh && \
255-
go run ./cmd/operator/main.go -metrics-bind-address ":$(METRICS_PORT)" -health-probe-bind-address ":$(HEALTH_PORT)" -pprof-bind-address ":$(PPROF_PORT)"
255+
go run ./cmd/operator/main.go -metrics-bind-address ":$(METRICS_PORT)" -health-probe-bind-address ":$(HEALTH_PORT)" -pprof-bind-address ":$(PPROF_PORT)" $(ARGS)
256256

257257
.PHONY: docker-build
258258
docker-build: ## Build docker image with the manager.

README.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,19 +123,16 @@ It uses [Controllers](https://kubernetes.io/docs/concepts/architecture/controlle
123123
which provides a reconcile function responsible for synchronizing resources untile the desired state is reached on the cluster
124124

125125
### Test It Out
126-
1. Install the CRDs into the cluster:
127126

128-
```sh
129-
make install
130-
```
131-
132-
2. Run your controller (this will run in the foreground, so switch to a new terminal if you want to leave it running):
127+
Install the CRDs into the cluster and run your controller (this will
128+
run in the foreground, so switch to a new terminal if you want to leave
129+
it running):
133130

134131
```sh
135-
make run
132+
make install run ARGS="--zap-devel"
136133
```
137134

138-
**NOTE:** You can also run this in one step by running: `make install run`
135+
**NOTE:** `--zap-devel` enable verbose (development) logging locally.
139136

140137
### Modifying the API definitions
141138
If you are editing the API definitions, generate the manifests such as CRs or CRDs using:

cmd/main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,9 @@ func main() {
171171
flag.BoolVar(&enableHTTP2, "enable-http2", false,
172172
"If set, HTTP/2 will be enabled for the metrics and webhook servers")
173173
opts := zap.Options{
174-
Development: true,
174+
// Development: false uses JSON encoding and omits stack traces / DPanic behaviour.
175+
// For local development use: make run ARGS="--zap-devel"
176+
Development: false,
175177
}
176178
opts.BindFlags(flag.CommandLine)
177179
flag.Parse()

cmd/operator/main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ func main() {
8787
flag.BoolVar(&enableHTTP2, "enable-http2", false,
8888
"If set, HTTP/2 will be enabled for the metrics and webhook servers")
8989
opts := zap.Options{
90-
Development: true,
90+
// Development: false uses JSON encoding and omits stack traces / DPanic behaviour.
91+
// For local development use: make run ARGS="--zap-devel"
92+
Development: false,
9193
}
9294
opts.BindFlags(flag.CommandLine)
9395
flag.Parse()

0 commit comments

Comments
 (0)