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
a5d5527e
Commit
a5d5527e
authored
Jan 24, 2017
by
Dr. Stefan Schimanski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pkg/genericapiserver/endpoints: cutting off pkg/api deps
parent
b51252ab
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
29 deletions
+28
-29
apiserver_test.go
pkg/genericapiserver/endpoints/apiserver_test.go
+0
-0
watch_test.go
pkg/genericapiserver/endpoints/watch_test.go
+18
-20
fuzzer.go
...ng/src/k8s.io/apiserver/pkg/apis/example/fuzzer/fuzzer.go
+10
-9
No files found.
pkg/genericapiserver/endpoints/apiserver_test.go
View file @
a5d5527e
This diff is collapsed.
Click to expand it.
pkg/genericapiserver/endpoints/watch_test.go
View file @
a5d5527e
...
@@ -30,6 +30,7 @@ import (
...
@@ -30,6 +30,7 @@ import (
"time"
"time"
"golang.org/x/net/websocket"
"golang.org/x/net/websocket"
apiequality
"k8s.io/apimachinery/pkg/api/equality"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/labels"
...
@@ -38,7 +39,7 @@ import (
...
@@ -38,7 +39,7 @@ import (
"k8s.io/apimachinery/pkg/util/diff"
"k8s.io/apimachinery/pkg/util/diff"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/kubernetes/pkg/api
"
example
"k8s.io/apiserver/pkg/apis/example
"
"k8s.io/kubernetes/pkg/genericapiserver/endpoints/handlers"
"k8s.io/kubernetes/pkg/genericapiserver/endpoints/handlers"
apitesting
"k8s.io/kubernetes/pkg/genericapiserver/endpoints/testing"
apitesting
"k8s.io/kubernetes/pkg/genericapiserver/endpoints/testing"
"k8s.io/kubernetes/pkg/genericapiserver/registry/rest"
"k8s.io/kubernetes/pkg/genericapiserver/registry/rest"
...
@@ -72,13 +73,19 @@ var watchTestTable = []struct {
...
@@ -72,13 +73,19 @@ var watchTestTable = []struct {
{
watch
.
Deleted
,
&
apitesting
.
Simple
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"bar"
}}},
{
watch
.
Deleted
,
&
apitesting
.
Simple
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"bar"
}}},
}
}
var
podWatchTestTable
=
[]
struct
{
func
podWatchTestTable
()
[]
struct
{
t
watch
.
EventType
t
watch
.
EventType
obj
runtime
.
Object
obj
runtime
.
Object
}{
}
{
{
watch
.
Added
,
roundTripOrDie
(
codec
,
&
api
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"foo"
}})},
// creaze lazily here in a func because podWatchTestTable can only be used after all types are registered.
{
watch
.
Modified
,
roundTripOrDie
(
codec
,
&
api
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"bar"
}})},
return
[]
struct
{
{
watch
.
Deleted
,
roundTripOrDie
(
codec
,
&
api
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"bar"
}})},
t
watch
.
EventType
obj
runtime
.
Object
}{
{
watch
.
Added
,
roundTripOrDie
(
codec
,
&
example
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"foo"
}})},
{
watch
.
Modified
,
roundTripOrDie
(
codec
,
&
example
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"bar"
}})},
{
watch
.
Deleted
,
roundTripOrDie
(
codec
,
&
example
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"bar"
}})},
}
}
}
func
TestWatchWebsocket
(
t
*
testing
.
T
)
{
func
TestWatchWebsocket
(
t
*
testing
.
T
)
{
...
@@ -114,9 +121,6 @@ func TestWatchWebsocket(t *testing.T) {
...
@@ -114,9 +121,6 @@ func TestWatchWebsocket(t *testing.T) {
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Decode error: %v
\n
%v"
,
err
,
got
)
t
.
Fatalf
(
"Decode error: %v
\n
%v"
,
err
,
got
)
}
}
if
_
,
err
:=
api
.
GetReference
(
api
.
Scheme
,
gotObj
);
err
!=
nil
{
t
.
Errorf
(
"Unable to construct reference: %v"
,
err
)
}
if
e
,
a
:=
object
,
gotObj
;
!
reflect
.
DeepEqual
(
e
,
a
)
{
if
e
,
a
:=
object
,
gotObj
;
!
reflect
.
DeepEqual
(
e
,
a
)
{
t
.
Errorf
(
"Expected %#v, got %#v"
,
e
,
a
)
t
.
Errorf
(
"Expected %#v, got %#v"
,
e
,
a
)
}
}
...
@@ -167,9 +171,6 @@ func TestWatchWebsocketClientClose(t *testing.T) {
...
@@ -167,9 +171,6 @@ func TestWatchWebsocketClientClose(t *testing.T) {
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Decode error: %v
\n
%v"
,
err
,
got
)
t
.
Fatalf
(
"Decode error: %v
\n
%v"
,
err
,
got
)
}
}
if
_
,
err
:=
api
.
GetReference
(
api
.
Scheme
,
gotObj
);
err
!=
nil
{
t
.
Errorf
(
"Unable to construct reference: %v"
,
err
)
}
if
e
,
a
:=
object
,
gotObj
;
!
reflect
.
DeepEqual
(
e
,
a
)
{
if
e
,
a
:=
object
,
gotObj
;
!
reflect
.
DeepEqual
(
e
,
a
)
{
t
.
Errorf
(
"Expected %#v, got %#v"
,
e
,
a
)
t
.
Errorf
(
"Expected %#v, got %#v"
,
e
,
a
)
}
}
...
@@ -300,7 +301,7 @@ func TestWatchRead(t *testing.T) {
...
@@ -300,7 +301,7 @@ func TestWatchRead(t *testing.T) {
for
_
,
protocol
:=
range
protocols
{
for
_
,
protocol
:=
range
protocols
{
for
_
,
test
:=
range
testCases
{
for
_
,
test
:=
range
testCases
{
func
()
{
func
()
{
info
,
ok
:=
runtime
.
SerializerInfoForMediaType
(
api
.
C
odecs
.
SupportedMediaTypes
(),
test
.
MediaType
)
info
,
ok
:=
runtime
.
SerializerInfoForMediaType
(
c
odecs
.
SupportedMediaTypes
(),
test
.
MediaType
)
if
!
ok
||
info
.
StreamSerializer
==
nil
{
if
!
ok
||
info
.
StreamSerializer
==
nil
{
t
.
Fatal
(
info
)
t
.
Fatal
(
info
)
}
}
...
@@ -312,7 +313,7 @@ func TestWatchRead(t *testing.T) {
...
@@ -312,7 +313,7 @@ func TestWatchRead(t *testing.T) {
if
contentType
!=
"__default__"
&&
contentType
!=
test
.
ExpectedContentType
{
if
contentType
!=
"__default__"
&&
contentType
!=
test
.
ExpectedContentType
{
t
.
Errorf
(
"Unexpected content type: %#v"
,
contentType
)
t
.
Errorf
(
"Unexpected content type: %#v"
,
contentType
)
}
}
objectCodec
:=
api
.
C
odecs
.
DecoderToVersion
(
info
.
Serializer
,
testInternalGroupVersion
)
objectCodec
:=
c
odecs
.
DecoderToVersion
(
info
.
Serializer
,
testInternalGroupVersion
)
var
fr
io
.
ReadCloser
=
r
var
fr
io
.
ReadCloser
=
r
if
!
protocol
.
selfFraming
{
if
!
protocol
.
selfFraming
{
...
@@ -326,7 +327,7 @@ func TestWatchRead(t *testing.T) {
...
@@ -326,7 +327,7 @@ func TestWatchRead(t *testing.T) {
time
.
Sleep
(
time
.
Millisecond
)
time
.
Sleep
(
time
.
Millisecond
)
}
}
for
i
,
item
:=
range
podWatchTestTable
{
for
i
,
item
:=
range
podWatchTestTable
()
{
action
,
object
:=
item
.
t
,
item
.
obj
action
,
object
:=
item
.
t
,
item
.
obj
name
:=
fmt
.
Sprintf
(
"%s-%s-%d"
,
protocol
.
name
,
test
.
MediaType
,
i
)
name
:=
fmt
.
Sprintf
(
"%s-%s-%d"
,
protocol
.
name
,
test
.
MediaType
,
i
)
...
@@ -346,10 +347,7 @@ func TestWatchRead(t *testing.T) {
...
@@ -346,10 +347,7 @@ func TestWatchRead(t *testing.T) {
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"%s: Decode error: %v"
,
name
,
err
)
t
.
Fatalf
(
"%s: Decode error: %v"
,
name
,
err
)
}
}
if
_
,
err
:=
api
.
GetReference
(
api
.
Scheme
,
gotObj
);
err
!=
nil
{
if
e
,
a
:=
object
,
gotObj
;
!
apiequality
.
Semantic
.
DeepEqual
(
e
,
a
)
{
t
.
Errorf
(
"%s: Unable to construct reference: %v"
,
name
,
err
)
}
if
e
,
a
:=
object
,
gotObj
;
!
api
.
Semantic
.
DeepEqual
(
e
,
a
)
{
t
.
Errorf
(
"%s: different: %s"
,
name
,
diff
.
ObjectDiff
(
e
,
a
))
t
.
Errorf
(
"%s: different: %s"
,
name
,
diff
.
ObjectDiff
(
e
,
a
))
}
}
}
}
...
@@ -569,7 +567,7 @@ func TestWatchHTTPTimeout(t *testing.T) {
...
@@ -569,7 +567,7 @@ func TestWatchHTTPTimeout(t *testing.T) {
timeoutCh
:=
make
(
chan
time
.
Time
)
timeoutCh
:=
make
(
chan
time
.
Time
)
done
:=
make
(
chan
struct
{})
done
:=
make
(
chan
struct
{})
info
,
ok
:=
runtime
.
SerializerInfoForMediaType
(
api
.
C
odecs
.
SupportedMediaTypes
(),
runtime
.
ContentTypeJSON
)
info
,
ok
:=
runtime
.
SerializerInfoForMediaType
(
c
odecs
.
SupportedMediaTypes
(),
runtime
.
ContentTypeJSON
)
if
!
ok
||
info
.
StreamSerializer
==
nil
{
if
!
ok
||
info
.
StreamSerializer
==
nil
{
t
.
Fatal
(
info
)
t
.
Fatal
(
info
)
}
}
...
...
staging/src/k8s.io/apiserver/pkg/apis/example/fuzzer.go
→
staging/src/k8s.io/apiserver/pkg/apis/example/fuzzer
/fuzzer
.go
View file @
a5d5527e
...
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
...
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
*/
*/
package
example
package
fuzzer
import
(
import
(
"github.com/google/gofuzz"
"github.com/google/gofuzz"
...
@@ -23,6 +23,7 @@ import (
...
@@ -23,6 +23,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime"
runtimeserializer
"k8s.io/apimachinery/pkg/runtime/serializer"
runtimeserializer
"k8s.io/apimachinery/pkg/runtime/serializer"
examplev1
"k8s.io/apiserver/pkg/apis/example/v1"
examplev1
"k8s.io/apiserver/pkg/apis/example/v1"
"k8s.io/apiserver/pkg/apis/example"
)
)
// overrideGenericFuncs override some generic fuzzer funcs from k8s.io/apiserver in order to have more realistic
// overrideGenericFuncs override some generic fuzzer funcs from k8s.io/apiserver in order to have more realistic
...
@@ -38,7 +39,7 @@ func overrideGenericFuncs(t apitesting.TestingCommon, codecs runtimeserializer.C
...
@@ -38,7 +39,7 @@ func overrideGenericFuncs(t apitesting.TestingCommon, codecs runtimeserializer.C
ContentType
:
runtime
.
ContentTypeJSON
,
ContentType
:
runtime
.
ContentTypeJSON
,
}
}
}
else
{
}
else
{
types
:=
[]
runtime
.
Object
{
&
Pod
{}}
types
:=
[]
runtime
.
Object
{
&
example
.
Pod
{}}
t
:=
types
[
c
.
Rand
.
Intn
(
len
(
types
))]
t
:=
types
[
c
.
Rand
.
Intn
(
len
(
types
))]
c
.
Fuzz
(
t
)
c
.
Fuzz
(
t
)
*
j
=
t
*
j
=
t
...
@@ -46,7 +47,7 @@ func overrideGenericFuncs(t apitesting.TestingCommon, codecs runtimeserializer.C
...
@@ -46,7 +47,7 @@ func overrideGenericFuncs(t apitesting.TestingCommon, codecs runtimeserializer.C
},
},
func
(
r
*
runtime
.
RawExtension
,
c
fuzz
.
Continue
)
{
func
(
r
*
runtime
.
RawExtension
,
c
fuzz
.
Continue
)
{
// Pick an arbitrary type and fuzz it
// Pick an arbitrary type and fuzz it
types
:=
[]
runtime
.
Object
{
&
Pod
{}}
types
:=
[]
runtime
.
Object
{
&
example
.
Pod
{}}
obj
:=
types
[
c
.
Rand
.
Intn
(
len
(
types
))]
obj
:=
types
[
c
.
Rand
.
Intn
(
len
(
types
))]
c
.
Fuzz
(
obj
)
c
.
Fuzz
(
obj
)
...
@@ -65,7 +66,7 @@ func overrideGenericFuncs(t apitesting.TestingCommon, codecs runtimeserializer.C
...
@@ -65,7 +66,7 @@ func overrideGenericFuncs(t apitesting.TestingCommon, codecs runtimeserializer.C
func
exampleFuncs
(
t
apitesting
.
TestingCommon
)
[]
interface
{}
{
func
exampleFuncs
(
t
apitesting
.
TestingCommon
)
[]
interface
{}
{
return
[]
interface
{}{
return
[]
interface
{}{
func
(
s
*
PodSpec
,
c
fuzz
.
Continue
)
{
func
(
s
*
example
.
PodSpec
,
c
fuzz
.
Continue
)
{
c
.
FuzzNoCustom
(
s
)
c
.
FuzzNoCustom
(
s
)
// has a default value
// has a default value
ttl
:=
int64
(
30
)
ttl
:=
int64
(
30
)
...
@@ -78,18 +79,18 @@ func exampleFuncs(t apitesting.TestingCommon) []interface{} {
...
@@ -78,18 +79,18 @@ func exampleFuncs(t apitesting.TestingCommon) []interface{} {
s
.
SchedulerName
=
"default-scheduler"
s
.
SchedulerName
=
"default-scheduler"
}
}
},
},
func
(
j
*
PodPhase
,
c
fuzz
.
Continue
)
{
func
(
j
*
example
.
PodPhase
,
c
fuzz
.
Continue
)
{
statuses
:=
[]
PodPhase
{
"Pending"
,
"Running"
,
"Succeeded"
,
"Failed"
,
"Unknown"
}
statuses
:=
[]
example
.
PodPhase
{
"Pending"
,
"Running"
,
"Succeeded"
,
"Failed"
,
"Unknown"
}
*
j
=
statuses
[
c
.
Rand
.
Intn
(
len
(
statuses
))]
*
j
=
statuses
[
c
.
Rand
.
Intn
(
len
(
statuses
))]
},
},
func
(
rp
*
RestartPolicy
,
c
fuzz
.
Continue
)
{
func
(
rp
*
example
.
RestartPolicy
,
c
fuzz
.
Continue
)
{
policies
:=
[]
RestartPolicy
{
"Always"
,
"Never"
,
"OnFailure"
}
policies
:=
[]
example
.
RestartPolicy
{
"Always"
,
"Never"
,
"OnFailure"
}
*
rp
=
policies
[
c
.
Rand
.
Intn
(
len
(
policies
))]
*
rp
=
policies
[
c
.
Rand
.
Intn
(
len
(
policies
))]
},
},
}
}
}
}
func
Fu
zzerFu
ncs
(
t
apitesting
.
TestingCommon
,
codecs
runtimeserializer
.
CodecFactory
)
[]
interface
{}
{
func
Funcs
(
t
apitesting
.
TestingCommon
,
codecs
runtimeserializer
.
CodecFactory
)
[]
interface
{}
{
return
apitesting
.
MergeFuzzerFuncs
(
t
,
return
apitesting
.
MergeFuzzerFuncs
(
t
,
apitesting
.
GenericFuzzerFuncs
(
t
,
codecs
),
apitesting
.
GenericFuzzerFuncs
(
t
,
codecs
),
overrideGenericFuncs
(
t
,
codecs
),
overrideGenericFuncs
(
t
,
codecs
),
...
...
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