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

Route hostnames are not admitted correctly #11496

Closed
liggitt opened this issue Oct 21, 2016 · 3 comments
Closed

Route hostnames are not admitted correctly #11496

liggitt opened this issue Oct 21, 2016 · 3 comments

Comments

@liggitt
Copy link
Contributor

liggitt commented Oct 21, 2016

Route hostnames are not admitted correctly

Version

openshift v1.4.0-alpha.0+2016d68
kubernetes v1.4.0+776c994
etcd 3.1.0-alpha.1

Steps To Reproduce

Create routes with these hostnames in ns1:

  • foo.example.com
  • ns1.com
  • com

Create routes with these hostnames in ns2:

  • bar.example.com
  • ns2.com
  • com
Current Result
  • bar.example.com incorrectly gets error that example.com is already taken
  • ns2.com gets error that "com" is already taken
  • neither com route is admitted and neither has an error recorded
Expected Result
  • all routes in ns1 are admitted
  • all routes except com in ns2 are admitted
  • com route in ns2 is rejected with an "AlreadyClaimed" error
@liggitt
Copy link
Contributor Author

liggitt commented Oct 22, 2016

testcase I used:

func TestValidRouteAdmissionFuzzing(t *testing.T) {
    p := &fakePlugin{}

    admitAll := func(route *routeapi.Route) (error, bool) { return nil, true }
    recorder := rejectionRecorder{rejections: make(map[string]string)}
    admitter := NewHostAdmitter(p, RouteAdmissionFunc(admitAll), true, recorder)

    oldest := unversioned.Time{Time: time.Now()}

    makeRoute := func(ns, name, host string, creationTimestamp unversioned.Time) *routeapi.Route {
        return &routeapi.Route{
            ObjectMeta: kapi.ObjectMeta{Name: name, Namespace: ns, CreationTimestamp: creationTimestamp},
            Spec:       routeapi.RouteSpec{Host: host},
        }
    }
    makeTime := func(d time.Duration) unversioned.Time {
        return unversioned.Time{Time: oldest.Add(d)}
    }

    routes := []*routeapi.Route{
        makeRoute("ns1", "r1", "net", makeTime(0*time.Second)),
        makeRoute("ns2", "r2", "com", makeTime(1*time.Second)),
        makeRoute("ns3", "r3", "domain1.com", makeTime(2*time.Second)),
        makeRoute("ns4", "r4", "domain2.com", makeTime(3*time.Second)),
        makeRoute("ns5", "r5", "foo.domain1.com", makeTime(4*time.Second)),
        makeRoute("ns6", "r6", "bar.domain1.com", makeTime(5*time.Second)),
        makeRoute("ns7", "r7", "*.foo.domain1.com", makeTime(6*time.Second)),
        makeRoute("ns8", "r8", "*.bar.domain1.com", makeTime(7*time.Second)),
    }

    rand.Seed(1)
    existing := sets.NewInt()
    errors := sets.NewString()
    for i := 0; i < 1000; i++ {
        add := false
        switch {
        case len(existing) == len(routes):
            add = false
        case len(existing) == 0:
            add = true
        default:
            add = (rand.Intn(4) > 0)
        }

        index := 0
        if add {
            index = rand.Intn(len(routes))
            if existing.Has(index) {
                // t.Logf("%d: updated route %d", i, index)
                if err := admitter.HandleRoute(watch.Modified, routes[index]); err != nil {
                    errors.Insert(fmt.Sprintf("error updating route %s/%s: %v", routes[index].Namespace, routes[index].Name, err.Error()))
                }
            } else {
                // t.Logf("%d: added route %d", i, index)
                if err := admitter.HandleRoute(watch.Added, routes[index]); err != nil {
                    errors.Insert(fmt.Sprintf("error adding route %s/%s: %v", routes[index].Namespace, routes[index].Name, err.Error()))
                }
            }
            existing.Insert(index)
        } else {
            index = existing.List()[rand.Intn(len(existing))]
            // t.Logf("%d: deleted route %d", i, index)
            if err := admitter.HandleRoute(watch.Deleted, routes[index]); err != nil {
                errors.Insert(fmt.Sprintf("error deleting route %s/%s: %v", routes[index].Namespace, routes[index].Name, err.Error()))
            }
            existing.Delete(index)
        }
    }

    if len(errors) > 0 {
        t.Errorf("Unexpected errors:\n%s", strings.Join(errors.List(), "\n"))
    }
    if len(recorder.rejections) > 0 {
        t.Errorf("Unexpected rejections: %#v", recorder.rejections)
    }
}

@ramr
Copy link
Contributor

ramr commented Oct 26, 2016

Fixes in PR: #11550

@knobunc
Copy link
Contributor

knobunc commented Nov 2, 2016

#11550 has landed.

@knobunc knobunc closed this as completed Nov 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants