Skip to content

Migrate Flux controllers to use runtime/secrets package #5433

@cappyzawa

Description

@cappyzawa

Migrate Flux controllers to use runtime/secrets package

Background

We have successfully consolidated secret handling patterns in the Flux ecosystem by creating a new runtime/secrets package in fluxcd/pkg. This package provides unified functions for handling Kubernetes secrets across all Flux components.

Key developments:

  • Issue fluxcd/pkg#949: Consolidate the handling of secrets
  • PR fluxcd/pkg#950: Add runtime/secrets package (merged)
  • Issue fluxcd/pkg#953: Add legacy field logging
  • PR fluxcd/pkg#955: Add legacy field logging to TLS functions (merged)
  • Release: fluxcd/pkg/runtime v0.62.0 now available for use across Flux

New runtime/secrets Package

The runtime/secrets package provides:

Core Functions

  • TLSConfigFromSecret(ctx, client, name, namespace, logger) - Creates TLS config with legacy field support
  • ProxyURLFromSecret(ctx, client, name, namespace) - Extracts proxy configuration
  • BasicAuthFromSecret(ctx, client, name, namespace) - Retrieves basic auth credentials
  • PullSecretsFromServiceAccount(ctx, client, name, namespace) - Resolves image pull secrets

Helper Functions

  • MakeTLSSecret(), MakeProxySecret(), MakeBasicAuthSecret(), etc.

Key Features

  • Legacy Field Support: Always supports deprecated field names (certFile, keyFile, caFile) for backward compatibility
  • Standard Field Priority: Standard Kubernetes field names (tls.crt, tls.key, ca.crt) take precedence
  • Migration Logging: Warns when legacy fields are used to encourage migration
  • Consistent API: Same behavior across all Flux components

Migration Goals

  1. Consistency: Ensure all Flux controllers handle secrets the same way
  2. Maintainability: Reduce code duplication across repositories
  3. User Experience: Provide consistent secret field support and clear migration paths
  4. Future-proofing: Prepare for eventual v2 API transition

Target Repositories

The following repositories contain secret handling functionality that can benefit from migrating to runtime/secrets:

mTLS Terminology and Consistency

Based on the implementation in notification-controller PR #1137, we've established important guidelines for mTLS terminology:

Historical Context

Decision

We will maintain consistency with pkg/runtime/secrets definition of mTLS:

  • mTLS configuration: tls.crt + tls.key + optional ca.crt
  • This definition should be used consistently across all controllers when implementing TLSConfigFromSecret

Metadata

Metadata

Assignees

Labels

umbrella-issueUmbrella issue for tracking progress of a larger effort

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions