mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Rename LabelSet labels.Set
This commit is contained in:
parent
5c3e4fab58
commit
c534d070e5
@ -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]
|
||||
}
|
||||
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user