code
stringlengths 12
335k
| docstring
stringlengths 20
20.8k
| func_name
stringlengths 1
105
| language
stringclasses 1
value | repo
stringclasses 498
values | path
stringlengths 5
172
| url
stringlengths 43
235
| license
stringclasses 4
values |
---|---|---|---|---|---|---|---|
func NewYAMLSerializer(meta MetaFactory, creater runtime.ObjectCreater, typer runtime.ObjectTyper) *Serializer {
return NewSerializerWithOptions(meta, creater, typer, SerializerOptions{true, false, false})
} | NewYAMLSerializer creates a YAML serializer that handles encoding versioned objects into the proper YAML form. If typer
is not nil, the object has the group, version, and kind fields set. This serializer supports only the subset of YAML that
matches JSON, and will error if constructs are used that do not serialize to JSON.
Deprecated: use NewSerializerWithOptions instead. | NewYAMLSerializer | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/serializer/json/json.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/serializer/json/json.go | Apache-2.0 |
func NewSerializerWithOptions(meta MetaFactory, creater runtime.ObjectCreater, typer runtime.ObjectTyper, options SerializerOptions) *Serializer {
return &Serializer{
meta: meta,
creater: creater,
typer: typer,
options: options,
identifier: identifier(options),
}
} | NewSerializerWithOptions creates a JSON/YAML serializer that handles encoding versioned objects into the proper JSON/YAML
form. If typer is not nil, the object has the group, version, and kind fields set. Options are copied into the Serializer
and are immutable. | NewSerializerWithOptions | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/serializer/json/json.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/serializer/json/json.go | Apache-2.0 |
func identifier(options SerializerOptions) runtime.Identifier {
result := map[string]string{
"name": "json",
"yaml": strconv.FormatBool(options.Yaml),
"pretty": strconv.FormatBool(options.Pretty),
"strict": strconv.FormatBool(options.Strict),
}
identifier, err := json.Marshal(result)
if err != nil {
klog.Fatalf("Failed marshaling identifier for json Serializer: %v", err)
}
return runtime.Identifier(identifier)
} | identifier computes Identifier of Encoder based on the given options. | identifier | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/serializer/json/json.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/serializer/json/json.go | Apache-2.0 |
func gvkWithDefaults(actual, defaultGVK schema.GroupVersionKind) schema.GroupVersionKind {
if len(actual.Kind) == 0 {
actual.Kind = defaultGVK.Kind
}
if len(actual.Version) == 0 && len(actual.Group) == 0 {
actual.Group = defaultGVK.Group
actual.Version = defaultGVK.Version
}
if len(actual.Version) == 0 && actual.Group == defaultGVK.Group {
actual.Version = defaultGVK.Version
}
return actual
} | gvkWithDefaults returns group kind and version defaulting from provided default | gvkWithDefaults | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/serializer/json/json.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/serializer/json/json.go | Apache-2.0 |
func (s *Serializer) Decode(originalData []byte, gvk *schema.GroupVersionKind, into runtime.Object) (runtime.Object, *schema.GroupVersionKind, error) {
data := originalData
if s.options.Yaml {
altered, err := yaml.YAMLToJSON(data)
if err != nil {
return nil, nil, err
}
data = altered
}
actual, err := s.meta.Interpret(data)
if err != nil {
return nil, nil, err
}
if gvk != nil {
*actual = gvkWithDefaults(*actual, *gvk)
}
if unk, ok := into.(*runtime.Unknown); ok && unk != nil {
unk.Raw = originalData
unk.ContentType = runtime.ContentTypeJSON
unk.GetObjectKind().SetGroupVersionKind(*actual)
return unk, actual, nil
}
if into != nil {
_, isUnstructured := into.(runtime.Unstructured)
types, _, err := s.typer.ObjectKinds(into)
switch {
case runtime.IsNotRegisteredError(err), isUnstructured:
strictErrs, err := s.unmarshal(into, data, originalData)
if err != nil {
return nil, actual, err
}
// when decoding directly into a provided unstructured object,
// extract the actual gvk decoded from the provided data,
// and ensure it is non-empty.
if isUnstructured {
*actual = into.GetObjectKind().GroupVersionKind()
if len(actual.Kind) == 0 {
return nil, actual, runtime.NewMissingKindErr(string(originalData))
}
// TODO(109023): require apiVersion here as well once unstructuredJSONScheme#Decode does
}
if len(strictErrs) > 0 {
return into, actual, runtime.NewStrictDecodingError(strictErrs)
}
return into, actual, nil
case err != nil:
return nil, actual, err
default:
*actual = gvkWithDefaults(*actual, types[0])
}
}
if len(actual.Kind) == 0 {
return nil, actual, runtime.NewMissingKindErr(string(originalData))
}
if len(actual.Version) == 0 {
return nil, actual, runtime.NewMissingVersionErr(string(originalData))
}
// use the target if necessary
obj, err := runtime.UseOrCreateObject(s.typer, s.creater, *actual, into)
if err != nil {
return nil, actual, err
}
strictErrs, err := s.unmarshal(obj, data, originalData)
if err != nil {
return nil, actual, err
} else if len(strictErrs) > 0 {
return obj, actual, runtime.NewStrictDecodingError(strictErrs)
}
return obj, actual, nil
} | Decode attempts to convert the provided data into YAML or JSON, extract the stored schema kind, apply the provided default gvk, and then
load that data into an object matching the desired schema kind or the provided into.
If into is *runtime.Unknown, the raw data will be extracted and no decoding will be performed.
If into is not registered with the typer, then the object will be straight decoded using normal JSON/YAML unmarshalling.
If into is provided and the original data is not fully qualified with kind/version/group, the type of the into will be used to alter the returned gvk.
If into is nil or data's gvk different from into's gvk, it will generate a new Object with ObjectCreater.New(gvk)
On success or most errors, the method will return the calculated schema kind.
The gvk calculate priority will be originalData > default gvk > into | Decode | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/serializer/json/json.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/serializer/json/json.go | Apache-2.0 |
func (s *Serializer) Encode(obj runtime.Object, w io.Writer) error {
if co, ok := obj.(runtime.CacheableObject); ok {
return co.CacheEncode(s.Identifier(), s.doEncode, w)
}
return s.doEncode(obj, w)
} | Encode serializes the provided object to the given writer. | Encode | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/serializer/json/json.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/serializer/json/json.go | Apache-2.0 |
func (s *Serializer) IsStrict() bool {
return s.options.Strict
} | IsStrict indicates whether the serializer
uses strict decoding or not | IsStrict | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/serializer/json/json.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/serializer/json/json.go | Apache-2.0 |
func (s *Serializer) Identifier() runtime.Identifier {
return s.identifier
} | Identifier implements runtime.Encoder interface. | Identifier | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/serializer/json/json.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/serializer/json/json.go | Apache-2.0 |
func (s *Serializer) RecognizesData(data []byte) (ok, unknown bool, err error) {
if s.options.Yaml {
// we could potentially look for '---'
return false, true, nil
}
return utilyaml.IsJSONBuffer(data), false, nil
} | RecognizesData implements the RecognizingDecoder interface. | RecognizesData | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/serializer/json/json.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/serializer/json/json.go | Apache-2.0 |
func (jsonFramer) NewFrameWriter(w io.Writer) io.Writer {
// we can write JSON objects directly to the writer, because they are self-framing
return w
} | NewFrameWriter implements stream framing for this serializer | NewFrameWriter | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/serializer/json/json.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/serializer/json/json.go | Apache-2.0 |
func (jsonFramer) NewFrameReader(r io.ReadCloser) io.ReadCloser {
// we need to extract the JSON chunks of data to pass to Decode()
return framer.NewJSONFramedReader(r)
} | NewFrameReader implements stream framing for this serializer | NewFrameReader | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/serializer/json/json.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/serializer/json/json.go | Apache-2.0 |
func (yamlFramer) NewFrameWriter(w io.Writer) io.Writer {
return yamlFrameWriter{w}
} | NewFrameWriter implements stream framing for this serializer | NewFrameWriter | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/serializer/json/json.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/serializer/json/json.go | Apache-2.0 |
func (yamlFramer) NewFrameReader(r io.ReadCloser) io.ReadCloser {
// extract the YAML document chunks directly
return utilyaml.NewDocumentDecoder(r)
} | NewFrameReader implements stream framing for this serializer | NewFrameReader | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/serializer/json/json.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/serializer/json/json.go | Apache-2.0 |
func (w yamlFrameWriter) Write(data []byte) (n int, err error) {
if _, err := w.w.Write([]byte("---\n")); err != nil {
return 0, err
}
return w.w.Write(data)
} | Write separates each document with the YAML document separator (`---` followed by line
break). Writers must write well formed YAML documents (include a final line break). | Write | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/serializer/json/json.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/serializer/json/json.go | Apache-2.0 |
func (SimpleMetaFactory) Interpret(data []byte) (*schema.GroupVersionKind, error) {
findKind := struct {
// +optional
APIVersion string `json:"apiVersion,omitempty"`
// +optional
Kind string `json:"kind,omitempty"`
}{}
if err := json.Unmarshal(data, &findKind); err != nil {
return nil, fmt.Errorf("couldn't get version/kind; json parse error: %v", err)
}
gv, err := schema.ParseGroupVersion(findKind.APIVersion)
if err != nil {
return nil, err
}
return &schema.GroupVersionKind{Group: gv.Group, Version: gv.Version, Kind: findKind.Kind}, nil
} | Interpret will return the APIVersion and Kind of the JSON wire-format
encoding of an object, or an error. | Interpret | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/serializer/json/meta.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/serializer/json/meta.go | Apache-2.0 |
func NewDefaultingCodecForScheme(
// TODO: I should be a scheme interface?
scheme *runtime.Scheme,
encoder runtime.Encoder,
decoder runtime.Decoder,
encodeVersion runtime.GroupVersioner,
decodeVersion runtime.GroupVersioner,
) runtime.Codec {
return NewCodec(encoder, decoder, runtime.UnsafeObjectConvertor(scheme), scheme, scheme, scheme, encodeVersion, decodeVersion, scheme.Name())
} | NewDefaultingCodecForScheme is a convenience method for callers that are using a scheme. | NewDefaultingCodecForScheme | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/serializer/versioning/versioning.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/serializer/versioning/versioning.go | Apache-2.0 |
func NewCodec(
encoder runtime.Encoder,
decoder runtime.Decoder,
convertor runtime.ObjectConvertor,
creater runtime.ObjectCreater,
typer runtime.ObjectTyper,
defaulter runtime.ObjectDefaulter,
encodeVersion runtime.GroupVersioner,
decodeVersion runtime.GroupVersioner,
originalSchemeName string,
) runtime.Codec {
internal := &codec{
encoder: encoder,
decoder: decoder,
convertor: convertor,
creater: creater,
typer: typer,
defaulter: defaulter,
encodeVersion: encodeVersion,
decodeVersion: decodeVersion,
identifier: identifier(encodeVersion, encoder),
originalSchemeName: originalSchemeName,
}
return internal
} | NewCodec takes objects in their internal versions and converts them to external versions before
serializing them. It assumes the serializer provided to it only deals with external versions.
This class is also a serializer, but is generally used with a specific version. | NewCodec | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/serializer/versioning/versioning.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/serializer/versioning/versioning.go | Apache-2.0 |
func identifier(encodeGV runtime.GroupVersioner, encoder runtime.Encoder) runtime.Identifier {
result := codecIdentifier{
Name: "versioning",
}
if encodeGV != nil {
result.EncodeGV = encodeGV.Identifier()
}
if encoder != nil {
result.Encoder = string(encoder.Identifier())
}
if id, ok := identifiersMap.Load(result); ok {
return id.(runtime.Identifier)
}
identifier, err := json.Marshal(result)
if err != nil {
klog.Fatalf("Failed marshaling identifier for codec: %v", err)
}
identifiersMap.Store(result, runtime.Identifier(identifier))
return runtime.Identifier(identifier)
} | identifier computes Identifier of Encoder based on codec parameters. | identifier | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/serializer/versioning/versioning.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/serializer/versioning/versioning.go | Apache-2.0 |
func (c *codec) Decode(data []byte, defaultGVK *schema.GroupVersionKind, into runtime.Object) (runtime.Object, *schema.GroupVersionKind, error) {
// If the into object is unstructured and expresses an opinion about its group/version,
// create a new instance of the type so we always exercise the conversion path (skips short-circuiting on `into == obj`)
decodeInto := into
if into != nil {
if _, ok := into.(runtime.Unstructured); ok && !into.GetObjectKind().GroupVersionKind().GroupVersion().Empty() {
decodeInto = reflect.New(reflect.TypeOf(into).Elem()).Interface().(runtime.Object)
}
}
var strictDecodingErrs []error
obj, gvk, err := c.decoder.Decode(data, defaultGVK, decodeInto)
if err != nil {
if strictErr, ok := runtime.AsStrictDecodingError(err); obj != nil && ok {
// save the strictDecodingError and let the caller decide what to do with it
strictDecodingErrs = append(strictDecodingErrs, strictErr.Errors()...)
} else {
return nil, gvk, err
}
}
if d, ok := obj.(runtime.NestedObjectDecoder); ok {
if err := d.DecodeNestedObjects(runtime.WithoutVersionDecoder{Decoder: c.decoder}); err != nil {
if strictErr, ok := runtime.AsStrictDecodingError(err); ok {
// save the strictDecodingError let and the caller decide what to do with it
strictDecodingErrs = append(strictDecodingErrs, strictErr.Errors()...)
} else {
return nil, gvk, err
}
}
}
// aggregate the strict decoding errors into one
var strictDecodingErr error
if len(strictDecodingErrs) > 0 {
strictDecodingErr = runtime.NewStrictDecodingError(strictDecodingErrs)
}
// if we specify a target, use generic conversion.
if into != nil {
// perform defaulting if requested
if c.defaulter != nil {
c.defaulter.Default(obj)
}
// Short-circuit conversion if the into object is same object
if into == obj {
return into, gvk, strictDecodingErr
}
if err := c.convertor.Convert(obj, into, c.decodeVersion); err != nil {
return nil, gvk, err
}
return into, gvk, strictDecodingErr
}
// perform defaulting if requested
if c.defaulter != nil {
c.defaulter.Default(obj)
}
out, err := c.convertor.ConvertToVersion(obj, c.decodeVersion)
if err != nil {
return nil, gvk, err
}
return out, gvk, strictDecodingErr
} | Decode attempts a decode of the object, then tries to convert it to the internal version. If into is provided and the decoding is
successful, the returned runtime.Object will be the value passed as into. Note that this may bypass conversion if you pass an
into that matches the serialized version. | Decode | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/serializer/versioning/versioning.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/serializer/versioning/versioning.go | Apache-2.0 |
func (c *codec) EncodeWithAllocator(obj runtime.Object, w io.Writer, memAlloc runtime.MemoryAllocator) error {
return c.encode(obj, w, memAlloc)
} | EncodeWithAllocator ensures the provided object is output in the appropriate group and version, invoking
conversion if necessary. Unversioned objects (according to the ObjectTyper) are output as is.
In addition, it allows for providing a memory allocator for efficient memory usage during object serialization. | EncodeWithAllocator | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/serializer/versioning/versioning.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/serializer/versioning/versioning.go | Apache-2.0 |
func (c *codec) Encode(obj runtime.Object, w io.Writer) error {
return c.encode(obj, w, nil)
} | Encode ensures the provided object is output in the appropriate group and version, invoking
conversion if necessary. Unversioned objects (according to the ObjectTyper) are output as is. | Encode | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/serializer/versioning/versioning.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/serializer/versioning/versioning.go | Apache-2.0 |
func ParseResourceArg(arg string) (*GroupVersionResource, GroupResource) {
var gvr *GroupVersionResource
if strings.Count(arg, ".") >= 2 {
s := strings.SplitN(arg, ".", 3)
gvr = &GroupVersionResource{Group: s[2], Version: s[1], Resource: s[0]}
}
return gvr, ParseGroupResource(arg)
} | ParseResourceArg takes the common style of string which may be either `resource.group.com` or `resource.version.group.com`
and parses it out into both possibilities. This code takes no responsibility for knowing which representation was intended
but with a knowledge of all GroupVersions, calling code can take a very good guess. If there are only two segments, then
`*GroupVersionResource` is nil.
`resource.group.com` -> `group=com, version=group, resource=resource` and `group=group.com, resource=resource` | ParseResourceArg | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/schema/group_version.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/schema/group_version.go | Apache-2.0 |
func ParseKindArg(arg string) (*GroupVersionKind, GroupKind) {
var gvk *GroupVersionKind
if strings.Count(arg, ".") >= 2 {
s := strings.SplitN(arg, ".", 3)
gvk = &GroupVersionKind{Group: s[2], Version: s[1], Kind: s[0]}
}
return gvk, ParseGroupKind(arg)
} | ParseKindArg takes the common style of string which may be either `Kind.group.com` or `Kind.version.group.com`
and parses it out into both possibilities. This code takes no responsibility for knowing which representation was intended
but with a knowledge of all GroupKinds, calling code can take a very good guess. If there are only two segments, then
`*GroupVersionKind` is nil.
`Kind.group.com` -> `group=com, version=group, kind=Kind` and `group=group.com, kind=Kind` | ParseKindArg | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/schema/group_version.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/schema/group_version.go | Apache-2.0 |
func ParseGroupResource(gr string) GroupResource {
if i := strings.Index(gr, "."); i >= 0 {
return GroupResource{Group: gr[i+1:], Resource: gr[:i]}
}
return GroupResource{Resource: gr}
} | ParseGroupResource turns "resource.group" string into a GroupResource struct. Empty strings are allowed
for each field. | ParseGroupResource | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/schema/group_version.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/schema/group_version.go | Apache-2.0 |
func (gvk GroupVersionKind) Empty() bool {
return len(gvk.Group) == 0 && len(gvk.Version) == 0 && len(gvk.Kind) == 0
} | Empty returns true if group, version, and kind are empty | Empty | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/schema/group_version.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/schema/group_version.go | Apache-2.0 |
func (gv GroupVersion) Empty() bool {
return len(gv.Group) == 0 && len(gv.Version) == 0
} | Empty returns true if group and version are empty | Empty | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/schema/group_version.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/schema/group_version.go | Apache-2.0 |
func (gv GroupVersion) String() string {
if len(gv.Group) > 0 {
return gv.Group + "/" + gv.Version
}
return gv.Version
} | String puts "group" and "version" into a single "group/version" string. For the legacy v1
it returns "v1". | String | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/schema/group_version.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/schema/group_version.go | Apache-2.0 |
func (gv GroupVersion) Identifier() string {
return gv.String()
} | Identifier implements runtime.GroupVersioner interface. | Identifier | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/schema/group_version.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/schema/group_version.go | Apache-2.0 |
func (gv GroupVersion) KindForGroupVersionKinds(kinds []GroupVersionKind) (target GroupVersionKind, ok bool) {
for _, gvk := range kinds {
if gvk.Group == gv.Group && gvk.Version == gv.Version {
return gvk, true
}
}
for _, gvk := range kinds {
if gvk.Group == gv.Group {
return gv.WithKind(gvk.Kind), true
}
}
return GroupVersionKind{}, false
} | KindForGroupVersionKinds identifies the preferred GroupVersionKind out of a list. It returns ok false
if none of the options match the group. It prefers a match to group and version over just group.
TODO: Move GroupVersion to a package under pkg/runtime, since it's used by scheme.
TODO: Introduce an adapter type between GroupVersion and runtime.GroupVersioner, and use LegacyCodec(GroupVersion)
in fewer places. | KindForGroupVersionKinds | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/schema/group_version.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/schema/group_version.go | Apache-2.0 |
func ParseGroupVersion(gv string) (GroupVersion, error) {
// this can be the internal version for the legacy kube types
// TODO once we've cleared the last uses as strings, this special case should be removed.
if (len(gv) == 0) || (gv == "/") {
return GroupVersion{}, nil
}
switch strings.Count(gv, "/") {
case 0:
return GroupVersion{"", gv}, nil
case 1:
i := strings.Index(gv, "/")
return GroupVersion{gv[:i], gv[i+1:]}, nil
default:
return GroupVersion{}, fmt.Errorf("unexpected GroupVersion string: %v", gv)
}
} | ParseGroupVersion turns "group/version" string into a GroupVersion struct. It reports error
if it cannot parse the string. | ParseGroupVersion | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/schema/group_version.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/schema/group_version.go | Apache-2.0 |
func (gv GroupVersion) WithKind(kind string) GroupVersionKind {
return GroupVersionKind{Group: gv.Group, Version: gv.Version, Kind: kind}
} | WithKind creates a GroupVersionKind based on the method receiver's GroupVersion and the passed Kind. | WithKind | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/schema/group_version.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/schema/group_version.go | Apache-2.0 |
func (gv GroupVersion) WithResource(resource string) GroupVersionResource {
return GroupVersionResource{Group: gv.Group, Version: gv.Version, Resource: resource}
} | WithResource creates a GroupVersionResource based on the method receiver's GroupVersion and the passed Resource. | WithResource | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/schema/group_version.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/schema/group_version.go | Apache-2.0 |
func (gvs GroupVersions) Identifier() string {
groupVersions := make([]string, 0, len(gvs))
for i := range gvs {
groupVersions = append(groupVersions, gvs[i].String())
}
return fmt.Sprintf("[%s]", strings.Join(groupVersions, ","))
} | Identifier implements runtime.GroupVersioner interface. | Identifier | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/schema/group_version.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/schema/group_version.go | Apache-2.0 |
func (gvs GroupVersions) KindForGroupVersionKinds(kinds []GroupVersionKind) (GroupVersionKind, bool) {
var targets []GroupVersionKind
for _, gv := range gvs {
target, ok := gv.KindForGroupVersionKinds(kinds)
if !ok {
continue
}
targets = append(targets, target)
}
if len(targets) == 1 {
return targets[0], true
}
if len(targets) > 1 {
return bestMatch(kinds, targets), true
}
return GroupVersionKind{}, false
} | KindForGroupVersionKinds identifies the preferred GroupVersionKind out of a list. It returns ok false
if none of the options match the group. | KindForGroupVersionKinds | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/schema/group_version.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/schema/group_version.go | Apache-2.0 |
func bestMatch(kinds []GroupVersionKind, targets []GroupVersionKind) GroupVersionKind {
for _, gvk := range targets {
for _, k := range kinds {
if k == gvk {
return k
}
}
}
return targets[0]
} | bestMatch tries to pick best matching GroupVersionKind and falls back to the first
found if no exact match exists. | bestMatch | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/schema/group_version.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/schema/group_version.go | Apache-2.0 |
func (gvk GroupVersionKind) ToAPIVersionAndKind() (string, string) {
if gvk.Empty() {
return "", ""
}
return gvk.GroupVersion().String(), gvk.Kind
} | ToAPIVersionAndKind is a convenience method for satisfying runtime.Object on types that
do not use TypeMeta. | ToAPIVersionAndKind | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/schema/group_version.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/schema/group_version.go | Apache-2.0 |
func FromAPIVersionAndKind(apiVersion, kind string) GroupVersionKind {
if gv, err := ParseGroupVersion(apiVersion); err == nil {
return GroupVersionKind{Group: gv.Group, Version: gv.Version, Kind: kind}
}
return GroupVersionKind{Kind: kind}
} | FromAPIVersionAndKind returns a GVK representing the provided fields for types that
do not use TypeMeta. This method exists to support test types and legacy serializations
that have a distinct group and kind.
TODO: further reduce usage of this method. | FromAPIVersionAndKind | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/schema/group_version.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/schema/group_version.go | Apache-2.0 |
func (emptyObjectKind) SetGroupVersionKind(gvk GroupVersionKind) {} | SetGroupVersionKind implements the ObjectKind interface | SetGroupVersionKind | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/schema/interfaces.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/schema/interfaces.go | Apache-2.0 |
func (emptyObjectKind) GroupVersionKind() GroupVersionKind { return GroupVersionKind{} } | GroupVersionKind implements the ObjectKind interface | GroupVersionKind | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/runtime/schema/interfaces.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/runtime/schema/interfaces.go | Apache-2.0 |
func Everything() Selector {
return sharedEverythingSelector
} | Everything returns a selector that matches all labels. | Everything | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/labels/selector.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/labels/selector.go | Apache-2.0 |
func Nothing() Selector {
return sharedNothingSelector
} | Nothing returns a selector that matches no labels | Nothing | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/labels/selector.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/labels/selector.go | Apache-2.0 |
func NewSelector() Selector {
return internalSelector(nil)
} | NewSelector returns a nil selector | NewSelector | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/labels/selector.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/labels/selector.go | Apache-2.0 |
func NewRequirement(key string, op selection.Operator, vals []string, opts ...field.PathOption) (*Requirement, error) {
var allErrs field.ErrorList
path := field.ToPath(opts...)
if err := validateLabelKey(key, path.Child("key")); err != nil {
allErrs = append(allErrs, err)
}
valuePath := path.Child("values")
switch op {
case selection.In, selection.NotIn:
if len(vals) == 0 {
allErrs = append(allErrs, field.Invalid(valuePath, vals, "for 'in', 'notin' operators, values set can't be empty"))
}
case selection.Equals, selection.DoubleEquals, selection.NotEquals:
if len(vals) != 1 {
allErrs = append(allErrs, field.Invalid(valuePath, vals, "exact-match compatibility requires one single value"))
}
case selection.Exists, selection.DoesNotExist:
if len(vals) != 0 {
allErrs = append(allErrs, field.Invalid(valuePath, vals, "values set must be empty for exists and does not exist"))
}
case selection.GreaterThan, selection.LessThan:
if len(vals) != 1 {
allErrs = append(allErrs, field.Invalid(valuePath, vals, "for 'Gt', 'Lt' operators, exactly one value is required"))
}
for i := range vals {
if _, err := strconv.ParseInt(vals[i], 10, 64); err != nil {
allErrs = append(allErrs, field.Invalid(valuePath.Index(i), vals[i], "for 'Gt', 'Lt' operators, the value must be an integer"))
}
}
default:
allErrs = append(allErrs, field.NotSupported(path.Child("operator"), op, validRequirementOperators))
}
for i := range vals {
if err := validateLabelValue(key, vals[i], valuePath.Index(i)); err != nil {
allErrs = append(allErrs, err)
}
}
return &Requirement{key: key, operator: op, strValues: vals}, allErrs.ToAggregate()
} | NewRequirement is the constructor for a Requirement.
If any of these rules is violated, an error is returned:
1. The operator can only be In, NotIn, Equals, DoubleEquals, Gt, Lt, NotEquals, Exists, or DoesNotExist.
2. If the operator is In or NotIn, the values set must be non-empty.
3. If the operator is Equals, DoubleEquals, or NotEquals, the values set must contain one value.
4. If the operator is Exists or DoesNotExist, the value set must be empty.
5. If the operator is Gt or Lt, the values set must contain only one value, which will be interpreted as an integer.
6. The key is invalid due to its length, or sequence of characters. See validateLabelKey for more details.
The empty string is a valid value in the input values set.
Returned error, if not nil, is guaranteed to be an aggregated field.ErrorList | NewRequirement | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/labels/selector.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/labels/selector.go | Apache-2.0 |
func (r *Requirement) Matches(ls Labels) bool {
switch r.operator {
case selection.In, selection.Equals, selection.DoubleEquals:
if !ls.Has(r.key) {
return false
}
return r.hasValue(ls.Get(r.key))
case selection.NotIn, selection.NotEquals:
if !ls.Has(r.key) {
return true
}
return !r.hasValue(ls.Get(r.key))
case selection.Exists:
return ls.Has(r.key)
case selection.DoesNotExist:
return !ls.Has(r.key)
case selection.GreaterThan, selection.LessThan:
if !ls.Has(r.key) {
return false
}
lsValue, err := strconv.ParseInt(ls.Get(r.key), 10, 64)
if err != nil {
klog.V(10).Infof("ParseInt failed for value %+v in label %+v, %+v", ls.Get(r.key), ls, err)
return false
}
// There should be only one strValue in r.strValues, and can be converted to an integer.
if len(r.strValues) != 1 {
klog.V(10).Infof("Invalid values count %+v of requirement %#v, for 'Gt', 'Lt' operators, exactly one value is required", len(r.strValues), r)
return false
}
var rValue int64
for i := range r.strValues {
rValue, err = strconv.ParseInt(r.strValues[i], 10, 64)
if err != nil {
klog.V(10).Infof("ParseInt failed for value %+v in requirement %#v, for 'Gt', 'Lt' operators, the value must be an integer", r.strValues[i], r)
return false
}
}
return (r.operator == selection.GreaterThan && lsValue > rValue) || (r.operator == selection.LessThan && lsValue < rValue)
default:
return false
}
} | Matches returns true if the Requirement matches the input Labels.
There is a match in the following cases:
1. The operator is Exists and Labels has the Requirement's key.
2. The operator is In, Labels has the Requirement's key and Labels'
value for that key is in Requirement's value set.
3. The operator is NotIn, Labels has the Requirement's key and
Labels' value for that key is not in Requirement's value set.
4. The operator is DoesNotExist or NotIn and Labels does not have the
Requirement's key.
5. The operator is GreaterThanOperator or LessThanOperator, and Labels has
the Requirement's key and the corresponding value satisfies mathematical inequality. | Matches | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/labels/selector.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/labels/selector.go | Apache-2.0 |
func (r *Requirement) Key() string {
return r.key
} | Key returns requirement key | Key | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/labels/selector.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/labels/selector.go | Apache-2.0 |
func (r *Requirement) Operator() selection.Operator {
return r.operator
} | Operator returns requirement operator | Operator | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/labels/selector.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/labels/selector.go | Apache-2.0 |
func (r *Requirement) Values() sets.String {
ret := sets.String{}
for i := range r.strValues {
ret.Insert(r.strValues[i])
}
return ret
} | Values returns requirement values | Values | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/labels/selector.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/labels/selector.go | Apache-2.0 |
func (r Requirement) Equal(x Requirement) bool {
if r.key != x.key {
return false
}
if r.operator != x.operator {
return false
}
return stringslices.Equal(r.strValues, x.strValues)
} | Equal checks the equality of requirement. | Equal | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/labels/selector.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/labels/selector.go | Apache-2.0 |
func (s internalSelector) Empty() bool {
if s == nil {
return true
}
return len(s) == 0
} | Empty returns true if the internalSelector doesn't restrict selection space | Empty | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/labels/selector.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/labels/selector.go | Apache-2.0 |
func (r *Requirement) String() string {
var sb strings.Builder
sb.Grow(
// length of r.key
len(r.key) +
// length of 'r.operator' + 2 spaces for the worst case ('in' and 'notin')
len(r.operator) + 2 +
// length of 'r.strValues' slice times. Heuristically 5 chars per word
+5*len(r.strValues))
if r.operator == selection.DoesNotExist {
sb.WriteString("!")
}
sb.WriteString(r.key)
switch r.operator {
case selection.Equals:
sb.WriteString("=")
case selection.DoubleEquals:
sb.WriteString("==")
case selection.NotEquals:
sb.WriteString("!=")
case selection.In:
sb.WriteString(" in ")
case selection.NotIn:
sb.WriteString(" notin ")
case selection.GreaterThan:
sb.WriteString(">")
case selection.LessThan:
sb.WriteString("<")
case selection.Exists, selection.DoesNotExist:
return sb.String()
}
switch r.operator {
case selection.In, selection.NotIn:
sb.WriteString("(")
}
if len(r.strValues) == 1 {
sb.WriteString(r.strValues[0])
} else { // only > 1 since == 0 prohibited by NewRequirement
// normalizes value order on output, without mutating the in-memory selector representation
// also avoids normalization when it is not required, and ensures we do not mutate shared data
sb.WriteString(strings.Join(safeSort(r.strValues), ","))
}
switch r.operator {
case selection.In, selection.NotIn:
sb.WriteString(")")
}
return sb.String()
} | String returns a human-readable string that represents this
Requirement. If called on an invalid Requirement, an error is
returned. See NewRequirement for creating a valid Requirement. | String | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/labels/selector.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/labels/selector.go | Apache-2.0 |
func safeSort(in []string) []string {
if sort.StringsAreSorted(in) {
return in
}
out := make([]string, len(in))
copy(out, in)
sort.Strings(out)
return out
} | safeSort sorts input strings without modification | safeSort | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/labels/selector.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/labels/selector.go | Apache-2.0 |
func (s internalSelector) Add(reqs ...Requirement) Selector {
ret := make(internalSelector, 0, len(s)+len(reqs))
ret = append(ret, s...)
ret = append(ret, reqs...)
sort.Sort(ByKey(ret))
return ret
} | Add adds requirements to the selector. It copies the current selector returning a new one | Add | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/labels/selector.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/labels/selector.go | Apache-2.0 |
func (s internalSelector) Matches(l Labels) bool {
for ix := range s {
if matches := s[ix].Matches(l); !matches {
return false
}
}
return true
} | Matches for a internalSelector returns true if all
its Requirements match the input Labels. If any
Requirement does not match, false is returned. | Matches | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/labels/selector.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/labels/selector.go | Apache-2.0 |
func (s internalSelector) String() string {
var reqs []string
for ix := range s {
reqs = append(reqs, s[ix].String())
}
return strings.Join(reqs, ",")
} | String returns a comma-separated string of all
the internalSelector Requirements' human-readable strings. | String | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/labels/selector.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/labels/selector.go | Apache-2.0 |
func (s internalSelector) RequiresExactMatch(label string) (value string, found bool) {
for ix := range s {
if s[ix].key == label {
switch s[ix].operator {
case selection.Equals, selection.DoubleEquals, selection.In:
if len(s[ix].strValues) == 1 {
return s[ix].strValues[0], true
}
}
return "", false
}
}
return "", false
} | RequiresExactMatch introspects whether a given selector requires a single specific field
to be set, and if so returns the value it requires. | RequiresExactMatch | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/labels/selector.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/labels/selector.go | Apache-2.0 |
func isWhitespace(ch byte) bool {
return ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n'
} | isWhitespace returns true if the rune is a space, tab, or newline. | isWhitespace | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/labels/selector.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/labels/selector.go | Apache-2.0 |
func isSpecialSymbol(ch byte) bool {
switch ch {
case '=', '!', '(', ')', ',', '>', '<':
return true
}
return false
} | isSpecialSymbol detects if the character ch can be an operator | isSpecialSymbol | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/labels/selector.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/labels/selector.go | Apache-2.0 |
func (l *Lexer) read() (b byte) {
b = 0
if l.pos < len(l.s) {
b = l.s[l.pos]
l.pos++
}
return b
} | read returns the character currently lexed
increment the position and check the buffer overflow | read | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/labels/selector.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/labels/selector.go | Apache-2.0 |
func (l *Lexer) unread() {
l.pos--
} | unread 'undoes' the last read character | unread | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/labels/selector.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/labels/selector.go | Apache-2.0 |
func (l *Lexer) scanIDOrKeyword() (tok Token, lit string) {
var buffer []byte
IdentifierLoop:
for {
switch ch := l.read(); {
case ch == 0:
break IdentifierLoop
case isSpecialSymbol(ch) || isWhitespace(ch):
l.unread()
break IdentifierLoop
default:
buffer = append(buffer, ch)
}
}
s := string(buffer)
if val, ok := string2token[s]; ok { // is a literal token?
return val, s
}
return IdentifierToken, s // otherwise is an identifier
} | scanIDOrKeyword scans string to recognize literal token (for example 'in') or an identifier. | scanIDOrKeyword | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/labels/selector.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/labels/selector.go | Apache-2.0 |
func (l *Lexer) scanSpecialSymbol() (Token, string) {
lastScannedItem := ScannedItem{}
var buffer []byte
SpecialSymbolLoop:
for {
switch ch := l.read(); {
case ch == 0:
break SpecialSymbolLoop
case isSpecialSymbol(ch):
buffer = append(buffer, ch)
if token, ok := string2token[string(buffer)]; ok {
lastScannedItem = ScannedItem{tok: token, literal: string(buffer)}
} else if lastScannedItem.tok != 0 {
l.unread()
break SpecialSymbolLoop
}
default:
l.unread()
break SpecialSymbolLoop
}
}
if lastScannedItem.tok == 0 {
return ErrorToken, fmt.Sprintf("error expected: keyword found '%s'", buffer)
}
return lastScannedItem.tok, lastScannedItem.literal
} | scanSpecialSymbol scans string starting with special symbol.
special symbol identify non literal operators. "!=", "==", "=" | scanSpecialSymbol | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/labels/selector.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/labels/selector.go | Apache-2.0 |
func (l *Lexer) skipWhiteSpaces(ch byte) byte {
for {
if !isWhitespace(ch) {
return ch
}
ch = l.read()
}
} | skipWhiteSpaces consumes all blank characters
returning the first non blank character | skipWhiteSpaces | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/labels/selector.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/labels/selector.go | Apache-2.0 |
func (l *Lexer) Lex() (tok Token, lit string) {
switch ch := l.skipWhiteSpaces(l.read()); {
case ch == 0:
return EndOfStringToken, ""
case isSpecialSymbol(ch):
l.unread()
return l.scanSpecialSymbol()
default:
l.unread()
return l.scanIDOrKeyword()
}
} | Lex returns a pair of Token and the literal
literal is meaningfull only for IdentifierToken token | Lex | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/labels/selector.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/labels/selector.go | Apache-2.0 |
func (p *Parser) lookahead(context ParserContext) (Token, string) {
tok, lit := p.scannedItems[p.position].tok, p.scannedItems[p.position].literal
if context == Values {
switch tok {
case InToken, NotInToken:
tok = IdentifierToken
}
}
return tok, lit
} | lookahead func returns the current token and string. No increment of current position | lookahead | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/labels/selector.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/labels/selector.go | Apache-2.0 |
func (p *Parser) consume(context ParserContext) (Token, string) {
p.position++
tok, lit := p.scannedItems[p.position-1].tok, p.scannedItems[p.position-1].literal
if context == Values {
switch tok {
case InToken, NotInToken:
tok = IdentifierToken
}
}
return tok, lit
} | consume returns current token and string. Increments the position | consume | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/labels/selector.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/labels/selector.go | Apache-2.0 |
func (p *Parser) scan() {
for {
token, literal := p.l.Lex()
p.scannedItems = append(p.scannedItems, ScannedItem{token, literal})
if token == EndOfStringToken {
break
}
}
} | scan runs through the input string and stores the ScannedItem in an array
Parser can now lookahead and consume the tokens | scan | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/labels/selector.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/labels/selector.go | Apache-2.0 |
func (p *Parser) parse() (internalSelector, error) {
p.scan() // init scannedItems
var requirements internalSelector
for {
tok, lit := p.lookahead(Values)
switch tok {
case IdentifierToken, DoesNotExistToken:
r, err := p.parseRequirement()
if err != nil {
return nil, fmt.Errorf("unable to parse requirement: %v", err)
}
requirements = append(requirements, *r)
t, l := p.consume(Values)
switch t {
case EndOfStringToken:
return requirements, nil
case CommaToken:
t2, l2 := p.lookahead(Values)
if t2 != IdentifierToken && t2 != DoesNotExistToken {
return nil, fmt.Errorf("found '%s', expected: identifier after ','", l2)
}
default:
return nil, fmt.Errorf("found '%s', expected: ',' or 'end of string'", l)
}
case EndOfStringToken:
return requirements, nil
default:
return nil, fmt.Errorf("found '%s', expected: !, identifier, or 'end of string'", lit)
}
}
} | parse runs the left recursive descending algorithm
on input string. It returns a list of Requirement objects. | parse | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/labels/selector.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/labels/selector.go | Apache-2.0 |
func (p *Parser) parseKeyAndInferOperator() (string, selection.Operator, error) {
var operator selection.Operator
tok, literal := p.consume(Values)
if tok == DoesNotExistToken {
operator = selection.DoesNotExist
tok, literal = p.consume(Values)
}
if tok != IdentifierToken {
err := fmt.Errorf("found '%s', expected: identifier", literal)
return "", "", err
}
if err := validateLabelKey(literal, p.path); err != nil {
return "", "", err
}
if t, _ := p.lookahead(Values); t == EndOfStringToken || t == CommaToken {
if operator != selection.DoesNotExist {
operator = selection.Exists
}
}
return literal, operator, nil
} | parseKeyAndInferOperator parses literals.
in case of no operator '!, in, notin, ==, =, !=' are found
the 'exists' operator is inferred | parseKeyAndInferOperator | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/labels/selector.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/labels/selector.go | Apache-2.0 |
func (p *Parser) parseOperator() (op selection.Operator, err error) {
tok, lit := p.consume(KeyAndOperator)
switch tok {
// DoesNotExistToken shouldn't be here because it's a unary operator, not a binary operator
case InToken:
op = selection.In
case EqualsToken:
op = selection.Equals
case DoubleEqualsToken:
op = selection.DoubleEquals
case GreaterThanToken:
op = selection.GreaterThan
case LessThanToken:
op = selection.LessThan
case NotInToken:
op = selection.NotIn
case NotEqualsToken:
op = selection.NotEquals
default:
return "", fmt.Errorf("found '%s', expected: %v", lit, strings.Join(binaryOperators, ", "))
}
return op, nil
} | parseOperator returns operator and eventually matchType
matchType can be exact | parseOperator | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/labels/selector.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/labels/selector.go | Apache-2.0 |
func (p *Parser) parseValues() (sets.String, error) {
tok, lit := p.consume(Values)
if tok != OpenParToken {
return nil, fmt.Errorf("found '%s' expected: '('", lit)
}
tok, lit = p.lookahead(Values)
switch tok {
case IdentifierToken, CommaToken:
s, err := p.parseIdentifiersList() // handles general cases
if err != nil {
return s, err
}
if tok, _ = p.consume(Values); tok != ClosedParToken {
return nil, fmt.Errorf("found '%s', expected: ')'", lit)
}
return s, nil
case ClosedParToken: // handles "()"
p.consume(Values)
return sets.NewString(""), nil
default:
return nil, fmt.Errorf("found '%s', expected: ',', ')' or identifier", lit)
}
} | parseValues parses the values for set based matching (x,y,z) | parseValues | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/labels/selector.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/labels/selector.go | Apache-2.0 |
func (p *Parser) parseIdentifiersList() (sets.String, error) {
s := sets.NewString()
for {
tok, lit := p.consume(Values)
switch tok {
case IdentifierToken:
s.Insert(lit)
tok2, lit2 := p.lookahead(Values)
switch tok2 {
case CommaToken:
continue
case ClosedParToken:
return s, nil
default:
return nil, fmt.Errorf("found '%s', expected: ',' or ')'", lit2)
}
case CommaToken: // handled here since we can have "(,"
if s.Len() == 0 {
s.Insert("") // to handle (,
}
tok2, _ := p.lookahead(Values)
if tok2 == ClosedParToken {
s.Insert("") // to handle ,) Double "" removed by StringSet
return s, nil
}
if tok2 == CommaToken {
p.consume(Values)
s.Insert("") // to handle ,, Double "" removed by StringSet
}
default: // it can be operator
return s, fmt.Errorf("found '%s', expected: ',', or identifier", lit)
}
}
} | parseIdentifiersList parses a (possibly empty) list of
of comma separated (possibly empty) identifiers | parseIdentifiersList | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/labels/selector.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/labels/selector.go | Apache-2.0 |
func (p *Parser) parseExactValue() (sets.String, error) {
s := sets.NewString()
tok, _ := p.lookahead(Values)
if tok == EndOfStringToken || tok == CommaToken {
s.Insert("")
return s, nil
}
tok, lit := p.consume(Values)
if tok == IdentifierToken {
s.Insert(lit)
return s, nil
}
return nil, fmt.Errorf("found '%s', expected: identifier", lit)
} | parseExactValue parses the only value for exact match style | parseExactValue | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/labels/selector.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/labels/selector.go | Apache-2.0 |
func Parse(selector string, opts ...field.PathOption) (Selector, error) {
parsedSelector, err := parse(selector, field.ToPath(opts...))
if err == nil {
return parsedSelector, nil
}
return nil, err
} | Parse takes a string representing a selector and returns a selector
object, or an error. This parsing function differs from ParseSelector
as they parse different selectors with different syntaxes.
The input will cause an error if it does not follow this form:
<selector-syntax> ::= <requirement> | <requirement> "," <selector-syntax>
<requirement> ::= [!] KEY [ <set-based-restriction> | <exact-match-restriction> ]
<set-based-restriction> ::= "" | <inclusion-exclusion> <value-set>
<inclusion-exclusion> ::= <inclusion> | <exclusion>
<exclusion> ::= "notin"
<inclusion> ::= "in"
<value-set> ::= "(" <values> ")"
<values> ::= VALUE | VALUE "," <values>
<exact-match-restriction> ::= ["="|"=="|"!="] VALUE
KEY is a sequence of one or more characters following [ DNS_SUBDOMAIN "/" ] DNS_LABEL. Max length is 63 characters.
VALUE is a sequence of zero or more characters "([A-Za-z0-9_-\.])". Max length is 63 characters.
Delimiter is white space: (' ', '\t')
Example of valid syntax:
"x in (foo,,baz),y,z notin ()"
Note:
1. Inclusion - " in " - denotes that the KEY exists and is equal to any of the
VALUEs in its requirement
2. Exclusion - " notin " - denotes that the KEY is not equal to any
of the VALUEs in its requirement or does not exist
3. The empty string is a valid VALUE
4. A requirement with just a KEY - as in "y" above - denotes that
the KEY exists and can be any VALUE.
5. A requirement with just !KEY requires that the KEY not exist. | Parse | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/labels/selector.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/labels/selector.go | Apache-2.0 |
func parse(selector string, path *field.Path) (internalSelector, error) {
p := &Parser{l: &Lexer{s: selector, pos: 0}, path: path}
items, err := p.parse()
if err != nil {
return nil, err
}
sort.Sort(ByKey(items)) // sort to grant determistic parsing
return internalSelector(items), err
} | parse parses the string representation of the selector and returns the internalSelector struct.
The callers of this method can then decide how to return the internalSelector struct to their
callers. This function has two callers now, one returns a Selector interface and the other
returns a list of requirements. | parse | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/labels/selector.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/labels/selector.go | Apache-2.0 |
func SelectorFromSet(ls Set) Selector {
return SelectorFromValidatedSet(ls)
} | SelectorFromSet returns a Selector which will match exactly the given Set. A
nil and empty Sets are considered equivalent to Everything().
It does not perform any validation, which means the server will reject
the request if the Set contains invalid values. | SelectorFromSet | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/labels/selector.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/labels/selector.go | Apache-2.0 |
func ValidatedSelectorFromSet(ls Set) (Selector, error) {
if ls == nil || len(ls) == 0 {
return internalSelector{}, nil
}
requirements := make([]Requirement, 0, len(ls))
for label, value := range ls {
r, err := NewRequirement(label, selection.Equals, []string{value})
if err != nil {
return nil, err
}
requirements = append(requirements, *r)
}
// sort to have deterministic string representation
sort.Sort(ByKey(requirements))
return internalSelector(requirements), nil
} | ValidatedSelectorFromSet returns a Selector which will match exactly the given Set. A
nil and empty Sets are considered equivalent to Everything().
The Set is validated client-side, which allows to catch errors early. | ValidatedSelectorFromSet | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/labels/selector.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/labels/selector.go | Apache-2.0 |
func SelectorFromValidatedSet(ls Set) Selector {
if ls == nil || len(ls) == 0 {
return internalSelector{}
}
requirements := make([]Requirement, 0, len(ls))
for label, value := range ls {
requirements = append(requirements, Requirement{key: label, operator: selection.Equals, strValues: []string{value}})
}
// sort to have deterministic string representation
sort.Sort(ByKey(requirements))
return internalSelector(requirements)
} | SelectorFromValidatedSet returns a Selector which will match exactly the given Set.
A nil and empty Sets are considered equivalent to Everything().
It assumes that Set is already validated and doesn't do any validation.
Note: this method copies the Set; if the Set is immutable, consider wrapping it with ValidatedSetSelector
instead, which does not copy. | SelectorFromValidatedSet | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/labels/selector.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/labels/selector.go | Apache-2.0 |
func ParseToRequirements(selector string, opts ...field.PathOption) ([]Requirement, error) {
return parse(selector, field.ToPath(opts...))
} | ParseToRequirements takes a string representing a selector and returns a list of
requirements. This function is suitable for those callers that perform additional
processing on selector requirements.
See the documentation for Parse() function for more details.
TODO: Consider exporting the internalSelector type instead. | ParseToRequirements | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/labels/selector.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/labels/selector.go | Apache-2.0 |
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, ",")
} | String returns all labels listed as a human readable string.
Conveniently, exactly the format that ParseSelector takes. | String | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/labels/labels.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/labels/labels.go | Apache-2.0 |
func (ls Set) Has(label string) bool {
_, exists := ls[label]
return exists
} | Has returns whether the provided label exists in the map. | Has | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/labels/labels.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/labels/labels.go | Apache-2.0 |
func (ls Set) Get(label string) string {
return ls[label]
} | Get returns the value in the map for the provided label. | Get | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/labels/labels.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/labels/labels.go | Apache-2.0 |
func (ls Set) AsSelector() Selector {
return SelectorFromSet(ls)
} | AsSelector converts labels into a selectors. It does not
perform any validation, which means the server will reject
the request if the Set contains invalid values. | AsSelector | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/labels/labels.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/labels/labels.go | Apache-2.0 |
func (ls Set) AsValidatedSelector() (Selector, error) {
return ValidatedSelectorFromSet(ls)
} | AsValidatedSelector converts labels into a selectors.
The Set is validated client-side, which allows to catch errors early. | AsValidatedSelector | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/labels/labels.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/labels/labels.go | Apache-2.0 |
func (ls Set) AsSelectorPreValidated() Selector {
return SelectorFromValidatedSet(ls)
} | AsSelectorPreValidated converts labels into a selector, but
assumes that labels are already validated and thus doesn't
perform any validation.
According to our measurements this is significantly faster
in codepaths that matter at high scale.
Note: this method copies the Set; if the Set is immutable, consider wrapping it with ValidatedSetSelector
instead, which does not copy. | AsSelectorPreValidated | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/labels/labels.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/labels/labels.go | Apache-2.0 |
func FormatLabels(labelMap map[string]string) string {
l := Set(labelMap).String()
if l == "" {
l = "<none>"
}
return l
} | FormatLabels converts label map into plain string | FormatLabels | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/labels/labels.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/labels/labels.go | Apache-2.0 |
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
} | 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 | Conflicts | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/labels/labels.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/labels/labels.go | Apache-2.0 |
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
} | Merge combines given maps, and does not check for any conflicts
between the maps. In case of conflicts, second map (labels2) wins | Merge | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/labels/labels.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/labels/labels.go | Apache-2.0 |
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
} | Equals returns true if the given maps are equal | Equals | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/labels/labels.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/labels/labels.go | Apache-2.0 |
func ConvertSelectorToLabelsMap(selector string, opts ...field.PathOption) (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, field.ToPath(opts...)); err != nil {
return labelsMap, err
}
value := strings.TrimSpace(l[1])
if err := validateLabelValue(key, value, field.ToPath(opts...)); err != nil {
return labelsMap, err
}
labelsMap[key] = value
}
return labelsMap, nil
} | ConvertSelectorToLabelsMap converts selector string to labels map
and validates keys and values | ConvertSelectorToLabelsMap | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/labels/labels.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/labels/labels.go | Apache-2.0 |
func (in *Requirement) DeepCopyInto(out *Requirement) {
*out = *in
if in.strValues != nil {
in, out := &in.strValues, &out.strValues
*out = make([]string, len(*in))
copy(*out, *in)
}
return
} | DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. | DeepCopyInto | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/labels/zz_generated.deepcopy.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/labels/zz_generated.deepcopy.go | Apache-2.0 |
func (in *Requirement) DeepCopy() *Requirement {
if in == nil {
return nil
}
out := new(Requirement)
in.DeepCopyInto(out)
return out
} | DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Requirement. | DeepCopy | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/labels/zz_generated.deepcopy.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/labels/zz_generated.deepcopy.go | Apache-2.0 |
func (n NamespacedName) String() string {
return n.Namespace + string(Separator) + n.Name
} | String returns the general purpose string representation | String | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/types/namespacedname.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/types/namespacedname.go | Apache-2.0 |
func (n NamespacedName) MarshalLog() interface{} {
return struct {
Name string `json:"name"`
Namespace string `json:"namespace,omitempty"`
}{
Name: n.Name,
Namespace: n.Namespace,
}
} | MarshalLog emits a struct containing required key/value pair | MarshalLog | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/types/namespacedname.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/types/namespacedname.go | Apache-2.0 |
func NewBroadcaster(queueLength int, fullChannelBehavior FullChannelBehavior) *Broadcaster {
m := &Broadcaster{
watchers: map[int64]*broadcasterWatcher{},
incoming: make(chan Event, incomingQueueLength),
stopped: make(chan struct{}),
watchQueueLength: queueLength,
fullChannelBehavior: fullChannelBehavior,
}
m.distributing.Add(1)
go m.loop()
return m
} | NewBroadcaster creates a new Broadcaster. queueLength is the maximum number of events to queue per watcher.
It is guaranteed that events will be distributed in the order in which they occur,
but the order in which a single event is distributed among all of the watchers is unspecified. | NewBroadcaster | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/watch/mux.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/watch/mux.go | Apache-2.0 |
func NewLongQueueBroadcaster(queueLength int, fullChannelBehavior FullChannelBehavior) *Broadcaster {
m := &Broadcaster{
watchers: map[int64]*broadcasterWatcher{},
incoming: make(chan Event, queueLength),
stopped: make(chan struct{}),
watchQueueLength: queueLength,
fullChannelBehavior: fullChannelBehavior,
}
m.distributing.Add(1)
go m.loop()
return m
} | NewLongQueueBroadcaster functions nearly identically to NewBroadcaster,
except that the incoming queue is the same size as the outgoing queues
(specified by queueLength). | NewLongQueueBroadcaster | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/watch/mux.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/watch/mux.go | Apache-2.0 |
func (m *Broadcaster) blockQueue(f func()) {
m.incomingBlock.Lock()
defer m.incomingBlock.Unlock()
select {
case <-m.stopped:
return
default:
}
var wg sync.WaitGroup
wg.Add(1)
m.incoming <- Event{
Type: internalRunFunctionMarker,
Object: functionFakeRuntimeObject(func() {
defer wg.Done()
f()
}),
}
wg.Wait()
} | Execute f, blocking the incoming queue (and waiting for it to drain first).
The purpose of this terrible hack is so that watchers added after an event
won't ever see that event, and will always see any event after they are
added. | blockQueue | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/watch/mux.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/watch/mux.go | Apache-2.0 |
func (m *Broadcaster) Watch() (Interface, error) {
var w *broadcasterWatcher
m.blockQueue(func() {
id := m.nextWatcher
m.nextWatcher++
w = &broadcasterWatcher{
result: make(chan Event, m.watchQueueLength),
stopped: make(chan struct{}),
id: id,
m: m,
}
m.watchers[id] = w
})
if w == nil {
return nil, fmt.Errorf("broadcaster already stopped")
}
return w, nil
} | Watch adds a new watcher to the list and returns an Interface for it.
Note: new watchers will only receive new events. They won't get an entire history
of previous events. It will block until the watcher is actually added to the
broadcaster. | Watch | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/watch/mux.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/watch/mux.go | Apache-2.0 |
func (m *Broadcaster) WatchWithPrefix(queuedEvents []Event) (Interface, error) {
var w *broadcasterWatcher
m.blockQueue(func() {
id := m.nextWatcher
m.nextWatcher++
length := m.watchQueueLength
if n := len(queuedEvents) + 1; n > length {
length = n
}
w = &broadcasterWatcher{
result: make(chan Event, length),
stopped: make(chan struct{}),
id: id,
m: m,
}
m.watchers[id] = w
for _, e := range queuedEvents {
w.result <- e
}
})
if w == nil {
return nil, fmt.Errorf("broadcaster already stopped")
}
return w, nil
} | WatchWithPrefix adds a new watcher to the list and returns an Interface for it. It sends
queuedEvents down the new watch before beginning to send ordinary events from Broadcaster.
The returned watch will have a queue length that is at least large enough to accommodate
all of the items in queuedEvents. It will block until the watcher is actually added to
the broadcaster. | WatchWithPrefix | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/watch/mux.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/watch/mux.go | Apache-2.0 |
func (m *Broadcaster) stopWatching(id int64) {
m.blockQueue(func() {
w, ok := m.watchers[id]
if !ok {
// No need to do anything, it's already been removed from the list.
return
}
delete(m.watchers, id)
close(w.result)
})
} | stopWatching stops the given watcher and removes it from the list. | stopWatching | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/watch/mux.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/watch/mux.go | Apache-2.0 |
func (m *Broadcaster) closeAll() {
for _, w := range m.watchers {
close(w.result)
}
// Delete everything from the map, since presence/absence in the map is used
// by stopWatching to avoid double-closing the channel.
m.watchers = map[int64]*broadcasterWatcher{}
} | closeAll disconnects all watchers (presumably in response to a Shutdown call). | closeAll | go | k8snetworkplumbingwg/multus-cni | vendor/k8s.io/apimachinery/pkg/watch/mux.go | https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/watch/mux.go | Apache-2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.