Skip to content

Commit e968a41

Browse files
committed
add more logging
1 parent 0f81a26 commit e968a41

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

modules/common/client/cache/cache.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func getCacheKey(token, key string) (string, error) {
3232

3333
contextKey, exists := contextCache.Get(token)
3434
if exists {
35+
klog.V(4).InfoS("context key found in cache", "key", contextKey)
3536
return fmt.Sprintf("%s:%s", contextKey, key), nil
3637
}
3738

@@ -79,13 +80,14 @@ func DeferredLoad[T any](token, key string, loadFunc func() (T, error)) {
7980

8081
_, locked := cacheLocks.Load(cacheKey)
8182
if locked {
82-
// Skip.
83+
klog.V(4).InfoS("cache is already being updated, skipping")
8384
return
8485
}
8586

8687
cacheLocks.Store(cacheKey, struct{}{})
8788
defer time.AfterFunc(args.CacheRefreshDebounce(), func() {
8889
cacheLocks.Delete(cacheKey)
90+
klog.V(4).InfoS("released cache update lock")
8991
})
9092

9193
cacheValue, err := loadFunc()
@@ -95,5 +97,6 @@ func DeferredLoad[T any](token, key string, loadFunc func() (T, error)) {
9597
}
9698

9799
_ = cache.SetWithTTL(cacheKey, cacheValue, 1, args.CacheTTL())
100+
klog.V(4).InfoS("cache updated successfully")
98101
}()
99102
}

modules/common/client/cache/client.go renamed to modules/common/client/cache/httpclient.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,23 @@ import (
44
"io"
55
"net/http"
66

7+
"k8s.io/klog/v2"
8+
79
"k8s.io/dashboard/client/args"
810
)
911

10-
type TokenExchangeTransport struct {
12+
type tokenExchangeTransport struct {
1113
token string
1214
transport http.RoundTripper
1315
}
1416

15-
func (in *TokenExchangeTransport) RoundTrip(req *http.Request) (*http.Response, error) {
17+
func (in *tokenExchangeTransport) RoundTrip(req *http.Request) (*http.Response, error) {
1618
req.Header.Set("Authorization", "Bearer "+in.token)
1719
return in.transport.RoundTrip(req)
1820
}
1921

2022
func exchangeToken(token string) (string, error) {
21-
client := &http.Client{Transport: &TokenExchangeTransport{
23+
client := &http.Client{Transport: &tokenExchangeTransport{
2224
token: token,
2325
transport: http.DefaultTransport,
2426
}}
@@ -34,5 +36,6 @@ func exchangeToken(token string) (string, error) {
3436
return "", err
3537
}
3638

39+
klog.V(3).InfoS("token exchange successful", "context", contextKey)
3740
return string(contextKey), nil
3841
}

modules/common/client/verber.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ func (v *resourceVerber) groupVersionResourceFromUnstructured(object *unstructur
5656

5757
func (v *resourceVerber) groupVersionResourceFromKind(kind string) (schema.GroupVersionResource, error) {
5858
if gvr, exists := kindToGroupVersionResource[kind]; exists {
59-
klog.V(3).InfoS("GroupVersionResource cache hit", "kind", kind)
59+
klog.V(4).InfoS("GroupVersionResource cache hit", "kind", kind)
6060
return gvr, nil
6161
}
6262

63-
klog.V(3).InfoS("GroupVersionResource cache miss", "kind", kind)
63+
klog.V(4).InfoS("GroupVersionResource cache miss", "kind", kind)
6464
_, resourceList, err := v.discovery.ServerGroupsAndResources()
6565
if err != nil {
6666
return schema.GroupVersionResource{}, err
@@ -151,7 +151,7 @@ func (v *resourceVerber) Update(object *unstructured.Unstructured) error {
151151
gvr := v.groupVersionResourceFromUnstructured(object)
152152

153153
return retry.RetryOnConflict(retry.DefaultRetry, func() error {
154-
klog.V(2).InfoS("fetching latest resource version", "group", gvr.Group, "version", gvr.Version, "resource", gvr.Resource, "name", name, "namespace", namespace)
154+
klog.V(4).InfoS("fetching latest resource version", "group", gvr.Group, "version", gvr.Version, "resource", gvr.Resource, "name", name, "namespace", namespace)
155155
result, getErr := v.client.Resource(gvr).Namespace(namespace).Get(context.TODO(), name, metav1.GetOptions{})
156156
if getErr != nil {
157157
return fmt.Errorf("failed to get latest %s version: %w", gvr.Resource, getErr)
@@ -174,7 +174,7 @@ func (v *resourceVerber) Update(object *unstructured.Unstructured) error {
174174
return fmt.Errorf("failed creating merge patch: %w", err)
175175
}
176176

177-
klog.V(3).InfoS("patching resource", "group", gvr.Group, "version", gvr.Version, "resource", gvr.Resource, "name", name, "namespace", namespace, "patch", string(patchBytes))
177+
klog.V(2).InfoS("patching resource", "group", gvr.Group, "version", gvr.Version, "resource", gvr.Resource, "name", name, "namespace", namespace, "patch", string(patchBytes))
178178
_, updateErr := v.client.Resource(gvr).Namespace(namespace).Patch(context.TODO(), name, k8stypes.MergePatchType, patchBytes, metav1.PatchOptions{})
179179
return updateErr
180180
})

0 commit comments

Comments
 (0)