From 892e9b89df6b713031fda4d7e9bcc751c3ee0334 Mon Sep 17 00:00:00 2001 From: Lukasz Szaszkiewicz Date: Mon, 16 Sep 2024 11:56:54 +0200 Subject: [PATCH] client-go/metadata: add watchlist method Kubernetes-commit: 3a0aa1093f5e11afb3d729e5799c2de526c20de9 --- metadata/metadata.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/metadata/metadata.go b/metadata/metadata.go index e8d263a2..7eddc673 100644 --- a/metadata/metadata.go +++ b/metadata/metadata.go @@ -253,6 +253,25 @@ func (c *client) list(ctx context.Context, opts metav1.ListOptions) (*metav1.Par return partial, nil } +// watchList establishes a watch stream with the server and returns PartialObjectMetadataList. +func (c *client) watchList(ctx context.Context, opts metav1.ListOptions) (*metav1.PartialObjectMetadataList, error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + + result := &metav1.PartialObjectMetadataList{} + err := c.client.client.Get(). + AbsPath(c.makeURLSegments("")...). + SetHeader("Accept", "application/vnd.kubernetes.protobuf;as=PartialObjectMetadata;g=meta.k8s.io;v=v1,application/json;as=PartialObjectMetadata;g=meta.k8s.io;v=v1,application/json"). + SpecificallyVersionedParams(&opts, dynamicParameterCodec, versionV1). + Timeout(timeout). + WatchList(ctx). + Into(result) + + return result, err +} + // Watch finds all changes to the resources in the specified scope (namespace or cluster). func (c *client) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) { var timeout time.Duration