Documentation
¶
Overview ¶
Package tokenrefresh provides a controller that keeps a ServiceAccount token from a ManagedControlPlane in a Secret on a workload cluster, independent of the service provider's main reconcile loop.
Index ¶
- Constants
- func CreationAnnotation(serviceProvider string) string
- func EnsureToken(ctx context.Context, mcp *clusters.Cluster, secret *corev1.Secret, ...) (*clusteraccess.ServiceAccountToken, error)
- func ExpirationAnnotation(serviceProvider string) string
- type Binding
- type BindingFunc
- type ClusterResolver
- type Reconciler
Constants ¶
const ( // DefaultTokenLifetime is the requested token lifetime if Reconciler.TokenLifetime is not set. DefaultTokenLifetime = time.Hour // MinTokenLifetime is the minimum token lifetime accepted by the API server. MinTokenLifetime = 10 * time.Minute // DefaultRetryInterval is the requeue time if Reconciler.RetryInterval is not set. DefaultRetryInterval = 10 * time.Second // SecretKeyToken, SecretKeyCA and SecretKeyNamespace are the Secret keys written by the Reconciler. // They match the layout of a projected ServiceAccount volume. SecretKeyToken = "token" SecretKeyCA = "ca.crt" SecretKeyNamespace = "namespace" )
Variables ¶
This section is empty.
Functions ¶
func CreationAnnotation ¶
CreationAnnotation returns the annotation key under which the token creation time is stored on the Secret.
func EnsureToken ¶
func EnsureToken(ctx context.Context, mcp *clusters.Cluster, secret *corev1.Secret, binding Binding, serviceProvider string, lifetime time.Duration) (*clusteraccess.ServiceAccountToken, error)
EnsureToken mints a token for binding.ServiceAccount on the mcp cluster and writes it into secret in memory, without persisting it. Callers may use it to mint the first token while creating the Secret. It returns the minted token.
func ExpirationAnnotation ¶
ExpirationAnnotation returns the annotation key under which the token expiration time is stored on the Secret.
Types ¶
type Binding ¶
type Binding struct {
ServiceAccount types.NamespacedName
Secret types.NamespacedName
}
Binding identifies the ServiceAccount on the MCP cluster and the Secret on the workload cluster that receives its token.
type BindingFunc ¶
BindingFunc returns the Binding for the given object. If ok is false, the object is not ready yet and is reconciled again later.
type ClusterResolver ¶
type ClusterResolver func(ctx context.Context, req reconcile.Request) (mcp, workload *clusters.Cluster, err error)
ClusterResolver returns the MCP and workload cluster for the reconciled object.
type Reconciler ¶
type Reconciler[T client.Object] struct { // Client reads objects of type T, usually the manager's client. Client client.Client // ServiceProviderName is used to build the expiration annotation key, see ExpirationAnnotation. ServiceProviderName string // NewObject returns an empty object of type T. NewObject func() T // Clusters resolves the MCP and workload cluster of an object. Clusters ClusterResolver // Binding returns the ServiceAccount and Secret of an object. Binding BindingFunc[T] // TokenLifetime is the requested token lifetime. Defaults to DefaultTokenLifetime. TokenLifetime time.Duration // RetryInterval is the requeue time if the token can not be refreshed yet. Defaults to DefaultRetryInterval. RetryInterval time.Duration }
Reconciler refreshes the token in the target Secret before it expires. It only writes the token data and the expiration annotation, the Secret itself has to be created by the caller, e.g. the service provider's main reconciler.
func (*Reconciler[T]) Reconcile ¶
Reconcile refreshes the token if needed or if it's missing and requeues until the next renewal time. Transient failures (object, cluster or secret not ready, or a token mint error) are requeued after the retry r.retryInterval().
func (*Reconciler[T]) SetupWithManager ¶
func (r *Reconciler[T]) SetupWithManager(mgr ctrl.Manager, name string) error
SetupWithManager registers the Reconciler with the given manager under the given controller name.