From c534d070e5a5cd3fadad68e912b5d78d8edb34ad Mon Sep 17 00:00:00 2001 From: Daniel Smith Date: Mon, 16 Jun 2014 19:22:46 -0700 Subject: [PATCH] Rename LabelSet labels.Set --- pkg/labels/labels.go | 6 ++-- pkg/labels/labels_test.go | 14 ++++----- pkg/labels/query.go | 6 ++-- pkg/labels/query_test.go | 44 ++++++++++++++--------------- pkg/registry/controller_registry.go | 2 +- pkg/registry/endpoints.go | 2 +- pkg/registry/etcd_registry.go | 2 +- pkg/registry/memory_registry.go | 2 +- pkg/registry/service_registry.go | 2 +- 9 files changed, 40 insertions(+), 40 deletions(-) diff --git a/pkg/labels/labels.go b/pkg/labels/labels.go index 96382c49cf4..38ec2ac0e94 100644 --- a/pkg/labels/labels.go +++ b/pkg/labels/labels.go @@ -26,11 +26,11 @@ type Labels interface { } // A map of label:value. Implements Labels. -type LabelSet map[string]string +type Set map[string]string // All labels listed as a human readable string. Conveiently, exactly the format // that ParseQuery takes. -func (ls LabelSet) String() string { +func (ls Set) String() string { query := make([]string, 0, len(ls)) for key, value := range ls { query = append(query, key+"="+value) @@ -39,6 +39,6 @@ func (ls LabelSet) String() string { } // Implement Labels interface. -func (ls LabelSet) Get(label string) string { +func (ls Set) Get(label string) string { return ls[label] } diff --git a/pkg/labels/labels_test.go b/pkg/labels/labels_test.go index a843074a408..76db00b951a 100644 --- a/pkg/labels/labels_test.go +++ b/pkg/labels/labels_test.go @@ -20,24 +20,24 @@ import ( "testing" ) -func matches(t *testing.T, ls LabelSet, want string) { +func matches(t *testing.T, ls Set, want string) { if ls.String() != want { t.Errorf("Expected '%s', but got '%s'", want, ls.String()) } } -func TestLabelSetString(t *testing.T) { - matches(t, LabelSet{"x": "y"}, "x=y") - matches(t, LabelSet{"foo": "bar"}, "foo=bar") - matches(t, LabelSet{"foo": "bar", "baz": "qup"}, "foo=bar,baz=qup") +func TestSetString(t *testing.T) { + matches(t, Set{"x": "y"}, "x=y") + matches(t, Set{"foo": "bar"}, "foo=bar") + matches(t, Set{"foo": "bar", "baz": "qup"}, "foo=bar,baz=qup") // TODO: Make our label representation robust enough to handel labels // with ",=!" characters in their names. } func TestLabelGet(t *testing.T) { - ls := LabelSet{"x": "y"} + ls := Set{"x": "y"} if ls.Get("x") != "y" { - t.Errorf("LabelSet.Get is broken") + t.Errorf("Set.Get is broken") } } diff --git a/pkg/labels/query.go b/pkg/labels/query.go index 0ad1c5d7a41..00f01bcb8b7 100644 --- a/pkg/labels/query.go +++ b/pkg/labels/query.go @@ -42,7 +42,7 @@ type queryTerm struct { // Exactly one of the below three items should be used. - // If non-nil, we match LabelSet l iff l[*label] == *value. + // If non-nil, we match Set l iff l[*label] == *value. label, value *string // A list of terms which must all match for this query term to return true. @@ -89,8 +89,8 @@ func try(queryPiece, op string) (lhs, rhs string, ok bool) { return "", "", false } -// Given a LabelSet, return a Query which will match exactly that LabelSet. -func QueryFromSet(ls LabelSet) Query { +// Given a Set, return a Query which will match exactly that Set. +func QueryFromSet(ls Set) Query { var query queryTerm for l, v := range ls { // Make a copy, because we're taking the address below diff --git a/pkg/labels/query_test.go b/pkg/labels/query_test.go index d42a4ede620..38dae8b4896 100644 --- a/pkg/labels/query_test.go +++ b/pkg/labels/query_test.go @@ -47,7 +47,7 @@ func TestQueryParse(t *testing.T) { } } -func expectMatch(t *testing.T, query string, ls LabelSet) { +func expectMatch(t *testing.T, query string, ls Set) { lq, err := ParseQuery(query) if err != nil { t.Errorf("Unable to parse %v as a query\n", query) @@ -58,7 +58,7 @@ func expectMatch(t *testing.T, query string, ls LabelSet) { } } -func expectNoMatch(t *testing.T, query string, ls LabelSet) { +func expectNoMatch(t *testing.T, query string, ls Set) { lq, err := ParseQuery(query) if err != nil { t.Errorf("Unable to parse %v as a query\n", query) @@ -70,21 +70,21 @@ func expectNoMatch(t *testing.T, query string, ls LabelSet) { } func TestEverything(t *testing.T) { - if !Everything().Matches(LabelSet{"x": "y"}) { + if !Everything().Matches(Set{"x": "y"}) { t.Errorf("Nil query didn't match") } } func TestLabelQueryMatches(t *testing.T) { - expectMatch(t, "", LabelSet{"x": "y"}) - expectMatch(t, "x=y", LabelSet{"x": "y"}) - expectMatch(t, "x=y,z=w", LabelSet{"x": "y", "z": "w"}) - expectMatch(t, "x!=y,z!=w", LabelSet{"x": "z", "z": "a"}) - expectNoMatch(t, "x=y", LabelSet{"x": "z"}) - expectNoMatch(t, "x=y,z=w", LabelSet{"x": "w", "z": "w"}) - expectNoMatch(t, "x!=y,z!=w", LabelSet{"x": "z", "z": "w"}) + expectMatch(t, "", Set{"x": "y"}) + expectMatch(t, "x=y", Set{"x": "y"}) + expectMatch(t, "x=y,z=w", Set{"x": "y", "z": "w"}) + expectMatch(t, "x!=y,z!=w", Set{"x": "z", "z": "a"}) + expectNoMatch(t, "x=y", Set{"x": "z"}) + expectNoMatch(t, "x=y,z=w", Set{"x": "w", "z": "w"}) + expectNoMatch(t, "x!=y,z!=w", Set{"x": "z", "z": "w"}) - labelset := LabelSet{ + labelset := Set{ "foo": "bar", "baz": "blah", } @@ -96,28 +96,28 @@ func TestLabelQueryMatches(t *testing.T) { expectNoMatch(t, "foo=bar,foobar=bar,baz=blah", labelset) } -func expectMatchDirect(t *testing.T, query, ls LabelSet) { +func expectMatchDirect(t *testing.T, query, ls Set) { if !QueryFromSet(query).Matches(ls) { t.Errorf("Wanted %s to match '%s', but it did not.\n", query, ls) } } -func expectNoMatchDirect(t *testing.T, query, ls LabelSet) { +func expectNoMatchDirect(t *testing.T, query, ls Set) { if QueryFromSet(query).Matches(ls) { t.Errorf("Wanted '%s' to not match '%s', but it did.", query, ls) } } -func TestLabelSetMatches(t *testing.T) { - labelset := LabelSet{ +func TestSetMatches(t *testing.T) { + labelset := Set{ "foo": "bar", "baz": "blah", } - expectMatchDirect(t, LabelSet{}, labelset) - expectMatchDirect(t, LabelSet{"foo": "bar"}, labelset) - expectMatchDirect(t, LabelSet{"baz": "blah"}, labelset) - expectMatchDirect(t, LabelSet{"foo": "bar", "baz": "blah"}, labelset) - expectNoMatchDirect(t, LabelSet{"foo": "=blah"}, labelset) - expectNoMatchDirect(t, LabelSet{"baz": "=bar"}, labelset) - expectNoMatchDirect(t, LabelSet{"foo": "=bar", "foobar": "bar", "baz": "blah"}, labelset) + expectMatchDirect(t, Set{}, labelset) + expectMatchDirect(t, Set{"foo": "bar"}, labelset) + expectMatchDirect(t, Set{"baz": "blah"}, labelset) + expectMatchDirect(t, Set{"foo": "bar", "baz": "blah"}, labelset) + expectNoMatchDirect(t, Set{"foo": "=blah"}, labelset) + expectNoMatchDirect(t, Set{"baz": "=bar"}, labelset) + expectNoMatchDirect(t, Set{"foo": "=bar", "foobar": "bar", "baz": "blah"}, labelset) } diff --git a/pkg/registry/controller_registry.go b/pkg/registry/controller_registry.go index b739082dcc3..1824ba965a2 100644 --- a/pkg/registry/controller_registry.go +++ b/pkg/registry/controller_registry.go @@ -40,7 +40,7 @@ func (storage *ControllerRegistryStorage) List(query labels.Query) (interface{}, controllers, err := storage.registry.ListControllers() if err == nil { for _, controller := range controllers { - if query.Matches(labels.LabelSet(controller.Labels)) { + if query.Matches(labels.Set(controller.Labels)) { result.Items = append(result.Items, controller) } } diff --git a/pkg/registry/endpoints.go b/pkg/registry/endpoints.go index cee7b424607..5601db2f136 100644 --- a/pkg/registry/endpoints.go +++ b/pkg/registry/endpoints.go @@ -42,7 +42,7 @@ func (e *EndpointController) SyncServiceEndpoints() error { } var resultErr error for _, service := range services.Items { - pods, err := e.podRegistry.ListPods(labels.QueryFromSet(labels.LabelSet(service.Labels))) + pods, err := e.podRegistry.ListPods(labels.QueryFromSet(labels.Set(service.Labels))) if err != nil { log.Printf("Error syncing service: %#v, skipping.", service) resultErr = err diff --git a/pkg/registry/etcd_registry.go b/pkg/registry/etcd_registry.go index 8bd882ced29..0f8062c96b5 100644 --- a/pkg/registry/etcd_registry.go +++ b/pkg/registry/etcd_registry.go @@ -75,7 +75,7 @@ func (registry *EtcdRegistry) ListPods(query labels.Query) ([]api.Pod, error) { return pods, err } for _, pod := range machinePods { - if query.Matches(labels.LabelSet(pod.Labels)) { + if query.Matches(labels.Set(pod.Labels)) { pods = append(pods, pod) } } diff --git a/pkg/registry/memory_registry.go b/pkg/registry/memory_registry.go index 0ff4263344e..a2175525914 100644 --- a/pkg/registry/memory_registry.go +++ b/pkg/registry/memory_registry.go @@ -39,7 +39,7 @@ func MakeMemoryRegistry() *MemoryRegistry { func (registry *MemoryRegistry) ListPods(query labels.Query) ([]api.Pod, error) { result := []api.Pod{} for _, value := range registry.podData { - if query.Matches(labels.LabelSet(value.Labels)) { + if query.Matches(labels.Set(value.Labels)) { result = append(result, value) } } diff --git a/pkg/registry/service_registry.go b/pkg/registry/service_registry.go index 102ffe174cc..aaf5c4f68a5 100644 --- a/pkg/registry/service_registry.go +++ b/pkg/registry/service_registry.go @@ -58,7 +58,7 @@ func (sr *ServiceRegistryStorage) List(query labels.Query) (interface{}, error) list.Kind = "cluster#serviceList" var filtered []api.Service for _, service := range list.Items { - if query.Matches(labels.LabelSet(service.Labels)) { + if query.Matches(labels.Set(service.Labels)) { filtered = append(filtered, service) } }