Description
Summary
This story tracks enabling a user-friendly option for telling controller-runtime to self-identify with a distinct ID when making HTTP calls to the Kubernetes API server.
Context
The actor that causes a raw Kubernetes event to occur is identified by a field named manager
, for example:
{
"type": "MODIFIED",
"object": {
"apiVersion": "vmoperator.vmware.com/v1alpha1",
"kind": "VirtualMachine",
"metadata": {
"annotations": {
"vsphere-cluster-module-group": "tkg7-cluster7-workers-0",
"vsphere-tag": "WorkerVmVmAATag"
},
"creationTimestamp": "2020-10-08T11:41:50Z",
"finalizers": [
"virtualmachine.vmoperator.vmware.com"
],
"generation": 19,
"labels": {
"capw.vmware.com/cluster.name": "tkg7-cluster7",
"capw.vmware.com/cluster.role": "node"
},
"managedFields": [
{
"apiVersion": "vmoperator.vmware.com/v1alpha1",
"fieldsType": "FieldsV1",
"fieldsV1": { ... }
"manager": "manager",
"operation": "Update",
"time": "2020-10-08T14:11:49Z"
}
],
"name": "tkg7-cluster7-workers-whph9-6ff8cdb6fb-fq2b6",
"namespace": "tkg7",
...
},
...
}
These raw, Kubernetes events are useful for root cause analysis (RCA). The field object.metadata.managedFields[0].manager
has a value of simply manager
. This is the identifier for the actor that caused this MODIFIED
event to occur, but manager
is not exactly helpful in identifying the component in question.
The reason, if the reader will permit this author to make a broad guess, is that the majority of projects based on controller-runtime and client-go have adopted the pattern of naming the manager binary simply manager for a few reasons:
- It simplifies Makefiles
- It simplifies CI
- It enables a standard pattern for managing/working on these projects
So, good reasons. Unfortunately it has the side effect that all the components send the same user agent to the API server when updating/patching resources. This happens because:
- When controller-runtime creates a
*rest.Config
, it creates a user-agent string for HTTP calls - This user-agent string is based on a call to client-go's
DefaultKubernetesUserAgent() string
, which builds part of the string fromos.Args[0]
; in other words, the name of the controller manager binary.
Suggestions
Therefore, instead of updating the name of the manager binary for all projects based on controller-runtime, this issue tracks a way to easily provide a unique way to identify the manager. Some suggested ideas are:
-
Standardizing on some environment variable (ex.
MANAGER_NAME
), flag (ex.--manager-name
), or manager option used to override the name given to the user agent -
Update
sig.k8s.io/controller-runtime/pkg/manager.Options
with a field like so:// Options are the arguments for creating a new Manager type Options struct { // // ... // // Name is an optional identifier to assign to the Manager. // This value is part of the User-Agent string used with HTTP calls to the API server, // and can help identify this controller-manager as the actor responsible for lifecycle // changes in resources, ex. ADDED, MODIFIED, DELETED. // Defaults to the name of the controller manager binary, ex. os.Args[0]. Name string // // ... // }
Thoughts, concerns?