Skip to content

Commit

Permalink
Add possibility to override logLevel and logFormat in Serverless CR (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
FilipRudy authored Jan 21, 2025
1 parent 5e78171 commit 045a0c3
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 28 deletions.
6 changes: 6 additions & 0 deletions components/operator/api/v1alpha1/serverless_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ type ServerlessSpec struct {
DefaultBuildJobPreset string `json:"defaultBuildJobPreset,omitempty"`
// Configures the default runtime Pod preset to be used
DefaultRuntimePodPreset string `json:"defaultRuntimePodPreset,omitempty"`
// Sets desired log level to be used. The default value is "info"
LogLevel string `json:"logLevel,omitempty"`
// Sets desired log format to be used. The default value is "json"
LogFormat string `json:"logFormat,omitempty"`
}

type State string
Expand Down Expand Up @@ -114,6 +118,8 @@ type ServerlessStatus struct {
HealthzLivenessTimeout string `json:"healthzLivenessTimeout,omitempty"`
DefaultBuildJobPreset string `json:"defaultBuildJobPreset,omitempty"`
DefaultRuntimePodPreset string `json:"defaultRuntimePodPreset,omitempty"`
LogLevel string `json:"logLevel,omitempty"`
LogFormat string `json:"logFormat,omitempty"`

// Used registry configuration.
// Contains registry URL or "internal"
Expand Down
18 changes: 18 additions & 0 deletions components/operator/internal/chart/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ type FlagsBuilder interface {
WithRegistryEnableInternal(enableInternal bool) *flagsBuilder
WithRegistryHttpSecret(httpSecret string) *flagsBuilder
WithNodePort(nodePort int64) *flagsBuilder
WithLogLevel(logLevel string) *flagsBuilder
WithLogFormat(logFormat string) *flagsBuilder
}

type flagsBuilder struct {
Expand Down Expand Up @@ -131,3 +133,19 @@ func (fb *flagsBuilder) WithNodePort(nodePort int64) *flagsBuilder {
fb.flags["global.registryNodePort"] = nodePort
return fb
}

func (fb *flagsBuilder) WithLogLevel(logLevel string) *flagsBuilder {
if logLevel != "" {
fb.flags["containers.manager.logConfiguration.data.logLevel"] = logLevel
}

return fb
}

func (fb *flagsBuilder) WithLogFormat(logFormat string) *flagsBuilder {
if logFormat != "" {
fb.flags["containers.manager.logConfiguration.data.logFormat"] = logFormat
}

return fb
}
10 changes: 9 additions & 1 deletion components/operator/internal/chart/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ func Test_flagsBuilder_Build(t *testing.T) {
},
},
},
"logConfiguration": map[string]interface{}{
"data": map[string]interface{}{
"logLevel": "testLogLevel",
"logFormat": "testLogFormat",
},
},
},
},
"docker-registry": map[string]interface{}{
Expand Down Expand Up @@ -71,7 +77,9 @@ func Test_flagsBuilder_Build(t *testing.T) {
"testBuildExecutorArgs",
"testMaxSimultaneousJobs",
"testHealthzLivenessTimeout",
).Build()
).
WithLogFormat("testLogFormat").
WithLogLevel("testLogLevel").Build()

require.Equal(t, expectedFlags, flags)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const (
slowRuntimePreset = "XS"
normalBuildPreset = "normal"
largeRuntimePreset = "L"
defaultLogLevel = "info"
defaultLogFormat = "json"
)

func sFnControllerConfiguration(ctx context.Context, r *reconciler, s *systemState) (stateFn, *controllerruntime.Result, error) {
Expand Down Expand Up @@ -56,6 +58,8 @@ func updateControllerConfigurationStatus(ctx context.Context, r *reconciler, ins
{spec.HealthzLivenessTimeout, &instance.Status.HealthzLivenessTimeout, "Duration of health check", ""},
{spec.DefaultBuildJobPreset, &instance.Status.DefaultBuildJobPreset, "Default build job preset", defaultBuildPreset},
{spec.DefaultRuntimePodPreset, &instance.Status.DefaultRuntimePodPreset, "Default runtime pod preset", defaultRuntimePreset},
{spec.LogLevel, &instance.Status.LogLevel, "Log level", defaultLogLevel},
{spec.LogFormat, &instance.Status.LogFormat, "Log format", defaultLogFormat},
}

updateStatusFields(r.k8s, instance, fields)
Expand All @@ -74,7 +78,9 @@ func configureControllerConfigurationFlags(s *systemState) {
WithDefaultPresetFlags(
s.instance.Status.DefaultBuildJobPreset,
s.instance.Status.DefaultRuntimePodPreset,
)
).
WithLogLevel(s.instance.Status.LogLevel).
WithLogFormat(s.instance.Status.LogFormat)
}

func getNodesLen(ctx context.Context, c client.Client) (int, error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const (
healthzLivenessTimeoutTest = "test-healthz-liveness-timeout"
buildJobPresetTest = "test=default-build-job-preset"
runtimePodPresetTest = "test-default-runtime-pod-preset"
logLevelTest = "test-log-level"
logFormatTest = "test-log-format"
)

func Test_sFnControllerConfiguration(t *testing.T) {
Expand All @@ -40,7 +42,7 @@ func Test_sFnControllerConfiguration(t *testing.T) {
fixTestNode("node-1"),
fixTestNode("node-2"),
).Build()
eventRecorder := record.NewFakeRecorder(2)
eventRecorder := record.NewFakeRecorder(4)
r := &reconciler{log: zap.NewNop().Sugar(), k8s: k8s{client: c, EventRecorder: eventRecorder}}
next, result, err := sFnControllerConfiguration(context.TODO(), r, s)
require.Nil(t, err)
Expand Down Expand Up @@ -87,7 +89,7 @@ func Test_sFnControllerConfiguration(t *testing.T) {
fixTestNode("node-3"),
fixTestNode("node-4"),
).Build()
eventRecorder := record.NewFakeRecorder(2)
eventRecorder := record.NewFakeRecorder(4)
r := &reconciler{log: zap.NewNop().Sugar(), k8s: k8s{client: c, EventRecorder: eventRecorder}}
next, result, err := sFnControllerConfiguration(context.TODO(), r, s)
require.Nil(t, err)
Expand Down Expand Up @@ -127,6 +129,8 @@ func Test_sFnControllerConfiguration(t *testing.T) {
HealthzLivenessTimeout: healthzLivenessTimeoutTest,
DefaultBuildJobPreset: buildJobPresetTest,
DefaultRuntimePodPreset: runtimePodPresetTest,
LogLevel: logLevelTest,
LogFormat: logFormatTest,
},
},
flagsBuilder: chart.NewFlagsBuilder(),
Expand All @@ -148,6 +152,8 @@ func Test_sFnControllerConfiguration(t *testing.T) {
require.Equal(t, healthzLivenessTimeoutTest, status.HealthzLivenessTimeout)
require.Equal(t, buildJobPresetTest, status.DefaultBuildJobPreset)
require.Equal(t, runtimePodPresetTest, status.DefaultRuntimePodPreset)
require.Equal(t, logLevelTest, status.LogLevel)
require.Equal(t, logFormatTest, status.LogFormat)

require.Equal(t, v1alpha1.StateProcessing, status.State)
requireContainsCondition(t, status,
Expand All @@ -165,6 +171,8 @@ func Test_sFnControllerConfiguration(t *testing.T) {
"Normal Configuration Duration of health check set from '' to 'test-healthz-liveness-timeout'",
"Normal Configuration Default build job preset set from '' to 'test=default-build-job-preset'",
"Normal Configuration Default runtime pod preset set from '' to 'test-default-runtime-pod-preset'",
"Normal Configuration Log level set from '' to 'test-log-level'",
"Normal Configuration Log format set from '' to 'test-log-format'",
}

for _, expectedEvent := range expectedEvents {
Expand Down Expand Up @@ -215,7 +223,7 @@ func Test_sFnControllerConfiguration(t *testing.T) {
log: zap.NewNop().Sugar(),
k8s: k8s{
client: fake.NewClientBuilder().WithObjects(secret).Build(),
EventRecorder: record.NewFakeRecorder(2),
EventRecorder: record.NewFakeRecorder(4),
},
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ spec:
required:
- endpoint
type: object
logFormat:
description: Sets desired log format to be used. The default value is "json"
type: string
logLevel:
description: Sets desired log level to be used. The default value is "info"
type: string
type: object
status:
properties:
Expand Down Expand Up @@ -199,6 +205,10 @@ spec:
type: string
healthzLivenessTimeout:
type: string
logFormat:
type: string
logLevel:
type: string
served:
description: |-
Served signifies that current Serverless is managed.
Expand Down
4 changes: 4 additions & 0 deletions config/operator/base/ui-extensions/serverless/details
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ body:
source: status.defaultBuildJobPreset
- name: Default Function Preset
source: status.defaultRuntimePodPreset
- name: Log Level
source: status.logLevel
- name: Log Format
source: status.logFormat
- widget: EventList
filter: '$matchEvents($$, $root.kind, $root.metadata.name)'
name: events
Expand Down
10 changes: 9 additions & 1 deletion config/operator/base/ui-extensions/serverless/form
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,12 @@
- S
- M
- L
- XL
- XL
- path: spec.logLevel
name: Log Level
simple: true
required: false
- path: spec.logFormat
name: Log Format
simple: true
required: false
Loading

0 comments on commit 045a0c3

Please sign in to comment.