Skip to content

Commit 981a40c

Browse files
authored
Merge pull request #116 from olamilekan000/configure-verbose-log-for-kcp-component
add log level to kcp component spec
2 parents 5c8362f + aec11f5 commit 981a40c

25 files changed

+347
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ go.work.sum
3030

3131
# e2e test logs and artifacts
3232
/.e2e-*
33+
.vscode

config/crd/bases/operator.kcp.io_cacheservers.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,20 @@ spec:
108108
Defaults to the latest kcp release that the operator supports.
109109
type: string
110110
type: object
111+
logLevel:
112+
description: 'Optional: LogLevel configures the logging verbosity
113+
for this cache server.'
114+
properties:
115+
verbosityLevel:
116+
default: 0
117+
description: |-
118+
VerbosityLevel sets the verbosity level for the component. Higher values mean more verbose logging.
119+
This corresponds to the -v flag in KCP components.
120+
format: int32
121+
maximum: 10
122+
minimum: 0
123+
type: integer
124+
type: object
111125
required:
112126
- etcd
113127
type: object

config/crd/bases/operator.kcp.io_frontproxies.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,6 +1564,20 @@ spec:
15641564
Defaults to the latest kcp release that the operator supports.
15651565
type: string
15661566
type: object
1567+
logLevel:
1568+
description: 'Optional: LogLevel configures the logging verbosity
1569+
for this front-proxy.'
1570+
properties:
1571+
verbosityLevel:
1572+
default: 0
1573+
description: |-
1574+
VerbosityLevel sets the verbosity level for the component. Higher values mean more verbose logging.
1575+
This corresponds to the -v flag in KCP components.
1576+
format: int32
1577+
maximum: 10
1578+
minimum: 0
1579+
type: integer
1580+
type: object
15671581
replicas:
15681582
description: 'Optional: Replicas configures the replica count for
15691583
the front-proxy Deployment.'

config/crd/bases/operator.kcp.io_rootshards.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,6 +1722,20 @@ spec:
17221722
Defaults to the latest kcp release that the operator supports.
17231723
type: string
17241724
type: object
1725+
logLevel:
1726+
description: 'Optional: LogLevel configures the logging verbosity
1727+
for this shard.'
1728+
properties:
1729+
verbosityLevel:
1730+
default: 0
1731+
description: |-
1732+
VerbosityLevel sets the verbosity level for the component. Higher values mean more verbose logging.
1733+
This corresponds to the -v flag in KCP components.
1734+
format: int32
1735+
maximum: 10
1736+
minimum: 0
1737+
type: integer
1738+
type: object
17251739
proxy:
17261740
description: |-
17271741
Proxy configures the internal front-proxy that is only (supposed to be) used by the kcp-operator
@@ -3092,6 +3106,20 @@ spec:
30923106
operator supports.
30933107
type: string
30943108
type: object
3109+
logLevel:
3110+
description: 'Optional: LogLevel configures the logging verbosity
3111+
for this proxy.'
3112+
properties:
3113+
verbosityLevel:
3114+
default: 0
3115+
description: |-
3116+
VerbosityLevel sets the verbosity level for the component. Higher values mean more verbose logging.
3117+
This corresponds to the -v flag in KCP components.
3118+
format: int32
3119+
maximum: 10
3120+
minimum: 0
3121+
type: integer
3122+
type: object
30953123
replicas:
30963124
description: 'Optional: Replicas configures how many instances
30973125
of this proxy run in parallel. Defaults to 2 if not set.'

config/crd/bases/operator.kcp.io_shards.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,6 +1635,20 @@ spec:
16351635
Defaults to the latest kcp release that the operator supports.
16361636
type: string
16371637
type: object
1638+
logLevel:
1639+
description: 'Optional: LogLevel configures the logging verbosity
1640+
for this shard.'
1641+
properties:
1642+
verbosityLevel:
1643+
default: 0
1644+
description: |-
1645+
VerbosityLevel sets the verbosity level for the component. Higher values mean more verbose logging.
1646+
This corresponds to the -v flag in KCP components.
1647+
format: int32
1648+
maximum: 10
1649+
minimum: 0
1650+
type: integer
1651+
type: object
16381652
replicas:
16391653
description: Replicas configures how many instances of this shard
16401654
run in parallel. Defaults to 2 if not set.

config/samples/operator.kcp.io_v1alpha1_shard.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ spec:
1212
rootShard:
1313
ref:
1414
name: shard-sample
15+
logLevel:
16+
verbosityLevel: 4
1517
deploymentTemplate:
1618
spec:
1719
template:

internal/resources/frontproxy/deployment.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,9 @@ func (r *reconciler) getArgs() []string {
246246
args = append(args, fmt.Sprintf("--authentication-pass-on-groups=%q", strings.Join(auth.PassOnGroups, ",")))
247247
}
248248
}
249+
250+
args = append(args, utils.GetLogLevelArgs(r.frontProxy.Spec.LogLevel)...)
251+
249252
if r.frontProxy.Spec.ExtraArgs != nil {
250253
args = append(args, r.frontProxy.Spec.ExtraArgs...)
251254
}

internal/resources/rootshard/deployment.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ func getArgs(rootShard *operatorv1alpha1.RootShard) []string {
192192
"--enable-leader-election=true",
193193
"--logging-format=json",
194194
}
195+
196+
args = append(args, utils.GetLogLevelArgs(rootShard.Spec.LogLevel)...)
197+
195198
if rootShard.Spec.ExtraArgs != nil {
196199
args = append(args, rootShard.Spec.ExtraArgs...)
197200
}

internal/resources/shard/deployment.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ func getArgs(shard *operatorv1alpha1.Shard, rootShard *operatorv1alpha1.RootShar
203203
"--enable-leader-election=true",
204204
"--logging-format=json",
205205
}
206+
207+
args = append(args, utils.GetLogLevelArgs(shard.Spec.LogLevel)...)
208+
206209
if shard.Spec.ExtraArgs != nil {
207210
args = append(args, shard.Spec.ExtraArgs...)
208211
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
Copyright 2025 The KCP Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package utils
18+
19+
import (
20+
"fmt"
21+
22+
operatorv1alpha1 "github.com/kcp-dev/kcp-operator/sdk/apis/operator/v1alpha1"
23+
)
24+
25+
// GetLogLevelArgs returns the command line arguments for log level configuration.
26+
// If logLevel is nil or verbosityLevel is nil, returns an empty slice.
27+
// Otherwise, returns a slice containing the -v flag with the specified verbosity level.
28+
func GetLogLevelArgs(logLevel *operatorv1alpha1.LogLevelSpec) []string {
29+
if logLevel == nil || logLevel.VerbosityLevel == nil {
30+
return []string{}
31+
}
32+
33+
verbosity := *logLevel.VerbosityLevel
34+
if verbosity == 0 {
35+
return []string{}
36+
}
37+
38+
return []string{fmt.Sprintf("-v=%d", verbosity)}
39+
}

0 commit comments

Comments
 (0)