This commit is contained in:
Mike Danese
2020-01-27 18:19:44 -08:00
parent 59e757afef
commit d55d6175f8
105 changed files with 415 additions and 325 deletions

View File

@@ -17,6 +17,7 @@ limitations under the License.
package testing
import (
"context"
"fmt"
"io/ioutil"
"net"
@@ -133,7 +134,7 @@ func StartTestServer(t Logger, customFlags []string) (result TestServer, err err
default:
}
result := client.CoreV1().RESTClient().Get().AbsPath("/healthz").Do()
result := client.CoreV1().RESTClient().Get().AbsPath("/healthz").Do(context.TODO())
status := 0
result.StatusCode(&status)
if status == 200 {

View File

@@ -17,6 +17,7 @@ limitations under the License.
package app
import (
"context"
"fmt"
"net/http"
"time"
@@ -33,7 +34,7 @@ func WaitForAPIServer(client clientset.Interface, timeout time.Duration) error {
err := wait.PollImmediate(time.Second, timeout, func() (bool, error) {
healthStatus := 0
result := client.Discovery().RESTClient().Get().AbsPath("/healthz").Do().StatusCode(&healthStatus)
result := client.Discovery().RESTClient().Get().AbsPath("/healthz").Do(context.TODO()).StatusCode(&healthStatus)
if result.Error() != nil {
lastErr = fmt.Errorf("failed to get apiserver /healthz status: %v", result.Error())
return false, nil

View File

@@ -17,6 +17,7 @@ limitations under the License.
package testing
import (
"context"
"fmt"
"io/ioutil"
"net"
@@ -210,7 +211,7 @@ func StartTestServer(t Logger, instanceOptions *TestServerInstanceOptions, custo
default:
}
result := client.CoreV1().RESTClient().Get().AbsPath("/healthz").Do()
result := client.CoreV1().RESTClient().Get().AbsPath("/healthz").Do(context.TODO())
status := 0
result.StatusCode(&status)
if status == 200 {

View File

@@ -17,6 +17,7 @@ limitations under the License.
package testing
import (
"context"
"fmt"
"io/ioutil"
"net"
@@ -133,7 +134,7 @@ func StartTestServer(t Logger, customFlags []string) (result TestServer, err err
default:
}
result := client.CoreV1().RESTClient().Get().AbsPath("/healthz").Do()
result := client.CoreV1().RESTClient().Get().AbsPath("/healthz").Do(context.TODO())
status := 0
result.StatusCode(&status)
if status == 200 {

View File

@@ -17,6 +17,7 @@ limitations under the License.
package options
import (
"context"
"fmt"
"io/ioutil"
"net/http"
@@ -640,7 +641,7 @@ pluginConfig:
// test the client talks to the endpoint we expect with the credentials we expect
username = ""
_, err = config.Client.Discovery().RESTClient().Get().AbsPath("/").DoRaw()
_, err = config.Client.Discovery().RESTClient().Get().AbsPath("/").DoRaw(context.TODO())
if err != nil {
t.Error(err)
return

View File

@@ -135,7 +135,7 @@ func StartTestServer(t Logger, customFlags []string) (result TestServer, err err
default:
}
result := client.CoreV1().RESTClient().Get().AbsPath("/healthz").Do()
result := client.CoreV1().RESTClient().Get().AbsPath("/healthz").Do(context.TODO())
status := 0
result.StatusCode(&status)
if status == 200 {

View File

@@ -17,6 +17,7 @@ limitations under the License.
package apiclient
import (
"context"
"fmt"
"io"
"net/http"
@@ -77,7 +78,7 @@ func (w *KubeWaiter) WaitForAPI() error {
start := time.Now()
return wait.PollImmediate(kubeadmconstants.APICallRetryInterval, w.timeout, func() (bool, error) {
healthStatus := 0
w.client.Discovery().RESTClient().Get().AbsPath("/healthz").Do().StatusCode(&healthStatus)
w.client.Discovery().RESTClient().Get().AbsPath("/healthz").Do(context.TODO()).StatusCode(&healthStatus)
if healthStatus != http.StatusOK {
return false, nil
}

View File

@@ -22,7 +22,7 @@ import (
"time"
v1authenticationapi "k8s.io/api/authentication/v1"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
@@ -207,7 +207,7 @@ func (b SAControllerClientBuilder) getAuthenticatedConfig(sa *v1.ServiceAccount,
if err != nil {
return nil, false, err
}
err = client.Get().AbsPath("/apis").Do().Error()
err = client.Get().AbsPath("/apis").Do(context.TODO()).Error()
if apierrors.IsUnauthorized(err) {
klog.Warningf("Token for %s/%s did not authenticate correctly: %v", sa.Namespace, sa.Name, err)
return nil, false, nil

View File

@@ -291,7 +291,7 @@ func waitForServer(cfg restclient.Config, deadline time.Duration) error {
var connected bool
wait.JitterUntil(func() {
if _, err := cli.Get().AbsPath("/healthz").Do().Raw(); err != nil {
if _, err := cli.Get().AbsPath("/healthz").Do(context.TODO()).Raw(); err != nil {
klog.Infof("Failed to connect to apiserver: %v", err)
return
}

View File

@@ -17,6 +17,7 @@ limitations under the License.
package certificate
import (
"context"
"crypto/tls"
"crypto/x509"
"fmt"
@@ -198,7 +199,7 @@ func TestRotateShutsDownConnections(t *testing.T) {
t.Fatal(err)
}
if err := client.Get().Do().Error(); err != nil {
if err := client.Get().Do(context.TODO()).Error(); err != nil {
t.Fatal(err)
}
firstCertSerial := lastSerialNumber()
@@ -209,7 +210,7 @@ func TestRotateShutsDownConnections(t *testing.T) {
for i := 0; i < 5; i++ {
time.Sleep(time.Millisecond * 10)
client.Get().Do()
client.Get().Do(context.TODO())
if firstCertSerial.Cmp(lastSerialNumber()) != 0 {
// The certificate changed!
return

View File

@@ -17,6 +17,7 @@ limitations under the License.
package master
import (
"context"
"fmt"
"net"
"net/http"
@@ -210,7 +211,7 @@ func (c *Controller) RunKubernetesService(ch chan struct{}) {
// wait until process is ready
wait.PollImmediateUntil(100*time.Millisecond, func() (bool, error) {
var code int
c.healthClient.Get().AbsPath("/healthz").Do().StatusCode(&code)
c.healthClient.Get().AbsPath("/healthz").Do(context.TODO()).StatusCode(&code)
return code == http.StatusOK, nil
}, ch)

View File

@@ -174,7 +174,7 @@ func (a *Plugin) admitPod(ctx context.Context, pod *api.Pod, attributes admissio
review.Status = entry.(v1alpha1.ImageReviewStatus)
} else {
result := a.webhook.WithExponentialBackoff(ctx, func() rest.Result {
return a.webhook.RestClient.Post().Context(ctx).Body(review).Do()
return a.webhook.RestClient.Post().Context(ctx).Body(review).Do(context.TODO())
})
if err := result.Error(); err != nil {

View File

@@ -271,7 +271,7 @@ func (c *webhookConverter) Convert(in runtime.Object, toGV schema.GroupVersion)
// TODO: Figure out if adding one second timeout make sense here.
ctx := context.TODO()
r := c.restClient.Post().Context(ctx).Body(request).Do()
r := c.restClient.Post().Context(ctx).Body(request).Do(context.TODO())
if err := r.Into(response); err != nil {
// TODO: Return a webhook specific error to be able to convert it to meta.Status
return nil, fmt.Errorf("conversion webhook for %v failed: %v", in.GetObjectKind().GroupVersionKind(), err)

View File

@@ -17,6 +17,7 @@ limitations under the License.
package testing
import (
"context"
"fmt"
"io/ioutil"
"net"
@@ -170,7 +171,7 @@ func StartTestServer(t Logger, instanceOptions *TestServerInstanceOptions, custo
default:
}
result := client.CoreV1().RESTClient().Get().AbsPath("/healthz").Do()
result := client.CoreV1().RESTClient().Get().AbsPath("/healthz").Do(context.TODO())
status := 0
result.StatusCode(&status)
if status == 200 {

View File

@@ -17,6 +17,7 @@ limitations under the License.
package integration
import (
"context"
"fmt"
"testing"
@@ -73,7 +74,7 @@ values:
Name("mytest").
Param("fieldManager", "apply_test").
Body(yamlBody).
DoRaw()
DoRaw(context.TODO())
if err != nil {
t.Fatal(err, string(result))
}
@@ -82,7 +83,7 @@ values:
AbsPath("/apis", noxuDefinition.Spec.Group, noxuDefinition.Spec.Version, noxuDefinition.Spec.Names.Plural).
Name("mytest").
Body([]byte(`{"values":{"numVal": 5}}`)).
DoRaw()
DoRaw(context.TODO())
if err != nil {
t.Fatal(err, string(result))
}
@@ -93,7 +94,7 @@ values:
Name("mytest").
Param("fieldManager", "apply_test").
Body(yamlBody).
DoRaw()
DoRaw(context.TODO())
if err == nil {
t.Fatalf("Expecting to get conflicts when applying object, got no error: %s", result)
}
@@ -112,7 +113,7 @@ values:
Param("force", "true").
Param("fieldManager", "apply_test").
Body(yamlBody).
DoRaw()
DoRaw(context.TODO())
if err != nil {
t.Fatal(err, string(result))
}

View File

@@ -17,6 +17,7 @@ limitations under the License.
package integration
import (
"context"
"fmt"
"reflect"
"sort"
@@ -1010,7 +1011,7 @@ func TestStatusGetAndPatch(t *testing.T) {
Resource("customresourcedefinitions").
Name(noxuDefinition.Name).
SubResource("status").
Do().
Do(context.TODO()).
Into(result)
if err != nil {
t.Fatal(err)

View File

@@ -17,6 +17,7 @@ limitations under the License.
package integration
import (
"context"
"fmt"
"strings"
"testing"
@@ -71,7 +72,7 @@ values: `+strings.Repeat("[", 3*1024*1024), apiVersion, kind))
SetHeader("Content-Type", "application/yaml").
AbsPath("/apis", noxuDefinition.Spec.Group, noxuDefinition.Spec.Version, noxuDefinition.Spec.Names.Plural).
Body(yamlBody).
DoRaw()
DoRaw(context.TODO())
if !apierrors.IsRequestEntityTooLargeError(err) {
t.Errorf("expected too large error, got %v", err)
}
@@ -91,7 +92,7 @@ values: `+strings.Repeat("[", 3*1024*1024), apiVersion, kind))
SetHeader("Content-Type", "application/yaml").
AbsPath("/apis", noxuDefinition.Spec.Group, noxuDefinition.Spec.Version, noxuDefinition.Spec.Names.Plural).
Body(yamlBody).
DoRaw()
DoRaw(context.TODO())
if !apierrors.IsBadRequest(err) {
t.Errorf("expected bad request, got %v", err)
}
@@ -111,7 +112,7 @@ values: `+strings.Repeat("[", 3*1024*1024), apiVersion, kind))
SetHeader("Content-Type", "application/yaml").
AbsPath("/apis", noxuDefinition.Spec.Group, noxuDefinition.Spec.Version, noxuDefinition.Spec.Names.Plural).
Body(yamlBody).
DoRaw()
DoRaw(context.TODO())
if !apierrors.IsBadRequest(err) {
t.Errorf("expected bad request, got %v", err)
}
@@ -132,7 +133,7 @@ values: `+strings.Repeat("[", 3*1024*1024), apiVersion, kind))
SetHeader("Content-Type", "application/json").
AbsPath("/apis", noxuDefinition.Spec.Group, noxuDefinition.Spec.Version, noxuDefinition.Spec.Names.Plural).
Body(jsonBody).
DoRaw()
DoRaw(context.TODO())
if !apierrors.IsRequestEntityTooLargeError(err) {
t.Errorf("expected too large error, got %v", err)
}
@@ -153,7 +154,7 @@ values: `+strings.Repeat("[", 3*1024*1024), apiVersion, kind))
SetHeader("Content-Type", "application/json").
AbsPath("/apis", noxuDefinition.Spec.Group, noxuDefinition.Spec.Version, noxuDefinition.Spec.Names.Plural).
Body(jsonBody).
DoRaw()
DoRaw(context.TODO())
if !apierrors.IsBadRequest(err) {
t.Errorf("expected bad request, got %v", err)
}
@@ -174,7 +175,7 @@ values: `+strings.Repeat("[", 3*1024*1024), apiVersion, kind))
SetHeader("Content-Type", "application/json").
AbsPath("/apis", noxuDefinition.Spec.Group, noxuDefinition.Spec.Version, noxuDefinition.Spec.Names.Plural).
Body(jsonBody).
DoRaw()
DoRaw(context.TODO())
if !apierrors.IsBadRequest(err) {
t.Errorf("expected bad request, got %v", err)
}
@@ -183,7 +184,7 @@ values: `+strings.Repeat("[", 3*1024*1024), apiVersion, kind))
// Create instance to allow patching
{
jsonBody := []byte(fmt.Sprintf(`{"apiVersion": %q, "kind": %q, "metadata": {"name": "test"}}`, apiVersion, kind))
_, err := rest.Post().AbsPath("/apis", noxuDefinition.Spec.Group, noxuDefinition.Spec.Version, noxuDefinition.Spec.Names.Plural).Body(jsonBody).DoRaw()
_, err := rest.Post().AbsPath("/apis", noxuDefinition.Spec.Group, noxuDefinition.Spec.Version, noxuDefinition.Spec.Names.Plural).Body(jsonBody).DoRaw(context.TODO())
if err != nil {
t.Fatalf("error creating object: %v", err)
}
@@ -192,7 +193,7 @@ values: `+strings.Repeat("[", 3*1024*1024), apiVersion, kind))
t.Run("JSONPatchType nested patch under limit", func(t *testing.T) {
patchBody := []byte(`[{"op":"add","path":"/foo","value":` + strings.Repeat("[", 3*1024*1024/2-100) + strings.Repeat("]", 3*1024*1024/2-100) + `}]`)
err = rest.Patch(types.JSONPatchType).AbsPath("/apis", noxuDefinition.Spec.Group, noxuDefinition.Spec.Version, noxuDefinition.Spec.Names.Plural, "test").
Body(patchBody).Do().Error()
Body(patchBody).Do(context.TODO()).Error()
if !apierrors.IsBadRequest(err) {
t.Errorf("expected success or bad request err, got %v", err)
}
@@ -200,7 +201,7 @@ values: `+strings.Repeat("[", 3*1024*1024), apiVersion, kind))
t.Run("MergePatchType nested patch under limit", func(t *testing.T) {
patchBody := []byte(`{"value":` + strings.Repeat("[", 3*1024*1024/2-100) + strings.Repeat("]", 3*1024*1024/2-100) + `}`)
err = rest.Patch(types.MergePatchType).AbsPath("/apis", noxuDefinition.Spec.Group, noxuDefinition.Spec.Version, noxuDefinition.Spec.Names.Plural, "test").
Body(patchBody).Do().Error()
Body(patchBody).Do(context.TODO()).Error()
if !apierrors.IsBadRequest(err) {
t.Errorf("expected success or bad request err, got %v", err)
}
@@ -208,7 +209,7 @@ values: `+strings.Repeat("[", 3*1024*1024), apiVersion, kind))
t.Run("ApplyPatchType nested patch under limit", func(t *testing.T) {
patchBody := []byte(`{"value":` + strings.Repeat("[", 3*1024*1024/2-100) + strings.Repeat("]", 3*1024*1024/2-100) + `}`)
err = rest.Patch(types.ApplyPatchType).Param("fieldManager", "test").AbsPath("/apis", noxuDefinition.Spec.Group, noxuDefinition.Spec.Version, noxuDefinition.Spec.Names.Plural, "test").
Body(patchBody).Do().Error()
Body(patchBody).Do(context.TODO()).Error()
if !apierrors.IsBadRequest(err) {
t.Errorf("expected bad request err, got %#v", err)
}

View File

@@ -17,6 +17,7 @@ limitations under the License.
package integration
import (
"context"
"fmt"
"testing"
"time"
@@ -164,7 +165,7 @@ func TestTableGet(t *testing.T) {
Resource(crd.Spec.Names.Plural).
SetHeader("Accept", fmt.Sprintf("application/json;as=Table;v=%s;g=%s, application/json", metav1beta1.SchemeGroupVersion.Version, metav1beta1.GroupName)).
VersionedParams(&metav1beta1.TableOptions{}, parameterCodec).
Do().
Do(context.TODO()).
Get()
if err != nil {
t.Fatalf("failed to list %v resources: %v", gvk, err)
@@ -262,7 +263,7 @@ func TestTableGet(t *testing.T) {
Resource(crd.Spec.Names.Plural).
SetHeader("Accept", fmt.Sprintf("application/json;as=Table;v=%s;g=%s, application/json", metav1.SchemeGroupVersion.Version, metav1.GroupName)).
VersionedParams(&metav1.TableOptions{}, parameterCodec).
Do().
Do(context.TODO()).
Get()
if err != nil {
t.Fatalf("failed to list %v resources: %v", gvk, err)

View File

@@ -17,6 +17,7 @@ limitations under the License.
package integration
import (
"context"
"encoding/json"
"fmt"
"net/http"
@@ -67,7 +68,7 @@ func TestYAML(t *testing.T) {
result, err := rest.Get().
SetHeader("Accept", "application/yaml").
AbsPath("/apis", noxuDefinition.Spec.Group, noxuDefinition.Spec.Version).
DoRaw()
DoRaw(context.TODO())
if err != nil {
t.Fatal(err, string(result))
}
@@ -88,7 +89,7 @@ func TestYAML(t *testing.T) {
result, err := rest.Get().
SetHeader("Accept", "application/yaml").
AbsPath("/apis", noxuDefinition.Spec.Group, noxuDefinition.Spec.Version, noxuDefinition.Spec.Names.Plural, "missingname").
DoRaw()
DoRaw(context.TODO())
if !errors.IsNotFound(err) {
t.Fatalf("expected not found, got %v", err)
}
@@ -124,7 +125,7 @@ values:
SetHeader("Content-Type", "application/yaml").
AbsPath("/apis", noxuDefinition.Spec.Group, noxuDefinition.Spec.Version, noxuDefinition.Spec.Names.Plural).
Body(yamlBody).
DoRaw()
DoRaw(context.TODO())
if err != nil {
t.Fatal(err, string(result))
}
@@ -159,7 +160,7 @@ values:
result, err := rest.Get().
SetHeader("Accept", "application/yaml").
AbsPath("/apis", noxuDefinition.Spec.Group, noxuDefinition.Spec.Version, noxuDefinition.Spec.Names.Plural, "mytest").
DoRaw()
DoRaw(context.TODO())
if err != nil {
t.Fatal(err)
}
@@ -192,7 +193,7 @@ values:
result, err := rest.Get().
SetHeader("Accept", "application/yaml").
AbsPath("/apis", noxuDefinition.Spec.Group, noxuDefinition.Spec.Version, noxuDefinition.Spec.Names.Plural).
DoRaw()
DoRaw(context.TODO())
if err != nil {
t.Fatal(err, string(result))
}
@@ -237,7 +238,7 @@ values:
SetHeader("Accept", "application/yaml").
AbsPath("/apis", noxuDefinition.Spec.Group, noxuDefinition.Spec.Version, noxuDefinition.Spec.Names.Plural).
Param("watch", "true").
DoRaw()
DoRaw(context.TODO())
if !errors.IsNotAcceptable(err) {
t.Fatalf("expected not acceptable error, got %v (%s)", err, string(result))
}
@@ -274,7 +275,7 @@ values:
SetHeader("Content-Type", "application/yaml").
AbsPath("/apis", noxuDefinition.Spec.Group, noxuDefinition.Spec.Version, noxuDefinition.Spec.Names.Plural, "mytest").
Body(yamlBody).
DoRaw()
DoRaw(context.TODO())
if err != nil {
t.Fatal(err, string(result))
}
@@ -315,7 +316,7 @@ values:
SetHeader("Content-Type", "application/yaml").
AbsPath("/apis", noxuDefinition.Spec.Group, noxuDefinition.Spec.Version, noxuDefinition.Spec.Names.Plural, "mytest").
Body(yamlBody).
DoRaw()
DoRaw(context.TODO())
if !errors.IsUnsupportedMediaType(err) {
t.Fatalf("Expected bad request, got %v\n%s", err, string(result))
}
@@ -336,7 +337,7 @@ values:
result, err := rest.Delete().
SetHeader("Accept", "application/yaml").
AbsPath("/apis", noxuDefinition.Spec.Group, noxuDefinition.Spec.Version, noxuDefinition.Spec.Names.Plural, "mytest").
DoRaw()
DoRaw(context.TODO())
if err != nil {
t.Fatal(err, string(result))
}
@@ -398,7 +399,7 @@ spec:
SetHeader("Content-Type", "application/yaml").
AbsPath("/apis", noxuDefinition.Spec.Group, noxuDefinition.Spec.Version, noxuDefinition.Spec.Names.Plural).
Body(yamlBody).
DoRaw()
DoRaw(context.TODO())
if err != nil {
t.Fatal(err, string(result))
}
@@ -427,7 +428,7 @@ spec:
result, err := rest.Get().
SetHeader("Accept", "application/yaml").
AbsPath("/apis", noxuDefinition.Spec.Group, noxuDefinition.Spec.Version, noxuDefinition.Spec.Names.Plural, "mytest", "status").
DoRaw()
DoRaw(context.TODO())
if err != nil {
t.Fatal(err)
}
@@ -467,7 +468,7 @@ status:
SetHeader("Content-Type", "application/yaml").
AbsPath("/apis", noxuDefinition.Spec.Group, noxuDefinition.Spec.Version, noxuDefinition.Spec.Names.Plural, "mytest", "status").
Body(yamlBody).
DoRaw()
DoRaw(context.TODO())
if err != nil {
t.Fatal(err, string(result))
}
@@ -500,7 +501,7 @@ status:
result, err := rest.Get().
SetHeader("Accept", "application/yaml").
AbsPath("/apis", noxuDefinition.Spec.Group, noxuDefinition.Spec.Version, noxuDefinition.Spec.Names.Plural, "mytest", "scale").
DoRaw()
DoRaw(context.TODO())
if err != nil {
t.Fatal(err)
}

View File

@@ -24,6 +24,7 @@ import (
"time"
jsonpatch "github.com/evanphx/json-patch"
apiequality "k8s.io/apimachinery/pkg/api/equality"
"k8s.io/klog"
@@ -250,7 +251,7 @@ func (a *mutatingDispatcher) callAttrMutatingHook(ctx context.Context, h *admiss
}
}
if err := r.Do().Into(response); err != nil {
if err := r.Do(context.TODO()).Into(response); err != nil {
return false, &webhookutil.ErrCallingWebhook{WebhookName: h.Name, Reason: err}
}
trace.Step("Request completed")

View File

@@ -22,7 +22,7 @@ import (
"sync"
"time"
"k8s.io/api/admissionregistration/v1"
v1 "k8s.io/api/admissionregistration/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime/schema"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
@@ -211,7 +211,7 @@ func (d *validatingDispatcher) callHook(ctx context.Context, h *v1.ValidatingWeb
}
}
if err := r.Do().Into(response); err != nil {
if err := r.Do(context.TODO()).Into(response); err != nil {
return &webhookutil.ErrCallingWebhook{WebhookName: h.Name, Reason: err}
}
trace.Step("Request completed")

View File

@@ -37,7 +37,7 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd/api/v1"
v1 "k8s.io/client-go/tools/clientcmd/api/v1"
)
const (
@@ -397,7 +397,7 @@ func TestTLSConfig(t *testing.T) {
wh, err := NewGenericWebhook(runtime.NewScheme(), scheme.Codecs, configFile, groupVersions, retryBackoff)
if err == nil {
err = wh.RestClient.Get().Do().Error()
err = wh.RestClient.Get().Do(context.TODO()).Error()
}
if err == nil {
@@ -466,7 +466,7 @@ func TestRequestTimeout(t *testing.T) {
resultCh := make(chan rest.Result)
go func() { resultCh <- wh.RestClient.Get().Do() }()
go func() { resultCh <- wh.RestClient.Get().Do(context.TODO()) }()
select {
case <-time.After(time.Second * 5):
t.Errorf("expected request to timeout after %s", requestTimeout)
@@ -552,7 +552,7 @@ func TestWithExponentialBackoff(t *testing.T) {
}
result := wh.WithExponentialBackoff(context.Background(), func() rest.Result {
return wh.RestClient.Get().Do()
return wh.RestClient.Get().Do(context.TODO())
})
var statusCode int
@@ -564,7 +564,7 @@ func TestWithExponentialBackoff(t *testing.T) {
}
result = wh.WithExponentialBackoff(context.Background(), func() rest.Result {
return wh.RestClient.Get().Do()
return wh.RestClient.Get().Do(context.TODO())
})
result.StatusCode(&statusCode)

View File

@@ -124,7 +124,7 @@ func (b *backend) processEvents(ev ...*auditinternal.Event) error {
// allow enough time for the serialization/deserialization of audit events, which
// contain nested request and response objects plus additional event fields.
defer trace.LogIfLong(time.Duration(50+25*len(list.Items)) * time.Millisecond)
return b.w.RestClient.Post().Body(&list).Do()
return b.w.RestClient.Post().Body(&list).Do(context.TODO())
}).Error()
}

View File

@@ -198,7 +198,7 @@ type tokenReviewV1Client struct {
func (t *tokenReviewV1Client) CreateContext(ctx context.Context, review *authenticationv1.TokenReview) (*authenticationv1.TokenReview, error) {
result := &authenticationv1.TokenReview{}
err := t.w.RestClient.Post().Context(ctx).Body(review).Do().Into(result)
err := t.w.RestClient.Post().Context(ctx).Body(review).Do(context.TODO()).Into(result)
return result, err
}
@@ -209,7 +209,7 @@ type tokenReviewV1beta1Client struct {
func (t *tokenReviewV1beta1Client) CreateContext(ctx context.Context, review *authenticationv1.TokenReview) (*authenticationv1.TokenReview, error) {
v1beta1Review := &authenticationv1beta1.TokenReview{Spec: v1SpecToV1beta1Spec(&review.Spec)}
v1beta1Result := &authenticationv1beta1.TokenReview{}
err := t.w.RestClient.Post().Context(ctx).Body(v1beta1Review).Do().Into(v1beta1Result)
err := t.w.RestClient.Post().Context(ctx).Body(v1beta1Review).Do(context.TODO()).Into(v1beta1Result)
if err != nil {
return nil, err
}

View File

@@ -289,7 +289,7 @@ type subjectAccessReviewV1Client struct {
func (t *subjectAccessReviewV1Client) CreateContext(ctx context.Context, subjectAccessReview *authorizationv1.SubjectAccessReview) (*authorizationv1.SubjectAccessReview, error) {
result := &authorizationv1.SubjectAccessReview{}
err := t.w.RestClient.Post().Context(ctx).Body(subjectAccessReview).Do().Into(result)
err := t.w.RestClient.Post().Context(ctx).Body(subjectAccessReview).Do(context.TODO()).Into(result)
return result, err
}
@@ -300,7 +300,7 @@ type subjectAccessReviewV1beta1Client struct {
func (t *subjectAccessReviewV1beta1Client) CreateContext(ctx context.Context, subjectAccessReview *authorizationv1.SubjectAccessReview) (*authorizationv1.SubjectAccessReview, error) {
v1beta1Review := &authorizationv1beta1.SubjectAccessReview{Spec: v1SpecToV1beta1Spec(&subjectAccessReview.Spec)}
v1beta1Result := &authorizationv1beta1.SubjectAccessReview{}
err := t.w.RestClient.Post().Context(ctx).Body(v1beta1Review).Do().Into(v1beta1Result)
err := t.w.RestClient.Post().Context(ctx).Body(v1beta1Review).Do(context.TODO()).Into(v1beta1Result)
if err == nil {
subjectAccessReview.Status = v1beta1StatusToV1Status(&v1beta1Result.Status)
}

View File

@@ -17,6 +17,7 @@ limitations under the License.
package resource
import (
"context"
"strconv"
"k8s.io/apimachinery/pkg/api/meta"
@@ -72,7 +73,7 @@ func (m *Helper) Get(namespace, name string, export bool) (runtime.Object, error
// TODO: I should be part of GetOptions
req.Param("export", strconv.FormatBool(export))
}
return req.Do().Get()
return req.Do(context.TODO()).Get()
}
func (m *Helper) List(namespace, apiVersion string, export bool, options *metav1.ListOptions) (runtime.Object, error) {
@@ -84,7 +85,7 @@ func (m *Helper) List(namespace, apiVersion string, export bool, options *metav1
// TODO: I should be part of ListOptions
req.Param("export", strconv.FormatBool(export))
}
return req.Do().Get()
return req.Do(context.TODO()).Get()
}
func (m *Helper) Watch(namespace, apiVersion string, options *metav1.ListOptions) (watch.Interface, error) {
@@ -93,7 +94,7 @@ func (m *Helper) Watch(namespace, apiVersion string, options *metav1.ListOptions
NamespaceIfScoped(namespace, m.NamespaceScoped).
Resource(m.Resource).
VersionedParams(options, metav1.ParameterCodec).
Watch()
Watch(context.TODO())
}
func (m *Helper) WatchSingle(namespace, name, resourceVersion string) (watch.Interface, error) {
@@ -105,7 +106,7 @@ func (m *Helper) WatchSingle(namespace, name, resourceVersion string) (watch.Int
Watch: true,
FieldSelector: fields.OneTermEqualSelector("metadata.name", name).String(),
}, metav1.ParameterCodec).
Watch()
Watch(context.TODO())
}
func (m *Helper) Delete(namespace, name string) (runtime.Object, error) {
@@ -125,7 +126,7 @@ func (m *Helper) DeleteWithOptions(namespace, name string, options *metav1.Delet
Resource(m.Resource).
Name(name).
Body(options).
Do().
Do(context.TODO()).
Get()
}
@@ -163,7 +164,7 @@ func (m *Helper) createResource(c RESTClient, resource, namespace string, obj ru
Resource(resource).
VersionedParams(options, metav1.ParameterCodec).
Body(obj).
Do().
Do(context.TODO()).
Get()
}
func (m *Helper) Patch(namespace, name string, pt types.PatchType, data []byte, options *metav1.PatchOptions) (runtime.Object, error) {
@@ -179,7 +180,7 @@ func (m *Helper) Patch(namespace, name string, pt types.PatchType, data []byte,
Name(name).
VersionedParams(options, metav1.ParameterCodec).
Body(data).
Do().
Do(context.TODO()).
Get()
}
@@ -198,7 +199,7 @@ func (m *Helper) Replace(namespace, name string, overwrite bool, obj runtime.Obj
}
if version == "" && overwrite {
// Retrieve the current version of the object to overwrite the server object
serverObj, err := c.Get().NamespaceIfScoped(namespace, m.NamespaceScoped).Resource(m.Resource).Name(name).Do().Get()
serverObj, err := c.Get().NamespaceIfScoped(namespace, m.NamespaceScoped).Resource(m.Resource).Name(name).Do(context.TODO()).Get()
if err != nil {
// The object does not exist, but we want it to be created
return m.replaceResource(c, m.Resource, namespace, name, obj, options)
@@ -222,6 +223,6 @@ func (m *Helper) replaceResource(c RESTClient, resource, namespace, name string,
Name(name).
VersionedParams(options, metav1.ParameterCodec).
Body(obj).
Do().
Do(context.TODO()).
Get()
}

View File

@@ -18,6 +18,7 @@ package resource
import (
"bytes"
"context"
"fmt"
"io"
"net/http"
@@ -30,6 +31,8 @@ import (
"golang.org/x/text/encoding/unicode"
"golang.org/x/text/transform"
"sigs.k8s.io/kustomize/pkg/fs"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -40,7 +43,6 @@ import (
"k8s.io/apimachinery/pkg/util/yaml"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/cli-runtime/pkg/kustomize"
"sigs.k8s.io/kustomize/pkg/fs"
)
const (
@@ -100,7 +102,7 @@ func (i *Info) Get() (err error) {
obj, err := NewHelper(i.Client, i.Mapping).Get(i.Namespace, i.Name, i.Export)
if err != nil {
if errors.IsNotFound(err) && len(i.Namespace) > 0 && i.Namespace != metav1.NamespaceDefault && i.Namespace != metav1.NamespaceAll {
err2 := i.Client.Get().AbsPath("api", "v1", "namespaces", i.Namespace).Do().Error()
err2 := i.Client.Get().AbsPath("api", "v1", "namespaces", i.Namespace).Do(context.TODO()).Error()
if err2 != nil && errors.IsNotFound(err2) {
return err2
}

View File

@@ -17,6 +17,7 @@ limitations under the License.
package discovery
import (
"context"
"encoding/json"
"fmt"
"net/url"
@@ -155,7 +156,7 @@ func apiVersionsToAPIGroup(apiVersions *metav1.APIVersions) (apiGroup metav1.API
func (d *DiscoveryClient) ServerGroups() (apiGroupList *metav1.APIGroupList, err error) {
// Get the groupVersions exposed at /api
v := &metav1.APIVersions{}
err = d.restClient.Get().AbsPath(d.LegacyPrefix).Do().Into(v)
err = d.restClient.Get().AbsPath(d.LegacyPrefix).Do(context.TODO()).Into(v)
apiGroup := metav1.APIGroup{}
if err == nil && len(v.Versions) != 0 {
apiGroup = apiVersionsToAPIGroup(v)
@@ -166,7 +167,7 @@ func (d *DiscoveryClient) ServerGroups() (apiGroupList *metav1.APIGroupList, err
// Get the groupVersions exposed at /apis
apiGroupList = &metav1.APIGroupList{}
err = d.restClient.Get().AbsPath("/apis").Do().Into(apiGroupList)
err = d.restClient.Get().AbsPath("/apis").Do(context.TODO()).Into(apiGroupList)
if err != nil && !errors.IsNotFound(err) && !errors.IsForbidden(err) {
return nil, err
}
@@ -196,7 +197,7 @@ func (d *DiscoveryClient) ServerResourcesForGroupVersion(groupVersion string) (r
resources = &metav1.APIResourceList{
GroupVersion: groupVersion,
}
err = d.restClient.Get().AbsPath(url.String()).Do().Into(resources)
err = d.restClient.Get().AbsPath(url.String()).Do(context.TODO()).Into(resources)
if err != nil {
// ignore 403 or 404 error to be compatible with an v1.0 server.
if groupVersion == "v1" && (errors.IsNotFound(err) || errors.IsForbidden(err)) {
@@ -405,7 +406,7 @@ func ServerPreferredNamespacedResources(d DiscoveryInterface) ([]*metav1.APIReso
// ServerVersion retrieves and parses the server's version (git version).
func (d *DiscoveryClient) ServerVersion() (*version.Info, error) {
body, err := d.restClient.Get().AbsPath("/version").Do().Raw()
body, err := d.restClient.Get().AbsPath("/version").Do(context.TODO()).Raw()
if err != nil {
return nil, err
}
@@ -419,12 +420,12 @@ func (d *DiscoveryClient) ServerVersion() (*version.Info, error) {
// OpenAPISchema fetches the open api schema using a rest client and parses the proto.
func (d *DiscoveryClient) OpenAPISchema() (*openapi_v2.Document, error) {
data, err := d.restClient.Get().AbsPath("/openapi/v2").SetHeader("Accept", mimePb).Do().Raw()
data, err := d.restClient.Get().AbsPath("/openapi/v2").SetHeader("Accept", mimePb).Do(context.TODO()).Raw()
if err != nil {
if errors.IsForbidden(err) || errors.IsNotFound(err) || errors.IsNotAcceptable(err) {
// single endpoint not found/registered in old server, try to fetch old endpoint
// TODO: remove this when kubectl/client-go don't work with 1.9 server
data, err = d.restClient.Get().AbsPath("/swagger-2.0.0.pb-v1").Do().Raw()
data, err = d.restClient.Get().AbsPath("/swagger-2.0.0.pb-v1").Do(context.TODO()).Raw()
if err != nil {
return nil, err
}

View File

@@ -17,6 +17,7 @@ limitations under the License.
package dynamic
import (
"context"
"fmt"
"k8s.io/apimachinery/pkg/api/meta"
@@ -111,7 +112,7 @@ func (c *dynamicResourceClient) Create(obj *unstructured.Unstructured, opts meta
AbsPath(append(c.makeURLSegments(name), subresources...)...).
Body(outBytes).
SpecificallyVersionedParams(&opts, dynamicParameterCodec, versionV1).
Do()
Do(context.TODO())
if err := result.Error(); err != nil {
return nil, err
}
@@ -146,7 +147,7 @@ func (c *dynamicResourceClient) Update(obj *unstructured.Unstructured, opts meta
AbsPath(append(c.makeURLSegments(name), subresources...)...).
Body(outBytes).
SpecificallyVersionedParams(&opts, dynamicParameterCodec, versionV1).
Do()
Do(context.TODO())
if err := result.Error(); err != nil {
return nil, err
}
@@ -182,7 +183,7 @@ func (c *dynamicResourceClient) UpdateStatus(obj *unstructured.Unstructured, opt
AbsPath(append(c.makeURLSegments(name), "status")...).
Body(outBytes).
SpecificallyVersionedParams(&opts, dynamicParameterCodec, versionV1).
Do()
Do(context.TODO())
if err := result.Error(); err != nil {
return nil, err
}
@@ -214,7 +215,7 @@ func (c *dynamicResourceClient) Delete(name string, opts *metav1.DeleteOptions,
Delete().
AbsPath(append(c.makeURLSegments(name), subresources...)...).
Body(deleteOptionsByte).
Do()
Do(context.TODO())
return result.Error()
}
@@ -232,7 +233,7 @@ func (c *dynamicResourceClient) DeleteCollection(opts *metav1.DeleteOptions, lis
AbsPath(c.makeURLSegments("")...).
Body(deleteOptionsByte).
SpecificallyVersionedParams(&listOptions, dynamicParameterCodec, versionV1).
Do()
Do(context.TODO())
return result.Error()
}
@@ -240,7 +241,7 @@ func (c *dynamicResourceClient) Get(name string, opts metav1.GetOptions, subreso
if len(name) == 0 {
return nil, fmt.Errorf("name is required")
}
result := c.client.client.Get().AbsPath(append(c.makeURLSegments(name), subresources...)...).SpecificallyVersionedParams(&opts, dynamicParameterCodec, versionV1).Do()
result := c.client.client.Get().AbsPath(append(c.makeURLSegments(name), subresources...)...).SpecificallyVersionedParams(&opts, dynamicParameterCodec, versionV1).Do(context.TODO())
if err := result.Error(); err != nil {
return nil, err
}
@@ -256,7 +257,7 @@ func (c *dynamicResourceClient) Get(name string, opts metav1.GetOptions, subreso
}
func (c *dynamicResourceClient) List(opts metav1.ListOptions) (*unstructured.UnstructuredList, error) {
result := c.client.client.Get().AbsPath(c.makeURLSegments("")...).SpecificallyVersionedParams(&opts, dynamicParameterCodec, versionV1).Do()
result := c.client.client.Get().AbsPath(c.makeURLSegments("")...).SpecificallyVersionedParams(&opts, dynamicParameterCodec, versionV1).Do(context.TODO())
if err := result.Error(); err != nil {
return nil, err
}
@@ -283,7 +284,7 @@ func (c *dynamicResourceClient) Watch(opts metav1.ListOptions) (watch.Interface,
opts.Watch = true
return c.client.client.Get().AbsPath(c.makeURLSegments("")...).
SpecificallyVersionedParams(&opts, dynamicParameterCodec, versionV1).
Watch()
Watch(context.TODO())
}
func (c *dynamicResourceClient) Patch(name string, pt types.PatchType, data []byte, opts metav1.PatchOptions, subresources ...string) (*unstructured.Unstructured, error) {
@@ -295,7 +296,7 @@ func (c *dynamicResourceClient) Patch(name string, pt types.PatchType, data []by
AbsPath(append(c.makeURLSegments(name), subresources...)...).
Body(data).
SpecificallyVersionedParams(&opts, dynamicParameterCodec, versionV1).
Do()
Do(context.TODO())
if err := result.Error(); err != nil {
return nil, err
}

View File

@@ -37,7 +37,7 @@ func (c *tokenReviews) CreateContext(ctx context.Context, tokenReview *authentic
Context(ctx).
Resource("tokenreviews").
Body(tokenReview).
Do().
Do(context.TODO()).
Into(result)
return
}

View File

@@ -37,7 +37,7 @@ func (c *tokenReviews) CreateContext(ctx context.Context, tokenReview *authentic
Context(ctx).
Resource("tokenreviews").
Body(tokenReview).
Do().
Do(context.TODO()).
Into(result)
return
}

View File

@@ -38,7 +38,7 @@ func (c *localSubjectAccessReviews) CreateContext(ctx context.Context, sar *auth
Namespace(c.ns).
Resource("localsubjectaccessreviews").
Body(sar).
Do().
Do(context.TODO()).
Into(result)
return
}

View File

@@ -37,7 +37,7 @@ func (c *selfSubjectAccessReviews) CreateContext(ctx context.Context, sar *autho
Context(ctx).
Resource("selfsubjectaccessreviews").
Body(sar).
Do().
Do(context.TODO()).
Into(result)
return
}

View File

@@ -37,7 +37,7 @@ func (c *selfSubjectRulesReviews) CreateContext(ctx context.Context, srr *author
Context(ctx).
Resource("selfsubjectrulesreviews").
Body(srr).
Do().
Do(context.TODO()).
Into(result)
return
}

View File

@@ -38,7 +38,7 @@ func (c *subjectAccessReviews) CreateContext(ctx context.Context, sar *authoriza
Context(ctx).
Resource("subjectaccessreviews").
Body(sar).
Do().
Do(context.TODO()).
Into(result)
return
}

View File

@@ -38,7 +38,7 @@ func (c *localSubjectAccessReviews) CreateContext(ctx context.Context, sar *auth
Namespace(c.ns).
Resource("localsubjectaccessreviews").
Body(sar).
Do().
Do(context.TODO()).
Into(result)
return
}

View File

@@ -37,7 +37,7 @@ func (c *selfSubjectAccessReviews) CreateContext(ctx context.Context, sar *autho
Context(ctx).
Resource("selfsubjectaccessreviews").
Body(sar).
Do().
Do(context.TODO()).
Into(result)
return
}

View File

@@ -37,7 +37,7 @@ func (c *selfSubjectRulesReviews) CreateContext(ctx context.Context, srr *author
Context(ctx).
Resource("selfsubjectrulesreviews").
Body(srr).
Do().
Do(context.TODO()).
Into(result)
return
}

View File

@@ -38,7 +38,7 @@ func (c *subjectAccessReviews) CreateContext(ctx context.Context, sar *authoriza
Context(ctx).
Resource("subjectaccessreviews").
Body(sar).
Do().
Do(context.TODO()).
Into(result)
return
}

View File

@@ -17,6 +17,8 @@ limitations under the License.
package v1beta1
import (
"context"
certificates "k8s.io/api/certificates/v1beta1"
)
@@ -31,7 +33,7 @@ func (c *certificateSigningRequests) UpdateApproval(certificateSigningRequest *c
Name(certificateSigningRequest.Name).
Body(certificateSigningRequest).
SubResource("approval").
Do().
Do(context.TODO()).
Into(result)
return
}

View File

@@ -17,9 +17,10 @@ limitations under the License.
package v1
import (
"context"
"fmt"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/runtime"
@@ -54,7 +55,7 @@ func (e *events) CreateWithEventNamespace(event *v1.Event) (*v1.Event, error) {
NamespaceIfScoped(event.Namespace, len(event.Namespace) > 0).
Resource("events").
Body(event).
Do().
Do(context.TODO()).
Into(result)
return result, err
}
@@ -71,7 +72,7 @@ func (e *events) UpdateWithEventNamespace(event *v1.Event) (*v1.Event, error) {
Resource("events").
Name(event.Name).
Body(event).
Do().
Do(context.TODO()).
Into(result)
return result, err
}
@@ -91,7 +92,7 @@ func (e *events) PatchWithEventNamespace(incompleteEvent *v1.Event, data []byte)
Resource("events").
Name(incompleteEvent.Name).
Body(data).
Do().
Do(context.TODO()).
Into(result)
return result, err
}

View File

@@ -16,7 +16,11 @@ limitations under the License.
package v1
import "k8s.io/api/core/v1"
import (
"context"
v1 "k8s.io/api/core/v1"
)
// The NamespaceExpansion interface allows manually adding extra methods to the NamespaceInterface.
type NamespaceExpansion interface {
@@ -26,6 +30,6 @@ type NamespaceExpansion interface {
// Finalize takes the representation of a namespace to update. Returns the server's representation of the namespace, and an error, if it occurs.
func (c *namespaces) Finalize(namespace *v1.Namespace) (result *v1.Namespace, err error) {
result = &v1.Namespace{}
err = c.client.Put().Resource("namespaces").Name(namespace.Name).SubResource("finalize").Body(namespace).Do().Into(result)
err = c.client.Put().Resource("namespaces").Name(namespace.Name).SubResource("finalize").Body(namespace).Do(context.TODO()).Into(result)
return
}

View File

@@ -17,7 +17,9 @@ limitations under the License.
package v1
import (
"k8s.io/api/core/v1"
"context"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
)
@@ -37,7 +39,7 @@ func (c *nodes) PatchStatus(nodeName string, data []byte) (*v1.Node, error) {
Name(nodeName).
SubResource("status").
Body(data).
Do().
Do(context.TODO()).
Into(result)
return result, err
}

View File

@@ -17,7 +17,9 @@ limitations under the License.
package v1
import (
"k8s.io/api/core/v1"
"context"
v1 "k8s.io/api/core/v1"
policy "k8s.io/api/policy/v1beta1"
"k8s.io/client-go/kubernetes/scheme"
restclient "k8s.io/client-go/rest"
@@ -32,11 +34,11 @@ type PodExpansion interface {
// Bind applies the provided binding to the named pod in the current namespace (binding.Namespace is ignored).
func (c *pods) Bind(binding *v1.Binding) error {
return c.client.Post().Namespace(c.ns).Resource("pods").Name(binding.Name).SubResource("binding").Body(binding).Do().Error()
return c.client.Post().Namespace(c.ns).Resource("pods").Name(binding.Name).SubResource("binding").Body(binding).Do(context.TODO()).Error()
}
func (c *pods) Evict(eviction *policy.Eviction) error {
return c.client.Post().Namespace(c.ns).Resource("pods").Name(eviction.Name).SubResource("eviction").Body(eviction).Do().Error()
return c.client.Post().Namespace(c.ns).Resource("pods").Name(eviction.Name).SubResource("eviction").Body(eviction).Do(context.TODO()).Error()
}
// Get constructs a request for getting the logs for a pod

View File

@@ -17,6 +17,8 @@ limitations under the License.
package v1
import (
"context"
authenticationv1 "k8s.io/api/authentication/v1"
)
@@ -35,7 +37,7 @@ func (c *serviceAccounts) CreateToken(name string, tr *authenticationv1.TokenReq
SubResource("token").
Name(name).
Body(tr).
Do().
Do(context.TODO()).
Into(result)
return result, err
}

View File

@@ -17,6 +17,7 @@ limitations under the License.
package v1beta1
import (
"context"
"fmt"
"k8s.io/api/events/v1beta1"
@@ -51,7 +52,7 @@ func (e *events) CreateWithEventNamespace(event *v1beta1.Event) (*v1beta1.Event,
NamespaceIfScoped(event.Namespace, len(event.Namespace) > 0).
Resource("events").
Body(event).
Do().
Do(context.TODO()).
Into(result)
return result, err
}
@@ -72,7 +73,7 @@ func (e *events) UpdateWithEventNamespace(event *v1beta1.Event) (*v1beta1.Event,
Resource("events").
Name(event.Name).
Body(event).
Do().
Do(context.TODO()).
Into(result)
return result, err
}
@@ -92,7 +93,7 @@ func (e *events) PatchWithEventNamespace(event *v1beta1.Event, data []byte) (*v1
Resource("events").
Name(event.Name).
Body(data).
Do().
Do(context.TODO()).
Into(result)
return result, err
}

View File

@@ -16,7 +16,11 @@ limitations under the License.
package v1beta1
import "k8s.io/api/extensions/v1beta1"
import (
"context"
"k8s.io/api/extensions/v1beta1"
)
// The DeploymentExpansion interface allows manually adding extra methods to the DeploymentInterface.
type DeploymentExpansion interface {
@@ -25,5 +29,5 @@ type DeploymentExpansion interface {
// Rollback applied the provided DeploymentRollback to the named deployment in the current namespace.
func (c *deployments) Rollback(deploymentRollback *v1beta1.DeploymentRollback) error {
return c.client.Post().Namespace(c.ns).Resource("deployments").Name(deploymentRollback.Name).SubResource("rollback").Body(deploymentRollback).Do().Error()
return c.client.Post().Namespace(c.ns).Resource("deployments").Name(deploymentRollback.Name).SubResource("rollback").Body(deploymentRollback).Do(context.TODO()).Error()
}

View File

@@ -17,6 +17,8 @@ limitations under the License.
package v1beta1
import (
"context"
policy "k8s.io/api/policy/v1beta1"
)
@@ -33,6 +35,6 @@ func (c *evictions) Evict(eviction *policy.Eviction) error {
Name(eviction.Name).
SubResource("eviction").
Body(eviction).
Do().
Do(context.TODO()).
Error()
}

View File

@@ -17,6 +17,7 @@ limitations under the License.
package metadata
import (
"context"
"encoding/json"
"fmt"
"time"
@@ -135,7 +136,7 @@ func (c *client) Delete(name string, opts *metav1.DeleteOptions, subresources ..
Delete().
AbsPath(append(c.makeURLSegments(name), subresources...)...).
Body(deleteOptionsByte).
Do()
Do(context.TODO())
return result.Error()
}
@@ -154,7 +155,7 @@ func (c *client) DeleteCollection(opts *metav1.DeleteOptions, listOptions metav1
AbsPath(c.makeURLSegments("")...).
Body(deleteOptionsByte).
SpecificallyVersionedParams(&listOptions, dynamicParameterCodec, versionV1).
Do()
Do(context.TODO())
return result.Error()
}
@@ -166,7 +167,7 @@ func (c *client) Get(name string, opts metav1.GetOptions, subresources ...string
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()
Do(context.TODO())
if err := result.Error(); err != nil {
return nil, err
}
@@ -202,7 +203,7 @@ func (c *client) List(opts metav1.ListOptions) (*metav1.PartialObjectMetadataLis
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()
Do(context.TODO())
if err := result.Error(); err != nil {
return nil, err
}
@@ -242,7 +243,7 @@ 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()
Watch(context.TODO())
}
// Patch modifies the named resource in the specified scope (namespace or cluster).
@@ -256,7 +257,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()
Do(context.TODO())
if err := result.Error(); err != nil {
return nil, err
}

View File

@@ -17,6 +17,7 @@ limitations under the License.
package scale
import (
"context"
"fmt"
autoscaling "k8s.io/api/autoscaling/v1"
@@ -154,7 +155,7 @@ func (c *namespacedScaleClient) Get(resource schema.GroupResource, name string)
Resource(gvr.Resource).
Name(name).
SubResource("scale").
Do()
Do(context.TODO())
if err := result.Error(); err != nil {
return nil, err
}
@@ -196,7 +197,7 @@ func (c *namespacedScaleClient) Update(resource schema.GroupResource, scale *aut
Name(scale.Name).
SubResource("scale").
Body(scaleUpdateBytes).
Do()
Do(context.TODO())
if err := result.Error(); err != nil {
// propagate "raw" error from the API
// this allows callers to interpret underlying Reason field
@@ -216,7 +217,7 @@ func (c *namespacedScaleClient) Patch(gvr schema.GroupVersionResource, name stri
Name(name).
SubResource("scale").
Body(data).
Do()
Do(context.TODO())
if err := result.Error(); err != nil {
return nil, err
}

View File

@@ -17,6 +17,8 @@ limitations under the License.
package cache
import (
"context"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/runtime"
@@ -82,7 +84,7 @@ func NewFilteredListWatchFromClient(c Getter, resource string, namespace string,
Namespace(namespace).
Resource(resource).
VersionedParams(&options, metav1.ParameterCodec).
Do().
Do(context.TODO()).
Get()
}
watchFunc := func(options metav1.ListOptions) (watch.Interface, error) {
@@ -92,7 +94,7 @@ func NewFilteredListWatchFromClient(c Getter, resource string, namespace string,
Namespace(namespace).
Resource(resource).
VersionedParams(&options, metav1.ParameterCodec).
Watch()
Watch(context.TODO())
}
return &ListWatch{ListFunc: listFunc, WatchFunc: watchFunc}
}

View File

@@ -18,6 +18,7 @@ package rawhttp
import (
"bytes"
"context"
"fmt"
"io"
"io/ioutil"
@@ -80,7 +81,7 @@ func raw(restClient *rest.RESTClient, streams genericclioptions.IOStreams, url,
return fmt.Errorf("unknown requestType: %q", requestType)
}
stream, err := request.Stream()
stream, err := request.Stream(context.TODO())
if err != nil {
return err
}

View File

@@ -17,6 +17,7 @@ limitations under the License.
package custom_metrics
import (
"context"
"fmt"
"reflect"
@@ -116,7 +117,7 @@ func (m *rootScopedMetrics) getForNamespace(namespace string, metricName string,
Namespace(namespace).
Name(metricName).
VersionedParams(params, scheme.ParameterCodec).
Do()
Do(context.TODO())
metricObj, err := versionConverter.ConvertResultToVersion(result, v1beta2.SchemeGroupVersion)
if err != nil {
@@ -158,7 +159,7 @@ func (m *rootScopedMetrics) GetForObject(groupKind schema.GroupKind, name string
Name(name).
SubResource(metricName).
VersionedParams(params, scheme.ParameterCodec).
Do()
Do(context.TODO())
metricObj, err := versionConverter.ConvertResultToVersion(result, v1beta2.SchemeGroupVersion)
if err != nil {
@@ -201,7 +202,7 @@ func (m *rootScopedMetrics) GetForObjects(groupKind schema.GroupKind, selector l
Name(v1beta1.AllObjects).
SubResource(metricName).
VersionedParams(params, scheme.ParameterCodec).
Do()
Do(context.TODO())
metricObj, err := versionConverter.ConvertResultToVersion(result, v1beta2.SchemeGroupVersion)
if err != nil {
@@ -240,7 +241,7 @@ func (m *namespacedMetrics) GetForObject(groupKind schema.GroupKind, name string
Name(name).
SubResource(metricName).
VersionedParams(params, scheme.ParameterCodec).
Do()
Do(context.TODO())
metricObj, err := versionConverter.ConvertResultToVersion(result, v1beta2.SchemeGroupVersion)
if err != nil {
@@ -279,7 +280,7 @@ func (m *namespacedMetrics) GetForObjects(groupKind schema.GroupKind, selector l
Name(v1beta1.AllObjects).
SubResource(metricName).
VersionedParams(params, scheme.ParameterCodec).
Do()
Do(context.TODO())
metricObj, err := versionConverter.ConvertResultToVersion(result, v1beta2.SchemeGroupVersion)
if err != nil {

View File

@@ -17,6 +17,7 @@ limitations under the License.
package external_metrics
import (
"context"
"fmt"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -88,7 +89,7 @@ func (m *namespacedMetrics) List(metricName string, metricSelector labels.Select
VersionedParams(&metav1.ListOptions{
LabelSelector: metricSelector.String(),
}, metav1.ParameterCodec).
Do().
Do(context.TODO()).
Into(res)
if err != nil {

View File

@@ -17,6 +17,7 @@ limitations under the License.
package apimachinery
import (
"context"
"crypto/rand"
"encoding/json"
"fmt"
@@ -365,7 +366,7 @@ func TestSampleAPIServer(f *framework.Framework, aggrclient *aggregatorclient.Cl
request := restClient.Get().AbsPath("/apis/wardle.example.com/v1alpha1/namespaces/default/flunders")
request.SetHeader("Accept", "application/json")
_, err := request.DoRaw()
_, err := request.DoRaw(context.TODO())
if err != nil {
status, ok := err.(*apierrors.StatusError)
if !ok {
@@ -405,7 +406,7 @@ func TestSampleAPIServer(f *framework.Framework, aggrclient *aggregatorclient.Cl
// curl -k -v -XPOST https://localhost/apis/wardle.example.com/v1alpha1/namespaces/default/flunders
// Request Body: {"apiVersion":"wardle.example.com/v1alpha1","kind":"Flunder","metadata":{"labels":{"sample-label":"true"},"name":"test-flunder","namespace":"default"}}
flunder := `{"apiVersion":"wardle.example.com/v1alpha1","kind":"Flunder","metadata":{"labels":{"sample-label":"true"},"name":"` + flunderName + `","namespace":"default"}}`
result := restClient.Post().AbsPath("/apis/wardle.example.com/v1alpha1/namespaces/default/flunders").Body([]byte(flunder)).SetHeader("Accept", "application/json").Do()
result := restClient.Post().AbsPath("/apis/wardle.example.com/v1alpha1/namespaces/default/flunders").Body([]byte(flunder)).SetHeader("Accept", "application/json").Do(context.TODO())
framework.ExpectNoError(result.Error(), "creating a new flunders resource")
var statusCode int
result.StatusCode(&statusCode)
@@ -425,7 +426,7 @@ func TestSampleAPIServer(f *framework.Framework, aggrclient *aggregatorclient.Cl
// kubectl get flunders -v 9
// curl -k -v -XGET https://localhost/apis/wardle.example.com/v1alpha1/namespaces/default/flunders
contents, err := restClient.Get().AbsPath("/apis/wardle.example.com/v1alpha1/namespaces/default/flunders").SetHeader("Accept", "application/json").DoRaw()
contents, err := restClient.Get().AbsPath("/apis/wardle.example.com/v1alpha1/namespaces/default/flunders").SetHeader("Accept", "application/json").DoRaw(context.TODO())
framework.ExpectNoError(err, "attempting to get a newly created flunders resource")
var flundersList samplev1alpha1.FlunderList
err = json.Unmarshal(contents, &flundersList)
@@ -436,12 +437,12 @@ func TestSampleAPIServer(f *framework.Framework, aggrclient *aggregatorclient.Cl
// kubectl delete flunder test-flunder -v 9
// curl -k -v -XDELETE https://35.193.112.40/apis/wardle.example.com/v1alpha1/namespaces/default/flunders/test-flunder
_, err = restClient.Delete().AbsPath("/apis/wardle.example.com/v1alpha1/namespaces/default/flunders/" + flunderName).DoRaw()
_, err = restClient.Delete().AbsPath("/apis/wardle.example.com/v1alpha1/namespaces/default/flunders/" + flunderName).DoRaw(context.TODO())
validateErrorWithDebugInfo(f, err, pods, "attempting to delete a newly created flunders(%v) resource", flundersList.Items)
// kubectl get flunders -v 9
// curl -k -v -XGET https://localhost/apis/wardle.example.com/v1alpha1/namespaces/default/flunders
contents, err = restClient.Get().AbsPath("/apis/wardle.example.com/v1alpha1/namespaces/default/flunders").SetHeader("Accept", "application/json").DoRaw()
contents, err = restClient.Get().AbsPath("/apis/wardle.example.com/v1alpha1/namespaces/default/flunders").SetHeader("Accept", "application/json").DoRaw(context.TODO())
framework.ExpectNoError(err, "confirming delete of a newly created flunders resource")
err = json.Unmarshal(contents, &flundersList)
validateErrorWithDebugInfo(f, err, pods, "Error in unmarshalling %T response from server %s", contents, "/apis/wardle.example.com/v1alpha1")

View File

@@ -17,6 +17,7 @@ limitations under the License.
package apimachinery
import (
"context"
"fmt"
"time"
@@ -197,7 +198,7 @@ var _ = SIGDescribe("CustomResourceDefinition resources [Privileged:ClusterAdmin
{
ginkgo.By("fetching the /apis discovery document")
apiGroupList := &metav1.APIGroupList{}
err := f.ClientSet.Discovery().RESTClient().Get().AbsPath("/apis").Do().Into(apiGroupList)
err := f.ClientSet.Discovery().RESTClient().Get().AbsPath("/apis").Do(context.TODO()).Into(apiGroupList)
framework.ExpectNoError(err, "fetching /apis")
ginkgo.By("finding the apiextensions.k8s.io API group in the /apis discovery document")
@@ -224,7 +225,7 @@ var _ = SIGDescribe("CustomResourceDefinition resources [Privileged:ClusterAdmin
{
ginkgo.By("fetching the /apis/apiextensions.k8s.io discovery document")
group := &metav1.APIGroup{}
err := f.ClientSet.Discovery().RESTClient().Get().AbsPath("/apis/apiextensions.k8s.io").Do().Into(group)
err := f.ClientSet.Discovery().RESTClient().Get().AbsPath("/apis/apiextensions.k8s.io").Do(context.TODO()).Into(group)
framework.ExpectNoError(err, "fetching /apis/apiextensions.k8s.io")
framework.ExpectEqual(group.Name, v1.GroupName, "verifying API group name in /apis/apiextensions.k8s.io discovery document")
@@ -242,7 +243,7 @@ var _ = SIGDescribe("CustomResourceDefinition resources [Privileged:ClusterAdmin
{
ginkgo.By("fetching the /apis/apiextensions.k8s.io/v1 discovery document")
apiResourceList := &metav1.APIResourceList{}
err := f.ClientSet.Discovery().RESTClient().Get().AbsPath("/apis/apiextensions.k8s.io/v1").Do().Into(apiResourceList)
err := f.ClientSet.Discovery().RESTClient().Get().AbsPath("/apis/apiextensions.k8s.io/v1").Do(context.TODO()).Into(apiResourceList)
framework.ExpectNoError(err, "fetching /apis/apiextensions.k8s.io/v1")
framework.ExpectEqual(apiResourceList.GroupVersion, v1.SchemeGroupVersion.String(), "verifying API group/version in /apis/apiextensions.k8s.io/v1 discovery document")

View File

@@ -26,7 +26,7 @@ import (
"github.com/onsi/gomega"
authorizationv1 "k8s.io/api/authorization/v1"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
metav1beta1 "k8s.io/apimachinery/pkg/apis/meta/v1beta1"
@@ -59,7 +59,7 @@ var _ = SIGDescribe("Servers with support for Table transformation", func() {
framework.ExpectNoError(err, "failed to create pod %s in namespace: %s", podName, ns)
table := &metav1beta1.Table{}
err = c.CoreV1().RESTClient().Get().Resource("pods").Namespace(ns).Name(podName).SetHeader("Accept", "application/json;as=Table;v=v1beta1;g=meta.k8s.io").Do().Into(table)
err = c.CoreV1().RESTClient().Get().Resource("pods").Namespace(ns).Name(podName).SetHeader("Accept", "application/json;as=Table;v=v1beta1;g=meta.k8s.io").Do(context.TODO()).Into(table)
framework.ExpectNoError(err, "failed to get pod %s in Table form in namespace: %s", podName, ns)
framework.Logf("Table: %#v", table)
@@ -107,7 +107,7 @@ var _ = SIGDescribe("Servers with support for Table transformation", func() {
err := c.CoreV1().RESTClient().Get().Namespace(ns).Resource("podtemplates").
VersionedParams(&metav1.ListOptions{Limit: 2}, metav1.ParameterCodec).
SetHeader("Accept", "application/json;as=Table;v=v1beta1;g=meta.k8s.io").
Do().Into(pagedTable)
Do(context.TODO()).Into(pagedTable)
framework.ExpectNoError(err, "failed to get pod templates in Table form in namespace: %s", ns)
framework.ExpectEqual(len(pagedTable.Rows), 2)
framework.ExpectNotEqual(pagedTable.ResourceVersion, "")
@@ -119,7 +119,7 @@ var _ = SIGDescribe("Servers with support for Table transformation", func() {
err = c.CoreV1().RESTClient().Get().Namespace(ns).Resource("podtemplates").
VersionedParams(&metav1.ListOptions{Continue: pagedTable.Continue}, metav1.ParameterCodec).
SetHeader("Accept", "application/json;as=Table;v=v1beta1;g=meta.k8s.io").
Do().Into(pagedTable)
Do(context.TODO()).Into(pagedTable)
framework.ExpectNoError(err, "failed to get pod templates in Table form in namespace: %s", ns)
gomega.Expect(len(pagedTable.Rows)).To(gomega.BeNumerically(">", 0))
framework.ExpectEqual(pagedTable.Rows[0].Cells[0], "template-0002")
@@ -129,7 +129,7 @@ var _ = SIGDescribe("Servers with support for Table transformation", func() {
c := f.ClientSet
table := &metav1beta1.Table{}
err := c.CoreV1().RESTClient().Get().Resource("nodes").SetHeader("Accept", "application/json;as=Table;v=v1beta1;g=meta.k8s.io").Do().Into(table)
err := c.CoreV1().RESTClient().Get().Resource("nodes").SetHeader("Accept", "application/json;as=Table;v=v1beta1;g=meta.k8s.io").Do(context.TODO()).Into(table)
framework.ExpectNoError(err, "failed to get nodes in Table form across all namespaces")
framework.Logf("Table: %#v", table)
@@ -163,7 +163,7 @@ var _ = SIGDescribe("Servers with support for Table transformation", func() {
},
},
}
err := c.AuthorizationV1().RESTClient().Post().Resource("selfsubjectaccessreviews").SetHeader("Accept", "application/json;as=Table;v=v1;g=meta.k8s.io").Body(sar).Do().Into(table)
err := c.AuthorizationV1().RESTClient().Post().Resource("selfsubjectaccessreviews").SetHeader("Accept", "application/json;as=Table;v=v1;g=meta.k8s.io").Body(sar).Do(context.TODO()).Into(table)
framework.ExpectError(err, "failed to return error when posting self subject access review: %+v, to a backend that does not implement metadata", sar)
framework.ExpectEqual(err.(apierrors.APIStatus).Status().Code, int32(406))
})

View File

@@ -17,6 +17,7 @@ limitations under the License.
package apimachinery
import (
"context"
"fmt"
"reflect"
"strings"
@@ -114,7 +115,7 @@ var _ = SIGDescribe("AdmissionWebhook [Privileged:ClusterAdmin]", func() {
{
ginkgo.By("fetching the /apis discovery document")
apiGroupList := &metav1.APIGroupList{}
err := client.Discovery().RESTClient().Get().AbsPath("/apis").Do().Into(apiGroupList)
err := client.Discovery().RESTClient().Get().AbsPath("/apis").Do(context.TODO()).Into(apiGroupList)
framework.ExpectNoError(err, "fetching /apis")
ginkgo.By("finding the admissionregistration.k8s.io API group in the /apis discovery document")
@@ -141,7 +142,7 @@ var _ = SIGDescribe("AdmissionWebhook [Privileged:ClusterAdmin]", func() {
{
ginkgo.By("fetching the /apis/admissionregistration.k8s.io discovery document")
group := &metav1.APIGroup{}
err := client.Discovery().RESTClient().Get().AbsPath("/apis/admissionregistration.k8s.io").Do().Into(group)
err := client.Discovery().RESTClient().Get().AbsPath("/apis/admissionregistration.k8s.io").Do(context.TODO()).Into(group)
framework.ExpectNoError(err, "fetching /apis/admissionregistration.k8s.io")
framework.ExpectEqual(group.Name, admissionregistrationv1.GroupName, "verifying API group name in /apis/admissionregistration.k8s.io discovery document")
@@ -159,7 +160,7 @@ var _ = SIGDescribe("AdmissionWebhook [Privileged:ClusterAdmin]", func() {
{
ginkgo.By("fetching the /apis/admissionregistration.k8s.io/v1 discovery document")
apiResourceList := &metav1.APIResourceList{}
err := client.Discovery().RESTClient().Get().AbsPath("/apis/admissionregistration.k8s.io/v1").Do().Into(apiResourceList)
err := client.Discovery().RESTClient().Get().AbsPath("/apis/admissionregistration.k8s.io/v1").Do(context.TODO()).Into(apiResourceList)
framework.ExpectNoError(err, "fetching /apis/admissionregistration.k8s.io/v1")
framework.ExpectEqual(apiResourceList.GroupVersion, admissionregistrationv1.SchemeGroupVersion.String(), "verifying API group/version in /apis/admissionregistration.k8s.io/v1 discovery document")

View File

@@ -17,6 +17,7 @@ limitations under the License.
package auth
import (
"context"
"encoding/json"
"fmt"
"strings"
@@ -733,7 +734,7 @@ func expectEvents(f *framework.Framework, expectedEvents []utils.AuditEvent) {
pollingTimeout := 5 * time.Minute
err := wait.Poll(pollingInterval, pollingTimeout, func() (bool, error) {
// Fetch the log stream.
stream, err := f.ClientSet.CoreV1().RESTClient().Get().AbsPath("/logs/kube-apiserver-audit.log").Stream()
stream, err := f.ClientSet.CoreV1().RESTClient().Get().AbsPath("/logs/kube-apiserver-audit.log").Stream(context.TODO())
if err != nil {
return false, err
}

View File

@@ -18,11 +18,12 @@ package common
import (
"bytes"
"context"
"fmt"
"strings"
"time"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/uuid"
"k8s.io/kubernetes/test/e2e/framework"
@@ -64,7 +65,7 @@ var _ = framework.KubeDescribe("Kubelet", func() {
})
gomega.Eventually(func() string {
sinceTime := metav1.NewTime(time.Now().Add(time.Duration(-1 * time.Hour)))
rc, err := podClient.GetLogs(podName, &v1.PodLogOptions{SinceTime: &sinceTime}).Stream()
rc, err := podClient.GetLogs(podName, &v1.PodLogOptions{SinceTime: &sinceTime}).Stream(context.TODO())
if err != nil {
return ""
}
@@ -167,7 +168,7 @@ var _ = framework.KubeDescribe("Kubelet", func() {
})
gomega.Eventually(func() error {
rc, err := podClient.GetLogs(podName, &v1.PodLogOptions{}).Stream()
rc, err := podClient.GetLogs(podName, &v1.PodLogOptions{}).Stream(context.TODO())
if err != nil {
return err
}
@@ -215,7 +216,7 @@ var _ = framework.KubeDescribe("Kubelet", func() {
},
})
gomega.Eventually(func() string {
rc, err := podClient.GetLogs(podName, &v1.PodLogOptions{}).Stream()
rc, err := podClient.GetLogs(podName, &v1.PodLogOptions{}).Stream(context.TODO())
if err != nil {
return ""
}

View File

@@ -38,6 +38,7 @@ import (
testutils "k8s.io/kubernetes/test/utils"
"github.com/onsi/ginkgo"
scaleclient "k8s.io/client-go/scale"
imageutils "k8s.io/kubernetes/test/utils/image"
)
@@ -253,7 +254,7 @@ func (rc *ResourceConsumer) sendConsumeCPURequest(millicores int) {
Param("durationSec", strconv.Itoa(rc.consumptionTimeInSeconds)).
Param("requestSizeMillicores", strconv.Itoa(rc.requestSizeInMillicores))
framework.Logf("ConsumeCPU URL: %v", *req.URL())
_, err = req.DoRaw()
_, err = req.DoRaw(context.TODO())
if err != nil {
framework.Logf("ConsumeCPU failure: %v", err)
return false, nil
@@ -280,7 +281,7 @@ func (rc *ResourceConsumer) sendConsumeMemRequest(megabytes int) {
Param("durationSec", strconv.Itoa(rc.consumptionTimeInSeconds)).
Param("requestSizeMegabytes", strconv.Itoa(rc.requestSizeInMegabytes))
framework.Logf("ConsumeMem URL: %v", *req.URL())
_, err = req.DoRaw()
_, err = req.DoRaw(context.TODO())
if err != nil {
framework.Logf("ConsumeMem failure: %v", err)
return false, nil
@@ -308,7 +309,7 @@ func (rc *ResourceConsumer) sendConsumeCustomMetric(delta int) {
Param("durationSec", strconv.Itoa(rc.consumptionTimeInSeconds)).
Param("requestSizeMetrics", strconv.Itoa(rc.requestSizeCustomMetric))
framework.Logf("ConsumeCustomMetric URL: %v", *req.URL())
_, err = req.DoRaw()
_, err = req.DoRaw(context.TODO())
if err != nil {
framework.Logf("ConsumeCustomMetric failure: %v", err)
return false, nil

View File

@@ -98,7 +98,7 @@ func ProxyRequest(c clientset.Interface, node, endpoint string, port int) (restc
SubResource("proxy").
Name(fmt.Sprintf("%v:%v", node, port)).
Suffix(endpoint).
Do()
Do(context.TODO())
finished <- struct{}{}
}()
@@ -225,7 +225,7 @@ func GetStatsSummary(c clientset.Interface, nodeName string) (*kubeletstatsv1alp
SubResource("proxy").
Name(fmt.Sprintf("%v:%v", nodeName, ports.KubeletPort)).
Suffix("stats/summary").
Do().Raw()
Do(context.TODO()).Raw()
if err != nil {
return nil, err
@@ -246,7 +246,7 @@ func getNodeStatsSummary(c clientset.Interface, nodeName string) (*kubeletstatsv
Name(fmt.Sprintf("%v:%v", nodeName, ports.KubeletPort)).
Suffix("stats/summary").
SetHeader("Content-Type", "application/json").
Do().Raw()
Do(context.TODO()).Raw()
if err != nil {
return nil, err

View File

@@ -16,7 +16,11 @@ limitations under the License.
package metrics
import "k8s.io/component-base/metrics/testutil"
import (
"context"
"k8s.io/component-base/metrics/testutil"
)
// APIServerMetrics is metrics for API server
type APIServerMetrics testutil.Metrics
@@ -40,7 +44,7 @@ func parseAPIServerMetrics(data string) (APIServerMetrics, error) {
}
func (g *Grabber) getMetricsFromAPIServer() (string, error) {
rawOutput, err := g.client.CoreV1().RESTClient().Get().RequestURI("/metrics").Do().Raw()
rawOutput, err := g.client.CoreV1().RESTClient().Get().RequestURI("/metrics").Do(context.TODO()).Raw()
if err != nil {
return "", err
}

View File

@@ -17,6 +17,7 @@ limitations under the License.
package metrics
import (
"context"
"fmt"
"io/ioutil"
"net/http"
@@ -85,7 +86,7 @@ func (g *Grabber) getMetricsFromNode(nodeName string, kubeletPort int) (string,
SubResource("proxy").
Name(fmt.Sprintf("%v:%v", nodeName, kubeletPort)).
Suffix("metrics").
Do().Raw()
Do(context.TODO()).Raw()
finished <- struct{}{}
}()
select {

View File

@@ -17,6 +17,7 @@ limitations under the License.
package metrics
import (
"context"
"fmt"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -241,7 +242,7 @@ func (g *Grabber) getMetricsFromPod(client clientset.Interface, podName string,
SubResource("proxy").
Name(fmt.Sprintf("%v:%v", podName, port)).
Suffix("metrics").
Do().Raw()
Do(context.TODO()).Raw()
if err != nil {
return "", err
}

View File

@@ -103,7 +103,7 @@ func (r ProxyResponseChecker) CheckAllResponses() (done bool, err error) {
Resource("pods").
SubResource("proxy").
Name(string(pod.Name)).
Do().
Do(context.TODO()).
Raw()
if err != nil {
@@ -516,7 +516,7 @@ func getPodLogsInternal(c clientset.Interface, namespace, podName, containerName
Name(podName).SubResource("log").
Param("container", containerName).
Param("previous", strconv.FormatBool(previous)).
Do().
Do(context.TODO()).
Raw()
if err != nil {
return "", err

View File

@@ -36,7 +36,7 @@ import (
"github.com/pkg/errors"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
clientset "k8s.io/client-go/kubernetes"
)
@@ -48,7 +48,7 @@ import (
// when the pod gets deleted while streaming.
func LogsForPod(ctx context.Context, cs clientset.Interface, ns, pod string, opts *v1.PodLogOptions) (io.ReadCloser, error) {
req := cs.CoreV1().Pods(ns).GetLogs(pod, opts)
return req.Context(ctx).Stream()
return req.Context(ctx).Stream(context.TODO())
}
// LogOutput determines where output from CopyAllLogs goes.

View File

@@ -299,7 +299,7 @@ func getStatsSummary(c clientset.Interface, nodeName string) (*kubeletstatsv1alp
SubResource("proxy").
Name(fmt.Sprintf("%v:%v", nodeName, ports.KubeletPort)).
Suffix("stats/summary").
Do().Raw()
Do(context.TODO()).Raw()
if err != nil {
return nil, err

View File

@@ -38,6 +38,7 @@ import (
"time"
"golang.org/x/net/websocket"
"k8s.io/klog"
"github.com/onsi/ginkgo"
@@ -1017,7 +1018,7 @@ func getKubeletPods(c clientset.Interface, node string) (*v1.PodList, error) {
SubResource("proxy").
Name(fmt.Sprintf("%v:%v", node, ports.KubeletPort)).
Suffix("pods").
Do()
Do(context.TODO())
finished <- struct{}{}
}()

View File

@@ -96,7 +96,7 @@ func ClusterLevelLoggingWithKibana(f *framework.Framework) {
_, err = req.Namespace(metav1.NamespaceSystem).
Context(ctx).
Name("kibana-logging").
DoRaw()
DoRaw(context.TODO())
if err != nil {
framework.Logf("Proxy call to kibana-logging failed: %v", err)
return false, nil

View File

@@ -17,6 +17,7 @@ limitations under the License.
package elasticsearch
import (
"context"
"encoding/json"
"fmt"
"strconv"
@@ -100,7 +101,7 @@ func (p *esLogProvider) Init() error {
// Query against the root URL for Elasticsearch.
response := proxyRequest.Namespace(api.NamespaceSystem).
Name("elasticsearch-logging").
Do()
Do(context.TODO())
err = response.Error()
response.StatusCode(&statusCode)
@@ -135,7 +136,7 @@ func (p *esLogProvider) Init() error {
Name("elasticsearch-logging").
Suffix("_cluster/health").
Param("level", "indices").
DoRaw()
DoRaw(context.TODO())
if err != nil {
continue
}
@@ -189,9 +190,8 @@ func (p *esLogProvider) ReadEntries(name string) []utils.LogEntry {
Name("elasticsearch-logging").
Suffix("_search").
Param("q", query).
// Ask for more in case we included some unrelated records in our query
Param("size", strconv.Itoa(searchPageSize)).
DoRaw()
DoRaw(context.TODO())
if err != nil {
framework.Logf("Failed to make proxy call to elasticsearch-logging: %v", err)
return nil

View File

@@ -42,6 +42,8 @@ import (
"github.com/elazarl/goproxy"
openapi_v2 "github.com/googleapis/gnostic/OpenAPIv2"
"sigs.k8s.io/yaml"
v1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
@@ -83,7 +85,6 @@ import (
imageutils "k8s.io/kubernetes/test/utils/image"
uexec "k8s.io/utils/exec"
"k8s.io/utils/pointer"
"sigs.k8s.io/yaml"
"github.com/onsi/ginkgo"
"github.com/onsi/gomega"
@@ -2373,7 +2374,7 @@ func makeRequestToGuestbook(c clientset.Interface, cmd, value string, ns string)
Param("cmd", cmd).
Param("key", "messages").
Param("value", value).
Do().
Do(context.TODO()).
Raw()
return string(result), err
}
@@ -2458,7 +2459,7 @@ func getUDData(jpgExpected string, ns string) func(clientset.Interface, string)
SubResource("proxy").
Name(podID).
Suffix("data.json").
Do().
Do(context.TODO()).
Raw()
if err != nil {

View File

@@ -26,6 +26,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
dnsutil "github.com/miekg/dns"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/util/intstr"
@@ -533,7 +534,7 @@ func assertFilesContain(fileNames []string, fileDir string, pod *v1.Pod, client
SubResource("proxy").
Name(pod.Name).
Suffix(fileDir, fileName).
Do().Raw()
Do(context.TODO()).Raw()
if err != nil {
if ctx.Err() != nil {

View File

@@ -26,6 +26,7 @@ import (
"time"
"github.com/onsi/ginkgo"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
@@ -194,7 +195,7 @@ func waitForServiceResponding(c clientset.Interface, ns, name string) error {
body, err := proxyRequest.Namespace(ns).
Context(ctx).
Name(name).
Do().
Do(context.TODO()).
Raw()
if err != nil {
if ctx.Err() != nil {

View File

@@ -17,6 +17,7 @@ limitations under the License.
package network
import (
"context"
"fmt"
"net/http"
"strconv"
@@ -138,7 +139,7 @@ var _ = SIGDescribe("Networking", func() {
ginkgo.By(fmt.Sprintf("testing: %s", test.path))
data, err := f.ClientSet.CoreV1().RESTClient().Get().
AbsPath(test.path).
DoRaw()
DoRaw(context.TODO())
if err != nil {
framework.Failf("ginkgo.Failed: %v\nBody: %s", err, string(data))
}

View File

@@ -19,6 +19,7 @@ limitations under the License.
package network
import (
"context"
"fmt"
"math"
"net/http"
@@ -249,7 +250,7 @@ var _ = SIGDescribe("Proxy", func() {
}
if len(errs) != 0 {
body, err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).GetLogs(pods[0].Name, &v1.PodLogOptions{}).Do().Raw()
body, err := f.ClientSet.CoreV1().Pods(f.Namespace.Name).GetLogs(pods[0].Name, &v1.PodLogOptions{}).Do(context.TODO()).Raw()
if err != nil {
framework.Logf("Error getting logs for pod %s: %v", pods[0].Name, err)
} else {
@@ -270,7 +271,7 @@ func doProxy(f *framework.Framework, path string, i int) (body []byte, statusCod
// chance of the things we are talking to being confused for an error
// that apiserver would have emitted.
start := time.Now()
body, err = f.ClientSet.CoreV1().RESTClient().Get().AbsPath(path).Do().StatusCode(&statusCode).Raw()
body, err = f.ClientSet.CoreV1().RESTClient().Get().AbsPath(path).Do(context.TODO()).StatusCode(&statusCode).Raw()
d = time.Since(start)
if len(body) > 0 {
framework.Logf("(%v) %v: %s (%v; %v)", i, path, truncate(body, maxDisplayBodyLen), statusCode, d)

View File

@@ -18,6 +18,7 @@ package network
import (
"bytes"
"context"
"errors"
"fmt"
"math/rand"
@@ -674,7 +675,7 @@ func restartKubeProxy(host string) error {
// waitForApiserverUp waits for the kube-apiserver to be up.
func waitForApiserverUp(c clientset.Interface) error {
for start := time.Now(); time.Since(start) < time.Minute; time.Sleep(5 * time.Second) {
body, err := c.CoreV1().RESTClient().Get().AbsPath("/healthz").Do().Raw()
body, err := c.CoreV1().RESTClient().Get().AbsPath("/healthz").Do(context.TODO()).Raw()
if err == nil && string(body) == "ok" {
return nil
}

View File

@@ -17,6 +17,7 @@ limitations under the License.
package node
import (
"context"
"encoding/json"
"net/http"
"strconv"
@@ -103,7 +104,7 @@ var _ = SIGDescribe("Pods Extended", func() {
ginkgo.By("deleting the pod gracefully")
var lastPod v1.Pod
var statusCode int
err = f.ClientSet.CoreV1().RESTClient().Delete().AbsPath("/api/v1/namespaces", pod.Namespace, "pods", pod.Name).Param("gracePeriodSeconds", "30").Do().StatusCode(&statusCode).Into(&lastPod)
err = f.ClientSet.CoreV1().RESTClient().Delete().AbsPath("/api/v1/namespaces", pod.Namespace, "pods", pod.Name).Param("gracePeriodSeconds", "30").Do(context.TODO()).StatusCode(&statusCode).Into(&lastPod)
framework.ExpectNoError(err, "failed to use http client to send delete")
framework.ExpectEqual(statusCode, http.StatusOK, "failed to delete gracefully by client request")

View File

@@ -141,7 +141,7 @@ func testPreStop(c clientset.Interface, ns string) {
SubResource("proxy").
Name(podDescr.Name).
Suffix("read").
DoRaw()
DoRaw(context.TODO())
if err != nil {
if ctx.Err() != nil {

View File

@@ -17,6 +17,7 @@ limitations under the License.
package testsuites
import (
"context"
"fmt"
"time"
@@ -608,7 +609,7 @@ func StopPod(c clientset.Interface, pod *v1.Pod) {
if pod == nil {
return
}
body, err := c.CoreV1().Pods(pod.Namespace).GetLogs(pod.Name, &v1.PodLogOptions{}).Do().Raw()
body, err := c.CoreV1().Pods(pod.Namespace).GetLogs(pod.Name, &v1.PodLogOptions{}).Do(context.TODO()).Raw()
if err != nil {
framework.Logf("Error getting logs for pod %s: %v", pod.Name, err)
} else {

View File

@@ -75,7 +75,7 @@ var _ = SIGDescribe("Kubernetes Dashboard [Feature:Dashboard]", func() {
Context(ctx).
Name(utilnet.JoinSchemeNamePort("https", uiServiceName, "")).
Timeout(framework.SingleCallTimeout).
Do().
Do(context.TODO()).
StatusCode(&status).
Error()
if err != nil {

View File

@@ -19,12 +19,13 @@ limitations under the License.
package e2enode
import (
"context"
"fmt"
"os"
"path"
"time"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/labels"
@@ -383,7 +384,7 @@ var _ = framework.KubeDescribe("NodeProblemDetector [NodeFeature:NodeProblemDete
gomega.Expect(c.CoreV1().Events(eventNamespace).DeleteCollection(metav1.NewDeleteOptions(0), eventListOptions)).To(gomega.Succeed())
ginkgo.By("Clean up the node condition")
patch := []byte(fmt.Sprintf(`{"status":{"conditions":[{"$patch":"delete","type":"%s"}]}}`, condition))
c.CoreV1().RESTClient().Patch(types.StrategicMergePatchType).Resource("nodes").Name(framework.TestContext.NodeName).SubResource("status").Body(patch).Do()
c.CoreV1().RESTClient().Patch(types.StrategicMergePatchType).Resource("nodes").Name(framework.TestContext.NodeName).SubResource("status").Body(patch).Do(context.TODO())
})
})
})

View File

@@ -17,6 +17,7 @@ limitations under the License.
package inclusterclient
import (
"context"
"crypto/sha256"
"encoding/base64"
"flag"
@@ -77,7 +78,7 @@ func main(cmd *cobra.Command, args []string) {
for {
<-t
klog.Infof("calling /healthz")
b, err := c.Get().AbsPath("/healthz").Do().Raw()
b, err := c.Get().AbsPath("/healthz").Do(context.TODO()).Raw()
if err != nil {
klog.Errorf("status=failed")
klog.Errorf("error checking /healthz: %v\n%s\n", err, string(b))

View File

@@ -17,6 +17,7 @@ limitations under the License.
package admissionwebhook
import (
"context"
"crypto/tls"
"crypto/x509"
"encoding/json"
@@ -1016,11 +1017,11 @@ func testPodConnectSubresource(c *testContext) {
var err error
switch c.gvr {
case gvr("", "v1", "pods/exec"):
err = c.clientset.CoreV1().RESTClient().Verb(httpMethod).Namespace(pod.GetNamespace()).Resource("pods").Name(pod.GetName()).SubResource("exec").Do().Error()
err = c.clientset.CoreV1().RESTClient().Verb(httpMethod).Namespace(pod.GetNamespace()).Resource("pods").Name(pod.GetName()).SubResource("exec").Do(context.TODO()).Error()
case gvr("", "v1", "pods/attach"):
err = c.clientset.CoreV1().RESTClient().Verb(httpMethod).Namespace(pod.GetNamespace()).Resource("pods").Name(pod.GetName()).SubResource("attach").Do().Error()
err = c.clientset.CoreV1().RESTClient().Verb(httpMethod).Namespace(pod.GetNamespace()).Resource("pods").Name(pod.GetName()).SubResource("attach").Do(context.TODO()).Error()
case gvr("", "v1", "pods/portforward"):
err = c.clientset.CoreV1().RESTClient().Verb(httpMethod).Namespace(pod.GetNamespace()).Resource("pods").Name(pod.GetName()).SubResource("portforward").Do().Error()
err = c.clientset.CoreV1().RESTClient().Verb(httpMethod).Namespace(pod.GetNamespace()).Resource("pods").Name(pod.GetName()).SubResource("portforward").Do(context.TODO()).Error()
default:
c.t.Errorf("unknown subresource %#v", c.gvr)
return
@@ -1061,19 +1062,19 @@ func testPodBindingEviction(c *testContext) {
err = c.clientset.CoreV1().RESTClient().Post().Namespace(pod.GetNamespace()).Resource("bindings").Body(&corev1.Binding{
ObjectMeta: metav1.ObjectMeta{Name: pod.GetName()},
Target: corev1.ObjectReference{Name: "foo", Kind: "Node", APIVersion: "v1"},
}).Do().Error()
}).Do(context.TODO()).Error()
case gvr("", "v1", "pods/binding"):
err = c.clientset.CoreV1().RESTClient().Post().Namespace(pod.GetNamespace()).Resource("pods").Name(pod.GetName()).SubResource("binding").Body(&corev1.Binding{
ObjectMeta: metav1.ObjectMeta{Name: pod.GetName()},
Target: corev1.ObjectReference{Name: "foo", Kind: "Node", APIVersion: "v1"},
}).Do().Error()
}).Do(context.TODO()).Error()
case gvr("", "v1", "pods/eviction"):
err = c.clientset.CoreV1().RESTClient().Post().Namespace(pod.GetNamespace()).Resource("pods").Name(pod.GetName()).SubResource("eviction").Body(&policyv1beta1.Eviction{
ObjectMeta: metav1.ObjectMeta{Name: pod.GetName()},
DeleteOptions: forceDelete,
}).Do().Error()
}).Do(context.TODO()).Error()
default:
c.t.Errorf("unhandled resource %#v", c.gvr)
@@ -1124,7 +1125,7 @@ func testSubresourceProxy(c *testContext) {
// set expectations
c.admissionHolder.expect(c.gvr, gvk(c.resource.Group, c.resource.Version, c.resource.Kind), schema.GroupVersionKind{}, v1beta1.Connect, obj.GetName(), obj.GetNamespace(), true, false, false)
// run the request. we don't actually care if the request is successful, just that admission gets called as expected
err = request.Resource(gvrWithoutSubresources.Resource).Name(obj.GetName()).SubResource(subresources...).Do().Error()
err = request.Resource(gvrWithoutSubresources.Resource).Name(obj.GetName()).SubResource(subresources...).Do(context.TODO()).Error()
if err != nil {
c.t.Logf("debug: result of subresource proxy (error expected): %v", err)
}

View File

@@ -17,6 +17,7 @@ limitations under the License.
package admissionwebhook
import (
"context"
"crypto/tls"
"crypto/x509"
"encoding/json"
@@ -291,7 +292,7 @@ func testWebhookTimeout(t *testing.T, watchCache bool) {
}
// set the timeout parameter manually so we don't actually cut off the request client-side, and wait for the server response
err = client.CoreV1().RESTClient().Post().Resource("pods").Namespace(ns).Body(body).Param("timeout", fmt.Sprintf("%ds", tt.timeoutSeconds)).Do().Error()
err = client.CoreV1().RESTClient().Post().Resource("pods").Namespace(ns).Body(body).Param("timeout", fmt.Sprintf("%ds", tt.timeoutSeconds)).Do(context.TODO()).Error()
// _, err = testClient.CoreV1().Pods(ns).Create(pod)
if tt.expectError {

View File

@@ -188,7 +188,7 @@ func Test4xxStatusCodeInvalidPatch(t *testing.T) {
AbsPath("/apis/apps/v1").
Namespace("default").
Resource("deployments").
Body(obj).Do().Get()
Body(obj).Do(context.TODO()).Get()
if err != nil {
t.Fatalf("Failed to create object: %v: %v", err, resp)
}
@@ -197,7 +197,7 @@ func Test4xxStatusCodeInvalidPatch(t *testing.T) {
Namespace("default").
Resource("deployments").
Name("deployment").
Body([]byte(`{"metadata":{"annotations":{"foo":["bar"]}}}`)).Do()
Body([]byte(`{"metadata":{"annotations":{"foo":["bar"]}}}`)).Do(context.TODO())
var statusCode int
result.StatusCode(&statusCode)
if statusCode != 422 {
@@ -208,7 +208,7 @@ func Test4xxStatusCodeInvalidPatch(t *testing.T) {
Namespace("default").
Resource("deployments").
Name("deployment").
Body([]byte(`{"metadata":{"annotations":{"foo":["bar"]}}}`)).Do()
Body([]byte(`{"metadata":{"annotations":{"foo":["bar"]}}}`)).Do(context.TODO())
result.StatusCode(&statusCode)
if statusCode != 422 {
t.Fatalf("Expected status code to be 422, got %v (%#v)", statusCode, result)
@@ -998,7 +998,7 @@ func TestAPICRDProtobuf(t *testing.T) {
w, err := client.Get().
Resource(resource).NamespaceIfScoped(obj.GetNamespace(), len(obj.GetNamespace()) > 0).Name(obj.GetName()).SubResource(tc.subresource).
SetHeader("Accept", tc.accept).
Stream()
Stream(context.TODO())
if (tc.wantErr != nil) != (err != nil) {
t.Fatalf("unexpected error: %v", err)
}
@@ -1611,7 +1611,7 @@ func TestTransform(t *testing.T) {
FieldSelector: fields.OneTermEqualSelector("metadata.name", obj.GetName()).String(),
}, metav1.ParameterCodec).
Param("includeObject", string(tc.includeObject)).
Stream()
Stream(context.TODO())
if (tc.wantErr != nil) != (err != nil) {
t.Fatalf("unexpected error: %v", err)
}

View File

@@ -17,6 +17,7 @@ limitations under the License.
package apiserver
import (
"context"
"encoding/json"
"fmt"
"reflect"
@@ -81,7 +82,7 @@ spec:
Name(name).
Param("fieldManager", "apply_test").
Body(yamlBody).
DoRaw()
DoRaw(context.TODO())
if err != nil {
t.Fatalf("failed to create custom resource with apply: %v:\n%v", err, string(result))
}
@@ -92,7 +93,7 @@ spec:
AbsPath("/apis", noxuDefinition.Spec.Group, noxuDefinition.Spec.Version, noxuDefinition.Spec.Names.Plural).
Name(name).
Body([]byte(`{"spec":{"replicas": 5}}`)).
DoRaw()
DoRaw(context.TODO())
if err != nil {
t.Fatalf("failed to update number of replicas with merge patch: %v:\n%v", err, string(result))
}
@@ -104,7 +105,7 @@ spec:
Name(name).
Param("fieldManager", "apply_test").
Body(yamlBody).
DoRaw()
DoRaw(context.TODO())
if err == nil {
t.Fatalf("Expecting to get conflicts when applying object after updating replicas, got no error: %s", result)
}
@@ -123,7 +124,7 @@ spec:
Param("force", "true").
Param("fieldManager", "apply_test").
Body(yamlBody).
DoRaw()
DoRaw(context.TODO())
if err != nil {
t.Fatalf("failed to apply object with force after updating replicas: %v:\n%v", err, string(result))
}
@@ -241,7 +242,7 @@ spec:
Name(name).
Param("fieldManager", "apply_test").
Body(yamlBody).
DoRaw()
DoRaw(context.TODO())
if err != nil {
t.Fatalf("failed to create custom resource with apply: %v:\n%v", err, string(result))
}
@@ -255,7 +256,7 @@ spec:
AbsPath("/apis", noxuDefinition.Spec.Group, noxuDefinition.Spec.Version, noxuDefinition.Spec.Names.Plural).
Name(name).
Body([]byte(`{"metadata":{"finalizers":["test-finalizer","another-one"]}}`)).
DoRaw()
DoRaw(context.TODO())
if err != nil {
t.Fatalf("failed to add finalizer with merge patch: %v:\n%v", err, string(result))
}
@@ -270,7 +271,7 @@ spec:
Param("fieldManager", "apply_test").
SetHeader("Accept", "application/json").
Body(yamlBody).
DoRaw()
DoRaw(context.TODO())
if err != nil {
t.Fatalf("failed to apply same config after adding a finalizer: %v:\n%v", err, string(result))
}
@@ -283,7 +284,7 @@ spec:
AbsPath("/apis", noxuDefinition.Spec.Group, noxuDefinition.Spec.Version, noxuDefinition.Spec.Names.Plural).
Name(name).
Body([]byte(`{"spec":{"replicas": 5}}`)).
DoRaw()
DoRaw(context.TODO())
if err != nil {
t.Fatalf("failed to update number of replicas with merge patch: %v:\n%v", err, string(result))
}
@@ -295,7 +296,7 @@ spec:
Name(name).
Param("fieldManager", "apply_test").
Body(yamlBody).
DoRaw()
DoRaw(context.TODO())
if err == nil {
t.Fatalf("Expecting to get conflicts when applying object after updating replicas, got no error: %s", result)
}
@@ -314,7 +315,7 @@ spec:
Param("force", "true").
Param("fieldManager", "apply_test").
Body(yamlBody).
DoRaw()
DoRaw(context.TODO())
if err != nil {
t.Fatalf("failed to apply object with force after updating replicas: %v:\n%v", err, string(result))
}
@@ -335,7 +336,7 @@ spec:
- name: "y"
containerPort: 80
protocol: TCP`, apiVersion, kind, name))).
DoRaw()
DoRaw(context.TODO())
if err == nil {
t.Fatalf("Expecting to get conflicts when a different applier updates existing list item, got no error: %s", result)
}
@@ -363,7 +364,7 @@ spec:
containerPort: 8080
protocol: TCP`, apiVersion, kind, name))).
SetHeader("Accept", "application/json").
DoRaw()
DoRaw(context.TODO())
if err != nil {
t.Fatalf("failed to add a new list item to the object as a different applier: %v:\n%v", err, string(result))
}
@@ -447,7 +448,7 @@ spec:
Name(name).
Param("fieldManager", "apply_test").
Body(yamlBody).
DoRaw()
DoRaw(context.TODO())
if err != nil {
t.Fatalf("failed to create custom resource with apply: %v:\n%v", err, string(result))
}
@@ -460,7 +461,7 @@ spec:
AbsPath("/apis", noxuDefinition.Spec.Group, noxuDefinition.Spec.Version, noxuDefinition.Spec.Names.Plural).
Name(name).
Body([]byte(`{"metadata":{"finalizers":["test-finalizer","another-one"]}}`)).
DoRaw()
DoRaw(context.TODO())
if err != nil {
t.Fatalf("failed to add finalizer with merge patch: %v:\n%v", err, string(result))
}
@@ -475,7 +476,7 @@ spec:
Param("fieldManager", "apply_test").
SetHeader("Accept", "application/json").
Body(yamlBody).
DoRaw()
DoRaw(context.TODO())
if err != nil {
t.Fatalf("failed to apply same config after adding a finalizer: %v:\n%v", err, string(result))
}
@@ -488,7 +489,7 @@ spec:
AbsPath("/apis", noxuDefinition.Spec.Group, noxuDefinition.Spec.Version, noxuDefinition.Spec.Names.Plural).
Name(name).
Body([]byte(`{"spec":{"replicas": 5}}`)).
DoRaw()
DoRaw(context.TODO())
if err != nil {
t.Fatalf("failed to update number of replicas with merge patch: %v:\n%v", err, string(result))
}
@@ -500,7 +501,7 @@ spec:
Name(name).
Param("fieldManager", "apply_test").
Body(yamlBody).
DoRaw()
DoRaw(context.TODO())
if err == nil {
t.Fatalf("Expecting to get conflicts when applying object after updating replicas, got no error: %s", result)
}
@@ -519,7 +520,7 @@ spec:
Param("force", "true").
Param("fieldManager", "apply_test").
Body(yamlBody).
DoRaw()
DoRaw(context.TODO())
if err != nil {
t.Fatalf("failed to apply object with force after updating replicas: %v:\n%v", err, string(result))
}
@@ -671,7 +672,7 @@ spec:
Name(name).
Param("fieldManager", "apply_test").
Body(yamlBody).
DoRaw()
DoRaw(context.TODO())
if err != nil {
t.Fatalf("failed to create custom resource with apply: %v:\n%v", err, string(result))
}
@@ -682,7 +683,7 @@ spec:
AbsPath("/apis", noxuDefinition.Spec.Group, noxuDefinition.Spec.Version, noxuDefinition.Spec.Names.Plural).
Name(name).
Body([]byte(`{"spec":{"replicas": 5}}`)).
DoRaw()
DoRaw(context.TODO())
if err != nil {
t.Fatalf("failed to update number of replicas with merge patch: %v:\n%v", err, string(result))
}
@@ -694,7 +695,7 @@ spec:
Name(name).
Param("fieldManager", "apply_test").
Body(yamlBody).
DoRaw()
DoRaw(context.TODO())
if err == nil {
t.Fatalf("Expecting to get conflicts when applying object after updating replicas, got no error: %s", result)
}
@@ -713,7 +714,7 @@ spec:
Param("force", "true").
Param("fieldManager", "apply_test").
Body(yamlBody).
DoRaw()
DoRaw(context.TODO())
if err != nil {
t.Fatalf("failed to apply object with force after updating replicas: %v:\n%v", err, string(result))
}

View File

@@ -17,6 +17,7 @@ limitations under the License.
package apiserver
import (
"context"
"encoding/json"
"flag"
"fmt"
@@ -27,6 +28,8 @@ import (
"testing"
"time"
"sigs.k8s.io/yaml"
v1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
@@ -41,7 +44,6 @@ import (
featuregatetesting "k8s.io/component-base/featuregate/testing"
"k8s.io/kubernetes/pkg/master"
"k8s.io/kubernetes/test/integration/framework"
"sigs.k8s.io/yaml"
)
func setup(t testing.TB, groupVersions ...schema.GroupVersion) (*httptest.Server, clientset.Interface, framework.CloseFunc) {
@@ -119,13 +121,13 @@ func TestApplyAlsoCreates(t *testing.T) {
Name(tc.name).
Param("fieldManager", "apply_test").
Body([]byte(tc.body)).
Do().
Do(context.TODO()).
Get()
if err != nil {
t.Fatalf("Failed to create object using Apply patch: %v", err)
}
_, err = client.CoreV1().RESTClient().Get().Namespace("default").Resource(tc.resource).Name(tc.name).Do().Get()
_, err = client.CoreV1().RESTClient().Get().Namespace("default").Resource(tc.resource).Name(tc.name).Do(context.TODO()).Get()
if err != nil {
t.Fatalf("Failed to retrieve object: %v", err)
}
@@ -137,7 +139,7 @@ func TestApplyAlsoCreates(t *testing.T) {
Name(tc.name).
Param("fieldManager", "apply_test_2").
Body([]byte(tc.body)).
Do().
Do(context.TODO()).
Get()
if err != nil {
t.Fatalf("Failed to re-apply object using Apply patch: %v", err)
@@ -186,7 +188,7 @@ func TestNoOpUpdateSameResourceVersion(t *testing.T) {
Resource(podResource).
Name(podName).
Body(podBytes).
Do().
Do(context.TODO()).
Get()
if err != nil {
t.Fatalf("Failed to create object: %v", err)
@@ -195,7 +197,7 @@ func TestNoOpUpdateSameResourceVersion(t *testing.T) {
// Sleep for one second to make sure that the times of each update operation is different.
time.Sleep(1 * time.Second)
createdObject, err := client.CoreV1().RESTClient().Get().Namespace("default").Resource(podResource).Name(podName).Do().Get()
createdObject, err := client.CoreV1().RESTClient().Get().Namespace("default").Resource(podResource).Name(podName).Do(context.TODO()).Get()
if err != nil {
t.Fatalf("Failed to retrieve created object: %v", err)
}
@@ -216,13 +218,13 @@ func TestNoOpUpdateSameResourceVersion(t *testing.T) {
Resource(podResource).
Name(podName).
Body(createdBytes).
Do().
Do(context.TODO()).
Get()
if err != nil {
t.Fatalf("Failed to apply no-op update: %v", err)
}
updatedObject, err := client.CoreV1().RESTClient().Get().Namespace("default").Resource(podResource).Name(podName).Do().Get()
updatedObject, err := client.CoreV1().RESTClient().Get().Namespace("default").Resource(podResource).Name(podName).Do(context.TODO()).Get()
if err != nil {
t.Fatalf("Failed to retrieve updated object: %v", err)
}
@@ -274,7 +276,7 @@ func TestCreateOnApplyFailsWithUID(t *testing.T) {
}]
}
}`)).
Do().
Do(context.TODO()).
Get()
if !apierrors.IsConflict(err) {
t.Fatalf("Expected conflict error but got: %v", err)
@@ -323,7 +325,7 @@ func TestApplyUpdateApplyConflictForced(t *testing.T) {
Resource("deployments").
Name("deployment").
Param("fieldManager", "apply_test").
Body(obj).Do().Get()
Body(obj).Do(context.TODO()).Get()
if err != nil {
t.Fatalf("Failed to create object using Apply patch: %v", err)
}
@@ -333,7 +335,7 @@ func TestApplyUpdateApplyConflictForced(t *testing.T) {
Namespace("default").
Resource("deployments").
Name("deployment").
Body([]byte(`{"spec":{"replicas": 5}}`)).Do().Get()
Body([]byte(`{"spec":{"replicas": 5}}`)).Do(context.TODO()).Get()
if err != nil {
t.Fatalf("Failed to patch object: %v", err)
}
@@ -344,7 +346,7 @@ func TestApplyUpdateApplyConflictForced(t *testing.T) {
Resource("deployments").
Name("deployment").
Param("fieldManager", "apply_test").
Body([]byte(obj)).Do().Get()
Body([]byte(obj)).Do(context.TODO()).Get()
if err == nil {
t.Fatalf("Expecting to get conflicts when applying object")
}
@@ -363,7 +365,7 @@ func TestApplyUpdateApplyConflictForced(t *testing.T) {
Name("deployment").
Param("force", "true").
Param("fieldManager", "apply_test").
Body([]byte(obj)).Do().Get()
Body([]byte(obj)).Do(context.TODO()).Get()
if err != nil {
t.Fatalf("Failed to apply object with force: %v", err)
}
@@ -391,7 +393,7 @@ func TestApplyGroupsManySeparateUpdates(t *testing.T) {
Resource("validatingwebhookconfigurations").
Name("webhook").
Param("fieldManager", "apply_test").
Body(obj).Do().Get()
Body(obj).Do(context.TODO()).Get()
if err != nil {
t.Fatalf("Failed to create object using Apply patch: %v", err)
}
@@ -407,7 +409,7 @@ func TestApplyGroupsManySeparateUpdates(t *testing.T) {
Resource("validatingwebhookconfigurations").
Name("webhook").
Param("fieldManager", unique).
Body([]byte(`{"metadata":{"labels":{"` + unique + `":"new"}}}`)).Do().Get()
Body([]byte(`{"metadata":{"labels":{"` + unique + `":"new"}}}`)).Do(context.TODO()).Get()
if err != nil {
t.Fatalf("Failed to patch object: %v", err)
}
@@ -464,7 +466,7 @@ func TestApplyManagedFields(t *testing.T) {
"key": "value"
}
}`)).
Do().
Do(context.TODO()).
Get()
if err != nil {
t.Fatalf("Failed to create object using Apply patch: %v", err)
@@ -475,7 +477,7 @@ func TestApplyManagedFields(t *testing.T) {
Resource("configmaps").
Name("test-cm").
Param("fieldManager", "updater").
Body([]byte(`{"data":{"new-key": "value"}}`)).Do().Get()
Body([]byte(`{"data":{"new-key": "value"}}`)).Do(context.TODO()).Get()
if err != nil {
t.Fatalf("Failed to patch object: %v", err)
}
@@ -490,12 +492,12 @@ func TestApplyManagedFields(t *testing.T) {
Resource("configmaps").
Name("test-cm").
Param("fieldManager", "updater").
Body([]byte(`{"data":{"key": "new value"}}`)).Do().Get()
Body([]byte(`{"data":{"key": "new value"}}`)).Do(context.TODO()).Get()
if err != nil {
t.Fatalf("Failed to patch object: %v", err)
}
object, err := client.CoreV1().RESTClient().Get().Namespace("default").Resource("configmaps").Name("test-cm").Do().Get()
object, err := client.CoreV1().RESTClient().Get().Namespace("default").Resource("configmaps").Name("test-cm").Do(context.TODO()).Get()
if err != nil {
t.Fatalf("Failed to retrieve object: %v", err)
}
@@ -588,7 +590,7 @@ func TestApplyRemovesEmptyManagedFields(t *testing.T) {
Name("test-cm").
Param("fieldManager", "apply_test").
Body(obj).
Do().
Do(context.TODO()).
Get()
if err != nil {
t.Fatalf("Failed to create object using Apply patch: %v", err)
@@ -599,12 +601,12 @@ func TestApplyRemovesEmptyManagedFields(t *testing.T) {
Resource("configmaps").
Name("test-cm").
Param("fieldManager", "apply_test").
Body(obj).Do().Get()
Body(obj).Do(context.TODO()).Get()
if err != nil {
t.Fatalf("Failed to patch object: %v", err)
}
object, err := client.CoreV1().RESTClient().Get().Namespace("default").Resource("configmaps").Name("test-cm").Do().Get()
object, err := client.CoreV1().RESTClient().Get().Namespace("default").Resource("configmaps").Name("test-cm").Do(context.TODO()).Get()
if err != nil {
t.Fatalf("Failed to retrieve object: %v", err)
}
@@ -639,7 +641,7 @@ func TestApplyRequiresFieldManager(t *testing.T) {
Resource("configmaps").
Name("test-cm").
Body(obj).
Do().
Do(context.TODO()).
Get()
if err == nil {
t.Fatalf("Apply should fail to create without fieldManager")
@@ -651,7 +653,7 @@ func TestApplyRequiresFieldManager(t *testing.T) {
Name("test-cm").
Param("fieldManager", "apply_test").
Body(obj).
Do().
Do(context.TODO()).
Get()
if err != nil {
t.Fatalf("Apply failed to create with fieldManager: %v", err)
@@ -705,7 +707,7 @@ func TestApplyRemoveContainerPort(t *testing.T) {
Resource("deployments").
Name("deployment").
Param("fieldManager", "apply_test").
Body(obj).Do().Get()
Body(obj).Do(context.TODO()).Get()
if err != nil {
t.Fatalf("Failed to create object using Apply patch: %v", err)
}
@@ -746,7 +748,7 @@ func TestApplyRemoveContainerPort(t *testing.T) {
Resource("deployments").
Name("deployment").
Param("fieldManager", "apply_test").
Body(obj).Do().Get()
Body(obj).Do(context.TODO()).Get()
if err != nil {
t.Fatalf("Failed to remove container port using Apply patch: %v", err)
}
@@ -805,7 +807,7 @@ func TestApplyFailsWithVersionMismatch(t *testing.T) {
Resource("deployments").
Name("deployment").
Param("fieldManager", "apply_test").
Body(obj).Do().Get()
Body(obj).Do(context.TODO()).Get()
if err != nil {
t.Fatalf("Failed to create object using Apply patch: %v", err)
}
@@ -845,7 +847,7 @@ func TestApplyFailsWithVersionMismatch(t *testing.T) {
Resource("deployments").
Name("deployment").
Param("fieldManager", "apply_test").
Body([]byte(obj)).Do().Get()
Body([]byte(obj)).Do(context.TODO()).Get()
if err == nil {
t.Fatalf("Expecting to get version mismatch when applying object")
}
@@ -925,7 +927,7 @@ func TestApplyConvertsManagedFieldsVersion(t *testing.T) {
AbsPath("/apis/apps/v1").
Namespace("default").
Resource("deployments").
Body(obj).Do().Get()
Body(obj).Do(context.TODO()).Get()
if err != nil {
t.Fatalf("Failed to create object: %v", err)
}
@@ -954,7 +956,7 @@ func TestApplyConvertsManagedFieldsVersion(t *testing.T) {
Resource("deployments").
Name("deployment").
Param("fieldManager", "sidecar_controller").
Body([]byte(obj)).Do().Get()
Body([]byte(obj)).Do(context.TODO()).Get()
if err != nil {
t.Fatalf("Failed to apply object: %v", err)
}
@@ -1028,7 +1030,7 @@ func TestClearManagedFieldsWithMergePatch(t *testing.T) {
"key": "value"
}
}`)).
Do().
Do(context.TODO()).
Get()
if err != nil {
t.Fatalf("Failed to create object using Apply patch: %v", err)
@@ -1038,12 +1040,12 @@ func TestClearManagedFieldsWithMergePatch(t *testing.T) {
Namespace("default").
Resource("configmaps").
Name("test-cm").
Body([]byte(`{"metadata":{"managedFields": [{}]}}`)).Do().Get()
Body([]byte(`{"metadata":{"managedFields": [{}]}}`)).Do(context.TODO()).Get()
if err != nil {
t.Fatalf("Failed to patch object: %v", err)
}
object, err := client.CoreV1().RESTClient().Get().Namespace("default").Resource("configmaps").Name("test-cm").Do().Get()
object, err := client.CoreV1().RESTClient().Get().Namespace("default").Resource("configmaps").Name("test-cm").Do(context.TODO()).Get()
if err != nil {
t.Fatalf("Failed to retrieve object: %v", err)
}
@@ -1084,7 +1086,7 @@ func TestClearManagedFieldsWithStrategicMergePatch(t *testing.T) {
"key": "value"
}
}`)).
Do().
Do(context.TODO()).
Get()
if err != nil {
t.Fatalf("Failed to create object using Apply patch: %v", err)
@@ -1094,12 +1096,12 @@ func TestClearManagedFieldsWithStrategicMergePatch(t *testing.T) {
Namespace("default").
Resource("configmaps").
Name("test-cm").
Body([]byte(`{"metadata":{"managedFields": [{}]}}`)).Do().Get()
Body([]byte(`{"metadata":{"managedFields": [{}]}}`)).Do(context.TODO()).Get()
if err != nil {
t.Fatalf("Failed to patch object: %v", err)
}
object, err := client.CoreV1().RESTClient().Get().Namespace("default").Resource("configmaps").Name("test-cm").Do().Get()
object, err := client.CoreV1().RESTClient().Get().Namespace("default").Resource("configmaps").Name("test-cm").Do(context.TODO()).Get()
if err != nil {
t.Fatalf("Failed to retrieve object: %v", err)
}
@@ -1144,7 +1146,7 @@ func TestClearManagedFieldsWithJSONPatch(t *testing.T) {
"key": "value"
}
}`)).
Do().
Do(context.TODO()).
Get()
if err != nil {
t.Fatalf("Failed to create object using Apply patch: %v", err)
@@ -1154,12 +1156,12 @@ func TestClearManagedFieldsWithJSONPatch(t *testing.T) {
Namespace("default").
Resource("configmaps").
Name("test-cm").
Body([]byte(`[{"op": "replace", "path": "/metadata/managedFields", "value": [{}]}]`)).Do().Get()
Body([]byte(`[{"op": "replace", "path": "/metadata/managedFields", "value": [{}]}]`)).Do(context.TODO()).Get()
if err != nil {
t.Fatalf("Failed to patch object: %v", err)
}
object, err := client.CoreV1().RESTClient().Get().Namespace("default").Resource("configmaps").Name("test-cm").Do().Get()
object, err := client.CoreV1().RESTClient().Get().Namespace("default").Resource("configmaps").Name("test-cm").Do(context.TODO()).Get()
if err != nil {
t.Fatalf("Failed to retrieve object: %v", err)
}
@@ -1200,7 +1202,7 @@ func TestClearManagedFieldsWithUpdate(t *testing.T) {
"key": "value"
}
}`)).
Do().
Do(context.TODO()).
Get()
if err != nil {
t.Fatalf("Failed to create object using Apply patch: %v", err)
@@ -1224,12 +1226,12 @@ func TestClearManagedFieldsWithUpdate(t *testing.T) {
"data": {
"key": "value"
}
}`)).Do().Get()
}`)).Do(context.TODO()).Get()
if err != nil {
t.Fatalf("Failed to patch object: %v", err)
}
object, err := client.CoreV1().RESTClient().Get().Namespace("default").Resource("configmaps").Name("test-cm").Do().Get()
object, err := client.CoreV1().RESTClient().Get().Namespace("default").Resource("configmaps").Name("test-cm").Do(context.TODO()).Get()
if err != nil {
t.Fatalf("Failed to retrieve object: %v", err)
}
@@ -1416,7 +1418,7 @@ func getPodBytesWhenEnabled(b *testing.B, pod v1.Pod, format string) []byte {
Param("fieldManager", "apply_test").
Resource("pods").
SetHeader("Accept", format).
Body(encodePod(pod)).DoRaw()
Body(encodePod(pod)).DoRaw(context.TODO())
if err != nil {
b.Fatalf("Failed to create object: %#v", err)
}
@@ -1439,7 +1441,7 @@ func BenchmarkNoServerSideApplyButSameSize(b *testing.B) {
Resource("pods").
SetHeader("Content-Type", "application/yaml").
SetHeader("Accept", "application/vnd.kubernetes.protobuf").
Body(encodePod(pod)).DoRaw()
Body(encodePod(pod)).DoRaw(context.TODO())
if err != nil {
b.Fatalf("Failed to create object: %v", err)
}
@@ -1485,7 +1487,7 @@ func benchAll(b *testing.B, client kubernetes.Interface, pod v1.Pod) {
Namespace("default").
Resource("pods").
SetHeader("Content-Type", "application/yaml").
Body(encodePod(pod)).Do().Get()
Body(encodePod(pod)).Do(context.TODO()).Get()
if err != nil {
b.Fatalf("Failed to create object: %v", err)
}
@@ -1516,7 +1518,7 @@ func benchPostPod(client kubernetes.Interface, pod v1.Pod, parallel int) func(*t
Namespace("default").
Resource("pods").
SetHeader("Content-Type", "application/yaml").
Body(encodePod(pod)).Do().Get()
Body(encodePod(pod)).Do(context.TODO()).Get()
c <- err
}(pod)
}
@@ -1540,7 +1542,7 @@ func createNamespace(client kubernetes.Interface, name string) error {
_, err = client.CoreV1().RESTClient().Get().
Resource("namespaces").
SetHeader("Content-Type", "application/yaml").
Body(namespaceBytes).Do().Get()
Body(namespaceBytes).Do(context.TODO()).Get()
if err != nil {
return fmt.Errorf("Failed to create namespace: %v", err)
}
@@ -1561,7 +1563,7 @@ func benchListPod(client kubernetes.Interface, pod v1.Pod, num int) func(*testin
Namespace(namespace).
Resource("pods").
SetHeader("Content-Type", "application/yaml").
Body(encodePod(pod)).Do().Get()
Body(encodePod(pod)).Do(context.TODO()).Get()
if err != nil {
b.Fatalf("Failed to create object: %v", err)
}
@@ -1574,7 +1576,7 @@ func benchListPod(client kubernetes.Interface, pod v1.Pod, num int) func(*testin
Namespace(namespace).
Resource("pods").
SetHeader("Accept", "application/vnd.kubernetes.protobuf").
Do().Get()
Do(context.TODO()).Get()
if err != nil {
b.Fatalf("Failed to patch object: %v", err)
}
@@ -1591,7 +1593,7 @@ func benchRepeatedUpdate(client kubernetes.Interface, podName string) func(*test
Namespace("default").
Resource("pods").
Name(podName).
Body([]byte(fmt.Sprintf(`[{"op": "replace", "path": "/spec/containers/0/image", "value": "image%d"}]`, i))).Do().Get()
Body([]byte(fmt.Sprintf(`[{"op": "replace", "path": "/spec/containers/0/image", "value": "image%d"}]`, i))).Do(context.TODO()).Get()
if err != nil {
b.Fatalf("Failed to patch object: %v", err)
}

View File

@@ -17,11 +17,12 @@ limitations under the License.
package apiserver
import (
"context"
"fmt"
"strings"
"testing"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
@@ -56,7 +57,7 @@ func TestMaxJSONPatchOperations(t *testing.T) {
}
err = c.Patch(types.JSONPatchType).AbsPath(fmt.Sprintf("/api/v1/namespaces/default/secrets/test")).
Body(hugePatch).Do().Error()
Body(hugePatch).Do(context.TODO()).Error()
if err == nil {
t.Fatalf("unexpected no error")
}

View File

@@ -17,6 +17,7 @@ limitations under the License.
package apiserver
import (
"context"
"fmt"
"strings"
"testing"
@@ -41,7 +42,7 @@ func TestMaxResourceSize(t *testing.T) {
c := clientSet.CoreV1().RESTClient()
t.Run("Create should limit the request body size", func(t *testing.T) {
err := c.Post().AbsPath(fmt.Sprintf("/api/v1/namespaces/default/pods")).
Body(hugeData).Do().Error()
Body(hugeData).Do(context.TODO()).Error()
if err == nil {
t.Fatalf("unexpected no error")
}
@@ -64,7 +65,7 @@ func TestMaxResourceSize(t *testing.T) {
t.Run("Update should limit the request body size", func(t *testing.T) {
err = c.Put().AbsPath(fmt.Sprintf("/api/v1/namespaces/default/secrets/test")).
Body(hugeData).Do().Error()
Body(hugeData).Do(context.TODO()).Error()
if err == nil {
t.Fatalf("unexpected no error")
}
@@ -75,7 +76,7 @@ func TestMaxResourceSize(t *testing.T) {
})
t.Run("Patch should limit the request body size", func(t *testing.T) {
err = c.Patch(types.JSONPatchType).AbsPath(fmt.Sprintf("/api/v1/namespaces/default/secrets/test")).
Body(hugeData).Do().Error()
Body(hugeData).Do(context.TODO()).Error()
if err == nil {
t.Fatalf("unexpected no error")
}
@@ -87,7 +88,7 @@ func TestMaxResourceSize(t *testing.T) {
t.Run("JSONPatchType should handle a patch just under the max limit", func(t *testing.T) {
patchBody := []byte(`[{"op":"add","path":"/foo","value":` + strings.Repeat("[", 3*1024*1024/2-100) + strings.Repeat("]", 3*1024*1024/2-100) + `}]`)
err = rest.Patch(types.JSONPatchType).AbsPath(fmt.Sprintf("/api/v1/namespaces/default/secrets/test")).
Body(patchBody).Do().Error()
Body(patchBody).Do(context.TODO()).Error()
if err != nil && !apierrors.IsBadRequest(err) {
t.Errorf("expected success or bad request err, got %v", err)
}
@@ -95,7 +96,7 @@ func TestMaxResourceSize(t *testing.T) {
t.Run("JSONPatchType should handle a valid patch just under the max limit", func(t *testing.T) {
patchBody := []byte(`[{"op":"add","path":"/foo","value":0` + strings.Repeat(" ", 3*1024*1024-100) + `}]`)
err = rest.Patch(types.JSONPatchType).AbsPath(fmt.Sprintf("/api/v1/namespaces/default/secrets/test")).
Body(patchBody).Do().Error()
Body(patchBody).Do(context.TODO()).Error()
if err != nil {
t.Errorf("unexpected error: %v", err)
}
@@ -103,7 +104,7 @@ func TestMaxResourceSize(t *testing.T) {
t.Run("MergePatchType should handle a patch just under the max limit", func(t *testing.T) {
patchBody := []byte(`{"value":` + strings.Repeat("[", 3*1024*1024/2-100) + strings.Repeat("]", 3*1024*1024/2-100) + `}`)
err = rest.Patch(types.MergePatchType).AbsPath(fmt.Sprintf("/api/v1/namespaces/default/secrets/test")).
Body(patchBody).Do().Error()
Body(patchBody).Do(context.TODO()).Error()
if err != nil && !apierrors.IsBadRequest(err) {
t.Errorf("expected success or bad request err, got %v", err)
}
@@ -111,7 +112,7 @@ func TestMaxResourceSize(t *testing.T) {
t.Run("MergePatchType should handle a valid patch just under the max limit", func(t *testing.T) {
patchBody := []byte(`{"value":0` + strings.Repeat(" ", 3*1024*1024-100) + `}`)
err = rest.Patch(types.MergePatchType).AbsPath(fmt.Sprintf("/api/v1/namespaces/default/secrets/test")).
Body(patchBody).Do().Error()
Body(patchBody).Do(context.TODO()).Error()
if err != nil {
t.Errorf("unexpected error: %v", err)
}
@@ -119,7 +120,7 @@ func TestMaxResourceSize(t *testing.T) {
t.Run("StrategicMergePatchType should handle a patch just under the max limit", func(t *testing.T) {
patchBody := []byte(`{"value":` + strings.Repeat("[", 3*1024*1024/2-100) + strings.Repeat("]", 3*1024*1024/2-100) + `}`)
err = rest.Patch(types.StrategicMergePatchType).AbsPath(fmt.Sprintf("/api/v1/namespaces/default/secrets/test")).
Body(patchBody).Do().Error()
Body(patchBody).Do(context.TODO()).Error()
if err != nil && !apierrors.IsBadRequest(err) {
t.Errorf("expected success or bad request err, got %v", err)
}
@@ -127,7 +128,7 @@ func TestMaxResourceSize(t *testing.T) {
t.Run("StrategicMergePatchType should handle a valid patch just under the max limit", func(t *testing.T) {
patchBody := []byte(`{"value":0` + strings.Repeat(" ", 3*1024*1024-100) + `}`)
err = rest.Patch(types.StrategicMergePatchType).AbsPath(fmt.Sprintf("/api/v1/namespaces/default/secrets/test")).
Body(patchBody).Do().Error()
Body(patchBody).Do(context.TODO()).Error()
if err != nil {
t.Errorf("unexpected error: %v", err)
}
@@ -135,7 +136,7 @@ func TestMaxResourceSize(t *testing.T) {
t.Run("ApplyPatchType should handle a patch just under the max limit", func(t *testing.T) {
patchBody := []byte(`{"value":` + strings.Repeat("[", 3*1024*1024/2-100) + strings.Repeat("]", 3*1024*1024/2-100) + `}`)
err = rest.Patch(types.ApplyPatchType).Param("fieldManager", "test").AbsPath(fmt.Sprintf("/api/v1/namespaces/default/secrets/test")).
Body(patchBody).Do().Error()
Body(patchBody).Do(context.TODO()).Error()
if err != nil && !apierrors.IsBadRequest(err) {
t.Errorf("expected success or bad request err, got %#v", err)
}
@@ -143,14 +144,14 @@ func TestMaxResourceSize(t *testing.T) {
t.Run("ApplyPatchType should handle a valid patch just under the max limit", func(t *testing.T) {
patchBody := []byte(`{"apiVersion":"v1","kind":"Secret"` + strings.Repeat(" ", 3*1024*1024-100) + `}`)
err = rest.Patch(types.ApplyPatchType).Param("fieldManager", "test").AbsPath(fmt.Sprintf("/api/v1/namespaces/default/secrets/test")).
Body(patchBody).Do().Error()
Body(patchBody).Do(context.TODO()).Error()
if err != nil {
t.Errorf("unexpected error: %v", err)
}
})
t.Run("Delete should limit the request body size", func(t *testing.T) {
err = c.Delete().AbsPath(fmt.Sprintf("/api/v1/namespaces/default/secrets/test")).
Body(hugeData).Do().Error()
Body(hugeData).Do(context.TODO()).Error()
if err == nil {
t.Fatalf("unexpected no error")
}
@@ -174,7 +175,7 @@ values: ` + strings.Repeat("[", 3*1024*1024))
SetHeader("Content-Type", "application/yaml").
AbsPath("/api/v1/namespaces/default/configmaps").
Body(yamlBody).
DoRaw()
DoRaw(context.TODO())
if !apierrors.IsRequestEntityTooLargeError(err) {
t.Errorf("expected too large error, got %v", err)
}
@@ -194,7 +195,7 @@ values: ` + strings.Repeat("[", 3*1024*1024/2-500) + strings.Repeat("]", 3*1024*
SetHeader("Content-Type", "application/yaml").
AbsPath("/api/v1/namespaces/default/configmaps").
Body(yamlBody).
DoRaw()
DoRaw(context.TODO())
if !apierrors.IsBadRequest(err) {
t.Errorf("expected bad request, got %v", err)
}
@@ -214,7 +215,7 @@ values: ` + strings.Repeat("[", 3*1024*1024-1000))
SetHeader("Content-Type", "application/yaml").
AbsPath("/api/v1/namespaces/default/configmaps").
Body(yamlBody).
DoRaw()
DoRaw(context.TODO())
if !apierrors.IsBadRequest(err) {
t.Errorf("expected bad request, got %v", err)
}
@@ -235,7 +236,7 @@ values: ` + strings.Repeat("[", 3*1024*1024-1000))
SetHeader("Content-Type", "application/json").
AbsPath("/api/v1/namespaces/default/configmaps").
Body(jsonBody).
DoRaw()
DoRaw(context.TODO())
if !apierrors.IsRequestEntityTooLargeError(err) {
t.Errorf("expected too large error, got %v", err)
}
@@ -256,7 +257,7 @@ values: ` + strings.Repeat("[", 3*1024*1024-1000))
SetHeader("Content-Type", "application/json").
AbsPath("/api/v1/namespaces/default/configmaps").
Body(jsonBody).
DoRaw()
DoRaw(context.TODO())
// TODO(liggitt): expect bad request on deep nesting, rather than success on dropped unknown field data
if err != nil && !apierrors.IsBadRequest(err) {
t.Errorf("expected bad request, got %v", err)
@@ -278,7 +279,7 @@ values: ` + strings.Repeat("[", 3*1024*1024-1000))
SetHeader("Content-Type", "application/json").
AbsPath("/api/v1/namespaces/default/configmaps").
Body(jsonBody).
DoRaw()
DoRaw(context.TODO())
if !apierrors.IsBadRequest(err) {
t.Errorf("expected bad request, got %v", err)
}

View File

@@ -17,6 +17,7 @@ limitations under the License.
package apiserver
import (
"context"
"fmt"
"sync"
"sync/atomic"
@@ -24,7 +25,7 @@ import (
"github.com/google/uuid"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -83,7 +84,7 @@ func TestPatchConflicts(t *testing.T) {
Resource("secrets").
Name("test").
Body([]byte(fmt.Sprintf(`{"metadata":{"labels":{"%s":"%s"}, "ownerReferences":[{"$patch":"delete","uid":"%s"}]}}`, labelName, value, UIDs[i]))).
Do().
Do(context.TODO()).
Get()
if apierrors.IsConflict(err) {

View File

@@ -17,6 +17,7 @@ limitations under the License.
package podlogs
import (
"context"
"net"
"net/http"
"net/http/httptest"
@@ -137,7 +138,7 @@ func TestInsecurePodLogs(t *testing.T) {
t.Fatal(err)
}
insecureResult := clientSet.CoreV1().Pods("ns").GetLogs(pod.Name, &corev1.PodLogOptions{InsecureSkipTLSVerifyBackend: true}).Do()
insecureResult := clientSet.CoreV1().Pods("ns").GetLogs(pod.Name, &corev1.PodLogOptions{InsecureSkipTLSVerifyBackend: true}).Do(context.TODO())
if err := insecureResult.Error(); err != nil {
t.Fatal(err)
}
@@ -147,7 +148,7 @@ func TestInsecurePodLogs(t *testing.T) {
t.Fatal(insecureStatusCode)
}
secureResult := clientSet.CoreV1().Pods("ns").GetLogs(pod.Name, &corev1.PodLogOptions{}).Do()
secureResult := clientSet.CoreV1().Pods("ns").GetLogs(pod.Name, &corev1.PodLogOptions{}).Do(context.TODO())
if err := secureResult.Error(); err == nil || !strings.Contains(err.Error(), "x509: certificate signed by unknown authority") {
t.Fatal(err)
}

View File

@@ -17,6 +17,7 @@ limitations under the License.
package apiserver
import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
@@ -238,7 +239,7 @@ func TestServerSidePrint(t *testing.T) {
if mapping.Scope.Name() == meta.RESTScopeNameNamespace {
req = req.Namespace(ns.Name)
}
body, err := req.Resource(mapping.Resource.Resource).SetHeader("Accept", tableParam).Do().Raw()
body, err := req.Resource(mapping.Resource.Resource).SetHeader("Accept", tableParam).Do(context.TODO()).Raw()
if err != nil {
t.Errorf("unexpected error getting %s: %v", gvk, err)
continue

View File

@@ -17,6 +17,7 @@ limitations under the License.
package auth
import (
"context"
"fmt"
"io/ioutil"
"strings"
@@ -84,7 +85,7 @@ func TestNodeAuthorizer(t *testing.T) {
// Wait for a healthy server
for {
result := superuserClient.CoreV1().RESTClient().Get().AbsPath("/healthz").Do()
result := superuserClient.CoreV1().RESTClient().Get().AbsPath("/healthz").Do(context.TODO())
_, err := result.Raw()
if err == nil {
break

View File

@@ -684,7 +684,7 @@ func TestBootstrapping(t *testing.T) {
t.Errorf("missing cluster-admin: %v", clusterRoles)
healthBytes, err := clientset.Discovery().RESTClient().Get().AbsPath("/healthz/poststarthook/rbac/bootstrap-roles").DoRaw()
healthBytes, err := clientset.Discovery().RESTClient().Get().AbsPath("/healthz/poststarthook/rbac/bootstrap-roles").DoRaw(context.TODO())
if err != nil {
t.Error(err)
}

View File

@@ -17,6 +17,7 @@ limitations under the License.
package client
import (
"context"
"fmt"
"log"
"reflect"
@@ -263,7 +264,7 @@ func TestPatch(t *testing.T) {
Namespace("default").
Name(name).
Body(body).
Do()
Do(context.TODO())
if result.Error() != nil {
return result.Error()
}
@@ -341,7 +342,7 @@ func TestPatchWithCreateOnUpdate(t *testing.T) {
}
patchEndpoint := func(json []byte) (runtime.Object, error) {
return c.CoreV1().RESTClient().Patch(types.MergePatchType).Resource("endpoints").Namespace("default").Name("patchendpoint").Body(json).Do().Get()
return c.CoreV1().RESTClient().Patch(types.MergePatchType).Resource("endpoints").Namespace("default").Name("patchendpoint").Body(json).Do(context.TODO()).Get()
}
// Make sure patch doesn't get to CreateOnUpdate
@@ -496,7 +497,7 @@ func TestSingleWatch(t *testing.T) {
Watch: true,
FieldSelector: fields.OneTermEqualSelector("metadata.name", "event-9").String(),
}, metav1.ParameterCodec).
Watch()
Watch(context.TODO())
if err != nil {
t.Fatalf("Failed watch: %v", err)
@@ -757,7 +758,7 @@ func runSelfLinkTestOnNamespace(t *testing.T, c clientset.Interface, namespace s
if err != nil {
t.Fatalf("Failed creating selflinktest pod: %v", err)
}
if err = c.CoreV1().RESTClient().Get().RequestURI(pod.SelfLink).Do().Into(pod); err != nil {
if err = c.CoreV1().RESTClient().Get().RequestURI(pod.SelfLink).Do(context.TODO()).Into(pod); err != nil {
t.Errorf("Failed listing pod with supplied self link '%v': %v", pod.SelfLink, err)
}
@@ -766,7 +767,7 @@ func runSelfLinkTestOnNamespace(t *testing.T, c clientset.Interface, namespace s
t.Errorf("Failed listing pods: %v", err)
}
if err = c.CoreV1().RESTClient().Get().RequestURI(podList.SelfLink).Do().Into(podList); err != nil {
if err = c.CoreV1().RESTClient().Get().RequestURI(podList.SelfLink).Do(context.TODO()).Into(podList); err != nil {
t.Errorf("Failed listing pods with supplied self link '%v': %v", podList.SelfLink, err)
}
@@ -777,7 +778,7 @@ func runSelfLinkTestOnNamespace(t *testing.T, c clientset.Interface, namespace s
continue
}
found = true
err = c.CoreV1().RESTClient().Get().RequestURI(item.SelfLink).Do().Into(pod)
err = c.CoreV1().RESTClient().Get().RequestURI(item.SelfLink).Do(context.TODO()).Into(pod)
if err != nil {
t.Errorf("Failed listing pod with supplied self link '%v': %v", item.SelfLink, err)
}

View File

@@ -146,7 +146,7 @@ func StartRealMasterOrDie(t *testing.T, configFuncs ...func(*options.ServerRunOp
attempt := 0
if err := wait.PollImmediate(time.Second, time.Minute, func() (done bool, err error) {
// wait for the server to be healthy
result := kubeClient.RESTClient().Get().AbsPath("/healthz").Do()
result := kubeClient.RESTClient().Get().AbsPath("/healthz").Do(context.TODO())
content, _ := result.Raw()
lastHealth = string(content)
if errResult := result.Error(); errResult != nil {

View File

@@ -17,6 +17,7 @@ limitations under the License.
package apiserver
import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
@@ -228,7 +229,7 @@ func waitForWardleRunning(t *testing.T, wardleToKASKubeConfig *rest.Config, ward
return false, nil
}
healthStatus := 0
result := wardleClient.Discovery().RESTClient().Get().AbsPath("/healthz").Do().StatusCode(&healthStatus)
result := wardleClient.Discovery().RESTClient().Get().AbsPath("/healthz").Do(context.TODO()).StatusCode(&healthStatus)
lastHealthContent, lastHealthErr = result.Raw()
if healthStatus != http.StatusOK {
return false, nil
@@ -345,7 +346,7 @@ func createKubeConfig(clientCfg *rest.Config) *clientcmdapi.Config {
}
func readResponse(client rest.Interface, location string) ([]byte, error) {
return client.Get().AbsPath(location).DoRaw()
return client.Get().AbsPath(location).DoRaw(context.TODO())
}
func testAPIGroupList(t *testing.T, client rest.Interface) {

View File

@@ -28,6 +28,7 @@ import (
"github.com/go-openapi/spec"
"github.com/google/uuid"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/wait"
authauthenticator "k8s.io/apiserver/pkg/authentication/authenticator"
@@ -216,7 +217,7 @@ func startMasterOrDie(masterConfig *master.Config, incomingServer *httptest.Serv
}
var lastHealthContent []byte
err = wait.PollImmediate(100*time.Millisecond, 30*time.Second, func() (bool, error) {
result := privilegedClient.Get().AbsPath("/healthz").Do()
result := privilegedClient.Get().AbsPath("/healthz").Do(context.TODO())
status := 0
result.StatusCode(&status)
if status == 200 {

View File

@@ -17,6 +17,7 @@ limitations under the License.
package framework
import (
"context"
"io/ioutil"
"net"
"net/http"
@@ -150,7 +151,7 @@ func StartTestServer(t *testing.T, stopCh <-chan struct{}, setup TestServerSetup
}
healthStatus := 0
kubeClient.Discovery().RESTClient().Get().AbsPath("/healthz").Do().StatusCode(&healthStatus)
kubeClient.Discovery().RESTClient().Get().AbsPath("/healthz").Do(context.TODO()).StatusCode(&healthStatus)
if healthStatus != http.StatusOK {
return false, nil
}

Some files were not shown because too many files have changed in this diff Show More