Skip to content
6 changes: 3 additions & 3 deletions e2e/testcases/override_log_level_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,15 @@ func TestOverrideRootSyncLogLevel(t *testing.T) {

// try invalid log level value
maxError := "logLevel in body should be less than or equal to 10"
minError := "logLevel in body should be greater than or equal to 0"
minError := "logLevel in body should be greater than or equal to -10"

err := nt.KubeClient.MergePatch(rootSyncV1, `{"spec": {"override": {"logLevels": [{"containerName": "reconciler", "logLevel": 13}]}}}`)
if !strings.Contains(err.Error(), maxError) {
nt.T.Fatalf("Expecting invalid value error: %q, got %s", maxError, err.Error())
}

err = nt.KubeClient.MergePatch(rootSyncV1, `{"spec": {"override": {"logLevels": [{"containerName": "reconciler", "logLevel": -3}]}}}`)
if !strings.Contains(err.Error(), minError) {
err = nt.KubeClient.MergePatch(rootSyncV1, `{"spec": {"override": {"logLevels": [{"containerName": "reconciler", "logLevel": -13}]}}}`)
if err == nil || !strings.Contains(err.Error(), minError) {
nt.T.Fatalf("Expecting invalid value error: %q, got %s", minError, err.Error())
}
}
Expand Down
8 changes: 4 additions & 4 deletions manifests/reposync-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -406,9 +406,9 @@ spec:
The "git-sync" and "otel-agent" containers default to 5, while all other containers default to 0.
Increasing the value of logLevel increases the verbosity of the logs.
Lower severity messages are logged at higher verbosity.
Allowed values are from 0 to 10.
Allowed values are from -10 to 10.
maximum: 10
minimum: 0
minimum: -10
type: integer
required:
- containerName
Expand Down Expand Up @@ -1531,9 +1531,9 @@ spec:
The "git-sync" and "otel-agent" containers default to 5, while all other containers default to 0.
Increasing the value of logLevel increases the verbosity of the logs.
Lower severity messages are logged at higher verbosity.
Allowed values are from 0 to 10.
Allowed values are from -10 to 10.
maximum: 10
minimum: 0
minimum: -10
type: integer
required:
- containerName
Expand Down
8 changes: 4 additions & 4 deletions manifests/rootsync-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,9 @@ spec:
The "git-sync" and "otel-agent" containers default to 5, while all other containers default to 0.
Increasing the value of logLevel increases the verbosity of the logs.
Lower severity messages are logged at higher verbosity.
Allowed values are from 0 to 10.
Allowed values are from -10 to 10.
maximum: 10
minimum: 0
minimum: -10
type: integer
required:
- containerName
Expand Down Expand Up @@ -1603,9 +1603,9 @@ spec:
The "git-sync" and "otel-agent" containers default to 5, while all other containers default to 0.
Increasing the value of logLevel increases the verbosity of the logs.
Lower severity messages are logged at higher verbosity.
Allowed values are from 0 to 10.
Allowed values are from -10 to 10.
maximum: 10
minimum: 0
minimum: -10
type: integer
required:
- containerName
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/configsync/v1alpha1/resource_override.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ type ContainerLogLevelOverride struct {
// The "git-sync" and "otel-agent" containers default to 5, while all other containers default to 0.
// Increasing the value of logLevel increases the verbosity of the logs.
// Lower severity messages are logged at higher verbosity.
// Allowed values are from 0 to 10.
// +kubebuilder:validation:Minimum=0
// Allowed values are from -10 to 10.
// +kubebuilder:validation:Minimum=-10
// +kubebuilder:validation:Maximum=10
// +kubebuilder:validation:Required
LogLevel int `json:"logLevel"`
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/configsync/v1beta1/resource_override.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ type ContainerLogLevelOverride struct {
// The "git-sync" and "otel-agent" containers default to 5, while all other containers default to 0.
// Increasing the value of logLevel increases the verbosity of the logs.
// Lower severity messages are logged at higher verbosity.
// Allowed values are from 0 to 10.
// +kubebuilder:validation:Minimum=0
// Allowed values are from -10 to 10.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This yields an update in doc of logLevel field https://docs.cloud.google.com/kubernetes-engine/config-sync/docs/reference/rootsync-reposync-fields. Worth noting that setting a logLevel to a high negative value (e.g., -10) may suppress almost all informational logs, making it difficult to monitor the container's health through standard output.

FYI run make generate to refresh the CRDs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks! Did so (but with make configsync-crds); also, note that the way the Makefile sets up the installation of controller-gen it doesn't lock the version, and also gets confused if the user has set GOBIN (since it only sets GOPATH when installing), so it took me a few tries to make it run the version you had used previously.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good catch! We could resolve this together with the Makefile improvement, focusing on the GOBIN consistency and version pinning ,@Camila-B the driver.

For now we could update the contribution doc to remind contributors to unset the var before building.

// +kubebuilder:validation:Minimum=-10
Comment thread
tomasaschan marked this conversation as resolved.
Comment thread
tiffanny29631 marked this conversation as resolved.
// +kubebuilder:validation:Maximum=10
// +kubebuilder:validation:Required
LogLevel int `json:"logLevel"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func mutateContainerLogLevel(c *corev1.Container, override []v1beta1.ContainerLo
// otel-agent surfaces the log level configuration differently.
// Our log levels range from 0-10, whereas zap ranges from -1 (debug) to 5 (fatal).
// We reverse the order for consistent behavior with our other log levels.
zapLevel := zapcore.Level(max(int(zapcore.FatalLevel)-logLevel.LogLevel, int(zapcore.DebugLevel)))
zapLevel := zapcore.Level(max(int(zapcore.FatalLevel)-max(logLevel.LogLevel, 0), int(zapcore.DebugLevel)))
// unmarshal and marshal to validate that the zap level is valid
if _, err := zapcore.ParseLevel(zapLevel.String()); err != nil {
return err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,46 @@ func TestMutateContainerLogLevelOtelAgent(t *testing.T) {
logLevel int
expectedLevel string
}{
"otel-agent with -10 log level": {
logLevel: -10,
expectedLevel: "fatal",
},
"otel-agent with -9 log level": {
logLevel: -9,
expectedLevel: "fatal",
},
"otel-agent with -8 log level": {
logLevel: -8,
expectedLevel: "fatal",
},
"otel-agent with -7 log level": {
logLevel: -7,
expectedLevel: "fatal",
},
"otel-agent with -6 log level": {
logLevel: -6,
expectedLevel: "fatal",
},
"otel-agent with -5 log level": {
logLevel: -5,
expectedLevel: "fatal",
},
"otel-agent with -4 log level": {
logLevel: -4,
expectedLevel: "fatal",
},
"otel-agent with -3 log level": {
logLevel: -3,
expectedLevel: "fatal",
},
"otel-agent with -2 log level": {
logLevel: -2,
expectedLevel: "fatal",
},
"otel-agent with -1 log level": {
logLevel: -1,
expectedLevel: "fatal",
},
"otel-agent with 0 log level": {
logLevel: 0,
expectedLevel: "fatal",
Expand Down
2 changes: 1 addition & 1 deletion pkg/remediator/watch/filteredwatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ func errorID(err error) string {
// and an error indicating that a watch.Error event type is encountered and the
// watch should be restarted.
func (w *filteredWatcher) handle(ctx context.Context, event watch.Event) (string, bool, error) {
klog.Infof("Remediator handling watch event %v %v", event.Type, w.gvk)
klog.V(0).Infof("Remediator handling watch event %v %v", event.Type, w.gvk)
var deleted bool
switch event.Type {
case watch.Added, watch.Modified:
Expand Down
16 changes: 8 additions & 8 deletions test/kustomization/expected.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -801,9 +801,9 @@ spec:
The "git-sync" and "otel-agent" containers default to 5, while all other containers default to 0.
Increasing the value of logLevel increases the verbosity of the logs.
Lower severity messages are logged at higher verbosity.
Allowed values are from 0 to 10.
Allowed values are from -10 to 10.
maximum: 10
minimum: 0
minimum: -10
type: integer
required:
- containerName
Expand Down Expand Up @@ -1926,9 +1926,9 @@ spec:
The "git-sync" and "otel-agent" containers default to 5, while all other containers default to 0.
Increasing the value of logLevel increases the verbosity of the logs.
Lower severity messages are logged at higher verbosity.
Allowed values are from 0 to 10.
Allowed values are from -10 to 10.
maximum: 10
minimum: 0
minimum: -10
type: integer
required:
- containerName
Expand Down Expand Up @@ -3374,9 +3374,9 @@ spec:
The "git-sync" and "otel-agent" containers default to 5, while all other containers default to 0.
Increasing the value of logLevel increases the verbosity of the logs.
Lower severity messages are logged at higher verbosity.
Allowed values are from 0 to 10.
Allowed values are from -10 to 10.
maximum: 10
minimum: 0
minimum: -10
type: integer
required:
- containerName
Expand Down Expand Up @@ -4559,9 +4559,9 @@ spec:
The "git-sync" and "otel-agent" containers default to 5, while all other containers default to 0.
Increasing the value of logLevel increases the verbosity of the logs.
Lower severity messages are logged at higher verbosity.
Allowed values are from 0 to 10.
Allowed values are from -10 to 10.
maximum: 10
minimum: 0
minimum: -10
type: integer
required:
- containerName
Expand Down