mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 03:11:40 +00:00
Merge pull request #88910 from liggitt/metadata-context
Metadata client: plumb context
This commit is contained in:
commit
f52cbea102
@ -17,6 +17,7 @@ limitations under the License.
|
||||
package garbagecollector
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"sync"
|
||||
@ -347,7 +348,7 @@ func (gc *GarbageCollector) isDangling(reference metav1.OwnerReference, item *no
|
||||
// TODO: It's only necessary to talk to the API server if the owner node
|
||||
// is a "virtual" node. The local graph could lag behind the real
|
||||
// status, but in practice, the difference is small.
|
||||
owner, err = gc.metadataClient.Resource(resource).Namespace(resourceDefaultNamespace(namespaced, item.identity.Namespace)).Get(reference.Name, metav1.GetOptions{})
|
||||
owner, err = gc.metadataClient.Resource(resource).Namespace(resourceDefaultNamespace(namespaced, item.identity.Namespace)).Get(context.TODO(), reference.Name, metav1.GetOptions{})
|
||||
switch {
|
||||
case errors.IsNotFound(err):
|
||||
gc.absentOwnerCache.Add(reference.UID)
|
||||
|
@ -17,6 +17,7 @@ limitations under the License.
|
||||
package garbagecollector
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
@ -56,7 +57,7 @@ func (gc *GarbageCollector) deleteObject(item objectReference, policy *metav1.De
|
||||
uid := item.UID
|
||||
preconditions := metav1.Preconditions{UID: &uid}
|
||||
deleteOptions := metav1.DeleteOptions{Preconditions: &preconditions, PropagationPolicy: policy}
|
||||
return gc.metadataClient.Resource(resource).Namespace(resourceDefaultNamespace(namespaced, item.Namespace)).Delete(item.Name, &deleteOptions)
|
||||
return gc.metadataClient.Resource(resource).Namespace(resourceDefaultNamespace(namespaced, item.Namespace)).Delete(context.TODO(), item.Name, deleteOptions)
|
||||
}
|
||||
|
||||
func (gc *GarbageCollector) getObject(item objectReference) (*metav1.PartialObjectMetadata, error) {
|
||||
@ -64,7 +65,7 @@ func (gc *GarbageCollector) getObject(item objectReference) (*metav1.PartialObje
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return gc.metadataClient.Resource(resource).Namespace(resourceDefaultNamespace(namespaced, item.Namespace)).Get(item.Name, metav1.GetOptions{})
|
||||
return gc.metadataClient.Resource(resource).Namespace(resourceDefaultNamespace(namespaced, item.Namespace)).Get(context.TODO(), item.Name, metav1.GetOptions{})
|
||||
}
|
||||
|
||||
func (gc *GarbageCollector) patchObject(item objectReference, patch []byte, pt types.PatchType) (*metav1.PartialObjectMetadata, error) {
|
||||
@ -72,7 +73,7 @@ func (gc *GarbageCollector) patchObject(item objectReference, patch []byte, pt t
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return gc.metadataClient.Resource(resource).Namespace(resourceDefaultNamespace(namespaced, item.Namespace)).Patch(item.Name, pt, patch, metav1.PatchOptions{})
|
||||
return gc.metadataClient.Resource(resource).Namespace(resourceDefaultNamespace(namespaced, item.Namespace)).Patch(context.TODO(), item.Name, pt, patch, metav1.PatchOptions{})
|
||||
}
|
||||
|
||||
func (gc *GarbageCollector) removeFinalizer(owner *node, targetFinalizer string) error {
|
||||
|
@ -17,6 +17,7 @@ limitations under the License.
|
||||
package garbagecollector
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
@ -67,7 +68,7 @@ func (gc *GarbageCollector) getMetadata(apiVersion, kind, namespace, name string
|
||||
m, ok := gc.dependencyGraphBuilder.monitors[apiResource]
|
||||
if !ok || m == nil {
|
||||
// If local cache doesn't exist for mapping.Resource, send a GET request to API server
|
||||
return gc.metadataClient.Resource(apiResource).Namespace(namespace).Get(name, metav1.GetOptions{})
|
||||
return gc.metadataClient.Resource(apiResource).Namespace(namespace).Get(context.TODO(), name, metav1.GetOptions{})
|
||||
}
|
||||
key := name
|
||||
if len(namespace) != 0 {
|
||||
@ -79,7 +80,7 @@ func (gc *GarbageCollector) getMetadata(apiVersion, kind, namespace, name string
|
||||
}
|
||||
if !exist {
|
||||
// If local cache doesn't contain the object, send a GET request to API server
|
||||
return gc.metadataClient.Resource(apiResource).Namespace(namespace).Get(name, metav1.GetOptions{})
|
||||
return gc.metadataClient.Resource(apiResource).Namespace(namespace).Get(context.TODO(), name, metav1.GetOptions{})
|
||||
}
|
||||
obj, ok := raw.(runtime.Object)
|
||||
if !ok {
|
||||
|
@ -318,8 +318,8 @@ func (d *namespacedResourcesDeleter) deleteCollection(gvr schema.GroupVersionRes
|
||||
// resource deletions generically. it will ensure all resources in the namespace are purged prior to releasing
|
||||
// namespace itself.
|
||||
background := metav1.DeletePropagationBackground
|
||||
opts := &metav1.DeleteOptions{PropagationPolicy: &background}
|
||||
err := d.metadataClient.Resource(gvr).Namespace(namespace).DeleteCollection(opts, metav1.ListOptions{})
|
||||
opts := metav1.DeleteOptions{PropagationPolicy: &background}
|
||||
err := d.metadataClient.Resource(gvr).Namespace(namespace).DeleteCollection(context.TODO(), opts, metav1.ListOptions{})
|
||||
|
||||
if err == nil {
|
||||
return true, nil
|
||||
@ -355,7 +355,7 @@ func (d *namespacedResourcesDeleter) listCollection(gvr schema.GroupVersionResou
|
||||
return nil, false, nil
|
||||
}
|
||||
|
||||
partialList, err := d.metadataClient.Resource(gvr).Namespace(namespace).List(metav1.ListOptions{})
|
||||
partialList, err := d.metadataClient.Resource(gvr).Namespace(namespace).List(context.TODO(), metav1.ListOptions{})
|
||||
if err == nil {
|
||||
return partialList, true, nil
|
||||
}
|
||||
@ -388,8 +388,8 @@ func (d *namespacedResourcesDeleter) deleteEachItem(gvr schema.GroupVersionResou
|
||||
}
|
||||
for _, item := range unstructuredList.Items {
|
||||
background := metav1.DeletePropagationBackground
|
||||
opts := &metav1.DeleteOptions{PropagationPolicy: &background}
|
||||
if err = d.metadataClient.Resource(gvr).Namespace(namespace).Delete(item.GetName(), opts); err != nil && !errors.IsNotFound(err) && !errors.IsMethodNotSupported(err) {
|
||||
opts := metav1.DeleteOptions{PropagationPolicy: &background}
|
||||
if err = d.metadataClient.Resource(gvr).Namespace(namespace).Delete(context.TODO(), item.GetName(), opts); err != nil && !errors.IsNotFound(err) && !errors.IsMethodNotSupported(err) {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ limitations under the License.
|
||||
package fake
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
@ -214,7 +215,7 @@ func (c *metadataResourceClient) UpdateStatus(obj *metav1.PartialObjectMetadata,
|
||||
}
|
||||
|
||||
// Delete records the object deletion and processes it via the reactor.
|
||||
func (c *metadataResourceClient) Delete(name string, opts *metav1.DeleteOptions, subresources ...string) error {
|
||||
func (c *metadataResourceClient) Delete(ctx context.Context, name string, opts metav1.DeleteOptions, subresources ...string) error {
|
||||
var err error
|
||||
switch {
|
||||
case len(c.namespace) == 0 && len(subresources) == 0:
|
||||
@ -238,7 +239,7 @@ func (c *metadataResourceClient) Delete(name string, opts *metav1.DeleteOptions,
|
||||
}
|
||||
|
||||
// DeleteCollection records the object collection deletion and processes it via the reactor.
|
||||
func (c *metadataResourceClient) DeleteCollection(opts *metav1.DeleteOptions, listOptions metav1.ListOptions) error {
|
||||
func (c *metadataResourceClient) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOptions metav1.ListOptions) error {
|
||||
var err error
|
||||
switch {
|
||||
case len(c.namespace) == 0:
|
||||
@ -255,7 +256,7 @@ func (c *metadataResourceClient) DeleteCollection(opts *metav1.DeleteOptions, li
|
||||
}
|
||||
|
||||
// Get records the object retrieval and processes it via the reactor.
|
||||
func (c *metadataResourceClient) Get(name string, opts metav1.GetOptions, subresources ...string) (*metav1.PartialObjectMetadata, error) {
|
||||
func (c *metadataResourceClient) Get(ctx context.Context, name string, opts metav1.GetOptions, subresources ...string) (*metav1.PartialObjectMetadata, error) {
|
||||
var uncastRet runtime.Object
|
||||
var err error
|
||||
switch {
|
||||
@ -290,7 +291,7 @@ func (c *metadataResourceClient) Get(name string, opts metav1.GetOptions, subres
|
||||
}
|
||||
|
||||
// List records the object deletion and processes it via the reactor.
|
||||
func (c *metadataResourceClient) List(opts metav1.ListOptions) (*metav1.PartialObjectMetadataList, error) {
|
||||
func (c *metadataResourceClient) List(ctx context.Context, opts metav1.ListOptions) (*metav1.PartialObjectMetadataList, error) {
|
||||
var obj runtime.Object
|
||||
var err error
|
||||
switch {
|
||||
@ -337,7 +338,7 @@ func (c *metadataResourceClient) List(opts metav1.ListOptions) (*metav1.PartialO
|
||||
return list, nil
|
||||
}
|
||||
|
||||
func (c *metadataResourceClient) Watch(opts metav1.ListOptions) (watch.Interface, error) {
|
||||
func (c *metadataResourceClient) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) {
|
||||
switch {
|
||||
case len(c.namespace) == 0:
|
||||
return c.client.Fake.
|
||||
@ -353,7 +354,7 @@ func (c *metadataResourceClient) Watch(opts metav1.ListOptions) (watch.Interface
|
||||
}
|
||||
|
||||
// Patch records the object patch and processes it via the reactor.
|
||||
func (c *metadataResourceClient) Patch(name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*metav1.PartialObjectMetadata, error) {
|
||||
func (c *metadataResourceClient) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*metav1.PartialObjectMetadata, error) {
|
||||
var uncastRet runtime.Object
|
||||
var err error
|
||||
switch {
|
||||
|
@ -17,6 +17,7 @@ limitations under the License.
|
||||
package fake
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
@ -72,7 +73,7 @@ func TestList(t *testing.T) {
|
||||
newPartialObjectMetadata("group/version", "TheKind", "ns-foo", "name-baz"),
|
||||
newPartialObjectMetadata("group2/version", "TheKind", "ns-foo", "name2-baz"),
|
||||
)
|
||||
listFirst, err := client.Resource(schema.GroupVersionResource{Group: "group", Version: "version", Resource: "thekinds"}).List(metav1.ListOptions{})
|
||||
listFirst, err := client.Resource(schema.GroupVersionResource{Group: "group", Version: "version", Resource: "thekinds"}).List(context.TODO(), metav1.ListOptions{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -100,7 +101,7 @@ func (tc *patchTestCase) runner(t *testing.T) {
|
||||
client := NewSimpleMetadataClient(scheme, tc.object)
|
||||
resourceInterface := client.Resource(schema.GroupVersionResource{Group: testGroup, Version: testVersion, Resource: testResource}).Namespace(testNamespace)
|
||||
|
||||
got, recErr := resourceInterface.Patch(testName, tc.patchType, tc.patchBytes, metav1.PatchOptions{})
|
||||
got, recErr := resourceInterface.Patch(context.TODO(), testName, tc.patchType, tc.patchBytes, metav1.PatchOptions{})
|
||||
|
||||
if err := tc.verifyErr(recErr); err != nil {
|
||||
t.Error(err)
|
||||
|
@ -17,6 +17,8 @@ limitations under the License.
|
||||
package metadata
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
@ -32,12 +34,12 @@ type Interface interface {
|
||||
// ResourceInterface contains the set of methods that may be invoked on objects by their metadata.
|
||||
// Update is not supported by the server, but Patch can be used for the actions Update would handle.
|
||||
type ResourceInterface interface {
|
||||
Delete(name string, options *metav1.DeleteOptions, subresources ...string) error
|
||||
DeleteCollection(options *metav1.DeleteOptions, listOptions metav1.ListOptions) error
|
||||
Get(name string, options metav1.GetOptions, subresources ...string) (*metav1.PartialObjectMetadata, error)
|
||||
List(opts metav1.ListOptions) (*metav1.PartialObjectMetadataList, error)
|
||||
Watch(opts metav1.ListOptions) (watch.Interface, error)
|
||||
Patch(name string, pt types.PatchType, data []byte, options metav1.PatchOptions, subresources ...string) (*metav1.PartialObjectMetadata, error)
|
||||
Delete(ctx context.Context, name string, options metav1.DeleteOptions, subresources ...string) error
|
||||
DeleteCollection(ctx context.Context, options metav1.DeleteOptions, listOptions metav1.ListOptions) error
|
||||
Get(ctx context.Context, name string, options metav1.GetOptions, subresources ...string) (*metav1.PartialObjectMetadata, error)
|
||||
List(ctx context.Context, opts metav1.ListOptions) (*metav1.PartialObjectMetadataList, error)
|
||||
Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error)
|
||||
Patch(ctx context.Context, name string, pt types.PatchType, data []byte, options metav1.PatchOptions, subresources ...string) (*metav1.PartialObjectMetadata, error)
|
||||
}
|
||||
|
||||
// Getter handles both namespaced and non-namespaced resource types consistently.
|
||||
|
@ -120,14 +120,11 @@ func (c *client) Namespace(ns string) ResourceInterface {
|
||||
}
|
||||
|
||||
// Delete removes the provided resource from the server.
|
||||
func (c *client) Delete(name string, opts *metav1.DeleteOptions, subresources ...string) error {
|
||||
func (c *client) Delete(ctx context.Context, name string, opts metav1.DeleteOptions, subresources ...string) error {
|
||||
if len(name) == 0 {
|
||||
return fmt.Errorf("name is required")
|
||||
}
|
||||
if opts == nil {
|
||||
opts = &metav1.DeleteOptions{}
|
||||
}
|
||||
deleteOptionsByte, err := runtime.Encode(deleteOptionsCodec.LegacyCodec(schema.GroupVersion{Version: "v1"}), opts)
|
||||
deleteOptionsByte, err := runtime.Encode(deleteOptionsCodec.LegacyCodec(schema.GroupVersion{Version: "v1"}), &opts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -136,16 +133,13 @@ func (c *client) Delete(name string, opts *metav1.DeleteOptions, subresources ..
|
||||
Delete().
|
||||
AbsPath(append(c.makeURLSegments(name), subresources...)...).
|
||||
Body(deleteOptionsByte).
|
||||
Do(context.TODO())
|
||||
Do(ctx)
|
||||
return result.Error()
|
||||
}
|
||||
|
||||
// DeleteCollection triggers deletion of all resources in the specified scope (namespace or cluster).
|
||||
func (c *client) DeleteCollection(opts *metav1.DeleteOptions, listOptions metav1.ListOptions) error {
|
||||
if opts == nil {
|
||||
opts = &metav1.DeleteOptions{}
|
||||
}
|
||||
deleteOptionsByte, err := runtime.Encode(deleteOptionsCodec.LegacyCodec(schema.GroupVersion{Version: "v1"}), opts)
|
||||
func (c *client) DeleteCollection(ctx context.Context, opts metav1.DeleteOptions, listOptions metav1.ListOptions) error {
|
||||
deleteOptionsByte, err := runtime.Encode(deleteOptionsCodec.LegacyCodec(schema.GroupVersion{Version: "v1"}), &opts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -155,19 +149,19 @@ func (c *client) DeleteCollection(opts *metav1.DeleteOptions, listOptions metav1
|
||||
AbsPath(c.makeURLSegments("")...).
|
||||
Body(deleteOptionsByte).
|
||||
SpecificallyVersionedParams(&listOptions, dynamicParameterCodec, versionV1).
|
||||
Do(context.TODO())
|
||||
Do(ctx)
|
||||
return result.Error()
|
||||
}
|
||||
|
||||
// Get returns the resource with name from the specified scope (namespace or cluster).
|
||||
func (c *client) Get(name string, opts metav1.GetOptions, subresources ...string) (*metav1.PartialObjectMetadata, error) {
|
||||
func (c *client) Get(ctx context.Context, name string, opts metav1.GetOptions, subresources ...string) (*metav1.PartialObjectMetadata, error) {
|
||||
if len(name) == 0 {
|
||||
return nil, fmt.Errorf("name is required")
|
||||
}
|
||||
result := c.client.client.Get().AbsPath(append(c.makeURLSegments(name), subresources...)...).
|
||||
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).
|
||||
Do(context.TODO())
|
||||
Do(ctx)
|
||||
if err := result.Error(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -199,11 +193,11 @@ func (c *client) Get(name string, opts metav1.GetOptions, subresources ...string
|
||||
}
|
||||
|
||||
// List returns all resources within the specified scope (namespace or cluster).
|
||||
func (c *client) List(opts metav1.ListOptions) (*metav1.PartialObjectMetadataList, error) {
|
||||
func (c *client) List(ctx context.Context, opts metav1.ListOptions) (*metav1.PartialObjectMetadataList, error) {
|
||||
result := c.client.client.Get().AbsPath(c.makeURLSegments("")...).
|
||||
SetHeader("Accept", "application/vnd.kubernetes.protobuf;as=PartialObjectMetadataList;g=meta.k8s.io;v=v1,application/json;as=PartialObjectMetadataList;g=meta.k8s.io;v=v1,application/json").
|
||||
SpecificallyVersionedParams(&opts, dynamicParameterCodec, versionV1).
|
||||
Do(context.TODO())
|
||||
Do(ctx)
|
||||
if err := result.Error(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -232,7 +226,7 @@ func (c *client) List(opts metav1.ListOptions) (*metav1.PartialObjectMetadataLis
|
||||
}
|
||||
|
||||
// Watch finds all changes to the resources in the specified scope (namespace or cluster).
|
||||
func (c *client) Watch(opts metav1.ListOptions) (watch.Interface, error) {
|
||||
func (c *client) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) {
|
||||
var timeout time.Duration
|
||||
if opts.TimeoutSeconds != nil {
|
||||
timeout = time.Duration(*opts.TimeoutSeconds) * time.Second
|
||||
@ -243,11 +237,11 @@ func (c *client) Watch(opts metav1.ListOptions) (watch.Interface, error) {
|
||||
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).
|
||||
Watch(context.TODO())
|
||||
Watch(ctx)
|
||||
}
|
||||
|
||||
// Patch modifies the named resource in the specified scope (namespace or cluster).
|
||||
func (c *client) Patch(name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*metav1.PartialObjectMetadata, error) {
|
||||
func (c *client) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*metav1.PartialObjectMetadata, error) {
|
||||
if len(name) == 0 {
|
||||
return nil, fmt.Errorf("name is required")
|
||||
}
|
||||
@ -257,7 +251,7 @@ func (c *client) Patch(name string, pt types.PatchType, data []byte, opts metav1
|
||||
Body(data).
|
||||
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).
|
||||
Do(context.TODO())
|
||||
Do(ctx)
|
||||
if err := result.Error(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ limitations under the License.
|
||||
package metadata
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
@ -72,7 +73,7 @@ func TestClient(t *testing.T) {
|
||||
})
|
||||
},
|
||||
want: func(t *testing.T, client *Client) {
|
||||
obj, err := client.Resource(gvr).Namespace("ns").Get("name", metav1.GetOptions{})
|
||||
obj, err := client.Resource(gvr).Namespace("ns").Get(context.TODO(), "name", metav1.GetOptions{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -120,7 +121,7 @@ func TestClient(t *testing.T) {
|
||||
})
|
||||
},
|
||||
want: func(t *testing.T, client *Client) {
|
||||
objs, err := client.Resource(gvr).Namespace("ns").List(metav1.ListOptions{})
|
||||
objs, err := client.Resource(gvr).Namespace("ns").List(context.TODO(), metav1.ListOptions{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -162,7 +163,7 @@ func TestClient(t *testing.T) {
|
||||
})
|
||||
},
|
||||
want: func(t *testing.T, client *Client) {
|
||||
obj, err := client.Resource(gvr).Namespace("ns").Get("name", metav1.GetOptions{})
|
||||
obj, err := client.Resource(gvr).Namespace("ns").Get(context.TODO(), "name", metav1.GetOptions{})
|
||||
if err == nil || !runtime.IsMissingKind(err) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -191,7 +192,7 @@ func TestClient(t *testing.T) {
|
||||
})
|
||||
},
|
||||
want: func(t *testing.T, client *Client) {
|
||||
obj, err := client.Resource(gvr).Namespace("ns").Get("name", metav1.GetOptions{})
|
||||
obj, err := client.Resource(gvr).Namespace("ns").Get(context.TODO(), "name", metav1.GetOptions{})
|
||||
if err == nil || !runtime.IsMissingVersion(err) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -219,7 +220,7 @@ func TestClient(t *testing.T) {
|
||||
})
|
||||
},
|
||||
want: func(t *testing.T, client *Client) {
|
||||
obj, err := client.Resource(gvr).Namespace("ns").Get("name", metav1.GetOptions{})
|
||||
obj, err := client.Resource(gvr).Namespace("ns").Get(context.TODO(), "name", metav1.GetOptions{})
|
||||
if err == nil || !strings.Contains(err.Error(), "object does not appear to match the ObjectMeta schema") {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ limitations under the License.
|
||||
package metadatainformer
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@ -124,13 +125,13 @@ func NewFilteredMetadataInformer(client metadata.Interface, gvr schema.GroupVers
|
||||
if tweakListOptions != nil {
|
||||
tweakListOptions(&options)
|
||||
}
|
||||
return client.Resource(gvr).Namespace(namespace).List(options)
|
||||
return client.Resource(gvr).Namespace(namespace).List(context.TODO(), options)
|
||||
},
|
||||
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
|
||||
if tweakListOptions != nil {
|
||||
tweakListOptions(&options)
|
||||
}
|
||||
return client.Resource(gvr).Namespace(namespace).Watch(options)
|
||||
return client.Resource(gvr).Namespace(namespace).Watch(context.TODO(), options)
|
||||
},
|
||||
},
|
||||
&metav1.PartialObjectMetadata{},
|
||||
|
@ -103,7 +103,7 @@ func TestMetadataSharedInformerFactory(t *testing.T) {
|
||||
gvr: schema.GroupVersionResource{Group: "extensions", Version: "v1beta1", Resource: "deployments"},
|
||||
existingObj: newPartialObjectMetadata("extensions/v1beta1", "Deployment", "ns-foo", "name-foo"),
|
||||
trigger: func(gvr schema.GroupVersionResource, ns string, fakeClient *fake.FakeMetadataClient, testObject *metav1.PartialObjectMetadata) *metav1.PartialObjectMetadata {
|
||||
err := fakeClient.Resource(gvr).Namespace(ns).Delete(testObject.GetName(), &metav1.DeleteOptions{})
|
||||
err := fakeClient.Resource(gvr).Namespace(ns).Delete(context.TODO(), testObject.GetName(), metav1.DeleteOptions{})
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
@ -547,7 +547,7 @@ func TestMetadataClient(t *testing.T) {
|
||||
})
|
||||
|
||||
client := metadata.NewForConfigOrDie(cfg).Resource(v1.SchemeGroupVersion.WithResource("services"))
|
||||
items, err := client.Namespace(ns).List(metav1.ListOptions{})
|
||||
items, err := client.Namespace(ns).List(context.TODO(), metav1.ListOptions{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -566,7 +566,7 @@ func TestMetadataClient(t *testing.T) {
|
||||
}
|
||||
wrapper.resp = nil
|
||||
|
||||
item, err := client.Namespace(ns).Get("test-1", metav1.GetOptions{})
|
||||
item, err := client.Namespace(ns).Get(context.TODO(), "test-1", metav1.GetOptions{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -577,7 +577,7 @@ func TestMetadataClient(t *testing.T) {
|
||||
t.Fatalf("unexpected response: %#v", wrapper.resp)
|
||||
}
|
||||
|
||||
item, err = client.Namespace(ns).Patch("test-1", types.MergePatchType, []byte(`{"metadata":{"annotations":{"foo":"baz"}}}`), metav1.PatchOptions{})
|
||||
item, err = client.Namespace(ns).Patch(context.TODO(), "test-1", types.MergePatchType, []byte(`{"metadata":{"annotations":{"foo":"baz"}}}`), metav1.PatchOptions{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -585,11 +585,11 @@ func TestMetadataClient(t *testing.T) {
|
||||
t.Fatalf("unexpected object: %#v", item)
|
||||
}
|
||||
|
||||
if err := client.Namespace(ns).Delete("test-1", &metav1.DeleteOptions{Preconditions: &metav1.Preconditions{UID: &item.UID}}); err != nil {
|
||||
if err := client.Namespace(ns).Delete(context.TODO(), "test-1", metav1.DeleteOptions{Preconditions: &metav1.Preconditions{UID: &item.UID}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if _, err := client.Namespace(ns).Get("test-1", metav1.GetOptions{}); !apierrors.IsNotFound(err) {
|
||||
if _, err := client.Namespace(ns).Get(context.TODO(), "test-1", metav1.GetOptions{}); !apierrors.IsNotFound(err) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
},
|
||||
@ -624,7 +624,7 @@ func TestMetadataClient(t *testing.T) {
|
||||
})
|
||||
|
||||
client := metadata.NewForConfigOrDie(cfg).Resource(crdGVR)
|
||||
items, err := client.Namespace(ns).List(metav1.ListOptions{})
|
||||
items, err := client.Namespace(ns).List(context.TODO(), metav1.ListOptions{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -643,7 +643,7 @@ func TestMetadataClient(t *testing.T) {
|
||||
}
|
||||
wrapper.resp = nil
|
||||
|
||||
item, err := client.Namespace(ns).Get("test-1", metav1.GetOptions{})
|
||||
item, err := client.Namespace(ns).Get(context.TODO(), "test-1", metav1.GetOptions{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -654,7 +654,7 @@ func TestMetadataClient(t *testing.T) {
|
||||
t.Fatalf("unexpected response: %#v", wrapper.resp)
|
||||
}
|
||||
|
||||
item, err = client.Namespace(ns).Patch("test-1", types.MergePatchType, []byte(`{"metadata":{"annotations":{"foo":"baz"}}}`), metav1.PatchOptions{})
|
||||
item, err = client.Namespace(ns).Patch(context.TODO(), "test-1", types.MergePatchType, []byte(`{"metadata":{"annotations":{"foo":"baz"}}}`), metav1.PatchOptions{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -662,10 +662,10 @@ func TestMetadataClient(t *testing.T) {
|
||||
t.Fatalf("unexpected object: %#v", item)
|
||||
}
|
||||
|
||||
if err := client.Namespace(ns).Delete("test-1", &metav1.DeleteOptions{Preconditions: &metav1.Preconditions{UID: &item.UID}}); err != nil {
|
||||
if err := client.Namespace(ns).Delete(context.TODO(), "test-1", metav1.DeleteOptions{Preconditions: &metav1.Preconditions{UID: &item.UID}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := client.Namespace(ns).Get("test-1", metav1.GetOptions{}); !apierrors.IsNotFound(err) {
|
||||
if _, err := client.Namespace(ns).Get(context.TODO(), "test-1", metav1.GetOptions{}); !apierrors.IsNotFound(err) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
},
|
||||
@ -690,7 +690,7 @@ func TestMetadataClient(t *testing.T) {
|
||||
})
|
||||
|
||||
client := metadata.NewForConfigOrDie(cfg).Resource(v1.SchemeGroupVersion.WithResource("services"))
|
||||
w, err := client.Namespace(ns).Watch(metav1.ListOptions{ResourceVersion: svc.ResourceVersion, Watch: true})
|
||||
w, err := client.Namespace(ns).Watch(context.TODO(), metav1.ListOptions{ResourceVersion: svc.ResourceVersion, Watch: true})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -747,7 +747,7 @@ func TestMetadataClient(t *testing.T) {
|
||||
cfg := metadata.ConfigFor(config)
|
||||
client := metadata.NewForConfigOrDie(cfg).Resource(crdGVR)
|
||||
|
||||
patched, err := client.Namespace(ns).Patch("test-2", types.MergePatchType, []byte(`{"metadata":{"annotations":{"test":"1"}}}`), metav1.PatchOptions{})
|
||||
patched, err := client.Namespace(ns).Patch(context.TODO(), "test-2", types.MergePatchType, []byte(`{"metadata":{"annotations":{"test":"1"}}}`), metav1.PatchOptions{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -762,7 +762,7 @@ func TestMetadataClient(t *testing.T) {
|
||||
})
|
||||
client = metadata.NewForConfigOrDie(cfg).Resource(crdGVR)
|
||||
|
||||
w, err := client.Namespace(ns).Watch(metav1.ListOptions{ResourceVersion: cr.GetResourceVersion(), Watch: true})
|
||||
w, err := client.Namespace(ns).Watch(context.TODO(), metav1.ListOptions{ResourceVersion: cr.GetResourceVersion(), Watch: true})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user