Update ingress godeps

This commit is contained in:
Manuel de Brito Fontes 2016-08-10 14:53:55 -04:00
parent d43021b3f1
commit 28db8fb16d
1068 changed files with 461467 additions and 117300 deletions

View file

@ -21,13 +21,14 @@ import (
"k8s.io/kubernetes/pkg/fields"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/storage"
)
// AttrFunc returns label and field sets for List or Watch to compare against, or an error.
type AttrFunc func(obj runtime.Object) (label labels.Set, field fields.Set, err error)
// ObjectMetaFieldsSet returns a fields set that represents the ObjectMeta.
func ObjectMetaFieldsSet(objectMeta api.ObjectMeta, hasNamespaceField bool) fields.Set {
// ObjectMetaFieldsSet returns a fields that represents the ObjectMeta.
func ObjectMetaFieldsSet(objectMeta *api.ObjectMeta, hasNamespaceField bool) fields.Set {
if !hasNamespaceField {
return fields.Set{
"metadata.name": objectMeta.Name,
@ -50,9 +51,10 @@ func MergeFieldsSets(source fields.Set, fragment fields.Set) fields.Set {
// SelectionPredicate implements a generic predicate that can be passed to
// GenericRegistry's List or Watch methods. Implements the Matcher interface.
type SelectionPredicate struct {
Label labels.Selector
Field fields.Selector
GetAttrs AttrFunc
Label labels.Selector
Field fields.Selector
GetAttrs AttrFunc
IndexFields []string
}
// Matches returns true if the given object's labels and fields (as
@ -66,7 +68,11 @@ func (s *SelectionPredicate) Matches(obj runtime.Object) (bool, error) {
if err != nil {
return false, err
}
return s.Label.Matches(labels) && s.Field.Matches(fields), nil
matched := s.Label.Matches(labels)
if s.Field != nil {
matched = (matched && s.Field.Matches(fields))
}
return matched, nil
}
// MatchesSingle will return (name, true) if and only if s.Field matches on the object's
@ -79,6 +85,20 @@ func (s *SelectionPredicate) MatchesSingle() (string, bool) {
return "", false
}
// For any index defined by IndexFields, if a matcher can match only (a subset)
// of objects that return <value> for a given index, a pair (<index name>, <value>)
// wil be returned.
// TODO: Consider supporting also labels.
func (s *SelectionPredicate) MatcherIndex() []storage.MatchValue {
var result []storage.MatchValue
for _, field := range s.IndexFields {
if value, ok := s.Field.RequiresExactMatch(field); ok {
result = append(result, storage.MatchValue{IndexName: field, Value: value})
}
}
return result
}
// Matcher can return true if an object matches the Matcher's selection
// criteria. If it is known that the matcher will match only a single object
// then MatchesSingle should return the key of that object and true. This is an
@ -93,50 +113,13 @@ type Matcher interface {
// include the object's namespace.
MatchesSingle() (key string, matchesSingleObject bool)
// TODO: when we start indexing objects, add something like the below:
// MatchesIndices() (indexName []string, indexValue []string)
// where indexName/indexValue are the same length.
}
// MatcherFunc makes a matcher from the provided function. For easy definition
// of matchers for testing. Note: use SelectionPredicate above for real code!
func MatcherFunc(f func(obj runtime.Object) (bool, error)) Matcher {
return matcherFunc(f)
}
type matcherFunc func(obj runtime.Object) (bool, error)
// Matches calls the embedded function.
func (m matcherFunc) Matches(obj runtime.Object) (bool, error) {
return m(obj)
}
// MatchesSingle always returns "", false-- because this is a predicate
// implementation of Matcher.
func (m matcherFunc) MatchesSingle() (string, bool) {
return "", false
}
// MatchOnKey returns a matcher that will send only the object matching key
// through the matching function f. For testing!
// Note: use SelectionPredicate above for real code!
func MatchOnKey(key string, f func(obj runtime.Object) (bool, error)) Matcher {
return matchKey{key, f}
}
type matchKey struct {
key string
matcherFunc
}
// MatchesSingle always returns its key, true.
func (m matchKey) MatchesSingle() (string, bool) {
return m.key, true
// For any known index, if a matcher can match only (a subset) of objects
// that return <value> for a given index, a pair (<index name>, <value>)
// will be returned.
MatcherIndex() []storage.MatchValue
}
var (
// Assert implementations match the interface.
_ = Matcher(matchKey{})
_ = Matcher(&SelectionPredicate{})
_ = Matcher(matcherFunc(nil))
)

View file

@ -16,13 +16,13 @@ limitations under the License.
package generic
import (
pkgstorage "k8s.io/kubernetes/pkg/storage"
)
import "k8s.io/kubernetes/pkg/storage/storagebackend"
// RESTOptions is set of configuration options to generic registries.
type RESTOptions struct {
Storage pkgstorage.Interface
StorageConfig *storagebackend.Config
Decorator StorageDecorator
DeleteCollectionWorkers int
ResourcePrefix string
}

View file

@ -17,28 +17,44 @@ limitations under the License.
package generic
import (
"github.com/golang/glog"
"k8s.io/kubernetes/pkg/api/rest"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/storage"
"k8s.io/kubernetes/pkg/storage/storagebackend"
"k8s.io/kubernetes/pkg/storage/storagebackend/factory"
)
// StorageDecorator is a function signature for producing
// a storage.Interface from given parameters.
type StorageDecorator func(
storageInterface storage.Interface,
config *storagebackend.Config,
capacity int,
objectType runtime.Object,
resourcePrefix string,
scopeStrategy rest.NamespaceScopedStrategy,
newListFunc func() runtime.Object) storage.Interface
newListFunc func() runtime.Object,
trigger storage.TriggerPublisherFunc) storage.Interface
// Returns given 'storageInterface' without any decoration.
func UndecoratedStorage(
storageInterface storage.Interface,
config *storagebackend.Config,
capacity int,
objectType runtime.Object,
resourcePrefix string,
scopeStrategy rest.NamespaceScopedStrategy,
newListFunc func() runtime.Object) storage.Interface {
return storageInterface
newListFunc func() runtime.Object,
trigger storage.TriggerPublisherFunc) storage.Interface {
return NewRawStorage(config)
}
// NewRawStorage creates the low level kv storage. This is a work-around for current
// two layer of same storage interface.
// TODO: Once cacher is enabled on all registries (event registry is special), we will remove this method.
func NewRawStorage(config *storagebackend.Config) storage.Interface {
s, err := factory.Create(*config)
if err != nil {
glog.Fatalf("Unable to create storage backend: config (%v), err (%v)", config, err)
}
return s
}

View file

@ -42,7 +42,7 @@ type thirdPartyObjectConverter struct {
converter runtime.ObjectConvertor
}
func (t *thirdPartyObjectConverter) ConvertToVersion(in runtime.Object, outVersion unversioned.GroupVersion) (out runtime.Object, err error) {
func (t *thirdPartyObjectConverter) ConvertToVersion(in runtime.Object, outVersion runtime.GroupVersioner) (out runtime.Object, err error) {
switch in.(type) {
// This seems weird, but in this case the ThirdPartyResourceData is really just a wrapper on the raw 3rd party data.
// The actual thing printed/sent to server is the actual raw third party resource data, which only has one version.
@ -53,8 +53,8 @@ func (t *thirdPartyObjectConverter) ConvertToVersion(in runtime.Object, outVersi
}
}
func (t *thirdPartyObjectConverter) Convert(in, out interface{}) error {
return t.converter.Convert(in, out)
func (t *thirdPartyObjectConverter) Convert(in, out, context interface{}) error {
return t.converter.Convert(in, out, context)
}
func (t *thirdPartyObjectConverter) ConvertFieldLabel(version, kind, label, value string) (string, string, error) {
@ -152,6 +152,27 @@ func (t *thirdPartyResourceDataMapper) RESTMapping(gk unversioned.GroupKind, ver
return mapping, nil
}
func (t *thirdPartyResourceDataMapper) RESTMappings(gk unversioned.GroupKind) ([]*meta.RESTMapping, error) {
if gk.Group != t.group {
return nil, fmt.Errorf("unknown group %q expected %s", gk.Group, t.group)
}
if gk.Kind != "ThirdPartyResourceData" {
return nil, fmt.Errorf("unknown kind %s expected %s", gk.Kind, t.kind)
}
// TODO figure out why we're doing this rewriting
extensionGK := unversioned.GroupKind{Group: extensions.GroupName, Kind: "ThirdPartyResourceData"}
mappings, err := t.mapper.RESTMappings(extensionGK)
if err != nil {
return nil, err
}
for _, m := range mappings {
m.ObjectConvertor = &thirdPartyObjectConverter{m.ObjectConvertor}
}
return mappings, nil
}
func (t *thirdPartyResourceDataMapper) AliasesForResource(resource string) ([]string, bool) {
return t.mapper.AliasesForResource(resource)
}
@ -213,11 +234,11 @@ func (t *thirdPartyResourceDataCodecFactory) StreamingSerializerForMediaType(med
}
}
func (t *thirdPartyResourceDataCodecFactory) EncoderForVersion(s runtime.Encoder, gv unversioned.GroupVersion) runtime.Encoder {
return &thirdPartyResourceDataEncoder{delegate: t.delegate.EncoderForVersion(s, gv), gvk: gv.WithKind(t.kind)}
func (t *thirdPartyResourceDataCodecFactory) EncoderForVersion(s runtime.Encoder, gv runtime.GroupVersioner) runtime.Encoder {
return &thirdPartyResourceDataEncoder{delegate: t.delegate.EncoderForVersion(s, gv), gvk: t.encodeGV.WithKind(t.kind)}
}
func (t *thirdPartyResourceDataCodecFactory) DecoderToVersion(s runtime.Decoder, gv unversioned.GroupVersion) runtime.Decoder {
func (t *thirdPartyResourceDataCodecFactory) DecoderToVersion(s runtime.Decoder, gv runtime.GroupVersioner) runtime.Decoder {
return NewDecoder(t.delegate.DecoderToVersion(s, gv), t.kind)
}
@ -248,35 +269,42 @@ func parseObject(data []byte) (map[string]interface{}, error) {
return mapObj, nil
}
func (t *thirdPartyResourceDataDecoder) populate(data []byte) (runtime.Object, error) {
func (t *thirdPartyResourceDataDecoder) populate(data []byte) (runtime.Object, *unversioned.GroupVersionKind, error) {
mapObj, err := parseObject(data)
if err != nil {
return nil, err
return nil, nil, err
}
return t.populateFromObject(mapObj, data)
}
func (t *thirdPartyResourceDataDecoder) populateFromObject(mapObj map[string]interface{}, data []byte) (runtime.Object, error) {
func (t *thirdPartyResourceDataDecoder) populateFromObject(mapObj map[string]interface{}, data []byte) (runtime.Object, *unversioned.GroupVersionKind, error) {
typeMeta := unversioned.TypeMeta{}
if err := json.Unmarshal(data, &typeMeta); err != nil {
return nil, err
return nil, nil, err
}
gv, err := unversioned.ParseGroupVersion(typeMeta.APIVersion)
if err != nil {
return nil, nil, err
}
gvk := gv.WithKind(typeMeta.Kind)
isList := strings.HasSuffix(typeMeta.Kind, "List")
switch {
case !isList && (len(t.kind) == 0 || typeMeta.Kind == t.kind):
result := &extensions.ThirdPartyResourceData{}
if err := t.populateResource(result, mapObj, data); err != nil {
return nil, err
return nil, nil, err
}
return result, nil
return result, &gvk, nil
case isList && (len(t.kind) == 0 || typeMeta.Kind == t.kind+"List"):
list := &extensions.ThirdPartyResourceDataList{}
if err := t.populateListResource(list, mapObj); err != nil {
return nil, err
return nil, nil, err
}
return list, nil
return list, &gvk, nil
default:
return nil, fmt.Errorf("unexpected kind: %s, expected %s", typeMeta.Kind, t.kind)
return nil, nil, fmt.Errorf("unexpected kind: %s, expected %s", typeMeta.Kind, t.kind)
}
}
@ -338,11 +366,7 @@ func (t *thirdPartyResourceDataDecoder) Decode(data []byte, gvk *unversioned.Gro
return t.delegate.Decode(data, gvk, into)
}
}
obj, err := t.populate(data)
if err != nil {
return nil, nil, err
}
return obj, gvk, nil
return t.populate(data)
}
switch o := into.(type) {
case *extensions.ThirdPartyResourceData:
@ -356,14 +380,14 @@ func (t *thirdPartyResourceDataDecoder) Decode(data []byte, gvk *unversioned.Gro
return t.delegate.Decode(data, gvk, into)
}
}
obj, err := t.populate(data)
obj, outGVK, err := t.populate(data)
if err != nil {
return nil, nil, err
}
o.Objects = []runtime.Object{
obj,
}
return o, gvk, nil
return o, outGVK, nil
default:
return t.delegate.Decode(data, gvk, into)
}
@ -451,13 +475,6 @@ func (t *thirdPartyResourceDataDecoder) populateListResource(objIn *extensions.T
return nil
}
const template = `{
"kind": "%s",
"apiVersion": "%s",
"metadata": {},
"items": [ %s ]
}`
type thirdPartyResourceDataEncoder struct {
delegate runtime.Encoder
gvk unversioned.GroupVersionKind
@ -488,19 +505,41 @@ func (t *thirdPartyResourceDataEncoder) Encode(obj runtime.Object, stream io.Wri
case *extensions.ThirdPartyResourceData:
return encodeToJSON(obj, stream)
case *extensions.ThirdPartyResourceDataList:
// TODO: There must be a better way to do this...
dataStrings := make([]string, len(obj.Items))
// TODO: There are likely still better ways to do this...
listItems := make([]json.RawMessage, len(obj.Items))
for ix := range obj.Items {
buff := &bytes.Buffer{}
err := encodeToJSON(&obj.Items[ix], buff)
if err != nil {
return err
}
dataStrings[ix] = buff.String()
listItems[ix] = json.RawMessage(buff.Bytes())
}
gv := t.gvk.GroupVersion()
fmt.Fprintf(stream, template, t.gvk.Kind+"List", gv.String(), strings.Join(dataStrings, ","))
return nil
if t.gvk.Empty() {
return fmt.Errorf("thirdPartyResourceDataEncoder was not given a target version")
}
encMap := struct {
Kind string `json:"kind,omitempty"`
Items []json.RawMessage `json:"items"`
Metadata unversioned.ListMeta `json:"metadata,omitempty"`
APIVersion string `json:"apiVersion,omitempty"`
}{
Kind: t.gvk.Kind + "List",
Items: listItems,
Metadata: obj.ListMeta,
APIVersion: t.gvk.GroupVersion().String(),
}
encBytes, err := json.Marshal(encMap)
if err != nil {
return err
}
_, err = stream.Write(encBytes)
return err
case *versioned.InternalEvent:
event := &versioned.Event{}
err := versioned.Convert_versioned_InternalEvent_to_versioned_Event(obj, event, nil)

View file

@ -48,7 +48,7 @@ func (strategy) NamespaceScoped() bool {
return true
}
func (strategy) PrepareForCreate(obj runtime.Object) {
func (strategy) PrepareForCreate(ctx api.Context, obj runtime.Object) {
}
func (strategy) Validate(ctx api.Context, obj runtime.Object) field.ErrorList {
@ -63,7 +63,7 @@ func (strategy) AllowCreateOnUpdate() bool {
return false
}
func (strategy) PrepareForUpdate(obj, old runtime.Object) {
func (strategy) PrepareForUpdate(ctx api.Context, obj, old runtime.Object) {
}
func (strategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) field.ErrorList {
@ -75,18 +75,21 @@ func (strategy) AllowUnconditionalUpdate() bool {
}
// Matcher returns a generic matcher for a given label and field selector.
func Matcher(label labels.Selector, field fields.Selector) generic.Matcher {
return generic.MatcherFunc(func(obj runtime.Object) (bool, error) {
sa, ok := obj.(*extensions.ThirdPartyResourceData)
if !ok {
return false, fmt.Errorf("not a ThirdPartyResourceData")
}
fields := SelectableFields(sa)
return label.Matches(labels.Set(sa.Labels)) && field.Matches(fields), nil
})
func Matcher(label labels.Selector, field fields.Selector) *generic.SelectionPredicate {
return &generic.SelectionPredicate{
Label: label,
Field: field,
GetAttrs: func(obj runtime.Object) (labels.Set, fields.Set, error) {
tprd, ok := obj.(*extensions.ThirdPartyResourceData)
if !ok {
return nil, nil, fmt.Errorf("not a ThirdPartyResourceData")
}
return labels.Set(tprd.Labels), SelectableFields(tprd), nil
},
}
}
// SelectableFields returns a label set that can be used for filter selection
func SelectableFields(obj *extensions.ThirdPartyResourceData) labels.Set {
return labels.Set{}
// SelectableFields returns a field set that can be used for filter selection
func SelectableFields(obj *extensions.ThirdPartyResourceData) fields.Set {
return nil
}