diff --git a/pkg/api/ref.go b/pkg/api/ref.go index 8e1aa998cfe..fc6fd51fc52 100644 --- a/pkg/api/ref.go +++ b/pkg/api/ref.go @@ -17,18 +17,24 @@ limitations under the License. package api import ( + "errors" "fmt" "regexp" "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" ) +var ErrNilObject = errors.New("Can't reference a nil object") + var versionFromSelfLink = regexp.MustCompile("/api/([^/]*)/") // GetReference returns an ObjectReference which refers to the given // object, or an error if the object doesn't follow the conventions // that would allow this. func GetReference(obj runtime.Object) (*ObjectReference, error) { + if obj == nil { + return nil, ErrNilObject + } jsonBase, err := runtime.FindTypeMeta(obj) if err != nil { return nil, err diff --git a/pkg/api/ref_test.go b/pkg/api/ref_test.go index 32cb5fb7d36..eca95cf6195 100644 --- a/pkg/api/ref_test.go +++ b/pkg/api/ref_test.go @@ -80,6 +80,11 @@ func TestGetReference(t *testing.T) { ref: nil, shouldErr: true, }, + "errorNil": { + obj: nil, + ref: nil, + shouldErr: true, + }, } for name, item := range table {