Skip to content

Commit

Permalink
Allow modifying log verbosity in CDI (#2882)
Browse files Browse the repository at this point in the history
* Allow modifying log verbosity from cdiConfig

This commit adds a new field in the cdiConfig API to allow specifying a log verbosity level to initialize all loggers.

Changes in this field will mean restarting all CDI components to initialize all loggers.

Signed-off-by: Alvaro Romero <alromero@redhat.com>

* Update debug documentation to cover log verbosity

Signed-off-by: Alvaro Romero <alromero@redhat.com>

---------

Signed-off-by: Alvaro Romero <alromero@redhat.com>
  • Loading branch information
alromeros committed Sep 8, 2023
1 parent 18e6607 commit 030846a
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 3 deletions.
5 changes: 5 additions & 0 deletions api/openapi-spec/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -4935,6 +4935,11 @@
"default": ""
}
},
"logVerbosity": {
"description": "LogVerbosity overrides the default verbosity level used to initialize loggers",
"type": "integer",
"format": "int32"
},
"podResourceRequirements": {
"description": "ResourceRequirements describes the compute resource requirements.",
"$ref": "#/definitions/v1.ResourceRequirements"
Expand Down
20 changes: 19 additions & 1 deletion doc/debug.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,22 @@ spec:
resources:
requests:
storage: 1Gi
```
```

## Log verbosity

Different levels of verbosity are used in CDI to control the amount of information that is logged. The verbosity level of logs in CDI can be adjusted using a dedicated field in CDIConfig. This feature enables users to control the amount of detail displayed in logs, ranging from minimal to detailed debugging information.

For example:

```yaml
apiVersion: cdi.kubevirt.io/v1beta1
kind: CDI
# ...
spec:
config:
# Overrides the default verbosity level with 4
logVerbosity: 4
```

Changing the verbosity level will automatically restart the CDI components to re-initialize the loggers with the new value.
7 changes: 7 additions & 0 deletions pkg/apis/core/v1beta1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions pkg/operator/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"os"
"reflect"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -558,6 +559,28 @@ var _ = Describe("Controller", func() {
Expect(cdi.Spec.Config).To(Equal(&cfg.Spec))
})

It("should set verbosity level into namespacedArguments", func() {
args := createArgs()
doReconcile(args)
Expect(args.reconciler.namespacedArgs.Verbosity).To(Equal("1"))
expectedValue := int32(5)
cfg := &cdiv1.CDIConfig{
ObjectMeta: metav1.ObjectMeta{
Name: "config",
},
Spec: cdiv1.CDIConfigSpec{
LogVerbosity: &expectedValue,
},
}

err := args.client.Create(context.TODO(), cfg)
Expect(err).ToNot(HaveOccurred())
doReconcile(args)
Expect(*args.cdi.Spec.Config.LogVerbosity).To(Equal(expectedValue))
args.reconciler.namespacedArgs = args.reconciler.getNamespacedArgs(args.cdi)
Expect(args.reconciler.namespacedArgs.Verbosity).To(Equal(strconv.Itoa(int(expectedValue))))
})

It("can become become ready, un-ready, and ready again", func() {
var deployment *appsv1.Deployment

Expand Down
11 changes: 9 additions & 2 deletions pkg/operator/controller/cr-manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package controller

import (
"context"
"strconv"

"kubevirt.io/containerized-data-importer/pkg/operator/resources/utils"

Expand Down Expand Up @@ -83,8 +84,14 @@ func (r *ReconcileCDI) getNamespacedArgs(cr *cdiv1.CDI) *cdinamespaced.FactoryAr
if cr.Spec.ImagePullPolicy != "" {
result.PullPolicy = string(cr.Spec.ImagePullPolicy)
}
if cr.Spec.Config != nil && len(cr.Spec.Config.ImagePullSecrets) > 0 {
result.ImagePullSecrets = cr.Spec.Config.ImagePullSecrets
if cr.Spec.Config != nil {
// Overrides default verbosity level
if logVerbosity := cr.Spec.Config.LogVerbosity; logVerbosity != nil {
result.Verbosity = strconv.Itoa(int(*logVerbosity))
}
if len(cr.Spec.Config.ImagePullSecrets) > 0 {
result.ImagePullSecrets = cr.Spec.Config.ImagePullSecrets
}
}
if cr.Spec.PriorityClass != nil && string(*cr.Spec.PriorityClass) != "" {
result.PriorityClassName = string(*cr.Spec.PriorityClass)
Expand Down
15 changes: 15 additions & 0 deletions pkg/operator/resources/crds_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ spec:
items:
type: string
type: array
logVerbosity:
description: LogVerbosity overrides the default verbosity level
used to initialize loggers
format: int32
type: integer
podResourceRequirements:
description: ResourceRequirements describes the compute resource
requirements.
Expand Down Expand Up @@ -2410,6 +2415,11 @@ spec:
items:
type: string
type: array
logVerbosity:
description: LogVerbosity overrides the default verbosity level
used to initialize loggers
format: int32
type: integer
podResourceRequirements:
description: ResourceRequirements describes the compute resource
requirements.
Expand Down Expand Up @@ -4616,6 +4626,11 @@ spec:
items:
type: string
type: array
logVerbosity:
description: LogVerbosity overrides the default verbosity level used
to initialize loggers
format: int32
type: integer
podResourceRequirements:
description: ResourceRequirements describes the compute resource requirements.
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,9 @@ type CDIConfigSpec struct {
TLSSecurityProfile *ocpconfigv1.TLSSecurityProfile `json:"tlsSecurityProfile,omitempty"`
// The imagePullSecrets used to pull the container images
ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
// LogVerbosity overrides the default verbosity level used to initialize loggers
// +optional
LogVerbosity *int32 `json:"logVerbosity,omitempty"`
}

// CDIConfigStatus provides the most recently observed status of the CDI Config resource
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 030846a

Please sign in to comment.