diff --git a/pkg/conversion/doc.go b/pkg/conversion/doc.go index 34fc08cc15b..f0626a569c2 100644 --- a/pkg/conversion/doc.go +++ b/pkg/conversion/doc.go @@ -28,7 +28,4 @@ limitations under the License. // reading. Currently, conversion writes JSON output, and interprets both JSON // and YAML input. // -// In the future, we plan to more explicitly separate the above two mechanisms, and -// add more serialization options, such as gob. -// package conversion diff --git a/pkg/conversion/scheme.go b/pkg/conversion/scheme.go index 39ecae81733..b2724eb496d 100644 --- a/pkg/conversion/scheme.go +++ b/pkg/conversion/scheme.go @@ -17,7 +17,6 @@ limitations under the License. package conversion import ( - "encoding/gob" "fmt" "reflect" ) @@ -113,10 +112,6 @@ func (s *Scheme) AddKnownTypes(version string, types ...interface{}) { knownTypes[t.Name()] = t s.typeToVersion[t] = version s.typeToKind[t] = append(s.typeToKind[t], t.Name()) - - // Register with gob so that DeepCopy can recognize all of our objects. This is creating a static list, but it appears that gob itself wants a static list - gobName := getGobTypeName(obj) - gob.RegisterName(gobName, obj) } } @@ -140,56 +135,6 @@ func (s *Scheme) AddKnownTypeWithName(version, kind string, obj interface{}) { knownTypes[kind] = t s.typeToVersion[t] = version s.typeToKind[t] = append(s.typeToKind[t], kind) - - // Register with gob so that DeepCopy can recognize all of our objects. This is creating a static list, but it appears that gob itself wants a static list - gobName := getGobTypeName(obj) - gob.RegisterName(gobName, obj) -} - -// getGobTypeName creates a fully unique type name for the object being passed through. There is a bug in the gob encoder's name mechanism that they are unwilling to fix -// due to backwards compatibility concerns. See https://github.com/golang/go/blob/master/src/encoding/gob/type.go#L857 . This gives us a fully qualified name to avoid -// conflicts amongst our objects and since we all agree on the names, this should be safe -func getGobTypeName(value interface{}) string { - // mostly copied from gob/type.go - - // Default to printed representation for unnamed types - rt := reflect.TypeOf(value) - name := rt.String() - - // But for named types (or pointers to them), qualify with import path (but see inner comment). - // Dereference one pointer looking for a named type. - star := "" - if rt.Name() == "" { - if pt := rt; pt.Kind() == reflect.Ptr { - star = "*" - // NOTE: The following line should be rt = pt.Elem() to implement - // what the comment above claims, but fixing it would break compatibility - // with existing gobs. - // - // Given package p imported as "full/p" with these definitions: - // package p - // type T1 struct { ... } - // this table shows the intended and actual strings used by gob to - // name the types: - // - // Type Correct string Actual string - // - // T1 full/p.T1 full/p.T1 - // *T1 *full/p.T1 *p.T1 - // - // The missing full path cannot be fixed without breaking existing gob decoders. - rt = pt.Elem() // TWEAKED HERE - } - } - if rt.Name() != "" { - if rt.PkgPath() == "" { - name = star + rt.Name() - } else { - name = star + rt.PkgPath() + "." + rt.Name() - } - } - - return name } // KnownTypes returns an array of the types that are known for a particular version. diff --git a/pkg/registry/service/rest_test.go b/pkg/registry/service/rest_test.go index 848126bac15..cb96eb4ca12 100644 --- a/pkg/registry/service/rest_test.go +++ b/pkg/registry/service/rest_test.go @@ -17,8 +17,6 @@ limitations under the License. package service import ( - "bytes" - "encoding/gob" "net" "strings" "testing" @@ -27,6 +25,7 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors" "github.com/GoogleCloudPlatform/kubernetes/pkg/api/rest" "github.com/GoogleCloudPlatform/kubernetes/pkg/api/rest/resttest" + "github.com/GoogleCloudPlatform/kubernetes/pkg/conversion" "github.com/GoogleCloudPlatform/kubernetes/pkg/fields" "github.com/GoogleCloudPlatform/kubernetes/pkg/labels" "github.com/GoogleCloudPlatform/kubernetes/pkg/registry/registrytest" @@ -54,13 +53,11 @@ func makeIPNet(t *testing.T) *net.IPNet { } func deepCloneService(svc *api.Service) *api.Service { - buff := new(bytes.Buffer) - enc := gob.NewEncoder(buff) - dec := gob.NewDecoder(buff) - enc.Encode(svc) - result := new(api.Service) - dec.Decode(result) - return result + value, err := conversion.DeepCopy(svc) + if err != nil { + panic("couldn't copy service") + } + return value.(*api.Service) } func TestServiceRegistryCreate(t *testing.T) {