From e134ac968399360ddbc94cb8ad10a7b43ee87443 Mon Sep 17 00:00:00 2001 From: Catherine Fang Date: Wed, 28 Jun 2023 08:28:09 -0400 Subject: [PATCH] fix Update pkg/app/discovery.go Co-authored-by: Pranshu Srivastava Update internal/discovery/types.go Co-authored-by: Pranshu Srivastava Update internal/discovery/types.go Co-authored-by: Pranshu Srivastava Update pkg/customresourcestate/config.go Co-authored-by: Pranshu Srivastava Update pkg/customresourcestate/config.go Co-authored-by: Pranshu Srivastava --- internal/discovery/types.go | 2 ++ pkg/app/discovery.go | 2 +- pkg/app/discovery_test.go | 1 + pkg/customresourcestate/config.go | 1 + tests/e2e/discovery_test.go | 5 +++-- 5 files changed, 8 insertions(+), 3 deletions(-) diff --git a/internal/discovery/types.go b/internal/discovery/types.go index 9d31176ed9..a2ec52bf1d 100644 --- a/internal/discovery/types.go +++ b/internal/discovery/types.go @@ -19,6 +19,7 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" ) +// GroupVersionKindPlural embeds schema.GroupVersionKind, in addition to the plural representation of the Kind. type GroupVersionKindPlural struct { schema.GroupVersionKind Plural string @@ -28,6 +29,7 @@ func (g GroupVersionKindPlural) String() string { return fmt.Sprintf("%s/%s, Kind=%s, Plural=%s", g.Group, g.Version, g.Kind, g.Plural) } +// KindPlural entails the Kind and its plural representation. type KindPlural struct { Kind string Plural string diff --git a/pkg/app/discovery.go b/pkg/app/discovery.go index 60b73d5f51..8ca3f548b4 100644 --- a/pkg/app/discovery.go +++ b/pkg/app/discovery.go @@ -11,7 +11,6 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Package discovery provides a discovery and resolution logic for GVKs. package app import ( @@ -40,6 +39,7 @@ import ( const Interval = 3 * time.Second // CRDiscoverer provides a cache of the collected GVKs, along with helper utilities. +// It implements customresourcestate.GVKToGVKP. type CRDiscoverer struct { // m is a mutex to protect the cache. m sync.RWMutex diff --git a/pkg/app/discovery_test.go b/pkg/app/discovery_test.go index fed0ea79fc..fec68ee391 100644 --- a/pkg/app/discovery_test.go +++ b/pkg/app/discovery_test.go @@ -19,6 +19,7 @@ import ( "testing" "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/kube-state-metrics/v2/internal/discovery" ) diff --git a/pkg/customresourcestate/config.go b/pkg/customresourcestate/config.go index 174694c865..ca736fe55e 100644 --- a/pkg/customresourcestate/config.go +++ b/pkg/customresourcestate/config.go @@ -165,6 +165,7 @@ type ConfigDecoder interface { Decode(v interface{}) (err error) } +// GVKToGVKP incorporates logic to resolve a given GVK, with variable version and/or kind, to it's []discovery.GroupVersionKindPlural representation. type GVKToGVKP interface { ResolveGVKToGVKPs(gvk schema.GroupVersionKind) (resolvedGVKPs []discovery.GroupVersionKindPlural, err error) } diff --git a/tests/e2e/discovery_test.go b/tests/e2e/discovery_test.go index 144e2c05d7..225792bfdc 100644 --- a/tests/e2e/discovery_test.go +++ b/tests/e2e/discovery_test.go @@ -29,12 +29,12 @@ import ( "k8s.io/klog/v2" "k8s.io/kube-state-metrics/v2/internal" - "k8s.io/kube-state-metrics/v2/pkg/customresourcestate" "k8s.io/kube-state-metrics/v2/pkg/options" ) // PopulateTimeout is the timeout on populating the cache for the first time. const PopulateTimeout = 10 * time.Second +const Interval = 3 * time.Second func TestVariableVKsDiscoveryAndResolution(t *testing.T) { @@ -140,7 +140,8 @@ func TestVariableVKsDiscoveryAndResolution(t *testing.T) { // Wait for the metric to be available. ch := make(chan bool, 1) klog.InfoS("waiting for metrics to become available") - err = wait.PollUntilContextTimeout(context.TODO(), customresourcestate.Interval, PopulateTimeout, true, func(ctx context.Context) (bool, error) { + + err = wait.PollUntilContextTimeout(context.TODO(), Interval, PopulateTimeout, true, func(ctx context.Context) (bool, error) { out, err := exec.Command("curl", "localhost:8080/metrics").Output() if err != nil { return false, err