Skip to content

Commit

Permalink
fix missingSACounter metric
Browse files Browse the repository at this point in the history
  • Loading branch information
modulitos committed Nov 27, 2024
1 parent bb56f02 commit 2d7664d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,9 @@ func (m *Modifier) buildPodPatchConfig(pod *corev1.Pod) *podPatchConfig {
// Use the STS WebIdentity method if set
request := cache.Request{Namespace: pod.Namespace, Name: pod.Spec.ServiceAccountName, RequestNotification: true}
response := m.Cache.Get(request)
if !response.FoundInCache && m.saLookupGraceTime == 0 {
missingSACounter.WithLabelValues().Inc()
}
if !response.FoundInCache && m.saLookupGraceTime > 0 {
klog.Warningf("Service account %s not found in the cache. Waiting up to %s to be notified", request.CacheKey(), m.saLookupGraceTime)
select {
Expand All @@ -443,10 +446,12 @@ func (m *Modifier) buildPodPatchConfig(pod *corev1.Pod) *podPatchConfig {
response = m.Cache.Get(request)
if !response.FoundInCache {
klog.Warningf("Service account %s not found in the cache after being notified. Not mutating.", request.CacheKey())
missingSACounter.WithLabelValues().Inc()
return nil
}
case <-time.After(m.saLookupGraceTime):
klog.Warningf("Service account %s not found in the cache after %s. Not mutating.", request.CacheKey(), m.saLookupGraceTime)
missingSACounter.WithLabelValues().Inc()
return nil
}
}
Expand Down Expand Up @@ -503,7 +508,6 @@ func (m *Modifier) MutatePod(ar *v1beta1.AdmissionReview) *v1beta1.AdmissionResp

patchConfig := m.buildPodPatchConfig(&pod)
if patchConfig == nil {
missingSACounter.WithLabelValues().Inc()
klog.V(4).Infof("Pod was not mutated. Reason: "+
"Service account did not have the right annotations or was not found in the cache. %s", logContext(pod.Name, pod.GenerateName, pod.Spec.ServiceAccountName, pod.Namespace))
return &v1beta1.AdmissionResponse{
Expand Down

0 comments on commit 2d7664d

Please sign in to comment.