only init cluster and csr client in bootstrap phase (#1229)

Signed-off-by: Wei Liu <liuweixa@redhat.com>
Co-authored-by: Wei Liu <liuweixa@redhat.com>
This commit is contained in:
OpenShift Cherrypick Robot
2025-10-29 01:09:05 +00:00
committed by GitHub
co-authored by Wei Liu
parent d8cd1adca1
commit ac48573cf4
+26 -16
View File
@@ -86,6 +86,32 @@ func (d *GRPCDriver) BuildClients(ctx context.Context, secretOption register.Sec
clusterClient, 10*time.Minute).Cluster().V1().ManagedClusters()
clusterWatchStore.SetInformer(clusterInformers.Informer())
csrClientHolder, err := cloudeventscsr.NewAgentClientHolder(ctx,
cloudeventsoptions.NewGenericClientOptions(
config,
cloudeventscsr.NewCSRCodec(),
secretOption.ClusterName,
).WithClusterName(secretOption.ClusterName),
)
if err != nil {
return nil, err
}
csrControl := &ceCSRControl{csrClientHolder: csrClientHolder}
if err := d.csrDriver.SetCSRControl(csrControl, secretOption.ClusterName); err != nil {
return nil, err
}
d.control = csrControl
// Initialize the cluster client and CSR control in the bootstrap phase.
// Other clients should not be initialized, since they require
// permissions that are not allowed in the bootstrap phase.
if bootstrapped {
return &register.Clients{
ClusterClient: clusterClient,
ClusterInformer: clusterInformers,
}, nil
}
leaseWatchStore := cloudeventsstore.NewSimpleStore[*coordv1.Lease]()
leaseClient, err := cloudeventslease.NewLeaseClient(
ctx,
@@ -128,22 +154,6 @@ func (d *GRPCDriver) BuildClients(ctx context.Context, secretOption register.Sec
Addon().V1alpha1().ManagedClusterAddOns()
addonWatchStore.SetInformer(addonInformer.Informer())
csrClientHolder, err := cloudeventscsr.NewAgentClientHolder(ctx,
cloudeventsoptions.NewGenericClientOptions(
config,
cloudeventscsr.NewCSRCodec(),
secretOption.ClusterName,
).WithClusterName(secretOption.ClusterName),
)
if err != nil {
return nil, err
}
csrControl := &ceCSRControl{csrClientHolder: csrClientHolder}
if err := d.csrDriver.SetCSRControl(csrControl, secretOption.ClusterName); err != nil {
return nil, err
}
d.control = csrControl
clients := &register.Clients{
ClusterClient: clusterClient,
ClusterInformer: clusterInformers,