Commit a5d5527e authored by Dr. Stefan Schimanski's avatar Dr. Stefan Schimanski

pkg/genericapiserver/endpoints: cutting off pkg/api deps

parent b51252ab
...@@ -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.Codecs.SupportedMediaTypes(), test.MediaType) info, ok := runtime.SerializerInfoForMediaType(codecs.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.Codecs.DecoderToVersion(info.Serializer, testInternalGroupVersion) objectCodec := codecs.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.Codecs.SupportedMediaTypes(), runtime.ContentTypeJSON) info, ok := runtime.SerializerInfoForMediaType(codecs.SupportedMediaTypes(), runtime.ContentTypeJSON)
if !ok || info.StreamSerializer == nil { if !ok || info.StreamSerializer == nil {
t.Fatal(info) t.Fatal(info)
} }
......
...@@ -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 FuzzerFuncs(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),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment