mirror of
https://github.com/kubernetes/kubernetes.git
synced 2026-06-11 09:53:38 -04:00
Fix nil check for store metrics
This commit is contained in:
parent
9991d72c6b
commit
e50a7f3dbc
2 changed files with 20 additions and 0 deletions
|
|
@ -402,6 +402,9 @@ func WithTransformer(transformer TransformFunc) StoreOption {
|
|||
func WithStoreMetrics(identifier InformerNameAndResource, metrics InformerMetricsProvider) StoreOption {
|
||||
return func(c *cache) {
|
||||
c.identifier = identifier
|
||||
if metrics == nil {
|
||||
metrics = globalInformerMetricsProvider
|
||||
}
|
||||
c.metrics = metrics
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
)
|
||||
|
||||
|
|
@ -246,3 +247,19 @@ func TestCacheTransactionShouldIndexErrors(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestWithStoreMetricsDefaulting(t *testing.T) {
|
||||
name, err := NewInformerName("test-informer")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create informer name: %v", err)
|
||||
}
|
||||
defer name.Release()
|
||||
gvr := schema.GroupVersionResource{Group: "apps", Version: "v1", Resource: "deployments"}
|
||||
id := name.WithResource(gvr)
|
||||
|
||||
s := NewStore(testStoreKeyFunc, WithStoreMetrics(id, nil)).(*cache)
|
||||
|
||||
if s.metrics == nil {
|
||||
t.Errorf("expected c.metrics to be populated, got nil")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue