@@ -24,6 +24,8 @@ type Version = version.Info
24
24
// DiscoveryRunner implements [APIs] by reading from a Kubernetes API client.
25
25
// Its methods are safe to call concurrently.
26
26
type DiscoveryRunner struct {
27
+ // NOTE(tracing): The methods of [discovery.DiscoveryClient] do not take
28
+ // a Context so their API calls won't have a parent span.
27
29
Client interface {
28
30
ServerGroups () (* metav1.APIGroupList , error )
29
31
ServerResourcesForGroupVersion (string ) (* metav1.APIResourceList , error )
@@ -100,11 +102,11 @@ func (r *DiscoveryRunner) IsOpenShift() bool {
100
102
func (r * DiscoveryRunner ) NeedLeaderElection () bool { return false }
101
103
102
104
// Read fetches available APIs from Kubernetes.
103
- func (r * DiscoveryRunner ) Read () error {
104
- return errors .Join (r .readAPIs (), r .readVersion ())
105
+ func (r * DiscoveryRunner ) Read (ctx context. Context ) error {
106
+ return errors .Join (r .readAPIs (ctx ), r .readVersion ())
105
107
}
106
108
107
- func (r * DiscoveryRunner ) readAPIs () error {
109
+ func (r * DiscoveryRunner ) readAPIs (ctx context. Context ) error {
108
110
// Build an index of the APIs we want to know about.
109
111
wantAPIs := make (map [string ]map [string ]sets.Set [string ])
110
112
for _ , want := range r .relevant {
@@ -160,6 +162,10 @@ func (r *DiscoveryRunner) readAPIs() error {
160
162
r .have .APISet = haveAPIs
161
163
r .have .Unlock ()
162
164
165
+ r .have .RLock ()
166
+ defer r .have .RUnlock ()
167
+ logging .FromContext (ctx ).V (1 ).Info ("Found APIs" , "index_size" , r .have .APISet .Len ())
168
+
163
169
return nil
164
170
}
165
171
@@ -181,11 +187,12 @@ func (r *DiscoveryRunner) Start(ctx context.Context) error {
181
187
defer ticker .Stop ()
182
188
183
189
log := logging .FromContext (ctx ).WithValues ("controller" , "kubernetes" )
190
+ ctx = logging .NewContext (ctx , log )
184
191
185
192
for {
186
193
select {
187
194
case <- ticker .C :
188
- if err := r .Read (); err != nil {
195
+ if err := r .Read (ctx ); err != nil {
189
196
log .Error (err , "Unable to detect Kubernetes APIs" )
190
197
}
191
198
case <- ctx .Done ():
0 commit comments