Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addresses issue #6596. #15510

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 1 addition & 9 deletions pkg/api/ref.go
Expand Up @@ -32,10 +32,6 @@ var (
ErrNoSelfLink = errors.New("selfLink was empty, can't make reference")
)

// ForTesting_ReferencesAllowBlankSelfLinks can be set to true in tests to avoid
// "ErrNoSelfLink" errors.
var ForTesting_ReferencesAllowBlankSelfLinks = false

// 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.
Expand Down Expand Up @@ -68,11 +64,7 @@ func GetReference(obj runtime.Object) (*ObjectReference, error) {
if version == "" {
selfLink := meta.SelfLink()
if selfLink == "" {
if ForTesting_ReferencesAllowBlankSelfLinks {
version = "testing"
} else {
return nil, ErrNoSelfLink
}
return nil, ErrNoSelfLink
} else {
selfLinkUrl, err := url.Parse(selfLink)
if err != nil {
Expand Down
4 changes: 0 additions & 4 deletions pkg/controller/daemon/controller_test.go
Expand Up @@ -38,10 +38,6 @@ var (
alwaysReady = func() bool { return true }
)

func init() {
api.ForTesting_ReferencesAllowBlankSelfLinks = true
}

func getKey(ds *extensions.DaemonSet, t *testing.T) string {
if key, err := controller.KeyFunc(ds); err != nil {
t.Errorf("Unexpected error getting key for ds %v: %v", ds.Name, err)
Expand Down
Expand Up @@ -24,6 +24,7 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/api/resource"
"k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
"k8s.io/kubernetes/pkg/volume"
"k8s.io/kubernetes/pkg/volume/host_path"
Expand Down Expand Up @@ -169,7 +170,6 @@ func TestExampleObjects(t *testing.T) {
}

func TestBindingWithExamples(t *testing.T) {
api.ForTesting_ReferencesAllowBlankSelfLinks = true
o := testclient.NewObjects(api.Scheme, api.Scheme)
if err := testclient.AddObjectsFromPath("../../../docs/user-guide/persistent-volumes/claims/claim-01.yaml", o, api.Scheme); err != nil {
t.Fatal(err)
Expand All @@ -186,11 +186,13 @@ func TestBindingWithExamples(t *testing.T) {
if err != nil {
t.Errorf("Unexpected error getting PV from client: %v", err)
}
pv.ObjectMeta.SelfLink = testapi.Default.SelfLink("pv", "")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the name should be any. as that is the name being requested on line 184. Using (or not using) the name doesn't seem to break anything in testing but it reads easier.

Another option would be to get it from pv and similar variables. I think ObjectMeta would carry the name.

Similar notes for other testapi.Default.SelfLink calls.


claim, error := client.PersistentVolumeClaims("ns").Get("any")
if error != nil {
t.Errorf("Unexpected error getting PVC from client: %v", err)
}
claim.ObjectMeta.SelfLink = testapi.Default.SelfLink("pvc", "")

volumeIndex := NewPersistentVolumeOrderedIndex()
mockClient := &mockBinderClient{
Expand Down Expand Up @@ -273,7 +275,6 @@ func TestBindingWithExamples(t *testing.T) {
}

func TestMissingFromIndex(t *testing.T) {
api.ForTesting_ReferencesAllowBlankSelfLinks = true
o := testclient.NewObjects(api.Scheme, api.Scheme)
if err := testclient.AddObjectsFromPath("../../../docs/user-guide/persistent-volumes/claims/claim-01.yaml", o, api.Scheme); err != nil {
t.Fatal(err)
Expand All @@ -289,11 +290,13 @@ func TestMissingFromIndex(t *testing.T) {
if err != nil {
t.Errorf("Unexpected error getting PV from client: %v", err)
}
pv.ObjectMeta.SelfLink = testapi.Default.SelfLink("pv", "")

claim, error := client.PersistentVolumeClaims("ns").Get("any")
if error != nil {
t.Errorf("Unexpected error getting PVC from client: %v", err)
}
claim.ObjectMeta.SelfLink = testapi.Default.SelfLink("pvc", "")

volumeIndex := NewPersistentVolumeOrderedIndex()
mockClient := &mockBinderClient{
Expand Down
4 changes: 0 additions & 4 deletions pkg/controller/replication/replication_controller_test.go
Expand Up @@ -39,10 +39,6 @@ import (

var alwaysReady = func() bool { return true }

func init() {
api.ForTesting_ReferencesAllowBlankSelfLinks = true
}

func getKey(rc *api.ReplicationController, t *testing.T) string {
if key, err := controller.KeyFunc(rc); err != nil {
t.Errorf("Unexpected error getting key for rc %v: %v", rc.Name, err)
Expand Down
4 changes: 0 additions & 4 deletions pkg/kubectl/describe_test.go
Expand Up @@ -39,10 +39,6 @@ type describeClient struct {
client.Interface
}

func init() {
api.ForTesting_ReferencesAllowBlankSelfLinks = true
}

func TestDescribePod(t *testing.T) {
fake := testclient.NewSimpleFake(&api.Pod{
ObjectMeta: api.ObjectMeta{
Expand Down
1 change: 0 additions & 1 deletion pkg/kubelet/dockertools/manager_test.go
Expand Up @@ -963,7 +963,6 @@ func TestSyncPodsDoesNothing(t *testing.T) {
}

func TestSyncPodWithPullPolicy(t *testing.T) {
api.ForTesting_ReferencesAllowBlankSelfLinks = true
dm, fakeDocker := newTestDockerManager()
puller := dm.dockerPuller.(*FakeDockerPuller)
puller.HasImages = []string{"existing_one", "want:latest"}
Expand Down
1 change: 0 additions & 1 deletion pkg/kubelet/kubelet_test.go
Expand Up @@ -59,7 +59,6 @@ import (
)

func init() {
api.ForTesting_ReferencesAllowBlankSelfLinks = true
util.ReallyCrash = true
}

Expand Down