Replace godep with dep

This commit is contained in:
Manuel de Brito Fontes 2017-10-06 17:26:14 -03:00
parent 1e7489927c
commit bf5616c65b
14883 changed files with 3937406 additions and 361781 deletions

39
vendor/k8s.io/kubernetes/pkg/fieldpath/BUILD generated vendored Normal file
View file

@ -0,0 +1,39 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
"go_test",
)
go_library(
name = "go_default_library",
srcs = [
"doc.go",
"fieldpath.go",
],
deps = ["//vendor/k8s.io/apimachinery/pkg/api/meta:go_default_library"],
)
go_test(
name = "go_default_test",
srcs = ["fieldpath_test.go"],
library = ":go_default_library",
deps = [
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
)

19
vendor/k8s.io/kubernetes/pkg/fieldpath/doc.go generated vendored Normal file
View file

@ -0,0 +1,19 @@
/*
Copyright 2015 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 fieldpath supplies methods for extracting fields from objects
// given a path to a field.
package fieldpath // import "k8s.io/kubernetes/pkg/fieldpath"

59
vendor/k8s.io/kubernetes/pkg/fieldpath/fieldpath.go generated vendored Normal file
View file

@ -0,0 +1,59 @@
/*
Copyright 2015 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 fieldpath
import (
"fmt"
"strings"
"k8s.io/apimachinery/pkg/api/meta"
)
// FormatMap formats map[string]string to a string.
func FormatMap(m map[string]string) (fmtStr string) {
for key, value := range m {
fmtStr += fmt.Sprintf("%v=%q\n", key, value)
}
fmtStr = strings.TrimSuffix(fmtStr, "\n")
return
}
// ExtractFieldPathAsString extracts the field from the given object
// and returns it as a string. The object must be a pointer to an
// API type.
func ExtractFieldPathAsString(obj interface{}, fieldPath string) (string, error) {
accessor, err := meta.Accessor(obj)
if err != nil {
return "", nil
}
switch fieldPath {
case "metadata.annotations":
return FormatMap(accessor.GetAnnotations()), nil
case "metadata.labels":
return FormatMap(accessor.GetLabels()), nil
case "metadata.name":
return accessor.GetName(), nil
case "metadata.namespace":
return accessor.GetNamespace(), nil
case "metadata.uid":
return string(accessor.GetUID()), nil
}
return "", fmt.Errorf("unsupported fieldPath: %v", fieldPath)
}

View file

@ -0,0 +1,118 @@
/*
Copyright 2015 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 fieldpath
import (
"strings"
"testing"
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func TestExtractFieldPathAsString(t *testing.T) {
cases := []struct {
name string
fieldPath string
obj interface{}
expectedValue string
expectedMessageFragment string
}{
{
name: "not an API object",
fieldPath: "metadata.name",
obj: "",
expectedMessageFragment: "expected struct",
},
{
name: "ok - namespace",
fieldPath: "metadata.namespace",
obj: &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Namespace: "object-namespace",
},
},
expectedValue: "object-namespace",
},
{
name: "ok - name",
fieldPath: "metadata.name",
obj: &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "object-name",
},
},
expectedValue: "object-name",
},
{
name: "ok - labels",
fieldPath: "metadata.labels",
obj: &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{"key": "value"},
},
},
expectedValue: "key=\"value\"",
},
{
name: "ok - labels bslash n",
fieldPath: "metadata.labels",
obj: &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{"key": "value\n"},
},
},
expectedValue: "key=\"value\\n\"",
},
{
name: "ok - annotations",
fieldPath: "metadata.annotations",
obj: &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{"builder": "john-doe"},
},
},
expectedValue: "builder=\"john-doe\"",
},
{
name: "invalid expression",
fieldPath: "metadata.whoops",
obj: &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Namespace: "object-namespace",
},
},
expectedMessageFragment: "unsupported fieldPath",
},
}
for _, tc := range cases {
actual, err := ExtractFieldPathAsString(tc.obj, tc.fieldPath)
if err != nil {
if tc.expectedMessageFragment != "" {
if !strings.Contains(err.Error(), tc.expectedMessageFragment) {
t.Errorf("%v: unexpected error message: %q, expected to contain %q", tc.name, err, tc.expectedMessageFragment)
}
} else {
t.Errorf("%v: unexpected error: %v", tc.name, err)
}
} else if e := tc.expectedValue; e != "" && e != actual {
t.Errorf("%v: unexpected result; got %q, expected %q", tc.name, actual, e)
}
}
}