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 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
}

View File

@@ -17,6 +17,7 @@ limitations under the License.
package master
import (
"context"
"encoding/json"
"fmt"
"strings"
@@ -211,7 +212,7 @@ func TestCRDOpenAPI(t *testing.T) {
etcd.CreateTestCRDs(t, apiextensionsclient, false, structuralCRD)
getPublishedSchema := func(defName string) (*spec.Schema, error) {
bs, err := kubeclient.RESTClient().Get().AbsPath("openapi", "v2").DoRaw()
bs, err := kubeclient.RESTClient().Get().AbsPath("openapi", "v2").DoRaw(context.TODO())
if err != nil {
return nil, err
}

View File

@@ -293,7 +293,7 @@ func getHealthz(checkName string, clientConfig *rest.Config) (int, error) {
return 0, fmt.Errorf("failed to create a client: %v", err)
}
result := client.CoreV1().RESTClient().Get().AbsPath(fmt.Sprintf("/healthz/%v", checkName)).Do()
result := client.CoreV1().RESTClient().Get().AbsPath(fmt.Sprintf("/healthz/%v", checkName)).Do(context.TODO())
status := 0
result.StatusCode(&status)
return status, nil

View File

@@ -18,6 +18,7 @@ package master
import (
"bytes"
"context"
"encoding/json"
"fmt"
"net/http"
@@ -27,6 +28,7 @@ import (
"time"
"github.com/go-openapi/spec"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
@@ -97,7 +99,7 @@ func TestRun(t *testing.T) {
}
func endpointReturnsStatusOK(client *kubernetes.Clientset, path string) bool {
res := client.CoreV1().RESTClient().Get().AbsPath(path).Do()
res := client.CoreV1().RESTClient().Get().AbsPath(path).Do(context.TODO())
var status int
res.StatusCode(&status)
return status == http.StatusOK
@@ -132,7 +134,7 @@ func TestOpenAPIDelegationChainPlumbing(t *testing.T) {
t.Fatalf("unexpected error: %v", err)
}
result := kubeclient.RESTClient().Get().AbsPath("/openapi/v2").Do()
result := kubeclient.RESTClient().Get().AbsPath("/openapi/v2").Do(context.TODO())
status := 0
result.StatusCode(&status)
if status != http.StatusOK {
@@ -343,7 +345,7 @@ func triggerSpecUpdateWithProbeCRD(t *testing.T, apiextensionsclient *apiextensi
}
func specHasProbe(clientset *apiextensionsclientset.Clientset, probe string) (bool, error) {
bs, err := clientset.RESTClient().Get().AbsPath("openapi", "v2").DoRaw()
bs, err := clientset.RESTClient().Get().AbsPath("openapi", "v2").DoRaw(context.TODO())
if err != nil {
return false, err
}
@@ -351,7 +353,7 @@ func specHasProbe(clientset *apiextensionsclientset.Clientset, probe string) (bo
}
func getOpenAPIPath(clientset *apiextensionsclientset.Clientset, path string) (spec.PathItem, bool, error) {
bs, err := clientset.RESTClient().Get().AbsPath("openapi", "v2").DoRaw()
bs, err := clientset.RESTClient().Get().AbsPath("openapi", "v2").DoRaw(context.TODO())
if err != nil {
return spec.PathItem{}, false, err
}
@@ -367,7 +369,7 @@ func getOpenAPIPath(clientset *apiextensionsclientset.Clientset, path string) (s
}
func getOpenAPIDefinition(clientset *apiextensionsclientset.Clientset, definition string) (spec.Schema, bool, error) {
bs, err := clientset.RESTClient().Get().AbsPath("openapi", "v2").DoRaw()
bs, err := clientset.RESTClient().Get().AbsPath("openapi", "v2").DoRaw(context.TODO())
if err != nil {
return spec.Schema{}, false, err
}

View File

@@ -17,6 +17,7 @@ limitations under the License.
package scale
import (
"context"
"encoding/json"
"path"
"strings"
@@ -145,7 +146,7 @@ func TestScaleSubresources(t *testing.T) {
urlPath := path.Join(prefix, gvr.Group, gvr.Version, "namespaces", "default", resourceParts[0], "test", resourceParts[1])
obj := &unstructured.Unstructured{}
getData, err := clientSet.CoreV1().RESTClient().Get().AbsPath(urlPath).DoRaw()
getData, err := clientSet.CoreV1().RESTClient().Get().AbsPath(urlPath).DoRaw(context.TODO())
if err != nil {
t.Errorf("error fetching %s: %v", urlPath, err)
continue
@@ -162,7 +163,7 @@ func TestScaleSubresources(t *testing.T) {
continue
}
updateData, err := clientSet.CoreV1().RESTClient().Put().AbsPath(urlPath).Body(getData).DoRaw()
updateData, err := clientSet.CoreV1().RESTClient().Put().AbsPath(urlPath).Body(getData).DoRaw(context.TODO())
if err != nil {
t.Errorf("error putting to %s: %v", urlPath, err)
t.Log(string(getData))

View File

@@ -23,6 +23,7 @@ a serivce
package main
import (
"context"
"flag"
"fmt"
"os"
@@ -273,7 +274,7 @@ func main() {
hostname, err := proxyRequest.
Namespace(ns).
Name("serve-hostnames").
DoRaw()
DoRaw(context.TODO())
if err != nil {
klog.Infof("After %v while making a proxy call got error %v", time.Since(start), err)
continue
@@ -303,7 +304,7 @@ func main() {
hostname, err := proxyRequest.
Namespace(ns).
Name("serve-hostnames").
DoRaw()
DoRaw(context.TODO())
klog.V(4).Infof("Proxy call in namespace %s took %v", ns, time.Since(t))
if err != nil {
klog.Warningf("Call failed during iteration %d query %d : %v", i, query, err)