// Annotations returns all the annotations corresponding to an entity.
555859
func (m *Model) Annotations(entity GlobalEntity) (map[string]string, error) {
	doc := new(annotatorDoc)
	annotations, closer := m.st.db().GetCollection(annotationsC)
	defer closer()
	err := annotations.FindId(entity.globalKey()).One(doc)
	if err == mgo.ErrNotFound {
		// Returning an empty map if there are no annotations.
		return make(map[string]string), nil
	}
	if err != nil {
		return nil, errors.Trace(err)
	}
	return doc.Annotations, nil
}
405699
func makeLabels(labels, annotations map[string]string) map[string]string {
	merged := make(map[string]string)
	for k, v := range labels {
		merged[k] = v
	}
	for k, v := range annotations {
		// Assume there won't be conflict.
		merged[fmt.Sprintf("%s%s", annotationPrefix, k)] = v
	}
	return merged
}
719048
func WriteAnnotations(bkt *bolt.Bucket, labels map[string]string) error {
	return writeMap(bkt, bucketKeyAnnotations, labels)
}
770855
func (v *Validator) CheckAnnotations() (errs error) {
	logrus.Debugf("check annotations")

	reversedDomain := regexp.MustCompile(`^[A-Za-z]{2,6}(\.[A-Za-z0-9-]{1,63})+$`)
	for key := range v.spec.Annotations {
		if strings.HasPrefix(key, "org.opencontainers") {
			errs = multierror.Append(errs,
				specerror.NewError(
					specerror.AnnotationsKeyReservedNS,
					fmt.Errorf("key %q is reserved", key),
					rspec.Version))
		}

		if !reversedDomain.MatchString(key) {
			errs = multierror.Append(errs,
				specerror.NewError(
					specerror.AnnotationsKeyReversedDomain,
					fmt.Errorf("key %q SHOULD be named using a reverse domain notation", key),
					rspec.Version))
		}
	}

	return
}
988668
func Annotatef(err error, format string, args ...interface{}) error {
	return annotate(err, fmt.Sprintf(format, args...))
}
1241454
func (r *CiliumNetworkPolicy) AnnotationsEquals(o *CiliumNetworkPolicy) bool {
	if o == nil {
		return r == nil
	}
	return reflect.DeepEqual(r.ObjectMeta.Annotations, o.ObjectMeta.Annotations)
}
37099
func (s *EntityRecognizerInputDataConfig) SetAnnotations(v *EntityRecognizerAnnotations) *EntityRecognizerInputDataConfig {
	s.Annotations = v
	return s
}
763857
func AnnotationFor(obj runtime.Object, key string) string {
	objectMeta, err := meta.Accessor(obj)
	if err != nil {
		return ""
	}
	if objectMeta == nil || reflect.ValueOf(objectMeta).IsNil() {
		return ""
	}
	return objectMeta.GetAnnotations()[key]
}
533
func WithAnnotations(annotations map[string]string) SpecOpts {
	return func(_ context.Context, _ Client, _ *containers.Container, s *Spec) error {
		if s.Annotations == nil {
			s.Annotations = make(map[string]string)
		}
		for k, v := range annotations {
			s.Annotations[k] = v
		}
		return nil
	}
}
1312667
func Annotate(src []byte, anns Annotations, writeContent func(io.Writer, []byte)) ([]byte, error) {
	out := bytes.NewBuffer(make([]byte, 0, len(src)+20*len(anns)))
	var err error

	// Keep a stack of open annotations (i.e., that have been opened and not yet
	// closed).
	var open []*Annotation

	for b := range src {
		// Open annotations that begin here.
		for i, a := range anns {
			if a.Start < 0 || a.Start == b {
				if a.Start < 0 {
					err = ErrStartOutOfBounds
				}

				out.Write(a.Left)

				if a.Start == a.End {
					out.Write(a.Right)
				} else {
					// Put this annotation on the stack of annotations that will need
					// to be closed. We remove it from anns at the end of the loop
					// (to avoid modifying anns while we're iterating over it).
					open = append(open, a)
				}
			} else if a.Start > b {
				// Remove all annotations that we opened (we already put them on the
				// stack of annotations that will need to be closed).
				anns = anns[i:]
				break
			}
		}

		if writeContent == nil {
			out.Write(src[b : b+1])
		} else {
			writeContent(out, src[b:b+1])
		}

		// Close annotations that end after this byte, handling overlapping
		// elements as described below. Elements of open are ordered by their
		// annotation start position.

		// We need to close all annotatations ending after this byte, as well as
		// annotations that overlap this annotation's end and should reopen
		// after it closes.
		var toClose []*Annotation

		// Find annotations ending after this byte.
		minStart := 0 // start of the leftmost annotation closing here
		for i := len(open) - 1; i >= 0; i-- {
			a := open[i]
			if a.End == b+1 {
				toClose = append(toClose, a)
				if minStart == 0 || a.Start < minStart {
					minStart = a.Start
				}
				open = append(open[:i], open[i+1:]...)
			}
		}

		// Find annotations that overlap annotations closing after this and
		// that should reopen after it closes.
		if toClose != nil {
			for i := len(open) - 1; i >= 0; i-- {
				if a := open[i]; a.Start > minStart {
					out.Write(a.Right)
				}
			}
		}

		for _, a := range toClose {
			out.Write(a.Right)
		}

		if toClose != nil {
			for _, a := range open {
				if a.Start > minStart {
					out.Write(a.Left)
				}
			}
		}
	}

	if len(open) > 0 {
		if err == ErrStartOutOfBounds {
			err = ErrStartAndEndOutOfBounds
		} else {
			err = ErrEndOutOfBounds
		}

		// Clean up by closing unclosed annotations, in the order they would
		// have been closed in.
		for i := len(open) - 1; i >= 0; i-- {
			a := open[i]
			out.Write(a.Right)
		}
	}

	return out.Bytes(), err
}
1092674
func GetTaintsFromNodeAnnotations(annotations map[string]string) ([]core.Taint, error) {
	var taints []core.Taint
	if len(annotations) > 0 && annotations[core.TaintsAnnotationKey] != "" {
		err := json.Unmarshal([]byte(annotations[core.TaintsAnnotationKey]), &taints)
		if err != nil {
			return []core.Taint{}, err
		}
	}
	return taints, nil
}
85425
func FormatAnnotations(anns []*Annotation) string {
	if len(anns) == 0 {
		return ""
	}

	as := make([]string, len(anns))
	for i, ann := range anns {
		as[i] = ann.String()
	}

	return "(" + strings.Join(as, ", ") + ")"
}
1276753
func (s *Segment) AddAnnotation(key string, value string) {
	s.addAnnotation(key, value)
}
847416
func (v *Validator) Fields() []string {
	fields := []string{}
	for _, vr := range v.results {
		fields = append(fields, vr.field)
	}
	return fields
}
1306979
func (a *TokenBasedAnnotation) Annotate(tokens []*Token) []*Token {
	for _, tokPair := range a.TokenGrouper.Group(tokens) {
		a.tokenAnnotation(tokPair[0], tokPair[1])
	}

	return tokens
}
181688
func (o AnnotateOptions) updateAnnotations(obj runtime.Object) error {
	meta, err := api.ObjectMetaFor(obj)
	if err != nil {
		return err
	}
	if !o.overwrite {
		if err := validateNoAnnotationOverwrites(meta, o.newAnnotations); err != nil {
			return err
		}
	}

	if meta.Annotations == nil {
		meta.Annotations = make(map[string]string)
	}

	for key, value := range o.newAnnotations {
		meta.Annotations[key] = value
	}
	for _, annotation := range o.removeAnnotations {
		delete(meta.Annotations, annotation)
	}

	if len(o.resourceVersion) != 0 {
		meta.ResourceVersion = o.resourceVersion
	}
	return nil
}
121545
func (a *AnnotationStore) queryAnnotations(ctx context.Context, query string) ([]chronograf.Annotation, error) {
	res, err := a.client.Query(ctx, chronograf.Query{
		Command: query,
		DB:      AnnotationsDB,
		Epoch:   "ns",
	})
	if err != nil {
		return nil, err
	}
	octets, err := res.MarshalJSON()
	if err != nil {
		return nil, err
	}

	results := influxResults{}
	d := json.NewDecoder(bytes.NewReader(octets))
	d.UseNumber()
	if err := d.Decode(&results); err != nil {
		return nil, err
	}
	return results.Annotations()
}