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 UnmarshalStrict(data []byte, v interface{}) error { preserveIntFloat := func(d *json.Decoder) *json.Decoder { d.UseNumber() return d } switch v := v.(type) { case *map[string]interface{}: if err := yaml.UnmarshalStrict(data, v, preserveIntFloat); err != nil { return err } return jsonutil.ConvertMapNumbers(*v, 0) case *[]interface{}: if err := yaml.UnmarshalStrict(data, v, preserveIntFloat); err != nil { return err } return jsonutil.ConvertSliceNumbers(*v, 0) case *interface{}: if err := yaml.UnmarshalStrict(data, v, preserveIntFloat); err != nil { return err } return jsonutil.ConvertInterfaceNumbers(v, 0) default: return yaml.UnmarshalStrict(data, v) }
UnmarshalStrict unmarshals the given data strictly (erroring when there are duplicate fields).
UnmarshalStrict
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/yaml/decoder.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/yaml/decoder.go
Apache-2.0
func ToJSON(data []byte) ([]byte, error) { if hasJSONPrefix(data) { return data, nil } return yaml.YAMLToJSON(data) }
ToJSON converts a single YAML document into a JSON document or returns an error. If the document appears to be JSON the YAML decoding path is not used (so that error messages are JSON specific).
ToJSON
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/yaml/decoder.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/yaml/decoder.go
Apache-2.0
func NewYAMLToJSONDecoder(r io.Reader) *YAMLToJSONDecoder { reader := bufio.NewReader(r) return &YAMLToJSONDecoder{ reader: NewYAMLReader(reader), } }
NewYAMLToJSONDecoder decodes YAML documents from the provided stream in chunks by converting each document (as defined by the YAML spec) into its own chunk, converting it to JSON via yaml.YAMLToJSON, and then passing it to json.Decoder.
NewYAMLToJSONDecoder
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/yaml/decoder.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/yaml/decoder.go
Apache-2.0
func NewDocumentDecoder(r io.ReadCloser) io.ReadCloser { scanner := bufio.NewScanner(r) // the size of initial allocation for buffer 4k buf := make([]byte, 4*1024) // the maximum size used to buffer a token 5M scanner.Buffer(buf, 5*1024*1024) scanner.Split(splitYAMLDocument) return &YAMLDecoder{ r: r, scanner: scanner, } }
NewDocumentDecoder decodes YAML documents from the provided stream in chunks by converting each document (as defined by the YAML spec) into its own chunk. io.ErrShortBuffer will be returned if the entire buffer could not be read to assist the caller in framing the chunk.
NewDocumentDecoder
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/yaml/decoder.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/yaml/decoder.go
Apache-2.0
func splitYAMLDocument(data []byte, atEOF bool) (advance int, token []byte, err error) { if atEOF && len(data) == 0 { return 0, nil, nil } sep := len([]byte(yamlSeparator)) if i := bytes.Index(data, []byte(yamlSeparator)); i >= 0 { // We have a potential document terminator i += sep after := data[i:] if len(after) == 0 { // we can't read any more characters if atEOF { return len(data), data[:len(data)-sep], nil } return 0, nil, nil } if j := bytes.IndexByte(after, '\n'); j >= 0 { return i + j + 1, data[0 : i-sep], nil } return 0, nil, nil } // If we're at EOF, we have a final, non-terminated line. Return it. if atEOF { return len(data), data, nil } // Request more data. return 0, nil, nil }
splitYAMLDocument is a bufio.SplitFunc for splitting YAML streams into individual documents.
splitYAMLDocument
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/yaml/decoder.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/yaml/decoder.go
Apache-2.0
func NewYAMLOrJSONDecoder(r io.Reader, bufferSize int) *YAMLOrJSONDecoder { return &YAMLOrJSONDecoder{ r: r, bufferSize: bufferSize, } }
NewYAMLOrJSONDecoder returns a decoder that will process YAML documents or JSON documents from the given reader as a stream. bufferSize determines how far into the stream the decoder will look to figure out whether this is a JSON stream (has whitespace followed by an open brace).
NewYAMLOrJSONDecoder
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/yaml/decoder.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/yaml/decoder.go
Apache-2.0
func GuessJSONStream(r io.Reader, size int) (io.Reader, []byte, bool) { buffer := bufio.NewReaderSize(r, size) b, _ := buffer.Peek(size) return buffer, b, hasJSONPrefix(b) }
GuessJSONStream scans the provided reader up to size, looking for an open brace indicating this is JSON. It will return the bufio.Reader it creates for the consumer.
GuessJSONStream
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/yaml/decoder.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/yaml/decoder.go
Apache-2.0
func IsJSONBuffer(buf []byte) bool { return hasJSONPrefix(buf) }
IsJSONBuffer scans the provided buffer, looking for an open brace indicating this is JSON.
IsJSONBuffer
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/yaml/decoder.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/yaml/decoder.go
Apache-2.0
func hasJSONPrefix(buf []byte) bool { return hasPrefix(buf, jsonPrefix) }
hasJSONPrefix returns true if the provided buffer appears to start with a JSON open brace.
hasJSONPrefix
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/yaml/decoder.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/yaml/decoder.go
Apache-2.0
func hasPrefix(buf []byte, prefix []byte) bool { trim := bytes.TrimLeftFunc(buf, unicode.IsSpace) return bytes.HasPrefix(trim, prefix) }
Return true if the first non-whitespace bytes in buf is prefix.
hasPrefix
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/yaml/decoder.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/yaml/decoder.go
Apache-2.0
func NewDeducedTypeConverter() TypeConverter { return internal.NewDeducedTypeConverter() }
NewDeducedTypeConverter creates a TypeConverter for CRDs that don't have a schema. It does implement the same interface though (and create the same types of objects), so that everything can still work the same. CRDs are merged with all their fields being "atomic" (lists included).
NewDeducedTypeConverter
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/typeconverter.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/typeconverter.go
Apache-2.0
func NewTypeConverter(openapiSpec map[string]*spec.Schema, preserveUnknownFields bool) (TypeConverter, error) { return internal.NewTypeConverter(openapiSpec, preserveUnknownFields) }
NewTypeConverter builds a TypeConverter from a map of OpenAPIV3 schemas. This will automatically find the proper version of the object, and the corresponding schema information. The keys to the map must be consistent with the names used by Refs within the schemas. The schemas should conform to the Kubernetes Structural Schema OpenAPI restrictions found in docs: https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#specifying-a-structural-schema
NewTypeConverter
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/typeconverter.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/typeconverter.go
Apache-2.0
func (p *GvkParser) Type(gvk schema.GroupVersionKind) *typed.ParseableType { typeName, ok := p.gvks[gvk] if !ok { return nil } t := p.parser.Type(typeName) return &t }
Type returns a helper which can produce objects of the given type. Any errors are deferred until a further function is called.
Type
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/gvkparser.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/gvkparser.go
Apache-2.0
func NewGVKParser(models proto.Models, preserveUnknownFields bool) (*GvkParser, error) { typeSchema, err := schemaconv.ToSchemaWithPreserveUnknownFields(models, preserveUnknownFields) if err != nil { return nil, fmt.Errorf("failed to convert models to schema: %v", err) } parser := GvkParser{ gvks: map[schema.GroupVersionKind]string{}, } parser.parser = typed.Parser{Schema: smdschema.Schema{Types: typeSchema.Types}} for _, modelName := range models.ListModels() { model := models.LookupModel(modelName) if model == nil { panic(fmt.Sprintf("ListModels returns a model that can't be looked-up for: %v", modelName)) } gvkList := parseGroupVersionKind(model) for _, gvk := range gvkList { if len(gvk.Kind) > 0 { _, ok := parser.gvks[gvk] if ok { return nil, fmt.Errorf("duplicate entry for %v", gvk) } parser.gvks[gvk] = modelName } } } return &parser, nil }
NewGVKParser builds a GVKParser from a proto.Models. This will automatically find the proper version of the object, and the corresponding schema information.
NewGVKParser
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/gvkparser.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/gvkparser.go
Apache-2.0
func parseGroupVersionKind(s proto.Schema) []schema.GroupVersionKind { extensions := s.GetExtensions() gvkListResult := []schema.GroupVersionKind{} // Get the extensions gvkExtension, ok := extensions[groupVersionKindExtensionKey] if !ok { return []schema.GroupVersionKind{} } // gvk extension must be a list of at least 1 element. gvkList, ok := gvkExtension.([]interface{}) if !ok { return []schema.GroupVersionKind{} } for _, gvk := range gvkList { // gvk extension list must be a map with group, version, and // kind fields gvkMap, ok := gvk.(map[interface{}]interface{}) if !ok { continue } group, ok := gvkMap["group"].(string) if !ok { continue } version, ok := gvkMap["version"].(string) if !ok { continue } kind, ok := gvkMap["kind"].(string) if !ok { continue } gvkListResult = append(gvkListResult, schema.GroupVersionKind{ Group: group, Version: version, Kind: kind, }) } return gvkListResult }
Get and parse GroupVersionKind from the extension. Returns empty if it doesn't have one.
parseGroupVersionKind
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/gvkparser.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/gvkparser.go
Apache-2.0
func NewDefaultFieldManager(typeConverter TypeConverter, objectConverter runtime.ObjectConvertor, objectDefaulter runtime.ObjectDefaulter, objectCreater runtime.ObjectCreater, kind schema.GroupVersionKind, hub schema.GroupVersion, subresource string, resetFields map[fieldpath.APIVersion]*fieldpath.Set) (*FieldManager, error) { f, err := internal.NewStructuredMergeManager(typeConverter, objectConverter, objectDefaulter, kind.GroupVersion(), hub, resetFields) if err != nil { return nil, fmt.Errorf("failed to create field manager: %v", err) } return internal.NewDefaultFieldManager(f, typeConverter, objectConverter, objectCreater, kind, subresource), nil }
NewDefaultFieldManager creates a new FieldManager that merges apply requests and update managed fields for other types of requests.
NewDefaultFieldManager
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/fieldmanager.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/fieldmanager.go
Apache-2.0
func NewDefaultCRDFieldManager(typeConverter TypeConverter, objectConverter runtime.ObjectConvertor, objectDefaulter runtime.ObjectDefaulter, objectCreater runtime.ObjectCreater, kind schema.GroupVersionKind, hub schema.GroupVersion, subresource string, resetFields map[fieldpath.APIVersion]*fieldpath.Set) (_ *FieldManager, err error) { f, err := internal.NewCRDStructuredMergeManager(typeConverter, objectConverter, objectDefaulter, kind.GroupVersion(), hub, resetFields) if err != nil { return nil, fmt.Errorf("failed to create field manager: %v", err) } return internal.NewDefaultFieldManager(f, typeConverter, objectConverter, objectCreater, kind, subresource), nil }
NewDefaultCRDFieldManager creates a new FieldManager specifically for CRDs. This allows for the possibility of fields which are not defined in models, as well as having no models defined at all.
NewDefaultCRDFieldManager
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/fieldmanager.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/fieldmanager.go
Apache-2.0
func NewScaleHandler(parentEntries []metav1.ManagedFieldsEntry, groupVersion schema.GroupVersion, mappings ResourcePathMappings) *ScaleHandler { return &ScaleHandler{ parentEntries: parentEntries, groupVersion: groupVersion, mappings: mappings, } }
NewScaleHandler creates a new ScaleHandler
NewScaleHandler
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/scalehandler.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/scalehandler.go
Apache-2.0
func (h *ScaleHandler) ToSubresource() ([]metav1.ManagedFieldsEntry, error) { managed, err := internal.DecodeManagedFields(h.parentEntries) if err != nil { return nil, err } f := fieldpath.ManagedFields{} t := map[string]*metav1.Time{} for manager, versionedSet := range managed.Fields() { path, ok := h.mappings[string(versionedSet.APIVersion())] // Skip the entry if the APIVersion is unknown if !ok || path == nil { continue } if versionedSet.Set().Has(path) { newVersionedSet := fieldpath.NewVersionedSet( fieldpath.NewSet(replicasPathInScale), fieldpath.APIVersion(scaleGroupVersion.String()), versionedSet.Applied(), ) f[manager] = newVersionedSet t[manager] = managed.Times()[manager] } } return managedFieldsEntries(internal.NewManaged(f, t)) }
ToSubresource filter the managed fields of the main resource and convert them so that they can be handled by scale. For the managed fields that have a replicas path it performs two changes: 1. APIVersion is changed to the APIVersion of the scale subresource 2. Replicas path of the main resource is transformed to the replicas path of the scale subresource
ToSubresource
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/scalehandler.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/scalehandler.go
Apache-2.0
func (h *ScaleHandler) ToParent(scaleEntries []metav1.ManagedFieldsEntry) ([]metav1.ManagedFieldsEntry, error) { decodedParentEntries, err := internal.DecodeManagedFields(h.parentEntries) if err != nil { return nil, err } parentFields := decodedParentEntries.Fields() decodedScaleEntries, err := internal.DecodeManagedFields(scaleEntries) if err != nil { return nil, err } scaleFields := decodedScaleEntries.Fields() f := fieldpath.ManagedFields{} t := map[string]*metav1.Time{} for manager, versionedSet := range parentFields { // Get the main resource "replicas" path path, ok := h.mappings[string(versionedSet.APIVersion())] // Drop the entry if the APIVersion is unknown. if !ok { continue } // If the parent entry does not have the replicas path or it is nil, just // keep it as it is. The path is nil for Custom Resources without scale // subresource. if path == nil || !versionedSet.Set().Has(path) { f[manager] = versionedSet t[manager] = decodedParentEntries.Times()[manager] continue } if _, ok := scaleFields[manager]; !ok { // "Steal" the replicas path from the main resource entry newSet := versionedSet.Set().Difference(fieldpath.NewSet(path)) if !newSet.Empty() { newVersionedSet := fieldpath.NewVersionedSet( newSet, versionedSet.APIVersion(), versionedSet.Applied(), ) f[manager] = newVersionedSet t[manager] = decodedParentEntries.Times()[manager] } } else { // Field wasn't stolen, let's keep the entry as it is. f[manager] = versionedSet t[manager] = decodedParentEntries.Times()[manager] delete(scaleFields, manager) } } for manager, versionedSet := range scaleFields { if !versionedSet.Set().Has(replicasPathInScale) { continue } newVersionedSet := fieldpath.NewVersionedSet( fieldpath.NewSet(h.mappings[h.groupVersion.String()]), fieldpath.APIVersion(h.groupVersion.String()), versionedSet.Applied(), ) f[manager] = newVersionedSet t[manager] = decodedParentEntries.Times()[manager] } return managedFieldsEntries(internal.NewManaged(f, t)) }
ToParent merges `scaleEntries` with the entries of the main resource and transforms them accordingly
ToParent
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/scalehandler.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/scalehandler.go
Apache-2.0
func ExtractInto(object runtime.Object, objectType typed.ParseableType, fieldManager string, applyConfiguration interface{}, subresource string) error { typedObj, err := toTyped(object, objectType) if err != nil { return fmt.Errorf("error converting obj to typed: %w", err) } accessor, err := meta.Accessor(object) if err != nil { return fmt.Errorf("error accessing metadata: %w", err) } fieldsEntry, ok := findManagedFields(accessor, fieldManager, subresource) if !ok { return nil } fieldset := &fieldpath.Set{} err = fieldset.FromJSON(bytes.NewReader(fieldsEntry.FieldsV1.Raw)) if err != nil { return fmt.Errorf("error marshalling FieldsV1 to JSON: %w", err) } u := typedObj.ExtractItems(fieldset.Leaves()).AsValue().Unstructured() m, ok := u.(map[string]interface{}) if !ok { return fmt.Errorf("unable to convert managed fields for %s to unstructured, expected map, got %T", fieldManager, u) } // set the type meta manually if it doesn't exist to avoid missing kind errors // when decoding from unstructured JSON if _, ok := m["kind"]; !ok && object.GetObjectKind().GroupVersionKind().Kind != "" { m["kind"] = object.GetObjectKind().GroupVersionKind().Kind m["apiVersion"] = object.GetObjectKind().GroupVersionKind().GroupVersion().String() } if err := runtime.DefaultUnstructuredConverter.FromUnstructured(m, applyConfiguration); err != nil { return fmt.Errorf("error extracting into obj from unstructured: %w", err) } return nil }
ExtractInto extracts the applied configuration state from object for fieldManager into applyConfiguration. If no managed fields are found for the given fieldManager, no error is returned, but applyConfiguration is left unpopulated. It is possible that no managed fields were found for the fieldManager because other field managers have taken ownership of all the fields previously owned by the fieldManager. It is also possible the fieldManager never owned fields. The provided object MUST bo a root resource object since subresource objects do not contain their own managed fields. For example, an autoscaling.Scale object read from a "scale" subresource does not have any managed fields and so cannot be used as the object. If the fields of a subresource are a subset of the fields of the root object, and their field paths and types are exactly the same, then ExtractInto can be called with the root resource as the object and the subresource as the applyConfiguration. This works for "status", obviously, because status is represented by the exact same object as the root resource. This does NOT work, for example, with the "scale" subresources of Deployment, ReplicaSet and StatefulSet. While the spec.replicas, status.replicas fields are in the same exact field path locations as they are in autoscaling.Scale, the selector fields are in different locations, and are a different type.
ExtractInto
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/extract.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/extract.go
Apache-2.0
func NewDeducedTypeConverter() TypeConverter { return deducedTypeConverter{} }
DeducedTypeConverter is a TypeConverter for CRDs that don't have a schema. It does implement the same interface though (and create the same types of objects), so that everything can still work the same. CRDs are merged with all their fields being "atomic" (lists included).
NewDeducedTypeConverter
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/typeconverter.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/typeconverter.go
Apache-2.0
func NewAtMostEvery(delay time.Duration) *AtMostEvery { return &AtMostEvery{ delay: delay, } }
NewAtMostEvery creates a new AtMostEvery, that will run the method at most every given duration.
NewAtMostEvery
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/atmostevery.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/atmostevery.go
Apache-2.0
func (s *AtMostEvery) updateLastCall() bool { s.mutex.Lock() defer s.mutex.Unlock() if time.Since(s.lastCall) < s.delay { return false } s.lastCall = time.Now() return true }
updateLastCall returns true if the lastCall time has been updated, false if it was too early.
updateLastCall
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/atmostevery.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/atmostevery.go
Apache-2.0
func (s *AtMostEvery) Do(fn func()) bool { if !s.updateLastCall() { return false } fn() return true }
Do will run the method if enough time has passed, and return true. Otherwise, it does nothing and returns false.
Do
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/atmostevery.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/atmostevery.go
Apache-2.0
func NewLastAppliedManager(fieldManager Manager, typeConverter TypeConverter, objectConverter runtime.ObjectConvertor, groupVersion schema.GroupVersion) Manager { return &lastAppliedManager{ fieldManager: fieldManager, typeConverter: typeConverter, objectConverter: objectConverter, groupVersion: groupVersion, } }
NewLastAppliedManager converts the client-side apply annotation to server-side apply managed fields
NewLastAppliedManager
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/lastappliedmanager.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/lastappliedmanager.go
Apache-2.0
func (f *lastAppliedManager) Update(liveObj, newObj runtime.Object, managed Managed, manager string) (runtime.Object, Managed, error) { return f.fieldManager.Update(liveObj, newObj, managed, manager) }
Update implements Manager.
Update
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/lastappliedmanager.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/lastappliedmanager.go
Apache-2.0
func (f *lastAppliedManager) Apply(liveObj, newObj runtime.Object, managed Managed, manager string, force bool) (runtime.Object, Managed, error) { newLiveObj, newManaged, newErr := f.fieldManager.Apply(liveObj, newObj, managed, manager, force) // Upgrade the client-side apply annotation only from kubectl server-side-apply. // To opt-out of this behavior, users may specify a different field manager. if manager != "kubectl" { return newLiveObj, newManaged, newErr } // Check if we have conflicts if newErr == nil { return newLiveObj, newManaged, newErr } conflicts, ok := newErr.(merge.Conflicts) if !ok { return newLiveObj, newManaged, newErr } conflictSet := conflictsToSet(conflicts) // Check if conflicts are allowed due to client-side apply, // and if so, then force apply allowedConflictSet, err := f.allowedConflictsFromLastApplied(liveObj) if err != nil { return newLiveObj, newManaged, newErr } if !conflictSet.Difference(allowedConflictSet).Empty() { newConflicts := conflictsDifference(conflicts, allowedConflictSet) return newLiveObj, newManaged, newConflicts } return f.fieldManager.Apply(liveObj, newObj, managed, manager, true) }
Apply will consider the last-applied annotation for upgrading an object managed by client-side apply to server-side apply without conflicts.
Apply
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/lastappliedmanager.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/lastappliedmanager.go
Apache-2.0
func NewFieldManager(f Manager, subresource string) *FieldManager { return &FieldManager{fieldManager: f, subresource: subresource} }
NewFieldManager creates a new FieldManager that decodes, manages, then re-encodes managedFields on update and apply requests.
NewFieldManager
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/fieldmanager.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/fieldmanager.go
Apache-2.0
func NewDefaultFieldManager(f Manager, typeConverter TypeConverter, objectConverter runtime.ObjectConvertor, objectCreater runtime.ObjectCreater, kind schema.GroupVersionKind, subresource string) *FieldManager { return NewFieldManager( NewVersionCheckManager( NewLastAppliedUpdater( NewLastAppliedManager( NewProbabilisticSkipNonAppliedManager( NewCapManagersManager( NewBuildManagerInfoManager( NewManagedFieldsUpdater( NewStripMetaManager(f), ), kind.GroupVersion(), subresource, ), DefaultMaxUpdateManagers, ), objectCreater, DefaultTrackOnCreateProbability, ), typeConverter, objectConverter, kind.GroupVersion(), ), ), kind, ), subresource, ) }
newDefaultFieldManager is a helper function which wraps a Manager with certain default logic.
NewDefaultFieldManager
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/fieldmanager.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/fieldmanager.go
Apache-2.0
func (f *FieldManager) Update(liveObj, newObj runtime.Object, manager string) (object runtime.Object, err error) { // First try to decode the managed fields provided in the update, // This is necessary to allow directly updating managed fields. isSubresource := f.subresource != "" managed, err := decodeLiveOrNew(liveObj, newObj, isSubresource) if err != nil { return newObj, nil } RemoveObjectManagedFields(newObj) if object, managed, err = f.fieldManager.Update(liveObj, newObj, managed, manager); err != nil { return nil, err } if err = EncodeObjectManagedFields(object, managed); err != nil { return nil, fmt.Errorf("failed to encode managed fields: %v", err) } return object, nil }
Update is used when the object has already been merged (non-apply use-case), and simply updates the managed fields in the output object.
Update
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/fieldmanager.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/fieldmanager.go
Apache-2.0
func (f *FieldManager) UpdateNoErrors(liveObj, newObj runtime.Object, manager string) runtime.Object { obj, err := f.Update(liveObj, newObj, manager) if err != nil { atMostEverySecond.Do(func() { ns, name := "unknown", "unknown" if accessor, err := meta.Accessor(newObj); err == nil { ns = accessor.GetNamespace() name = accessor.GetName() } klog.ErrorS(err, "[SHOULD NOT HAPPEN] failed to update managedFields", "versionKind", newObj.GetObjectKind().GroupVersionKind(), "namespace", ns, "name", name) }) // Explicitly remove managedFields on failure, so that // we can't have garbage in it. RemoveObjectManagedFields(newObj) return newObj } return obj }
UpdateNoErrors is the same as Update, but it will not return errors. If an error happens, the object is returned with managedFields cleared.
UpdateNoErrors
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/fieldmanager.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/fieldmanager.go
Apache-2.0
func isResetManagedFields(managedFields []metav1.ManagedFieldsEntry) bool { if len(managedFields) == 0 { return managedFields != nil } if len(managedFields) == 1 { return reflect.DeepEqual(managedFields[0], metav1.ManagedFieldsEntry{}) } return false }
Returns true if the managedFields indicate that the user is trying to reset the managedFields, i.e. if the list is non-nil but empty, or if the list has one empty item.
isResetManagedFields
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/fieldmanager.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/fieldmanager.go
Apache-2.0
func (f *FieldManager) Apply(liveObj, appliedObj runtime.Object, manager string, force bool) (object runtime.Object, err error) { // If the object doesn't have metadata, apply isn't allowed. accessor, err := meta.Accessor(liveObj) if err != nil { return nil, fmt.Errorf("couldn't get accessor: %v", err) } // Decode the managed fields in the live object, since it isn't allowed in the patch. managed, err := DecodeManagedFields(accessor.GetManagedFields()) if err != nil { return nil, fmt.Errorf("failed to decode managed fields: %v", err) } object, managed, err = f.fieldManager.Apply(liveObj, appliedObj, managed, manager, force) if err != nil { if conflicts, ok := err.(merge.Conflicts); ok { return nil, NewConflictError(conflicts) } return nil, err } if err = EncodeObjectManagedFields(object, managed); err != nil { return nil, fmt.Errorf("failed to encode managed fields: %v", err) } return object, nil }
Apply is used when server-side apply is called, as it merges the object and updates the managed fields.
Apply
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/fieldmanager.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/fieldmanager.go
Apache-2.0
func FieldsToSet(f metav1.FieldsV1) (s fieldpath.Set, err error) { err = s.FromJSON(bytes.NewReader(f.Raw)) return s, err }
FieldsToSet creates a set paths from an input trie of fields
FieldsToSet
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/fields.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/fields.go
Apache-2.0
func SetToFields(s fieldpath.Set) (f metav1.FieldsV1, err error) { f.Raw, err = s.ToJSON() return f, err }
SetToFields creates a trie of fields from an input set of paths
SetToFields
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/fields.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/fields.go
Apache-2.0
func NewStructuredMergeManager(typeConverter TypeConverter, objectConverter runtime.ObjectConvertor, objectDefaulter runtime.ObjectDefaulter, gv schema.GroupVersion, hub schema.GroupVersion, resetFields map[fieldpath.APIVersion]*fieldpath.Set) (Manager, error) { if typeConverter == nil { return nil, fmt.Errorf("typeconverter must not be nil") } return &structuredMergeManager{ typeConverter: typeConverter, objectConverter: objectConverter, objectDefaulter: objectDefaulter, groupVersion: gv, hubVersion: hub, updater: merge.Updater{ Converter: newVersionConverter(typeConverter, objectConverter, hub), // This is the converter provided to SMD from k8s IgnoredFields: resetFields, }, }, nil }
NewStructuredMergeManager creates a new Manager that merges apply requests and update managed fields for other types of requests.
NewStructuredMergeManager
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/structuredmerge.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/structuredmerge.go
Apache-2.0
func NewCRDStructuredMergeManager(typeConverter TypeConverter, objectConverter runtime.ObjectConvertor, objectDefaulter runtime.ObjectDefaulter, gv schema.GroupVersion, hub schema.GroupVersion, resetFields map[fieldpath.APIVersion]*fieldpath.Set) (_ Manager, err error) { return &structuredMergeManager{ typeConverter: typeConverter, objectConverter: objectConverter, objectDefaulter: objectDefaulter, groupVersion: gv, hubVersion: hub, updater: merge.Updater{ Converter: newCRDVersionConverter(typeConverter, objectConverter, hub), IgnoredFields: resetFields, }, }, nil }
NewCRDStructuredMergeManager creates a new Manager specifically for CRDs. This allows for the possibility of fields which are not defined in models, as well as having no models defined at all.
NewCRDStructuredMergeManager
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/structuredmerge.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/structuredmerge.go
Apache-2.0
func (f *structuredMergeManager) Update(liveObj, newObj runtime.Object, managed Managed, manager string) (runtime.Object, Managed, error) { newObjVersioned, err := f.toVersioned(newObj) if err != nil { return nil, nil, fmt.Errorf("failed to convert new object (%v) to proper version (%v): %v", objectGVKNN(newObj), f.groupVersion, err) } liveObjVersioned, err := f.toVersioned(liveObj) if err != nil { return nil, nil, fmt.Errorf("failed to convert live object (%v) to proper version: %v", objectGVKNN(liveObj), err) } newObjTyped, err := f.typeConverter.ObjectToTyped(newObjVersioned, typed.AllowDuplicates) if err != nil { return nil, nil, fmt.Errorf("failed to convert new object (%v) to smd typed: %v", objectGVKNN(newObjVersioned), err) } liveObjTyped, err := f.typeConverter.ObjectToTyped(liveObjVersioned, typed.AllowDuplicates) if err != nil { return nil, nil, fmt.Errorf("failed to convert live object (%v) to smd typed: %v", objectGVKNN(liveObjVersioned), err) } apiVersion := fieldpath.APIVersion(f.groupVersion.String()) // TODO(apelisse) use the first return value when unions are implemented _, managedFields, err := f.updater.Update(liveObjTyped, newObjTyped, apiVersion, managed.Fields(), manager) if err != nil { return nil, nil, fmt.Errorf("failed to update ManagedFields (%v): %v", objectGVKNN(newObjVersioned), err) } managed = NewManaged(managedFields, managed.Times()) return newObj, managed, nil }
Update implements Manager.
Update
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/structuredmerge.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/structuredmerge.go
Apache-2.0
func (f *structuredMergeManager) Apply(liveObj, patchObj runtime.Object, managed Managed, manager string, force bool) (runtime.Object, Managed, error) { // Check that the patch object has the same version as the live object if patchVersion := patchObj.GetObjectKind().GroupVersionKind().GroupVersion(); patchVersion != f.groupVersion { return nil, nil, errors.NewBadRequest( fmt.Sprintf("Incorrect version specified in apply patch. "+ "Specified patch version: %s, expected: %s", patchVersion, f.groupVersion)) } patchObjMeta, err := meta.Accessor(patchObj) if err != nil { return nil, nil, fmt.Errorf("couldn't get accessor: %v", err) } if patchObjMeta.GetManagedFields() != nil { return nil, nil, errors.NewBadRequest("metadata.managedFields must be nil") } liveObjVersioned, err := f.toVersioned(liveObj) if err != nil { return nil, nil, fmt.Errorf("failed to convert live object (%v) to proper version: %v", objectGVKNN(liveObj), err) } // Don't allow duplicates in the applied object. patchObjTyped, err := f.typeConverter.ObjectToTyped(patchObj) if err != nil { return nil, nil, fmt.Errorf("failed to create typed patch object (%v): %v", objectGVKNN(patchObj), err) } liveObjTyped, err := f.typeConverter.ObjectToTyped(liveObjVersioned, typed.AllowDuplicates) if err != nil { return nil, nil, fmt.Errorf("failed to create typed live object (%v): %v", objectGVKNN(liveObjVersioned), err) } apiVersion := fieldpath.APIVersion(f.groupVersion.String()) newObjTyped, managedFields, err := f.updater.Apply(liveObjTyped, patchObjTyped, apiVersion, managed.Fields(), manager, force) if err != nil { return nil, nil, err } managed = NewManaged(managedFields, managed.Times()) if newObjTyped == nil { return nil, managed, nil } newObj, err := f.typeConverter.TypedToObject(newObjTyped) if err != nil { return nil, nil, fmt.Errorf("failed to convert new typed object (%v) to object: %v", objectGVKNN(patchObj), err) } newObjVersioned, err := f.toVersioned(newObj) if err != nil { return nil, nil, fmt.Errorf("failed to convert new object (%v) to proper version: %v", objectGVKNN(patchObj), err) } f.objectDefaulter.Default(newObjVersioned) newObjUnversioned, err := f.toUnversioned(newObjVersioned) if err != nil { return nil, nil, fmt.Errorf("failed to convert to unversioned (%v): %v", objectGVKNN(patchObj), err) } return newObjUnversioned, managed, nil }
Apply implements Manager.
Apply
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/structuredmerge.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/structuredmerge.go
Apache-2.0
func (m *managedStruct) Fields() fieldpath.ManagedFields { return m.fields }
Fields implements ManagedInterface.
Fields
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/managedfields.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/managedfields.go
Apache-2.0
func (m *managedStruct) Times() map[string]*metav1.Time { return m.times }
Times implements ManagedInterface.
Times
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/managedfields.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/managedfields.go
Apache-2.0
func NewEmptyManaged() ManagedInterface { return NewManaged(fieldpath.ManagedFields{}, map[string]*metav1.Time{}) }
NewEmptyManaged creates an empty ManagedInterface.
NewEmptyManaged
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/managedfields.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/managedfields.go
Apache-2.0
func NewManaged(f fieldpath.ManagedFields, t map[string]*metav1.Time) ManagedInterface { return &managedStruct{ fields: f, times: t, } }
NewManaged creates a ManagedInterface from a fieldpath.ManagedFields and the timestamps associated with each operation.
NewManaged
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/managedfields.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/managedfields.go
Apache-2.0
func RemoveObjectManagedFields(obj runtime.Object) { accessor, err := meta.Accessor(obj) if err != nil { panic(fmt.Sprintf("couldn't get accessor: %v", err)) } accessor.SetManagedFields(nil) }
RemoveObjectManagedFields removes the ManagedFields from the object before we merge so that it doesn't appear in the ManagedFields recursively.
RemoveObjectManagedFields
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/managedfields.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/managedfields.go
Apache-2.0
func EncodeObjectManagedFields(obj runtime.Object, managed ManagedInterface) error { accessor, err := meta.Accessor(obj) if err != nil { panic(fmt.Sprintf("couldn't get accessor: %v", err)) } encodedManagedFields, err := encodeManagedFields(managed) if err != nil { return fmt.Errorf("failed to convert back managed fields to API: %v", err) } accessor.SetManagedFields(encodedManagedFields) return nil }
EncodeObjectManagedFields converts and stores the fieldpathManagedFields into the objects ManagedFields
EncodeObjectManagedFields
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/managedfields.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/managedfields.go
Apache-2.0
func DecodeManagedFields(encodedManagedFields []metav1.ManagedFieldsEntry) (ManagedInterface, error) { managed := managedStruct{} managed.fields = make(fieldpath.ManagedFields, len(encodedManagedFields)) managed.times = make(map[string]*metav1.Time, len(encodedManagedFields)) for i, encodedVersionedSet := range encodedManagedFields { switch encodedVersionedSet.Operation { case metav1.ManagedFieldsOperationApply, metav1.ManagedFieldsOperationUpdate: default: return nil, fmt.Errorf("operation must be `Apply` or `Update`") } if len(encodedVersionedSet.APIVersion) < 1 { return nil, fmt.Errorf("apiVersion must not be empty") } switch encodedVersionedSet.FieldsType { case "FieldsV1": // Valid case. case "": return nil, fmt.Errorf("missing fieldsType in managed fields entry %d", i) default: return nil, fmt.Errorf("invalid fieldsType %q in managed fields entry %d", encodedVersionedSet.FieldsType, i) } manager, err := BuildManagerIdentifier(&encodedVersionedSet) if err != nil { return nil, fmt.Errorf("error decoding manager from %v: %v", encodedVersionedSet, err) } managed.fields[manager], err = decodeVersionedSet(&encodedVersionedSet) if err != nil { return nil, fmt.Errorf("error decoding versioned set from %v: %v", encodedVersionedSet, err) } managed.times[manager] = encodedVersionedSet.Time } return &managed, nil }
DecodeManagedFields converts ManagedFields from the wire format (api format) to the format used by sigs.k8s.io/structured-merge-diff
DecodeManagedFields
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/managedfields.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/managedfields.go
Apache-2.0
func BuildManagerIdentifier(encodedManager *metav1.ManagedFieldsEntry) (manager string, err error) { encodedManagerCopy := *encodedManager // Never include fields type in the manager identifier encodedManagerCopy.FieldsType = "" // Never include the fields in the manager identifier encodedManagerCopy.FieldsV1 = nil // Never include the time in the manager identifier encodedManagerCopy.Time = nil // For appliers, don't include the APIVersion in the manager identifier, // so it will always have the same manager identifier each time it applied. if encodedManager.Operation == metav1.ManagedFieldsOperationApply { encodedManagerCopy.APIVersion = "" } // Use the remaining fields to build the manager identifier b, err := json.Marshal(&encodedManagerCopy) if err != nil { return "", fmt.Errorf("error marshalling manager identifier: %v", err) } return string(b), nil }
BuildManagerIdentifier creates a manager identifier string from a ManagedFieldsEntry
BuildManagerIdentifier
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/managedfields.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/managedfields.go
Apache-2.0
func encodeManagedFields(managed ManagedInterface) (encodedManagedFields []metav1.ManagedFieldsEntry, err error) { if len(managed.Fields()) == 0 { return nil, nil } encodedManagedFields = []metav1.ManagedFieldsEntry{} for manager := range managed.Fields() { versionedSet := managed.Fields()[manager] v, err := encodeManagerVersionedSet(manager, versionedSet) if err != nil { return nil, fmt.Errorf("error encoding versioned set for %v: %v", manager, err) } if t, ok := managed.Times()[manager]; ok { v.Time = t } encodedManagedFields = append(encodedManagedFields, *v) } return sortEncodedManagedFields(encodedManagedFields) }
encodeManagedFields converts ManagedFields from the format used by sigs.k8s.io/structured-merge-diff to the wire format (api format)
encodeManagedFields
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/managedfields.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/managedfields.go
Apache-2.0
func NewConflictError(conflicts merge.Conflicts) *errors.StatusError { causes := []metav1.StatusCause{} for _, conflict := range conflicts { causes = append(causes, metav1.StatusCause{ Type: metav1.CauseTypeFieldManagerConflict, Message: fmt.Sprintf("conflict with %v", printManager(conflict.Manager)), Field: conflict.Path.String(), }) } return errors.NewApplyConflict(causes, getConflictMessage(conflicts)) }
NewConflictError returns an error including details on the requests apply conflicts
NewConflictError
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/conflict.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/conflict.go
Apache-2.0
func newVersionConverter(t TypeConverter, o runtime.ObjectConvertor, h schema.GroupVersion) merge.Converter { return &versionConverter{ typeConverter: t, objectConvertor: o, hubGetter: func(from schema.GroupVersion) schema.GroupVersion { return schema.GroupVersion{ Group: from.Group, Version: h.Version, } }, } }
NewVersionConverter builds a VersionConverter from a TypeConverter and an ObjectConvertor.
newVersionConverter
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/versionconverter.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/versionconverter.go
Apache-2.0
func newCRDVersionConverter(t TypeConverter, o runtime.ObjectConvertor, h schema.GroupVersion) merge.Converter { return &versionConverter{ typeConverter: t, objectConvertor: o, hubGetter: func(from schema.GroupVersion) schema.GroupVersion { return h }, } }
NewCRDVersionConverter builds a VersionConverter for CRDs from a TypeConverter and an ObjectConvertor.
newCRDVersionConverter
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/versionconverter.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/versionconverter.go
Apache-2.0
func (v *versionConverter) Convert(object *typed.TypedValue, version fieldpath.APIVersion) (*typed.TypedValue, error) { // Convert the smd typed value to a kubernetes object. objectToConvert, err := v.typeConverter.TypedToObject(object) if err != nil { return object, err } // Parse the target groupVersion. groupVersion, err := schema.ParseGroupVersion(string(version)) if err != nil { return object, err } // If attempting to convert to the same version as we already have, just return it. fromVersion := objectToConvert.GetObjectKind().GroupVersionKind().GroupVersion() if fromVersion == groupVersion { return object, nil } // Convert to internal internalObject, err := v.objectConvertor.ConvertToVersion(objectToConvert, v.hubGetter(fromVersion)) if err != nil { return object, err } // Convert the object into the target version convertedObject, err := v.objectConvertor.ConvertToVersion(internalObject, groupVersion) if err != nil { return object, err } // Convert the object back to a smd typed value and return it. return v.typeConverter.ObjectToTyped(convertedObject) }
Convert implements sigs.k8s.io/structured-merge-diff/merge.Converter
Convert
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/versionconverter.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/versionconverter.go
Apache-2.0
func (v *versionConverter) IsMissingVersionError(err error) bool { return runtime.IsNotRegisteredError(err) || isNoCorrespondingTypeError(err) }
IsMissingVersionError
IsMissingVersionError
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/versionconverter.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/versionconverter.go
Apache-2.0
func NewBuildManagerInfoManager(f Manager, gv schema.GroupVersion, subresource string) Manager { return &buildManagerInfoManager{ fieldManager: f, groupVersion: gv, subresource: subresource, } }
NewBuildManagerInfoManager creates a new Manager that converts the manager name into a unique identifier combining operation and version for update requests, and just operation for apply requests.
NewBuildManagerInfoManager
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/buildmanagerinfo.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/buildmanagerinfo.go
Apache-2.0
func (f *buildManagerInfoManager) Update(liveObj, newObj runtime.Object, managed Managed, manager string) (runtime.Object, Managed, error) { manager, err := f.buildManagerInfo(manager, metav1.ManagedFieldsOperationUpdate) if err != nil { return nil, nil, fmt.Errorf("failed to build manager identifier: %v", err) } return f.fieldManager.Update(liveObj, newObj, managed, manager) }
Update implements Manager.
Update
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/buildmanagerinfo.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/buildmanagerinfo.go
Apache-2.0
func (f *buildManagerInfoManager) Apply(liveObj, appliedObj runtime.Object, managed Managed, manager string, force bool) (runtime.Object, Managed, error) { manager, err := f.buildManagerInfo(manager, metav1.ManagedFieldsOperationApply) if err != nil { return nil, nil, fmt.Errorf("failed to build manager identifier: %v", err) } return f.fieldManager.Apply(liveObj, appliedObj, managed, manager, force) }
Apply implements Manager.
Apply
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/buildmanagerinfo.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/buildmanagerinfo.go
Apache-2.0
func NewManagedFieldsUpdater(fieldManager Manager) Manager { return &managedFieldsUpdater{ fieldManager: fieldManager, } }
NewManagedFieldsUpdater is responsible for updating the managedfields in the object, updating the time of the operation as necessary. For updates, it uses a hard-coded manager to detect if things have changed, and swaps back the correct manager after the operation is done.
NewManagedFieldsUpdater
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/managedfieldsupdater.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/managedfieldsupdater.go
Apache-2.0
func (f *managedFieldsUpdater) Update(liveObj, newObj runtime.Object, managed Managed, manager string) (runtime.Object, Managed, error) { self := "current-operation" object, managed, err := f.fieldManager.Update(liveObj, newObj, managed, self) if err != nil { return object, managed, err } // If the current operation took any fields from anything, it means the object changed, // so update the timestamp of the managedFieldsEntry and merge with any previous updates from the same manager if vs, ok := managed.Fields()[self]; ok { delete(managed.Fields(), self) if previous, ok := managed.Fields()[manager]; ok { managed.Fields()[manager] = fieldpath.NewVersionedSet(vs.Set().Union(previous.Set()), vs.APIVersion(), vs.Applied()) } else { managed.Fields()[manager] = vs } managed.Times()[manager] = &metav1.Time{Time: time.Now().UTC()} } return object, managed, nil }
Update implements Manager.
Update
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/managedfieldsupdater.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/managedfieldsupdater.go
Apache-2.0
func (f *managedFieldsUpdater) Apply(liveObj, appliedObj runtime.Object, managed Managed, fieldManager string, force bool) (runtime.Object, Managed, error) { object, managed, err := f.fieldManager.Apply(liveObj, appliedObj, managed, fieldManager, force) if err != nil { return object, managed, err } if object != nil { managed.Times()[fieldManager] = &metav1.Time{Time: time.Now().UTC()} } else { object = liveObj.DeepCopyObject() RemoveObjectManagedFields(object) } return object, managed, nil }
Apply implements Manager.
Apply
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/managedfieldsupdater.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/managedfieldsupdater.go
Apache-2.0
func NewLastAppliedUpdater(fieldManager Manager) Manager { return &lastAppliedUpdater{ fieldManager: fieldManager, } }
NewLastAppliedUpdater sets the client-side apply annotation up to date with server-side apply managed fields
NewLastAppliedUpdater
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/lastappliedupdater.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/lastappliedupdater.go
Apache-2.0
func (f *lastAppliedUpdater) Update(liveObj, newObj runtime.Object, managed Managed, manager string) (runtime.Object, Managed, error) { return f.fieldManager.Update(liveObj, newObj, managed, manager) }
Update implements Manager.
Update
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/lastappliedupdater.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/lastappliedupdater.go
Apache-2.0
func (f *lastAppliedUpdater) Apply(liveObj, newObj runtime.Object, managed Managed, manager string, force bool) (runtime.Object, Managed, error) { liveObj, managed, err := f.fieldManager.Apply(liveObj, newObj, managed, manager, force) if err != nil { return liveObj, managed, err } // Sync the client-side apply annotation only from kubectl server-side apply. // To opt-out of this behavior, users may specify a different field manager. // // If the client-side apply annotation doesn't exist, // then continue because we have no annotation to update if manager == "kubectl" && hasLastApplied(liveObj) { lastAppliedValue, err := buildLastApplied(newObj) if err != nil { return nil, nil, fmt.Errorf("failed to build last-applied annotation: %v", err) } err = SetLastApplied(liveObj, lastAppliedValue) if err != nil { return nil, nil, fmt.Errorf("failed to set last-applied annotation: %v", err) } } return liveObj, managed, err }
server-side apply managed fields
Apply
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/lastappliedupdater.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/lastappliedupdater.go
Apache-2.0
func NewCapManagersManager(fieldManager Manager, maxUpdateManagers int) Manager { return &capManagersManager{ fieldManager: fieldManager, maxUpdateManagers: maxUpdateManagers, oldUpdatesManagerName: "ancient-changes", } }
NewCapManagersManager creates a new wrapped FieldManager which ensures that the number of managers from updates does not exceed maxUpdateManagers, by merging some of the oldest entries on each update.
NewCapManagersManager
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/capmanagers.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/capmanagers.go
Apache-2.0
func (f *capManagersManager) Update(liveObj, newObj runtime.Object, managed Managed, manager string) (runtime.Object, Managed, error) { object, managed, err := f.fieldManager.Update(liveObj, newObj, managed, manager) if err != nil { return object, managed, err } if managed, err = f.capUpdateManagers(managed); err != nil { return nil, nil, fmt.Errorf("failed to cap update managers: %v", err) } return object, managed, nil }
Update implements Manager.
Update
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/capmanagers.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/capmanagers.go
Apache-2.0
func (f *capManagersManager) Apply(liveObj, appliedObj runtime.Object, managed Managed, fieldManager string, force bool) (runtime.Object, Managed, error) { return f.fieldManager.Apply(liveObj, appliedObj, managed, fieldManager, force) }
Apply implements Manager.
Apply
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/capmanagers.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/capmanagers.go
Apache-2.0
func (f *capManagersManager) capUpdateManagers(managed Managed) (newManaged Managed, err error) { // Gather all entries from updates updaters := []string{} for manager, fields := range managed.Fields() { if !fields.Applied() { updaters = append(updaters, manager) } } if len(updaters) <= f.maxUpdateManagers { return managed, nil } // If we have more than the maximum, sort the update entries by time, oldest first. sort.Slice(updaters, func(i, j int) bool { iTime, jTime, iSeconds, jSeconds := managed.Times()[updaters[i]], managed.Times()[updaters[j]], int64(0), int64(0) if iTime != nil { iSeconds = iTime.Unix() } if jTime != nil { jSeconds = jTime.Unix() } if iSeconds != jSeconds { return iSeconds < jSeconds } return updaters[i] < updaters[j] }) // Merge the oldest updaters with versioned bucket managers until the number of updaters is under the cap versionToFirstManager := map[string]string{} for i, length := 0, len(updaters); i < len(updaters) && length > f.maxUpdateManagers; i++ { manager := updaters[i] vs := managed.Fields()[manager] time := managed.Times()[manager] version := string(vs.APIVersion()) // Create a new manager identifier for the versioned bucket entry. // The version for this manager comes from the version of the update being merged into the bucket. bucket, err := BuildManagerIdentifier(&metav1.ManagedFieldsEntry{ Manager: f.oldUpdatesManagerName, Operation: metav1.ManagedFieldsOperationUpdate, APIVersion: version, }) if err != nil { return managed, fmt.Errorf("failed to create bucket manager for version %v: %v", version, err) } // Merge the fieldets if this is not the first time the version was seen. // Otherwise just record the manager name in versionToFirstManager if first, ok := versionToFirstManager[version]; ok { // If the bucket doesn't exists yet, create one. if _, ok := managed.Fields()[bucket]; !ok { s := managed.Fields()[first] delete(managed.Fields(), first) managed.Fields()[bucket] = s } managed.Fields()[bucket] = fieldpath.NewVersionedSet(vs.Set().Union(managed.Fields()[bucket].Set()), vs.APIVersion(), vs.Applied()) delete(managed.Fields(), manager) length-- // Use the time from the update being merged into the bucket, since it is more recent. managed.Times()[bucket] = time } else { versionToFirstManager[version] = manager } } return managed, nil }
capUpdateManagers merges a number of the oldest update entries into versioned buckets, such that the number of entries from updates does not exceed f.maxUpdateManagers.
capUpdateManagers
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/capmanagers.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/capmanagers.go
Apache-2.0
func SetLastApplied(obj runtime.Object, value string) error { accessor, err := meta.Accessor(obj) if err != nil { panic(fmt.Sprintf("couldn't get accessor: %v", err)) } var annotations = accessor.GetAnnotations() if annotations == nil { annotations = map[string]string{} } annotations[LastAppliedConfigAnnotation] = value if err := apimachineryvalidation.ValidateAnnotationsSize(annotations); err != nil { delete(annotations, LastAppliedConfigAnnotation) } accessor.SetAnnotations(annotations) return nil }
SetLastApplied sets the last-applied annotation the given value in the object.
SetLastApplied
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/lastapplied.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/lastapplied.go
Apache-2.0
func NewSkipNonAppliedManager(fieldManager Manager, objectCreater runtime.ObjectCreater) Manager { return NewProbabilisticSkipNonAppliedManager(fieldManager, objectCreater, 0.0) }
NewSkipNonAppliedManager creates a new wrapped FieldManager that only starts tracking managers after the first apply.
NewSkipNonAppliedManager
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/skipnonapplied.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/skipnonapplied.go
Apache-2.0
func NewProbabilisticSkipNonAppliedManager(fieldManager Manager, objectCreater runtime.ObjectCreater, p float32) Manager { return &skipNonAppliedManager{ fieldManager: fieldManager, objectCreater: objectCreater, beforeApplyManagerName: "before-first-apply", probability: p, } }
NewProbabilisticSkipNonAppliedManager creates a new wrapped FieldManager that starts tracking managers after the first apply, or starts tracking on create with p probability.
NewProbabilisticSkipNonAppliedManager
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/skipnonapplied.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/skipnonapplied.go
Apache-2.0
func (f *skipNonAppliedManager) Update(liveObj, newObj runtime.Object, managed Managed, manager string) (runtime.Object, Managed, error) { accessor, err := meta.Accessor(liveObj) if err != nil { return newObj, managed, nil } // If managed fields is empty, we need to determine whether to skip tracking managed fields. if len(managed.Fields()) == 0 { // Check if the operation is a create, by checking whether lastObj's UID is empty. // If the operation is create, P(tracking managed fields) = f.probability // If the operation is update, skip tracking managed fields, since we already know managed fields is empty. if len(accessor.GetUID()) == 0 { if f.probability <= rand.Float32() { return newObj, managed, nil } } else { return newObj, managed, nil } } return f.fieldManager.Update(liveObj, newObj, managed, manager) }
Update implements Manager.
Update
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/skipnonapplied.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/skipnonapplied.go
Apache-2.0
func (f *skipNonAppliedManager) Apply(liveObj, appliedObj runtime.Object, managed Managed, fieldManager string, force bool) (runtime.Object, Managed, error) { if len(managed.Fields()) == 0 { gvk := appliedObj.GetObjectKind().GroupVersionKind() emptyObj, err := f.objectCreater.New(gvk) if err != nil { return nil, nil, fmt.Errorf("failed to create empty object of type %v: %v", gvk, err) } liveObj, managed, err = f.fieldManager.Update(emptyObj, liveObj, managed, f.beforeApplyManagerName) if err != nil { return nil, nil, fmt.Errorf("failed to create manager for existing fields: %v", err) } } return f.fieldManager.Apply(liveObj, appliedObj, managed, fieldManager, force) }
Apply implements Manager.
Apply
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/skipnonapplied.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/skipnonapplied.go
Apache-2.0
func NewVersionCheckManager(fieldManager Manager, gvk schema.GroupVersionKind) Manager { return &versionCheckManager{fieldManager: fieldManager, gvk: gvk} }
NewVersionCheckManager creates a manager that makes sure that the applied object is in the proper version.
NewVersionCheckManager
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/versioncheck.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/versioncheck.go
Apache-2.0
func (f *versionCheckManager) Update(liveObj, newObj runtime.Object, managed Managed, manager string) (runtime.Object, Managed, error) { // Nothing to do for updates, this is checked in many other places. return f.fieldManager.Update(liveObj, newObj, managed, manager) }
Update implements Manager.
Update
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/versioncheck.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/versioncheck.go
Apache-2.0
func (f *versionCheckManager) Apply(liveObj, appliedObj runtime.Object, managed Managed, fieldManager string, force bool) (runtime.Object, Managed, error) { if gvk := appliedObj.GetObjectKind().GroupVersionKind(); gvk != f.gvk { return nil, nil, errors.NewBadRequest(fmt.Sprintf("invalid object type: %v", gvk)) } return f.fieldManager.Apply(liveObj, appliedObj, managed, fieldManager, force) }
Apply implements Manager.
Apply
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/versioncheck.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/versioncheck.go
Apache-2.0
func NewPathElement(s string) (fieldpath.PathElement, error) { split := strings.SplitN(s, Separator, 2) if len(split) < 2 { return fieldpath.PathElement{}, fmt.Errorf("missing colon: %v", s) } switch split[0] { case Field: return fieldpath.PathElement{ FieldName: &split[1], }, nil case Value: val, err := value.FromJSON([]byte(split[1])) if err != nil { return fieldpath.PathElement{}, err } return fieldpath.PathElement{ Value: &val, }, nil case Index: i, err := strconv.Atoi(split[1]) if err != nil { return fieldpath.PathElement{}, err } return fieldpath.PathElement{ Index: &i, }, nil case Key: kv := map[string]json.RawMessage{} err := json.Unmarshal([]byte(split[1]), &kv) if err != nil { return fieldpath.PathElement{}, err } fields := value.FieldList{} for k, v := range kv { b, err := json.Marshal(v) if err != nil { return fieldpath.PathElement{}, err } val, err := value.FromJSON(b) if err != nil { return fieldpath.PathElement{}, err } fields = append(fields, value.Field{ Name: k, Value: val, }) } return fieldpath.PathElement{ Key: &fields, }, nil default: // Ignore unknown key types return fieldpath.PathElement{}, nil } }
NewPathElement parses a serialized path element
NewPathElement
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/pathelement.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/pathelement.go
Apache-2.0
func PathElementString(pe fieldpath.PathElement) (string, error) { switch { case pe.FieldName != nil: return Field + Separator + *pe.FieldName, nil case pe.Key != nil: kv := map[string]json.RawMessage{} for _, k := range *pe.Key { b, err := value.ToJSON(k.Value) if err != nil { return "", err } m := json.RawMessage{} err = json.Unmarshal(b, &m) if err != nil { return "", err } kv[k.Name] = m } b, err := json.Marshal(kv) if err != nil { return "", err } return Key + ":" + string(b), nil case pe.Value != nil: b, err := value.ToJSON(*pe.Value) if err != nil { return "", err } return Value + ":" + string(b), nil case pe.Index != nil: return Index + ":" + strconv.Itoa(*pe.Index), nil default: return "", errors.New("Invalid type of path element") } }
PathElementString serializes a path element
PathElementString
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/pathelement.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/pathelement.go
Apache-2.0
func NewStripMetaManager(fieldManager Manager) Manager { return &stripMetaManager{ fieldManager: fieldManager, stripSet: fieldpath.NewSet( fieldpath.MakePathOrDie("apiVersion"), fieldpath.MakePathOrDie("kind"), fieldpath.MakePathOrDie("metadata"), fieldpath.MakePathOrDie("metadata", "name"), fieldpath.MakePathOrDie("metadata", "namespace"), fieldpath.MakePathOrDie("metadata", "creationTimestamp"), fieldpath.MakePathOrDie("metadata", "selfLink"), fieldpath.MakePathOrDie("metadata", "uid"), fieldpath.MakePathOrDie("metadata", "clusterName"), fieldpath.MakePathOrDie("metadata", "generation"), fieldpath.MakePathOrDie("metadata", "managedFields"), fieldpath.MakePathOrDie("metadata", "resourceVersion"), ), } }
NewStripMetaManager creates a new Manager that strips metadata and typemeta fields from the manager's fieldset.
NewStripMetaManager
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/stripmeta.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/stripmeta.go
Apache-2.0
func (f *stripMetaManager) Update(liveObj, newObj runtime.Object, managed Managed, manager string) (runtime.Object, Managed, error) { newObj, managed, err := f.fieldManager.Update(liveObj, newObj, managed, manager) if err != nil { return nil, nil, err } f.stripFields(managed.Fields(), manager) return newObj, managed, nil }
Update implements Manager.
Update
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/stripmeta.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/stripmeta.go
Apache-2.0
func (f *stripMetaManager) Apply(liveObj, appliedObj runtime.Object, managed Managed, manager string, force bool) (runtime.Object, Managed, error) { newObj, managed, err := f.fieldManager.Apply(liveObj, appliedObj, managed, manager, force) if err != nil { return nil, nil, err } f.stripFields(managed.Fields(), manager) return newObj, managed, nil }
Apply implements Manager.
Apply
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/stripmeta.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/stripmeta.go
Apache-2.0
func (f *stripMetaManager) stripFields(managed fieldpath.ManagedFields, manager string) { vs, ok := managed[manager] if ok { if vs == nil { panic(fmt.Sprintf("Found unexpected nil manager which should never happen: %s", manager)) } newSet := vs.Set().Difference(f.stripSet) if newSet.Empty() { delete(managed, manager) } else { managed[manager] = fieldpath.NewVersionedSet(newSet, vs.APIVersion(), vs.Applied()) } } }
stripFields removes a predefined set of paths found in typed from managed
stripFields
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/stripmeta.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/managedfields/internal/stripmeta.go
Apache-2.0
func StringDiff(a, b string) string { return legacyDiff(a, b) }
StringDiff diffs a and b and returns a human readable diff. DEPRECATED: use github.com/google/go-cmp/cmp.Diff
StringDiff
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/diff/diff.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/diff/diff.go
Apache-2.0
func ObjectDiff(a, b interface{}) string { return legacyDiff(a, b) }
ObjectDiff prints the diff of two go objects and fails if the objects contain unhandled unexported fields. DEPRECATED: use github.com/google/go-cmp/cmp.Diff
ObjectDiff
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/diff/diff.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/diff/diff.go
Apache-2.0
func ObjectGoPrintDiff(a, b interface{}) string { return legacyDiff(a, b) }
ObjectGoPrintDiff prints the diff of two go objects and fails if the objects contain unhandled unexported fields. DEPRECATED: use github.com/google/go-cmp/cmp.Diff
ObjectGoPrintDiff
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/diff/diff.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/diff/diff.go
Apache-2.0
func ObjectReflectDiff(a, b interface{}) string { return legacyDiff(a, b) }
ObjectReflectDiff prints the diff of two go objects and fails if the objects contain unhandled unexported fields. DEPRECATED: use github.com/google/go-cmp/cmp.Diff
ObjectReflectDiff
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/diff/diff.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/diff/diff.go
Apache-2.0
func ObjectGoPrintSideBySide(a, b interface{}) string { sA := dump.Pretty(a) sB := dump.Pretty(b) linesA := strings.Split(sA, "\n") linesB := strings.Split(sB, "\n") width := 0 for _, s := range linesA { l := len(s) if l > width { width = l } } for _, s := range linesB { l := len(s) if l > width { width = l } } buf := &bytes.Buffer{} w := tabwriter.NewWriter(buf, width, 0, 1, ' ', 0) max := len(linesA) if len(linesB) > max { max = len(linesB) } for i := 0; i < max; i++ { var a, b string if i < len(linesA) { a = linesA[i] } if i < len(linesB) { b = linesB[i] } fmt.Fprintf(w, "%s\t%s\n", a, b) } w.Flush() return buf.String() }
ObjectGoPrintSideBySide prints a and b as textual dumps side by side, enabling easy visual scanning for mismatches.
ObjectGoPrintSideBySide
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/diff/diff.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/diff/diff.go
Apache-2.0
func IgnoreUnset() cmp.Option { return cmp.Options{ // ignore unset fields in v2 cmp.FilterPath(func(path cmp.Path) bool { _, v2 := path.Last().Values() switch v2.Kind() { case reflect.Slice, reflect.Map: if v2.IsNil() || v2.Len() == 0 { return true } case reflect.String: if v2.Len() == 0 { return true } case reflect.Interface, reflect.Pointer: if v2.IsNil() { return true } } return false }, cmp.Ignore()), // ignore map entries that aren't set in v2 cmp.FilterPath(func(path cmp.Path) bool { switch i := path.Last().(type) { case cmp.MapIndex: if _, v2 := i.Values(); !v2.IsValid() { fmt.Println("E") return true } } return false }, cmp.Ignore()), }
IgnoreUnset is an option that ignores fields that are unset on the right hand side of a comparison. This is useful in testing to assert that an object is a derivative.
IgnoreUnset
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/util/diff/diff.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/util/diff/diff.go
Apache-2.0
func Nothing() Selector { return nothingSelector{} }
Nothing returns a selector that matches no fields
Nothing
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/fields/selector.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/fields/selector.go
Apache-2.0
func Everything() Selector { return andTerm{} }
Everything returns a selector that matches all fields.
Everything
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/fields/selector.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/fields/selector.go
Apache-2.0
func SelectorFromSet(ls Set) Selector { if ls == nil { return Everything() } items := make([]Selector, 0, len(ls)) for field, value := range ls { items = append(items, &hasTerm{field: field, value: value}) } if len(items) == 1 { return items[0] } return andTerm(items) }
SelectorFromSet returns a Selector which will match exactly the given Set. A nil Set is considered equivalent to Everything().
SelectorFromSet
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/fields/selector.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/fields/selector.go
Apache-2.0
func EscapeValue(s string) string { return valueEscaper.Replace(s) }
EscapeValue escapes an arbitrary literal string for use as a fieldSelector value
EscapeValue
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/fields/selector.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/fields/selector.go
Apache-2.0
func UnescapeValue(s string) (string, error) { // if there's no escaping or special characters, just return to avoid allocation if !strings.ContainsAny(s, `\,=`) { return s, nil } v := bytes.NewBuffer(make([]byte, 0, len(s))) inSlash := false for _, c := range s { if inSlash { switch c { case '\\', ',', '=': // omit the \ for recognized escape sequences v.WriteRune(c) default: // error on unrecognized escape sequences return "", InvalidEscapeSequence{sequence: string([]rune{'\\', c})} } inSlash = false continue } switch c { case '\\': inSlash = true case ',', '=': // unescaped , and = characters are not allowed in field selector values return "", UnescapedRune{r: c} default: v.WriteRune(c) } } // Ending with a single backslash is an invalid sequence if inSlash { return "", InvalidEscapeSequence{sequence: "\\"} } return v.String(), nil }
UnescapeValue unescapes a fieldSelector value and returns the original literal value. May return the original string if it contains no escaped or special characters.
UnescapeValue
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/fields/selector.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/fields/selector.go
Apache-2.0
func ParseSelectorOrDie(s string) Selector { selector, err := ParseSelector(s) if err != nil { panic(err) } return selector }
ParseSelectorOrDie takes a string representing a selector and returns an object suitable for matching, or panic when an error occur.
ParseSelectorOrDie
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/fields/selector.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/fields/selector.go
Apache-2.0
func ParseSelector(selector string) (Selector, error) { return parseSelector(selector, func(lhs, rhs string) (newLhs, newRhs string, err error) { return lhs, rhs, nil }) }
ParseSelector takes a string representing a selector and returns an object suitable for matching, or an error.
ParseSelector
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/fields/selector.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/fields/selector.go
Apache-2.0
func ParseAndTransformSelector(selector string, fn TransformFunc) (Selector, error) { return parseSelector(selector, fn) }
ParseAndTransformSelector parses the selector and runs them through the given TransformFunc.
ParseAndTransformSelector
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/fields/selector.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/fields/selector.go
Apache-2.0
func splitTerms(fieldSelector string) []string { if len(fieldSelector) == 0 { return nil } terms := make([]string, 0, 1) startIndex := 0 inSlash := false for i, c := range fieldSelector { switch { case inSlash: inSlash = false case c == '\\': inSlash = true case c == ',': terms = append(terms, fieldSelector[startIndex:i]) startIndex = i + 1 } } terms = append(terms, fieldSelector[startIndex:]) return terms }
splitTerms returns the comma-separated terms contained in the given fieldSelector. Backslash-escaped commas are treated as data instead of delimiters, and are included in the returned terms, with the leading backslash preserved.
splitTerms
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/fields/selector.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/fields/selector.go
Apache-2.0
func splitTerm(term string) (lhs, op, rhs string, ok bool) { for i := range term { remaining := term[i:] for _, op := range termOperators { if strings.HasPrefix(remaining, op) { return term[0:i], op, term[i+len(op):], true } } } return "", "", "", false }
splitTerm returns the lhs, operator, and rhs parsed from the given term, along with an indicator of whether the parse was successful. no escaping of special characters is supported in the lhs value, so the first occurrence of a recognized operator is used as the split point. the literal rhs is returned, and the caller is responsible for applying any desired unescaping.
splitTerm
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/fields/selector.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/fields/selector.go
Apache-2.0
func OneTermEqualSelector(k, v string) Selector { return &hasTerm{field: k, value: v} }
OneTermEqualSelector returns an object that matches objects where one field/field equals one value. Cannot return an error.
OneTermEqualSelector
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/fields/selector.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/fields/selector.go
Apache-2.0
func OneTermNotEqualSelector(k, v string) Selector { return &notHasTerm{field: k, value: v} }
OneTermNotEqualSelector returns an object that matches objects where one field/field does not equal one value. Cannot return an error.
OneTermNotEqualSelector
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/fields/selector.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/fields/selector.go
Apache-2.0
func AndSelectors(selectors ...Selector) Selector { return andTerm(selectors) }
AndSelectors creates a selector that is the logical AND of all the given selectors
AndSelectors
go
k8snetworkplumbingwg/multus-cni
vendor/k8s.io/apimachinery/pkg/fields/selector.go
https://github.com/k8snetworkplumbingwg/multus-cni/blob/master/vendor/k8s.io/apimachinery/pkg/fields/selector.go
Apache-2.0