Skip to content

Commit e6e5e96

Browse files
authored
Merge pull request #119 from xrstf/improve-logging-api
rename logLevel to logging, cleanup API, fix codegen script
2 parents 981a40c + f5318a5 commit e6e5e96

27 files changed

+130
-298
lines changed

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,14 @@ 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.'
111+
logging:
112+
description: 'Optional: Logging configures the logging settings for
113+
the cache server.'
114114
properties:
115-
verbosityLevel:
116-
default: 0
115+
level:
117116
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
117+
Level sets the verbosity level for the component. Higher values mean more verbose logging.
118+
This corresponds to the -v flag in kcp components.
121119
maximum: 10
122120
minimum: 0
123121
type: integer

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,16 +1564,14 @@ 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.'
1567+
logging:
1568+
description: 'Optional: Logging configures the logging settings for
1569+
the front-proxy.'
15701570
properties:
1571-
verbosityLevel:
1572-
default: 0
1571+
level:
15731572
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
1573+
Level sets the verbosity level for the component. Higher values mean more verbose logging.
1574+
This corresponds to the -v flag in kcp components.
15771575
maximum: 10
15781576
minimum: 0
15791577
type: integer

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

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,16 +1722,14 @@ 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.'
1725+
logging:
1726+
description: 'Optional: Logging configures the logging settings for
1727+
the shard.'
17281728
properties:
1729-
verbosityLevel:
1730-
default: 0
1729+
level:
17311730
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
1731+
Level sets the verbosity level for the component. Higher values mean more verbose logging.
1732+
This corresponds to the -v flag in kcp components.
17351733
maximum: 10
17361734
minimum: 0
17371735
type: integer
@@ -3106,16 +3104,14 @@ spec:
31063104
operator supports.
31073105
type: string
31083106
type: object
3109-
logLevel:
3110-
description: 'Optional: LogLevel configures the logging verbosity
3111-
for this proxy.'
3107+
logging:
3108+
description: 'Optional: Logging configures the logging settings
3109+
for the root shard.'
31123110
properties:
3113-
verbosityLevel:
3114-
default: 0
3111+
level:
31153112
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
3113+
Level sets the verbosity level for the component. Higher values mean more verbose logging.
3114+
This corresponds to the -v flag in kcp components.
31193115
maximum: 10
31203116
minimum: 0
31213117
type: integer

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,16 +1635,14 @@ 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.'
1638+
logging:
1639+
description: 'Optional: Logging configures the logging settings for
1640+
the shard.'
16411641
properties:
1642-
verbosityLevel:
1643-
default: 0
1642+
level:
16441643
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
1644+
Level sets the verbosity level for the component. Higher values mean more verbose logging.
1645+
This corresponds to the -v flag in kcp components.
16481646
maximum: 10
16491647
minimum: 0
16501648
type: integer

hack/update-codegen.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ go run sigs.k8s.io/controller-tools/cmd/controller-gen \
3838
output:crd:artifacts:config=config/crd/bases
3939

4040
# generate SDK
41-
rm -rf -- "$SDK_DIR/{applyconfiguration,clientset,informers,listers}"
41+
rm -rf -- $SDK_DIR/{applyconfiguration,clientset,informers,listers}
4242

4343
go run k8s.io/code-generator/cmd/applyconfiguration-gen \
4444
--go-header-file "$BOILERPLATE_HEADER" \

internal/resources/frontproxy/deployment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ func (r *reconciler) getArgs() []string {
247247
}
248248
}
249249

250-
args = append(args, utils.GetLogLevelArgs(r.frontProxy.Spec.LogLevel)...)
250+
args = append(args, utils.GetLoggingArgs(r.frontProxy.Spec.Logging)...)
251251

252252
if r.frontProxy.Spec.ExtraArgs != nil {
253253
args = append(args, r.frontProxy.Spec.ExtraArgs...)

internal/resources/rootshard/deployment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ func getArgs(rootShard *operatorv1alpha1.RootShard) []string {
193193
"--logging-format=json",
194194
}
195195

196-
args = append(args, utils.GetLogLevelArgs(rootShard.Spec.LogLevel)...)
196+
args = append(args, utils.GetLoggingArgs(rootShard.Spec.Logging)...)
197197

198198
if rootShard.Spec.ExtraArgs != nil {
199199
args = append(args, rootShard.Spec.ExtraArgs...)

internal/resources/shard/deployment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ func getArgs(shard *operatorv1alpha1.Shard, rootShard *operatorv1alpha1.RootShar
204204
"--logging-format=json",
205205
}
206206

207-
args = append(args, utils.GetLogLevelArgs(shard.Spec.LogLevel)...)
207+
args = append(args, utils.GetLoggingArgs(shard.Spec.Logging)...)
208208

209209
if shard.Spec.ExtraArgs != nil {
210210
args = append(args, shard.Spec.ExtraArgs...)

internal/resources/utils/logging.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,16 @@ import (
2222
operatorv1alpha1 "github.com/kcp-dev/kcp-operator/sdk/apis/operator/v1alpha1"
2323
)
2424

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{}
25+
// GetLoggingArgs returns the command line arguments for logging configuration.
26+
func GetLoggingArgs(spec *operatorv1alpha1.LoggingSpec) []string {
27+
if spec == nil {
28+
return nil
3129
}
3230

33-
verbosity := *logLevel.VerbosityLevel
34-
if verbosity == 0 {
35-
return []string{}
31+
var args []string
32+
if spec.Level != 0 {
33+
args = append(args, fmt.Sprintf("-v=%d", spec.Level))
3634
}
3735

38-
return []string{fmt.Sprintf("-v=%d", verbosity)}
36+
return args
3937
}

internal/resources/utils/logging_test.go

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,42 +25,40 @@ import (
2525
func TestGetLogLevelArgs(t *testing.T) {
2626
tests := []struct {
2727
name string
28-
logLevel *operatorv1alpha1.LogLevelSpec
28+
logging *operatorv1alpha1.LoggingSpec
2929
expected []string
3030
}{
3131
{
32-
name: "nil verbosityLevel",
33-
logLevel: &operatorv1alpha1.LogLevelSpec{
34-
VerbosityLevel: nil,
35-
},
32+
name: "no config at alll",
33+
logging: nil,
3634
expected: []string{},
3735
},
3836
{
3937
name: "verbosityLevel 0",
40-
logLevel: &operatorv1alpha1.LogLevelSpec{
41-
VerbosityLevel: func() *int32 { v := int32(0); return &v }(),
38+
logging: &operatorv1alpha1.LoggingSpec{
39+
Level: 0,
4240
},
4341
expected: []string{},
4442
},
4543
{
46-
name: "verbosityLevel 1",
47-
logLevel: &operatorv1alpha1.LogLevelSpec{
48-
VerbosityLevel: func() *int32 { v := int32(1); return &v }(),
44+
name: "verbosityLevel 2",
45+
logging: &operatorv1alpha1.LoggingSpec{
46+
Level: 2,
4947
},
50-
expected: []string{"-v=1"},
48+
expected: []string{"-v=2"},
5149
},
5250
}
5351

5452
for _, tt := range tests {
5553
t.Run(tt.name, func(t *testing.T) {
56-
result := GetLogLevelArgs(tt.logLevel)
54+
result := GetLoggingArgs(tt.logging)
5755
if len(result) != len(tt.expected) {
58-
t.Errorf("GetLogLevelArgs() returned %d arguments, expected %d", len(result), len(tt.expected))
59-
return
56+
t.Fatalf("Expected %d arguments, got %d.", len(tt.expected), len(result))
6057
}
58+
6159
for i, arg := range result {
6260
if arg != tt.expected[i] {
63-
t.Errorf("GetLogLevelArgs() argument %d = %v, expected %v", i, arg, tt.expected[i])
61+
t.Errorf("Expected args.#%d to be %q, got %q.", i, tt.expected[i], arg)
6462
}
6563
}
6664
})

0 commit comments

Comments
 (0)