Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
config: Add handler field to configuration
Using the field we can avoid changing the actual logging during testing
by assigning a different function to the field.

We can now also verify that the handler field is being executed.
  • Loading branch information
DavidHurta committed Sep 23, 2025
commit 539bd466e2bc605c57799a5dbb875e8d08aab504
14 changes: 13 additions & 1 deletion pkg/cvo/configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ type ClusterVersionOperatorConfiguration struct {
started bool

configuration configuration

// Function to handle an update to the internal configuration.
//
// In the future, the desired configuration may be consumed via other controllers.
// This will require some sort of synchronization upon a configuration change.
// For the moment, the log level is the sole consumer of the configuration.
// Apply the log level directly here for simplicity for the time being.
handler func(configuration) error
}

func (config *ClusterVersionOperatorConfiguration) Queue() workqueue.TypedRateLimitingInterface[any] {
Expand Down Expand Up @@ -87,6 +95,7 @@ func NewClusterVersionOperatorConfiguration(client operatorclientset.Interface,
client: client.OperatorV1alpha1().ClusterVersionOperators(),
factory: factory,
configuration: configuration{desiredLogLevel: desiredLogLevel},
handler: func(c configuration) error { return applyLogLevel(c.desiredLogLevel) },
}
}

Expand Down Expand Up @@ -152,5 +161,8 @@ func (config *ClusterVersionOperatorConfiguration) sync(ctx context.Context, des
config.configuration.desiredLogLevel = operatorv1.Normal
}

return applyLogLevel(config.configuration.desiredLogLevel)
if config.handler != nil {
return config.handler(config.configuration)
}
return nil
}
15 changes: 15 additions & 0 deletions pkg/cvo/configuration/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func TestClusterVersionOperatorConfiguration_sync(t *testing.T) {
expectedConfig operatorv1alpha1.ClusterVersionOperator
internalConfig configuration
expectedInternalConfig configuration
handlerFunctionCalled bool
}{
{
name: "first sync run correctly updates the status",
Expand Down Expand Up @@ -54,6 +55,7 @@ func TestClusterVersionOperatorConfiguration_sync(t *testing.T) {
desiredLogLevel: operatorv1.Normal,
lastObservedGeneration: 1,
},
handlerFunctionCalled: true,
},
{
name: "sync updates observed generation correctly",
Expand Down Expand Up @@ -87,6 +89,7 @@ func TestClusterVersionOperatorConfiguration_sync(t *testing.T) {
desiredLogLevel: operatorv1.Normal,
lastObservedGeneration: 3,
},
handlerFunctionCalled: true,
},
{
name: "sync updates desired log level correctly",
Expand Down Expand Up @@ -120,6 +123,7 @@ func TestClusterVersionOperatorConfiguration_sync(t *testing.T) {
desiredLogLevel: operatorv1.Trace,
lastObservedGeneration: 4,
},
handlerFunctionCalled: true,
},
{
name: "number of not observed generations does not impact sync",
Expand Down Expand Up @@ -153,6 +157,7 @@ func TestClusterVersionOperatorConfiguration_sync(t *testing.T) {
desiredLogLevel: operatorv1.TraceAll,
lastObservedGeneration: 40,
},
handlerFunctionCalled: true,
},
}
for _, tt := range tests {
Expand All @@ -166,6 +171,12 @@ func TestClusterVersionOperatorConfiguration_sync(t *testing.T) {

configController := NewClusterVersionOperatorConfiguration(client, factory)

called := false
configController.handler = func(_ configuration) error {
called = true
return nil
}

ctx, cancelFunc := context.WithDeadline(context.Background(), time.Now().Add(time.Minute))

if err := configController.Start(ctx); err != nil {
Expand Down Expand Up @@ -194,6 +205,10 @@ func TestClusterVersionOperatorConfiguration_sync(t *testing.T) {
t.Errorf("unexpected config (-want, +got) = %v", diff)
}

if tt.handlerFunctionCalled != called {
t.Errorf("unexpected handler function execution; wanted=%v, got=%v", tt.handlerFunctionCalled, called)
}

// Shutdown created resources
cancelFunc()
})
Expand Down