@@ -52,7 +52,7 @@ type Response struct {
5252type ServiceAccountCache interface {
5353 Start (stop chan struct {})
5454 Get (name , namespace string ) Response
55- GetOrNotify (name , namespace string , handler chan any ) Response
55+ GetOrNotify (name , namespace string , handler chan struct {} ) Response
5656 GetCommonConfigurations (name , namespace string ) (useRegionalSTS bool , tokenExpiration int64 )
5757 // ToJSON returns cache contents as JSON string
5858 ToJSON () string
@@ -70,7 +70,7 @@ type serviceAccountCache struct {
7070 composeRoleArn ComposeRoleArn
7171 defaultTokenExpiration int64
7272 webhookUsage prometheus.Gauge
73- notificationHandlers map [string ]chan any // type of channel doesn't matter. It's just for being notified
73+ notificationHandlers map [string ]chan struct {}
7474}
7575
7676type ComposeRoleArn struct {
@@ -106,32 +106,32 @@ func (c *serviceAccountCache) Get(name, namespace string) Response {
106106// It will first look at the set of ServiceAccounts configured using annotations. If none is found, it will register
107107// handler to be notified as soon as a ServiceAccount with given key is populated to the cache. Afterwards it will check
108108// for a ServiceAccount configured through the pod-identity-webhook ConfigMap.
109- func (c * serviceAccountCache ) GetOrNotify (name , namespace string , handler chan any ) Response {
109+ func (c * serviceAccountCache ) GetOrNotify (name , namespace string , handler chan struct {} ) Response {
110110 result := Response {
111111 TokenExpiration : pkg .DefaultTokenExpiration ,
112112 }
113113 klog .V (5 ).Infof ("Fetching sa %s/%s from cache" , namespace , name )
114114 {
115- resp := c .getSAorNotify (name , namespace , handler )
116- if resp != nil {
115+ entry := c .getSAorNotify (name , namespace , handler )
116+ if entry != nil {
117117 result .FoundInSACache = true
118118 }
119- if resp != nil && resp .RoleARN != "" {
120- result .RoleARN = resp .RoleARN
121- result .Audience = resp .Audience
122- result .UseRegionalSTS = resp .UseRegionalSTS
123- result .TokenExpiration = resp .TokenExpiration
119+ if entry != nil && entry .RoleARN != "" {
120+ result .RoleARN = entry .RoleARN
121+ result .Audience = entry .Audience
122+ result .UseRegionalSTS = entry .UseRegionalSTS
123+ result .TokenExpiration = entry .TokenExpiration
124124 return result
125125 }
126126 }
127127 {
128- resp := c .getCM (name , namespace )
129- if resp != nil {
128+ entry := c .getCM (name , namespace )
129+ if entry != nil {
130130 result .FoundInCMCache = true
131- result .RoleARN = resp .RoleARN
132- result .Audience = resp .Audience
133- result .UseRegionalSTS = resp .UseRegionalSTS
134- result .TokenExpiration = resp .TokenExpiration
131+ result .RoleARN = entry .RoleARN
132+ result .Audience = entry .Audience
133+ result .UseRegionalSTS = entry .UseRegionalSTS
134+ result .TokenExpiration = entry .TokenExpiration
135135 return result
136136 }
137137 }
@@ -143,34 +143,34 @@ func (c *serviceAccountCache) GetOrNotify(name, namespace string, handler chan a
143143// The config file for the container credentials does not contain "TokenExpiration" or "UseRegionalSTS". For backward compatibility,
144144// Use these fields if they are set in the sa annotations or config map.
145145func (c * serviceAccountCache ) GetCommonConfigurations (name , namespace string ) (useRegionalSTS bool , tokenExpiration int64 ) {
146- if resp := c .getSAorNotify (name , namespace , nil ); resp != nil {
147- return resp .UseRegionalSTS , resp .TokenExpiration
148- } else if resp := c .getCM (name , namespace ); resp != nil {
149- return resp .UseRegionalSTS , resp .TokenExpiration
146+ if entry := c .getSAorNotify (name , namespace , nil ); entry != nil {
147+ return entry .UseRegionalSTS , entry .TokenExpiration
148+ } else if entry := c .getCM (name , namespace ); entry != nil {
149+ return entry .UseRegionalSTS , entry .TokenExpiration
150150 }
151151 return false , pkg .DefaultTokenExpiration
152152}
153153
154- func (c * serviceAccountCache ) getSAorNotify (name , namespace string , handler chan any ) * Entry {
154+ func (c * serviceAccountCache ) getSAorNotify (name , namespace string , handler chan struct {} ) * Entry {
155155 c .mu .RLock ()
156156 defer c .mu .RUnlock ()
157- resp , ok := c .saCache [namespace + "/" + name ]
157+ entry , ok := c .saCache [namespace + "/" + name ]
158158 if ! ok && handler != nil {
159159 klog .V (5 ).Infof ("Service Account %s/%s not found in cache, adding notification handler" , namespace , name )
160160 c .notificationHandlers [namespace + "/" + name ] = handler
161161 return nil
162162 }
163- return resp
163+ return entry
164164}
165165
166166func (c * serviceAccountCache ) getCM (name , namespace string ) * Entry {
167167 c .mu .RLock ()
168168 defer c .mu .RUnlock ()
169- resp , ok := c .cmCache [namespace + "/" + name ]
169+ entry , ok := c .cmCache [namespace + "/" + name ]
170170 if ! ok {
171171 return nil
172172 }
173- return resp
173+ return entry
174174}
175175
176176func (c * serviceAccountCache ) popSA (name , namespace string ) {
@@ -200,7 +200,7 @@ func (c *serviceAccountCache) ToJSON() string {
200200}
201201
202202func (c * serviceAccountCache ) addSA (sa * v1.ServiceAccount ) {
203- resp := & Entry {}
203+ entry := & Entry {}
204204
205205 arn , ok := sa .Annotations [c .annotationPrefix + "/" + pkg .RoleARNAnnotation ]
206206 if ok {
@@ -214,57 +214,57 @@ func (c *serviceAccountCache) addSA(sa *v1.ServiceAccount) {
214214 } else if ! matched {
215215 klog .Warningf ("arn is invalid: %s" , arn )
216216 }
217- resp .RoleARN = arn
217+ entry .RoleARN = arn
218218 }
219219
220- resp .Audience = c .defaultAudience
220+ entry .Audience = c .defaultAudience
221221 if audience , ok := sa .Annotations [c .annotationPrefix + "/" + pkg .AudienceAnnotation ]; ok {
222- resp .Audience = audience
222+ entry .Audience = audience
223223 }
224224
225- resp .UseRegionalSTS = c .defaultRegionalSTS
225+ entry .UseRegionalSTS = c .defaultRegionalSTS
226226 if useRegionalStr , ok := sa .Annotations [c .annotationPrefix + "/" + pkg .UseRegionalSTSAnnotation ]; ok {
227227 useRegional , err := strconv .ParseBool (useRegionalStr )
228228 if err != nil {
229229 klog .V (4 ).Infof ("Ignoring service account %s/%s invalid value for disable-regional-sts annotation" , sa .Namespace , sa .Name )
230230 } else {
231- resp .UseRegionalSTS = useRegional
231+ entry .UseRegionalSTS = useRegional
232232 }
233233 }
234234
235- resp .TokenExpiration = c .defaultTokenExpiration
235+ entry .TokenExpiration = c .defaultTokenExpiration
236236 if tokenExpirationStr , ok := sa .Annotations [c .annotationPrefix + "/" + pkg .TokenExpirationAnnotation ]; ok {
237237 if tokenExpiration , err := strconv .ParseInt (tokenExpirationStr , 10 , 64 ); err != nil {
238- klog .V (4 ).Infof ("Found invalid value for token expiration, using %d seconds as default: %v" , resp .TokenExpiration , err )
238+ klog .V (4 ).Infof ("Found invalid value for token expiration, using %d seconds as default: %v" , entry .TokenExpiration , err )
239239 } else {
240- resp .TokenExpiration = pkg .ValidateMinTokenExpiration (tokenExpiration )
240+ entry .TokenExpiration = pkg .ValidateMinTokenExpiration (tokenExpiration )
241241 }
242242 }
243243 c .webhookUsage .Set (1 )
244244
245- c .setSA (sa .Name , sa .Namespace , resp )
245+ c .setSA (sa .Name , sa .Namespace , entry )
246246}
247247
248- func (c * serviceAccountCache ) setSA (name , namespace string , resp * Entry ) {
248+ func (c * serviceAccountCache ) setSA (name , namespace string , entry * Entry ) {
249249 c .mu .Lock ()
250250 defer c .mu .Unlock ()
251251
252252 key := namespace + "/" + name
253- klog .V (5 ).Infof ("Adding SA %q to SA cache: %+v" , key , resp )
254- c .saCache [namespace + "/" + name ] = resp
253+ klog .V (5 ).Infof ("Adding SA %q to SA cache: %+v" , key , entry )
254+ c .saCache [key ] = entry
255255
256256 if handler , found := c .notificationHandlers [key ]; found {
257257 klog .V (5 ).Infof ("Notifying handler for %q" , key )
258- handler <- 1
258+ handler <- struct {}{}
259259 delete (c .notificationHandlers , key )
260260 }
261261}
262262
263- func (c * serviceAccountCache ) setCM (name , namespace string , resp * Entry ) {
263+ func (c * serviceAccountCache ) setCM (name , namespace string , entry * Entry ) {
264264 c .mu .Lock ()
265265 defer c .mu .Unlock ()
266- klog .V (5 ).Infof ("Adding SA %s/%s to CM cache: %+v" , namespace , name , resp )
267- c .cmCache [namespace + "/" + name ] = resp
266+ klog .V (5 ).Infof ("Adding SA %s/%s to CM cache: %+v" , namespace , name , entry )
267+ c .cmCache [namespace + "/" + name ] = entry
268268}
269269
270270func New (defaultAudience , prefix string , defaultRegionalSTS bool , defaultTokenExpiration int64 , saInformer coreinformers.ServiceAccountInformer , cmInformer coreinformers.ConfigMapInformer , composeRoleArn ComposeRoleArn ) ServiceAccountCache {
@@ -286,7 +286,7 @@ func New(defaultAudience, prefix string, defaultRegionalSTS bool, defaultTokenEx
286286 defaultTokenExpiration : defaultTokenExpiration ,
287287 hasSynced : hasSynced ,
288288 webhookUsage : webhookUsage ,
289- notificationHandlers : map [string ]chan any {},
289+ notificationHandlers : map [string ]chan struct {} {},
290290 }
291291
292292 saInformer .Informer ().AddEventHandler (
@@ -348,12 +348,12 @@ func (c *serviceAccountCache) populateCacheFromCM(oldCM, newCM *v1.ConfigMap) er
348348 if err != nil {
349349 return fmt .Errorf ("failed to unmarshal new config %q: %v" , newConfig , err )
350350 }
351- for key , resp := range sas {
351+ for key , entry := range sas {
352352 parts := strings .Split (key , "/" )
353- if resp .TokenExpiration == 0 {
354- resp .TokenExpiration = c .defaultTokenExpiration
353+ if entry .TokenExpiration == 0 {
354+ entry .TokenExpiration = c .defaultTokenExpiration
355355 }
356- c .setCM (parts [1 ], parts [0 ], resp )
356+ c .setCM (parts [1 ], parts [0 ], entry )
357357 }
358358
359359 if oldCM != nil {
0 commit comments