forked from barak/tarpoon
Add glide.yaml and vendor deps
This commit is contained in:
parent
db918f12ad
commit
5b3d5e81bd
18880 changed files with 5166045 additions and 1 deletions
41
vendor/k8s.io/kubernetes/pkg/labels/BUILD
generated
vendored
Normal file
41
vendor/k8s.io/kubernetes/pkg/labels/BUILD
generated
vendored
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
licenses(["notice"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_binary",
|
||||
"go_library",
|
||||
"go_test",
|
||||
"cgo_library",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"doc.go",
|
||||
"labels.go",
|
||||
"selector.go",
|
||||
],
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//pkg/selection:go_default_library",
|
||||
"//pkg/util/sets:go_default_library",
|
||||
"//pkg/util/validation:go_default_library",
|
||||
"//vendor:github.com/golang/glog",
|
||||
],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = [
|
||||
"labels_test.go",
|
||||
"selector_test.go",
|
||||
],
|
||||
library = "go_default_library",
|
||||
tags = ["automanaged"],
|
||||
deps = [
|
||||
"//pkg/selection:go_default_library",
|
||||
"//pkg/util/sets:go_default_library",
|
||||
],
|
||||
)
|
||||
19
vendor/k8s.io/kubernetes/pkg/labels/doc.go
generated
vendored
Normal file
19
vendor/k8s.io/kubernetes/pkg/labels/doc.go
generated
vendored
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
Copyright 2014 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// Package labels implements a simple label system, parsing and matching
|
||||
// selectors with sets of labels.
|
||||
package labels // import "k8s.io/kubernetes/pkg/labels"
|
||||
181
vendor/k8s.io/kubernetes/pkg/labels/labels.go
generated
vendored
Normal file
181
vendor/k8s.io/kubernetes/pkg/labels/labels.go
generated
vendored
Normal file
|
|
@ -0,0 +1,181 @@
|
|||
/*
|
||||
Copyright 2014 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package labels
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Labels allows you to present labels independently from their storage.
|
||||
type Labels interface {
|
||||
// Has returns whether the provided label exists.
|
||||
Has(label string) (exists bool)
|
||||
|
||||
// Get returns the value for the provided label.
|
||||
Get(label string) (value string)
|
||||
}
|
||||
|
||||
// Set is a map of label:value. It implements Labels.
|
||||
type Set map[string]string
|
||||
|
||||
// String returns all labels listed as a human readable string.
|
||||
// Conveniently, exactly the format that ParseSelector takes.
|
||||
func (ls Set) String() string {
|
||||
selector := make([]string, 0, len(ls))
|
||||
for key, value := range ls {
|
||||
selector = append(selector, key+"="+value)
|
||||
}
|
||||
// Sort for determinism.
|
||||
sort.StringSlice(selector).Sort()
|
||||
return strings.Join(selector, ",")
|
||||
}
|
||||
|
||||
// Has returns whether the provided label exists in the map.
|
||||
func (ls Set) Has(label string) bool {
|
||||
_, exists := ls[label]
|
||||
return exists
|
||||
}
|
||||
|
||||
// Get returns the value in the map for the provided label.
|
||||
func (ls Set) Get(label string) string {
|
||||
return ls[label]
|
||||
}
|
||||
|
||||
// AsSelector converts labels into a selectors.
|
||||
func (ls Set) AsSelector() Selector {
|
||||
return SelectorFromSet(ls)
|
||||
}
|
||||
|
||||
// AsSelectorPreValidated converts labels into a selector, but
|
||||
// assumes that labels are already validated and thus don't
|
||||
// preform any validation.
|
||||
// According to our measurements this is significantly faster
|
||||
// in codepaths that matter at high sccale.
|
||||
func (ls Set) AsSelectorPreValidated() Selector {
|
||||
return SelectorFromValidatedSet(ls)
|
||||
}
|
||||
|
||||
// FormatLables convert label map into plain string
|
||||
func FormatLabels(labelMap map[string]string) string {
|
||||
l := Set(labelMap).String()
|
||||
if l == "" {
|
||||
l = "<none>"
|
||||
}
|
||||
return l
|
||||
}
|
||||
|
||||
// Conflicts takes 2 maps and returns true if there a key match between
|
||||
// the maps but the value doesn't match, and returns false in other cases
|
||||
func Conflicts(labels1, labels2 Set) bool {
|
||||
small := labels1
|
||||
big := labels2
|
||||
if len(labels2) < len(labels1) {
|
||||
small = labels2
|
||||
big = labels1
|
||||
}
|
||||
|
||||
for k, v := range small {
|
||||
if val, match := big[k]; match {
|
||||
if val != v {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// Merge combines given maps, and does not check for any conflicts
|
||||
// between the maps. In case of conflicts, second map (labels2) wins
|
||||
func Merge(labels1, labels2 Set) Set {
|
||||
mergedMap := Set{}
|
||||
|
||||
for k, v := range labels1 {
|
||||
mergedMap[k] = v
|
||||
}
|
||||
for k, v := range labels2 {
|
||||
mergedMap[k] = v
|
||||
}
|
||||
return mergedMap
|
||||
}
|
||||
|
||||
// Equals returns true if the given maps are equal
|
||||
func Equals(labels1, labels2 Set) bool {
|
||||
if len(labels1) != len(labels2) {
|
||||
return false
|
||||
}
|
||||
|
||||
for k, v := range labels1 {
|
||||
value, ok := labels2[k]
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
if value != v {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// AreLabelsInWhiteList verifies if the provided label list
|
||||
// is in the provided whitelist and returns true, otherwise false.
|
||||
func AreLabelsInWhiteList(labels, whitelist Set) bool {
|
||||
if len(whitelist) == 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
for k, v := range labels {
|
||||
value, ok := whitelist[k]
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
if value != v {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// ConvertSelectorToLabelsMap converts selector string to labels map
|
||||
// and validates keys and values
|
||||
func ConvertSelectorToLabelsMap(selector string) (Set, error) {
|
||||
labelsMap := Set{}
|
||||
|
||||
if len(selector) == 0 {
|
||||
return labelsMap, nil
|
||||
}
|
||||
|
||||
labels := strings.Split(selector, ",")
|
||||
for _, label := range labels {
|
||||
l := strings.Split(label, "=")
|
||||
if len(l) != 2 {
|
||||
return labelsMap, fmt.Errorf("invalid selector: %s", l)
|
||||
}
|
||||
key := strings.TrimSpace(l[0])
|
||||
if err := validateLabelKey(key); err != nil {
|
||||
return labelsMap, err
|
||||
}
|
||||
value := strings.TrimSpace(l[1])
|
||||
if err := validateLabelValue(value); err != nil {
|
||||
return labelsMap, err
|
||||
}
|
||||
labelsMap[key] = value
|
||||
}
|
||||
return labelsMap, nil
|
||||
}
|
||||
231
vendor/k8s.io/kubernetes/pkg/labels/labels_test.go
generated
vendored
Normal file
231
vendor/k8s.io/kubernetes/pkg/labels/labels_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,231 @@
|
|||
/*
|
||||
Copyright 2014 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package labels
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func matches(t *testing.T, ls Set, want string) {
|
||||
if ls.String() != want {
|
||||
t.Errorf("Expected '%s', but got '%s'", want, ls.String())
|
||||
}
|
||||
}
|
||||
|
||||
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"}, "baz=qup,foo=bar")
|
||||
|
||||
// TODO: Make our label representation robust enough to handle labels
|
||||
// with ",=!" characters in their names.
|
||||
}
|
||||
|
||||
func TestLabelHas(t *testing.T) {
|
||||
labelHasTests := []struct {
|
||||
Ls Labels
|
||||
Key string
|
||||
Has bool
|
||||
}{
|
||||
{Set{"x": "y"}, "x", true},
|
||||
{Set{"x": ""}, "x", true},
|
||||
{Set{"x": "y"}, "foo", false},
|
||||
}
|
||||
for _, lh := range labelHasTests {
|
||||
if has := lh.Ls.Has(lh.Key); has != lh.Has {
|
||||
t.Errorf("%#v.Has(%#v) => %v, expected %v", lh.Ls, lh.Key, has, lh.Has)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestLabelGet(t *testing.T) {
|
||||
ls := Set{"x": "y"}
|
||||
if ls.Get("x") != "y" {
|
||||
t.Errorf("Set.Get is broken")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLabelConflict(t *testing.T) {
|
||||
tests := []struct {
|
||||
labels1 map[string]string
|
||||
labels2 map[string]string
|
||||
conflict bool
|
||||
}{
|
||||
{
|
||||
labels1: map[string]string{},
|
||||
labels2: map[string]string{},
|
||||
conflict: false,
|
||||
},
|
||||
{
|
||||
labels1: map[string]string{"env": "test"},
|
||||
labels2: map[string]string{"infra": "true"},
|
||||
conflict: false,
|
||||
},
|
||||
{
|
||||
labels1: map[string]string{"env": "test"},
|
||||
labels2: map[string]string{"infra": "true", "env": "test"},
|
||||
conflict: false,
|
||||
},
|
||||
{
|
||||
labels1: map[string]string{"env": "test"},
|
||||
labels2: map[string]string{"env": "dev"},
|
||||
conflict: true,
|
||||
},
|
||||
{
|
||||
labels1: map[string]string{"env": "test", "infra": "false"},
|
||||
labels2: map[string]string{"infra": "true", "color": "blue"},
|
||||
conflict: true,
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
conflict := Conflicts(Set(test.labels1), Set(test.labels2))
|
||||
if conflict != test.conflict {
|
||||
t.Errorf("expected: %v but got: %v", test.conflict, conflict)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestLabelMerge(t *testing.T) {
|
||||
tests := []struct {
|
||||
labels1 map[string]string
|
||||
labels2 map[string]string
|
||||
mergedLabels map[string]string
|
||||
}{
|
||||
{
|
||||
labels1: map[string]string{},
|
||||
labels2: map[string]string{},
|
||||
mergedLabels: map[string]string{},
|
||||
},
|
||||
{
|
||||
labels1: map[string]string{"infra": "true"},
|
||||
labels2: map[string]string{},
|
||||
mergedLabels: map[string]string{"infra": "true"},
|
||||
},
|
||||
{
|
||||
labels1: map[string]string{"infra": "true"},
|
||||
labels2: map[string]string{"env": "test", "color": "blue"},
|
||||
mergedLabels: map[string]string{"infra": "true", "env": "test", "color": "blue"},
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
mergedLabels := Merge(Set(test.labels1), Set(test.labels2))
|
||||
if !Equals(mergedLabels, test.mergedLabels) {
|
||||
t.Errorf("expected: %v but got: %v", test.mergedLabels, mergedLabels)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestLabelSelectorParse(t *testing.T) {
|
||||
tests := []struct {
|
||||
selector string
|
||||
labels map[string]string
|
||||
valid bool
|
||||
}{
|
||||
{
|
||||
selector: "",
|
||||
labels: map[string]string{},
|
||||
valid: true,
|
||||
},
|
||||
{
|
||||
selector: "x=a",
|
||||
labels: map[string]string{"x": "a"},
|
||||
valid: true,
|
||||
},
|
||||
{
|
||||
selector: "x=a,y=b,z=c",
|
||||
labels: map[string]string{"x": "a", "y": "b", "z": "c"},
|
||||
valid: true,
|
||||
},
|
||||
{
|
||||
selector: " x = a , y = b , z = c ",
|
||||
labels: map[string]string{"x": "a", "y": "b", "z": "c"},
|
||||
valid: true,
|
||||
},
|
||||
{
|
||||
selector: "color=green,env=test,service=front",
|
||||
labels: map[string]string{"color": "green", "env": "test", "service": "front"},
|
||||
valid: true,
|
||||
},
|
||||
{
|
||||
selector: "color=green, env=test, service=front",
|
||||
labels: map[string]string{"color": "green", "env": "test", "service": "front"},
|
||||
valid: true,
|
||||
},
|
||||
{
|
||||
selector: ",",
|
||||
labels: map[string]string{},
|
||||
valid: false,
|
||||
},
|
||||
{
|
||||
selector: "x",
|
||||
labels: map[string]string{},
|
||||
valid: false,
|
||||
},
|
||||
{
|
||||
selector: "x,y",
|
||||
labels: map[string]string{},
|
||||
valid: false,
|
||||
},
|
||||
{
|
||||
selector: "x=$y",
|
||||
labels: map[string]string{},
|
||||
valid: false,
|
||||
},
|
||||
{
|
||||
selector: "x!=y",
|
||||
labels: map[string]string{},
|
||||
valid: false,
|
||||
},
|
||||
{
|
||||
selector: "x==y",
|
||||
labels: map[string]string{},
|
||||
valid: false,
|
||||
},
|
||||
{
|
||||
selector: "x=a||y=b",
|
||||
labels: map[string]string{},
|
||||
valid: false,
|
||||
},
|
||||
{
|
||||
selector: "x in (y)",
|
||||
labels: map[string]string{},
|
||||
valid: false,
|
||||
},
|
||||
{
|
||||
selector: "x notin (y)",
|
||||
labels: map[string]string{},
|
||||
valid: false,
|
||||
},
|
||||
{
|
||||
selector: "x y",
|
||||
labels: map[string]string{},
|
||||
valid: false,
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
labels, err := ConvertSelectorToLabelsMap(test.selector)
|
||||
if test.valid && err != nil {
|
||||
t.Errorf("selector: %s, expected no error but got: %s", test.selector, err)
|
||||
} else if !test.valid && err == nil {
|
||||
t.Errorf("selector: %s, expected an error", test.selector)
|
||||
}
|
||||
|
||||
if !Equals(Set(labels), test.labels) {
|
||||
t.Errorf("expected: %s but got: %s", test.labels, labels)
|
||||
}
|
||||
}
|
||||
}
|
||||
835
vendor/k8s.io/kubernetes/pkg/labels/selector.go
generated
vendored
Normal file
835
vendor/k8s.io/kubernetes/pkg/labels/selector.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
575
vendor/k8s.io/kubernetes/pkg/labels/selector_test.go
generated
vendored
Normal file
575
vendor/k8s.io/kubernetes/pkg/labels/selector_test.go
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue