Problem
Valkey client creation is scattered across multiple controllers and utility files. Each caller constructs its own connection with its own TLS config, credential lookup, and error handling. This makes it hard to add cross-cutting concerns (retry logic, connection pooling, observability) consistently, and leads to subtle divergences between how different parts of the code connect to pods.
This was noted as a future improvement in PR #228:
"I would like to propose a client registry that handles this in the future."
Proposed solution
Introduce an internal ClientProvider interface and a ClientRegistry implementation:
type ClientProvider interface {
// ForNode returns a connected client for the given ValkeyNode.
ForNode(ctx context.Context, node *valkeyiov1alpha1.ValkeyNode) (Client, error)
// ForPod returns a connected client for a pod IP and port.
ForPod(ctx context.Context, podIP string, port int, opts ...ClientOption) (Client, error)
}
The registry handles TLS config resolution, credential lookup, and connection reuse. All controllers go through this interface instead of instantiating clients directly. Tests inject a fake via the interface.
Acceptance criteria
References
Problem
Valkey client creation is scattered across multiple controllers and utility files. Each caller constructs its own connection with its own TLS config, credential lookup, and error handling. This makes it hard to add cross-cutting concerns (retry logic, connection pooling, observability) consistently, and leads to subtle divergences between how different parts of the code connect to pods.
This was noted as a future improvement in PR #228:
Proposed solution
Introduce an internal
ClientProviderinterface and aClientRegistryimplementation:The registry handles TLS config resolution, credential lookup, and connection reuse. All controllers go through this interface instead of instantiating clients directly. Tests inject a fake via the interface.
Acceptance criteria
ClientProviderinterface defined ininternal/client/vclient.NewClientcalls in controllers replaced withClientProvider.ForNodeorForPodFakeClientProvideravailable for unit testsReferences