@@ -9,8 +9,10 @@ package writers
99
1010import (
1111 "context"
12+ "fmt"
1213
1314 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
15+ "k8s.io/client-go/kubernetes"
1416 "k8s.io/client-go/rest"
1517
1618 applyoperatorv1 "github.com/openshift/client-go/operator/applyconfigurations/operator/v1"
@@ -22,7 +24,7 @@ import (
2224// NewAuthenticationWriter writes into Authentication/cluster at
2325// .status.oauthAPIServer.encryptionStatus. The auth operator manages the
2426// oauth-apiserver. There is an extra hop the other two operators don't have.
25- func NewAuthenticationWriter (restConfig * rest.Config , fieldManager string ) (health.EncryptionStatusWriter , error ) {
27+ func NewAuthenticationWriter (restConfig * rest.Config , _ string ) (health.EncryptionStatusWriter , error ) {
2628 client , err := operatorclient .NewForConfig (restConfig )
2729 if err != nil {
2830 return nil , err
@@ -37,21 +39,42 @@ func NewAuthenticationWriter(restConfig *rest.Config, fieldManager string) (heal
3739 ),
3840 ),
3941
40- metav1.ApplyOptions {FieldManager : fieldManager , Force : true },
42+ // A single reporter writes this status, so a constant fieldManager
43+ // is enough and always fits the apiserver's length limit.
44+ metav1.ApplyOptions {FieldManager : health .Subcommand , Force : true },
4145 )
4246 return err
4347 }, nil
4448}
4549
4650// NewKubeAPIServerWriter writes into KubeAPIServer/cluster at
4751// .status.encryptionStatus.
48- func NewKubeAPIServerWriter (restConfig * rest.Config , fieldManager string ) (health.EncryptionStatusWriter , error ) {
52+ func NewKubeAPIServerWriter (restConfig * rest.Config , nodeName string ) (health.EncryptionStatusWriter , error ) {
4953 client , err := operatorclient .NewForConfig (restConfig )
5054 if err != nil {
5155 return nil , err
5256 }
57+ kubeClient , err := kubernetes .NewForConfig (restConfig )
58+ if err != nil {
59+ return nil , err
60+ }
5361
62+ // One reporter runs per control-plane node and each applies its own row, so
63+ // the fieldManager must be per-node. The node UID is a fixed-length,
64+ // instance-stable identity that fits the fieldManager length limit, unlike
65+ // the node name (a DNS subdomain up to 253 chars).
66+ //
67+ // Lazy evaluation on first call as constructor isn't concerned with any context.
68+ var fieldManager string
5469 return func (ctx context.Context , status * applyoperatorv1.KMSEncryptionStatusApplyConfiguration ) error {
70+ if fieldManager == "" {
71+ node , err := kubeClient .CoreV1 ().Nodes ().Get (ctx , nodeName , metav1.GetOptions {})
72+ if err != nil {
73+ return fmt .Errorf ("get node %q: %w" , nodeName , err )
74+ }
75+ fieldManager = fmt .Sprintf ("%s-%s" , health .Subcommand , node .UID )
76+ }
77+
5578 _ , err := client .OperatorV1 ().KubeAPIServers ().ApplyStatus (
5679 ctx ,
5780 applyoperatorv1 .KubeAPIServer ("cluster" ).WithStatus (
@@ -65,7 +88,7 @@ func NewKubeAPIServerWriter(restConfig *rest.Config, fieldManager string) (healt
6588
6689// NewOpenShiftAPIServerWriter writes into OpenShiftAPIServer/cluster at
6790// .status.encryptionStatus.
68- func NewOpenShiftAPIServerWriter (restConfig * rest.Config , fieldManager string ) (health.EncryptionStatusWriter , error ) {
91+ func NewOpenShiftAPIServerWriter (restConfig * rest.Config , _ string ) (health.EncryptionStatusWriter , error ) {
6992 client , err := operatorclient .NewForConfig (restConfig )
7093 if err != nil {
7194 return nil , err
@@ -78,7 +101,9 @@ func NewOpenShiftAPIServerWriter(restConfig *rest.Config, fieldManager string) (
78101 applyoperatorv1 .OpenShiftAPIServerStatus ().WithEncryptionStatus (status ),
79102 ),
80103
81- metav1.ApplyOptions {FieldManager : fieldManager , Force : true },
104+ // A single reporter writes this status, so a constant fieldManager
105+ // is enough and always fits the apiserver's length limit.
106+ metav1.ApplyOptions {FieldManager : health .Subcommand , Force : true },
82107 )
83108 return err
84109 }, nil
0 commit comments