Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
493bc79c
Commit
493bc79c
authored
Sep 21, 2018
by
David Eads
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update client generator for local timeout
parent
7c4d097f
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
80 additions
and
0 deletions
+80
-0
timeout_test.go
staging/src/k8s.io/client-go/kubernetes_test/timeout_test.go
+60
-0
generator_for_type.go
...generator/cmd/client-gen/generators/generator_for_type.go
+20
-0
No files found.
staging/src/k8s.io/client-go/kubernetes_test/timeout_test.go
0 → 100644
View file @
493bc79c
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
kubernetes_test
import
(
"bytes"
"io/ioutil"
"net/http"
"testing"
"github.com/davecgh/go-spew/spew"
appsv1
"k8s.io/api/apps/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
manualfake
"k8s.io/client-go/rest/fake"
)
func
TestListTimeout
(
t
*
testing
.
T
)
{
fakeClient
:=
&
manualfake
.
RESTClient
{
GroupVersion
:
appsv1
.
SchemeGroupVersion
,
NegotiatedSerializer
:
scheme
.
Codecs
,
Client
:
manualfake
.
CreateHTTPClient
(
func
(
req
*
http
.
Request
)
(
*
http
.
Response
,
error
)
{
if
req
.
URL
.
Query
()
.
Get
(
"timeout"
)
!=
"21s"
{
t
.
Fatal
(
spew
.
Sdump
(
req
.
URL
.
Query
()))
}
return
&
http
.
Response
{
StatusCode
:
http
.
StatusNotFound
,
Body
:
ioutil
.
NopCloser
(
&
bytes
.
Buffer
{})},
nil
}),
}
clientConfig
:=
&
rest
.
Config
{
APIPath
:
"/apis"
,
ContentConfig
:
rest
.
ContentConfig
{
NegotiatedSerializer
:
scheme
.
Codecs
,
GroupVersion
:
&
appsv1
.
SchemeGroupVersion
,
},
}
restClient
,
_
:=
rest
.
RESTClientFor
(
clientConfig
)
restClient
.
Client
=
fakeClient
.
Client
realClient
:=
kubernetes
.
New
(
restClient
)
timeout
:=
int64
(
21
)
realClient
.
AppsV1
()
.
DaemonSets
(
""
)
.
List
(
metav1
.
ListOptions
{
TimeoutSeconds
:
&
timeout
})
realClient
.
AppsV1
()
.
DaemonSets
(
""
)
.
Watch
(
metav1
.
ListOptions
{
TimeoutSeconds
:
&
timeout
})
}
staging/src/k8s.io/code-generator/cmd/client-gen/generators/generator_for_type.go
View file @
493bc79c
...
@@ -387,11 +387,16 @@ func new$.type|publicPlural$(c *$.GroupGoName$$.Version$Client) *$.type|privateP
...
@@ -387,11 +387,16 @@ func new$.type|publicPlural$(c *$.GroupGoName$$.Version$Client) *$.type|privateP
var
listTemplate
=
`
var
listTemplate
=
`
// List takes label and field selectors, and returns the list of $.resultType|publicPlural$ that match those selectors.
// List takes label and field selectors, and returns the list of $.resultType|publicPlural$ that match those selectors.
func (c *$.type|privatePlural$) List(opts $.ListOptions|raw$) (result *$.resultType|raw$List, err error) {
func (c *$.type|privatePlural$) List(opts $.ListOptions|raw$) (result *$.resultType|raw$List, err error) {
var timeout time.Duration
if opts.TimeoutSeconds != nil{
timeout = time.Duration(*opts.TimeoutSeconds) * time.Second
}
result = &$.resultType|raw$List{}
result = &$.resultType|raw$List{}
err = c.client.Get().
err = c.client.Get().
$if .namespaced$Namespace(c.ns).$end$
$if .namespaced$Namespace(c.ns).$end$
Resource("$.type|resource$").
Resource("$.type|resource$").
VersionedParams(&opts, $.schemeParameterCodec|raw$).
VersionedParams(&opts, $.schemeParameterCodec|raw$).
Timeout(timeout).
Do().
Do().
Into(result)
Into(result)
return
return
...
@@ -401,6 +406,10 @@ func (c *$.type|privatePlural$) List(opts $.ListOptions|raw$) (result *$.resultT
...
@@ -401,6 +406,10 @@ func (c *$.type|privatePlural$) List(opts $.ListOptions|raw$) (result *$.resultT
var
listSubresourceTemplate
=
`
var
listSubresourceTemplate
=
`
// List takes $.type|raw$ name, label and field selectors, and returns the list of $.resultType|publicPlural$ that match those selectors.
// List takes $.type|raw$ name, label and field selectors, and returns the list of $.resultType|publicPlural$ that match those selectors.
func (c *$.type|privatePlural$) List($.type|private$Name string, opts $.ListOptions|raw$) (result *$.resultType|raw$List, err error) {
func (c *$.type|privatePlural$) List($.type|private$Name string, opts $.ListOptions|raw$) (result *$.resultType|raw$List, err error) {
var timeout time.Duration
if opts.TimeoutSeconds != nil{
timeout = time.Duration(*opts.TimeoutSeconds) * time.Second
}
result = &$.resultType|raw$List{}
result = &$.resultType|raw$List{}
err = c.client.Get().
err = c.client.Get().
$if .namespaced$Namespace(c.ns).$end$
$if .namespaced$Namespace(c.ns).$end$
...
@@ -408,6 +417,7 @@ func (c *$.type|privatePlural$) List($.type|private$Name string, opts $.ListOpti
...
@@ -408,6 +417,7 @@ func (c *$.type|privatePlural$) List($.type|private$Name string, opts $.ListOpti
Name($.type|private$Name).
Name($.type|private$Name).
SubResource("$.subresourcePath$").
SubResource("$.subresourcePath$").
VersionedParams(&opts, $.schemeParameterCodec|raw$).
VersionedParams(&opts, $.schemeParameterCodec|raw$).
Timeout(timeout).
Do().
Do().
Into(result)
Into(result)
return
return
...
@@ -461,10 +471,15 @@ func (c *$.type|privatePlural$) Delete(name string, options *$.DeleteOptions|raw
...
@@ -461,10 +471,15 @@ func (c *$.type|privatePlural$) Delete(name string, options *$.DeleteOptions|raw
var
deleteCollectionTemplate
=
`
var
deleteCollectionTemplate
=
`
// DeleteCollection deletes a collection of objects.
// DeleteCollection deletes a collection of objects.
func (c *$.type|privatePlural$) DeleteCollection(options *$.DeleteOptions|raw$, listOptions $.ListOptions|raw$) error {
func (c *$.type|privatePlural$) DeleteCollection(options *$.DeleteOptions|raw$, listOptions $.ListOptions|raw$) error {
var timeout time.Duration
if listOptions.TimeoutSeconds != nil{
timeout = time.Duration(*listOptions.TimeoutSeconds) * time.Second
}
return c.client.Delete().
return c.client.Delete().
$if .namespaced$Namespace(c.ns).$end$
$if .namespaced$Namespace(c.ns).$end$
Resource("$.type|resource$").
Resource("$.type|resource$").
VersionedParams(&listOptions, $.schemeParameterCodec|raw$).
VersionedParams(&listOptions, $.schemeParameterCodec|raw$).
Timeout(timeout).
Body(options).
Body(options).
Do().
Do().
Error()
Error()
...
@@ -553,11 +568,16 @@ func (c *$.type|privatePlural$) UpdateStatus($.type|private$ *$.type|raw$) (resu
...
@@ -553,11 +568,16 @@ func (c *$.type|privatePlural$) UpdateStatus($.type|private$ *$.type|raw$) (resu
var
watchTemplate
=
`
var
watchTemplate
=
`
// Watch returns a $.watchInterface|raw$ that watches the requested $.type|privatePlural$.
// Watch returns a $.watchInterface|raw$ that watches the requested $.type|privatePlural$.
func (c *$.type|privatePlural$) Watch(opts $.ListOptions|raw$) ($.watchInterface|raw$, error) {
func (c *$.type|privatePlural$) Watch(opts $.ListOptions|raw$) ($.watchInterface|raw$, error) {
var timeout time.Duration
if opts.TimeoutSeconds != nil{
timeout = time.Duration(*opts.TimeoutSeconds) * time.Second
}
opts.Watch = true
opts.Watch = true
return c.client.Get().
return c.client.Get().
$if .namespaced$Namespace(c.ns).$end$
$if .namespaced$Namespace(c.ns).$end$
Resource("$.type|resource$").
Resource("$.type|resource$").
VersionedParams(&opts, $.schemeParameterCodec|raw$).
VersionedParams(&opts, $.schemeParameterCodec|raw$).
Timeout(timeout).
Watch()
Watch()
}
}
`
`
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment