| 1 | // Copyright 2016 CoreOS, Inc. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package mergescip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/ |
| 16 | |
| 17 | import ( |
| 18 | "fmtscip-go gomod github.com/golang/go/src go1.15 fmt/" |
| 19 | "reflectscip-go gomod github.com/golang/go/src go1.15 reflect/" |
| 20 | "stringsscip-go gomod github.com/golang/go/src go1.15 strings/" |
| 21 | |
| 22 | "github.com/coreos/ignition/v2/config/utilscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/util`/" |
| 23 | |
| 24 | "github.com/coreos/vcontext/pathscip-go gomod github.com/coreos/vcontext f1dbbca7bef4 `github.com/coreos/vcontext/path`/" |
| 25 | ) |
| 26 | |
| 27 | // Rules of Config Merging: |
| 28 | // 1) Parent and child configs must be the same version/type |
| 29 | // 2) Only valid configs can be merged |
| 30 | // 3) It is possible to merge two valid configs and get an invalid config |
| 31 | // 3) For structs: |
| 32 | // a) Members that are structs get merged recursively (i.e. ignition.storage) |
| 33 | // b) Members that are primitives get replaced by the child's member (e.g. ignition.storage.files[i].path) |
| 34 | // c) Members that are pointers only get replaced by the child's value if the child's value is non-nil (e.g. ignition.config.replace.source) |
| 35 | // d) List merging of a list with IgnoreDuplicates: append the lists (e.g. ignition.storage.files[i].append) |
| 36 | // e) List merging of a list not merged with other lists: merge any entries with the same Key() and append the others (e.g. ignition.storage.filesystems by path) |
| 37 | // f) List merging of a list merged with other lists: (e.g. ignition.storage.{files,links,directories} by path) |
| 38 | // - merge entries with the same Key() that are in the same list |
| 39 | // - remove entries from the parent with the same Key() that are not in the same list |
| 40 | // - append entries that are unique to the child |
| 41 | |
| 42 | const ( |
| 43 | TAG_PARENTscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/TAG_PARENT. = "parent" |
| 44 | TAG_CHILDscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/TAG_CHILD. = "child" |
| 45 | TAG_RESULTscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/TAG_RESULT. = "result" |
| 46 | ) |
| 47 | |
| 48 | // The path to one output field, and its corresponding input. From.Tag will |
| 49 | // be TAG_PARENT or TAG_CHILD depending on the origin of the field. |
| 50 | type Mappingscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/Mapping# struct { |
| 51 | Fromscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/Mapping#From. pathscip-go gomod github.com/coreos/vcontext f1dbbca7bef4 `github.com/coreos/vcontext/path`/.ContextPathscip-go gomod github.com/coreos/vcontext f1dbbca7bef4 `github.com/coreos/vcontext/path`/ContextPath# |
| 52 | Toscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/Mapping#To. pathscip-go gomod github.com/coreos/vcontext f1dbbca7bef4 `github.com/coreos/vcontext/path`/.ContextPathscip-go gomod github.com/coreos/vcontext f1dbbca7bef4 `github.com/coreos/vcontext/path`/ContextPath# |
| 53 | } |
| 54 | |
| 55 | func (m Mappingscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/Mapping#) Stringscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/Mapping#String().() string { |
| 56 | return fmtscip-go gomod github.com/golang/go/src go1.15 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.15 fmt/Sprintf().("%s:%s → %s", m.Fromscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/Mapping#From..Tagscip-go gomod github.com/coreos/vcontext f1dbbca7bef4 `github.com/coreos/vcontext/path`/ContextPath#Tag., m.Fromscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/Mapping#From., m.Toscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/Mapping#To.) |
| 57 | } |
| 58 | |
| 59 | type Transcriptscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/Transcript# struct { |
| 60 | Mappingsscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/Transcript#Mappings. []Mappingscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/Mapping# |
| 61 | } |
| 62 | |
| 63 | func (t Transcriptscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/Transcript#) Stringscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/Transcript#String().() string { |
| 64 | var lines []string |
| 65 | for _, m := range t.Mappingsscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/Transcript#Mappings. { |
| 66 | lines = append(lines, m.Stringscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/Mapping#String().()) |
| 67 | } |
| 68 | return stringsscip-go gomod github.com/golang/go/src go1.15 strings/.Joinscip-go gomod github.com/golang/go/src go1.15 strings/Join().(lines, "\n") |
| 69 | } |
| 70 | |
| 71 | // pathAppendField looks up the JSON field name for field and returns base |
| 72 | // with that field name appended. |
| 73 | func pathAppendFieldscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/pathAppendField().(base pathscip-go gomod github.com/coreos/vcontext f1dbbca7bef4 `github.com/coreos/vcontext/path`/.ContextPathscip-go gomod github.com/coreos/vcontext f1dbbca7bef4 `github.com/coreos/vcontext/path`/ContextPath#, field reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.StructFieldscip-go gomod github.com/golang/go/src go1.15 reflect/StructField#) pathscip-go gomod github.com/coreos/vcontext f1dbbca7bef4 `github.com/coreos/vcontext/path`/.ContextPathscip-go gomod github.com/coreos/vcontext f1dbbca7bef4 `github.com/coreos/vcontext/path`/ContextPath# { |
| 74 | tagName := stringsscip-go gomod github.com/golang/go/src go1.15 strings/.Splitscip-go gomod github.com/golang/go/src go1.15 strings/Split().(field.Tagscip-go gomod github.com/golang/go/src go1.15 reflect/StructField#Tag..Getscip-go gomod github.com/golang/go/src go1.15 reflect/StructTag#Get().("json"), ",")[0] |
| 75 | if tagName != "" { |
| 76 | return base.Appendscip-go gomod github.com/coreos/vcontext f1dbbca7bef4 `github.com/coreos/vcontext/path`/ContextPath#Append().(tagName) |
| 77 | } |
| 78 | if field.Anonymousscip-go gomod github.com/golang/go/src go1.15 reflect/StructField#Anonymous. { |
| 79 | // field is a struct embedded in another struct (e.g. |
| 80 | // FileEmbedded1). Pretend it doesn't exist. |
| 81 | return base |
| 82 | } |
| 83 | panic("no JSON struct tag for " + field.Namescip-go gomod github.com/golang/go/src go1.15 reflect/StructField#Name.) |
| 84 | } |
| 85 | |
| 86 | // appendToSlice is a helper that appends to a slice without returning a new one. |
| 87 | // panics if len >= cap |
| 88 | func appendToSlicescip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/appendToSlice().(s, v reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Valuescip-go gomod github.com/golang/go/src go1.15 reflect/Value#) { |
| 89 | s.SetLenscip-go gomod github.com/golang/go/src go1.15 reflect/Value#SetLen().(s.Lenscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Len().() + 1) |
| 90 | s.Indexscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Index().(s.Lenscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Len().() - 1).Setscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Set().(v) |
| 91 | } |
| 92 | |
| 93 | type handleKeyscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/handleKey# struct { |
| 94 | handlescip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/handleKey#handle. string |
| 95 | keyscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/handleKey#key. string |
| 96 | } |
| 97 | |
| 98 | // structInfo holds information about a struct being processed and has helper methods for querying that |
| 99 | // information in a way that is more clear what the intent is. |
| 100 | type structInfoscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/structInfo# struct { |
| 101 | // set of field names to not do duplicate merging on |
| 102 | ignoreDupsscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/structInfo#ignoreDups. map[string]struct{} |
| 103 | |
| 104 | // map from field names to a handle indicating all those with the same handle should have duplication |
| 105 | // checking done across all fields that share that handle |
| 106 | mergedKeysscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/structInfo#mergedKeys. map[string]string |
| 107 | |
| 108 | // map from each handle + key() to the corresponding item |
| 109 | keysToValuesscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/structInfo#keysToValues. map[handleKeyscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/handleKey#]reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Valuescip-go gomod github.com/golang/go/src go1.15 reflect/Value# |
| 110 | |
| 111 | // map from each handle + key() to the list it came from |
| 112 | keysToListsscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/structInfo#keysToLists. map[handleKeyscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/handleKey#]string |
| 113 | |
| 114 | // map from each handle + key() to the index within the list |
| 115 | keysToListIndexesscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/structInfo#keysToListIndexes. map[handleKeyscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/handleKey#]int |
| 116 | } |
| 117 | |
| 118 | // returns if this field should not do duplicate checking/merging |
| 119 | func (s structInfoscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/structInfo#) ignoreFieldscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/structInfo#ignoreField().(name string) bool { |
| 120 | _, ignore := s.ignoreDupsscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/structInfo#ignoreDups.[name] |
| 121 | return ignore |
| 122 | } |
| 123 | |
| 124 | // getChildEntryByKey takes the name of a field (not handle) in the parent and a key and looks that entry |
| 125 | // up in the child. It will look up across all slices that share the same handle. It returns the value, |
| 126 | // name of the field in the child it was found in, and the list index within that field. The bool indicates |
| 127 | // whether it was found. |
| 128 | func (s structInfoscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/structInfo#) getChildEntryByKeyscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/structInfo#getChildEntryByKey().(fieldName, key string) (reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Valuescip-go gomod github.com/golang/go/src go1.15 reflect/Value#, string, int, bool) { |
| 129 | handle := fieldName |
| 130 | if tmp, ok := s.mergedKeysscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/structInfo#mergedKeys.[fieldName]; ok { |
| 131 | handle = tmp |
| 132 | } |
| 133 | |
| 134 | hkey := handleKeyscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/handleKey#{ |
| 135 | handlescip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/handleKey#handle.: handle, |
| 136 | keyscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/handleKey#key.: key, |
| 137 | } |
| 138 | if v, ok := s.keysToValuesscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/structInfo#keysToValues.[hkey]; ok { |
| 139 | return v, s.keysToListsscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/structInfo#keysToLists.[hkey], s.keysToListIndexesscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/structInfo#keysToListIndexes.[hkey], true |
| 140 | } |
| 141 | return reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Valuescip-go gomod github.com/golang/go/src go1.15 reflect/Value#{}, "", 0, false |
| 142 | } |
| 143 | |
| 144 | func newStructInfoscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/newStructInfo().(parent, child reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Valuescip-go gomod github.com/golang/go/src go1.15 reflect/Value#) structInfoscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/structInfo# { |
| 145 | ignoreDups := map[string]struct{}{} |
| 146 | if ignorer, ok := parent.Interfacescip-go gomod github.com/golang/go/src go1.15 reflect/Value#Interface().().(utilscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/util`/.IgnoresDupsscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/util`/IgnoresDups#); ok { |
| 147 | ignoreDups = ignorer.IgnoreDuplicatesscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/util`/IgnoresDups#IgnoreDuplicates.() |
| 148 | } |
| 149 | |
| 150 | mergedKeys := map[string]string{} |
| 151 | if merger, ok := parent.Interfacescip-go gomod github.com/golang/go/src go1.15 reflect/Value#Interface().().(utilscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/util`/.MergesKeysscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/util`/MergesKeys#); ok { |
| 152 | mergedKeys = merger.MergedKeysscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/util`/MergesKeys#MergedKeys.() |
| 153 | } |
| 154 | |
| 155 | keysToValues := map[handleKeyscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/handleKey#]reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Valuescip-go gomod github.com/golang/go/src go1.15 reflect/Value#{} |
| 156 | keysToLists := map[handleKeyscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/handleKey#]string{} |
| 157 | keysToListIndexes := map[handleKeyscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/handleKey#]int{} |
| 158 | for i := 0; i < child.NumFieldscip-go gomod github.com/golang/go/src go1.15 reflect/Value#NumField().(); i++ { |
| 159 | field := child.Fieldscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Field().(i) |
| 160 | if field.Kindscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Kind().() != reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Slicescip-go gomod github.com/golang/go/src go1.15 reflect/Slice. { |
| 161 | continue |
| 162 | } |
| 163 | |
| 164 | fieldName := child.Typescip-go gomod github.com/golang/go/src go1.15 reflect/Value#Type().().Fieldscip-go gomod github.com/golang/go/src go1.15 reflect/Type#Field().(i).Namescip-go gomod github.com/golang/go/src go1.15 reflect/StructField#Name. |
| 165 | if _, ok := ignoreDups[fieldName]; ok { |
| 166 | continue |
| 167 | } |
| 168 | |
| 169 | handle := fieldName |
| 170 | if tmp, ok := mergedKeys[handle]; ok { |
| 171 | handle = tmp |
| 172 | } |
| 173 | |
| 174 | for j := 0; j < field.Lenscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Len().(); j++ { |
| 175 | v := field.Indexscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Index().(j) |
| 176 | hkey := handleKeyscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/handleKey#{ |
| 177 | handlescip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/handleKey#handle.: handle, |
| 178 | keyscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/handleKey#key.: utilscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/util`/.CallKeyscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/util`/CallKey().(v), |
| 179 | } |
| 180 | keysToValues[hkey] = v |
| 181 | keysToLists[hkey] = fieldName |
| 182 | keysToListIndexes[hkey] = j |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | return structInfoscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/structInfo#{ |
| 187 | ignoreDupsscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/structInfo#ignoreDups.: ignoreDups, |
| 188 | mergedKeysscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/structInfo#mergedKeys.: mergedKeys, |
| 189 | keysToValuesscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/structInfo#keysToValues.: keysToValues, |
| 190 | keysToListsscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/structInfo#keysToLists.: keysToLists, |
| 191 | keysToListIndexesscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/structInfo#keysToListIndexes.: keysToListIndexes, |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | // Deprecated: Use MergeStructTranscribe() instead. |
| 196 | func MergeStructscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/MergeStruct().(parent, child reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Valuescip-go gomod github.com/golang/go/src go1.15 reflect/Value#) reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Valuescip-go gomod github.com/golang/go/src go1.15 reflect/Value# { |
| 197 | result, _ := MergeStructTranscribescip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/MergeStructTranscribe().(parent.Interfacescip-go gomod github.com/golang/go/src go1.15 reflect/Value#Interface().(), child.Interfacescip-go gomod github.com/golang/go/src go1.15 reflect/Value#Interface().()) |
| 198 | return reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.ValueOfscip-go gomod github.com/golang/go/src go1.15 reflect/ValueOf().(result) |
| 199 | } |
| 200 | |
| 201 | // MergeStructTranscribe is intended for use by config/vX_Y/ packages and |
| 202 | // by generic external translation code. Most users should use the properly |
| 203 | // typed wrappers provided by the config/vX_Y/ packages. |
| 204 | // |
| 205 | // MergeStructTranscribe merges the specified configs and returns a |
| 206 | // transcript of the actions taken. parent and child MUST be the same type. |
| 207 | func MergeStructTranscribescip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/MergeStructTranscribe().(parent, child interface{}) (interface{}, Transcriptscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/Transcript#) { |
| 208 | var transcript Transcriptscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/Transcript# |
| 209 | result := mergeStructscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/mergeStruct().(reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.ValueOfscip-go gomod github.com/golang/go/src go1.15 reflect/ValueOf().(parent), pathscip-go gomod github.com/coreos/vcontext f1dbbca7bef4 `github.com/coreos/vcontext/path`/.Newscip-go gomod github.com/coreos/vcontext f1dbbca7bef4 `github.com/coreos/vcontext/path`/New().(TAG_PARENTscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/TAG_PARENT.), reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.ValueOfscip-go gomod github.com/golang/go/src go1.15 reflect/ValueOf().(child), pathscip-go gomod github.com/coreos/vcontext f1dbbca7bef4 `github.com/coreos/vcontext/path`/.Newscip-go gomod github.com/coreos/vcontext f1dbbca7bef4 `github.com/coreos/vcontext/path`/New().(TAG_CHILDscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/TAG_CHILD.), pathscip-go gomod github.com/coreos/vcontext f1dbbca7bef4 `github.com/coreos/vcontext/path`/.Newscip-go gomod github.com/coreos/vcontext f1dbbca7bef4 `github.com/coreos/vcontext/path`/New().(TAG_RESULTscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/TAG_RESULT.), &transcript) |
| 210 | return result.Interfacescip-go gomod github.com/golang/go/src go1.15 reflect/Value#Interface().(), transcript |
| 211 | } |
| 212 | |
| 213 | // parent and child MUST be the same type |
| 214 | // the transcript lists children before parents |
| 215 | // all interior nodes that have contributions from both parent and child |
| 216 | // receive separate transcript mappings for parent and child, in that order |
| 217 | func mergeStructscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/mergeStruct().(parent reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Valuescip-go gomod github.com/golang/go/src go1.15 reflect/Value#, parentPath pathscip-go gomod github.com/coreos/vcontext f1dbbca7bef4 `github.com/coreos/vcontext/path`/.ContextPathscip-go gomod github.com/coreos/vcontext f1dbbca7bef4 `github.com/coreos/vcontext/path`/ContextPath#, child reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Valuescip-go gomod github.com/golang/go/src go1.15 reflect/Value#, childPath pathscip-go gomod github.com/coreos/vcontext f1dbbca7bef4 `github.com/coreos/vcontext/path`/.ContextPathscip-go gomod github.com/coreos/vcontext f1dbbca7bef4 `github.com/coreos/vcontext/path`/ContextPath#, resultPath pathscip-go gomod github.com/coreos/vcontext f1dbbca7bef4 `github.com/coreos/vcontext/path`/.ContextPathscip-go gomod github.com/coreos/vcontext f1dbbca7bef4 `github.com/coreos/vcontext/path`/ContextPath#, transcript *Transcriptscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/Transcript#) reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Valuescip-go gomod github.com/golang/go/src go1.15 reflect/Value# { |
| 218 | // use New() so it's settable, addr-able, etc |
| 219 | result := reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Newscip-go gomod github.com/golang/go/src go1.15 reflect/New().(parent.Typescip-go gomod github.com/golang/go/src go1.15 reflect/Value#Type().()).Elemscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Elem().() |
| 220 | info := newStructInfoscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/newStructInfo().(parent, child) |
| 221 | |
| 222 | for i := 0; i < parent.NumFieldscip-go gomod github.com/golang/go/src go1.15 reflect/Value#NumField().(); i++ { |
| 223 | fieldMeta := parent.Typescip-go gomod github.com/golang/go/src go1.15 reflect/Value#Type().().Fieldscip-go gomod github.com/golang/go/src go1.15 reflect/Type#Field().(i) |
| 224 | parentField := parent.Fieldscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Field().(i) |
| 225 | childField := child.Fieldscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Field().(i) |
| 226 | resultField := result.Fieldscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Field().(i) |
| 227 | parentFieldPath := pathAppendFieldscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/pathAppendField().(parentPath, fieldMeta) |
| 228 | childFieldPath := pathAppendFieldscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/pathAppendField().(childPath, fieldMeta) |
| 229 | resultFieldPath := pathAppendFieldscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/pathAppendField().(resultPath, fieldMeta) |
| 230 | |
| 231 | kind := parentField.Kindscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Kind().() |
| 232 | switch { |
| 233 | case utilscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/util`/.IsPrimitivescip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/util`/IsPrimitive().(kind): |
| 234 | resultField.Setscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Set().(childField) |
| 235 | transcribescip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/transcribe().(childFieldPath, resultFieldPath, resultField, fieldMeta, transcript) |
| 236 | case kind == reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Ptrscip-go gomod github.com/golang/go/src go1.15 reflect/Ptr. && !parentField.IsNilscip-go gomod github.com/golang/go/src go1.15 reflect/Value#IsNil().() && !childField.IsNilscip-go gomod github.com/golang/go/src go1.15 reflect/Value#IsNil().() && parentField.Elemscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Elem().().Kindscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Kind().() == reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Structscip-go gomod github.com/golang/go/src go1.15 reflect/Struct.: |
| 237 | // we're not supposed to have struct pointers, but some |
| 238 | // ended up in the Clevis and Luks structs in spec 3.2.0 |
| 239 | // https://github.com/coreos/ignition/issues/1132 |
| 240 | resultField.Setscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Set().(mergeStructscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/mergeStruct().(parentField.Elemscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Elem().(), parentFieldPath, childField.Elemscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Elem().(), childFieldPath, resultFieldPath, transcript).Addrscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Addr().()) |
| 241 | transcribeOnescip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/transcribeOne().(parentFieldPath, resultFieldPath, transcript) |
| 242 | transcribeOnescip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/transcribeOne().(childFieldPath, resultFieldPath, transcript) |
| 243 | case kind == reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Ptrscip-go gomod github.com/golang/go/src go1.15 reflect/Ptr. && childField.IsNilscip-go gomod github.com/golang/go/src go1.15 reflect/Value#IsNil().(): |
| 244 | resultField.Setscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Set().(parentField) |
| 245 | transcribescip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/transcribe().(parentFieldPath, resultFieldPath, resultField, fieldMeta, transcript) |
| 246 | case kind == reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Ptrscip-go gomod github.com/golang/go/src go1.15 reflect/Ptr. && !childField.IsNilscip-go gomod github.com/golang/go/src go1.15 reflect/Value#IsNil().(): |
| 247 | resultField.Setscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Set().(childField) |
| 248 | transcribescip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/transcribe().(childFieldPath, resultFieldPath, resultField, fieldMeta, transcript) |
| 249 | case kind == reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Structscip-go gomod github.com/golang/go/src go1.15 reflect/Struct. && childField.IsZeroscip-go gomod github.com/golang/go/src go1.15 reflect/Value#IsZero().(): |
| 250 | resultField.Setscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Set().(parentField) |
| 251 | transcribescip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/transcribe().(parentFieldPath, resultFieldPath, resultField, fieldMeta, transcript) |
| 252 | case kind == reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Structscip-go gomod github.com/golang/go/src go1.15 reflect/Struct. && parentField.IsZeroscip-go gomod github.com/golang/go/src go1.15 reflect/Value#IsZero().(): |
| 253 | resultField.Setscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Set().(childField) |
| 254 | transcribescip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/transcribe().(childFieldPath, resultFieldPath, resultField, fieldMeta, transcript) |
| 255 | case kind == reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Structscip-go gomod github.com/golang/go/src go1.15 reflect/Struct.: |
| 256 | resultField.Setscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Set().(mergeStructscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/mergeStruct().(parentField, parentFieldPath, childField, childFieldPath, resultFieldPath, transcript)) |
| 257 | if !fieldMeta.Anonymousscip-go gomod github.com/golang/go/src go1.15 reflect/StructField#Anonymous. { |
| 258 | transcribeOnescip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/transcribeOne().(parentFieldPath, resultFieldPath, transcript) |
| 259 | transcribeOnescip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/transcribeOne().(childFieldPath, resultFieldPath, transcript) |
| 260 | } |
| 261 | case kind == reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Slicescip-go gomod github.com/golang/go/src go1.15 reflect/Slice. && info.ignoreFieldscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/structInfo#ignoreField().(fieldMeta.Namescip-go gomod github.com/golang/go/src go1.15 reflect/StructField#Name.): |
| 262 | if parentField.Lenscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Len().()+childField.Lenscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Len().() == 0 { |
| 263 | continue |
| 264 | } |
| 265 | resultField.Setscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Set().(reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.MakeSlicescip-go gomod github.com/golang/go/src go1.15 reflect/MakeSlice().(parentField.Typescip-go gomod github.com/golang/go/src go1.15 reflect/Value#Type().(), 0, parentField.Lenscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Len().()+childField.Lenscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Len().())) |
| 266 | for i := 0; i < parentField.Lenscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Len().(); i++ { |
| 267 | item := parentField.Indexscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Index().(i) |
| 268 | appendToSlicescip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/appendToSlice().(resultField, item) |
| 269 | transcribescip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/transcribe().(parentFieldPath.Appendscip-go gomod github.com/coreos/vcontext f1dbbca7bef4 `github.com/coreos/vcontext/path`/ContextPath#Append().(i), resultFieldPath.Appendscip-go gomod github.com/coreos/vcontext f1dbbca7bef4 `github.com/coreos/vcontext/path`/ContextPath#Append().(i), item, fieldMeta, transcript) |
| 270 | } |
| 271 | for i := 0; i < childField.Lenscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Len().(); i++ { |
| 272 | item := childField.Indexscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Index().(i) |
| 273 | appendToSlicescip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/appendToSlice().(resultField, item) |
| 274 | transcribescip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/transcribe().(childFieldPath.Appendscip-go gomod github.com/coreos/vcontext f1dbbca7bef4 `github.com/coreos/vcontext/path`/ContextPath#Append().(i), resultFieldPath.Appendscip-go gomod github.com/coreos/vcontext f1dbbca7bef4 `github.com/coreos/vcontext/path`/ContextPath#Append().(parentField.Lenscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Len().()+i), item, fieldMeta, transcript) |
| 275 | } |
| 276 | // transcribe the list itself |
| 277 | if parentField.Lenscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Len().() > 0 { |
| 278 | transcribeOnescip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/transcribeOne().(parentFieldPath, resultFieldPath, transcript) |
| 279 | } |
| 280 | if childField.Lenscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Len().() > 0 { |
| 281 | transcribeOnescip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/transcribeOne().(childFieldPath, resultFieldPath, transcript) |
| 282 | } |
| 283 | case kind == reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Slicescip-go gomod github.com/golang/go/src go1.15 reflect/Slice. && !info.ignoreFieldscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/structInfo#ignoreField().(fieldMeta.Namescip-go gomod github.com/golang/go/src go1.15 reflect/StructField#Name.): |
| 284 | // ooph, this is a doosey |
| 285 | maxlen := parentField.Lenscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Len().() + childField.Lenscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Len().() |
| 286 | if maxlen == 0 { |
| 287 | continue |
| 288 | } |
| 289 | resultField.Setscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Set().(reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.MakeSlicescip-go gomod github.com/golang/go/src go1.15 reflect/MakeSlice().(parentField.Typescip-go gomod github.com/golang/go/src go1.15 reflect/Value#Type().(), 0, parentField.Lenscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Len().()+childField.Lenscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Len().())) |
| 290 | parentKeys := getKeySetscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/getKeySet().(parentField) |
| 291 | var itemFromParent, itemFromChild bool |
| 292 | |
| 293 | // walk parent items |
| 294 | for i := 0; i < parentField.Lenscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Len().(); i++ { |
| 295 | parentItem := parentField.Indexscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Index().(i) |
| 296 | parentItemPath := parentFieldPath.Appendscip-go gomod github.com/coreos/vcontext f1dbbca7bef4 `github.com/coreos/vcontext/path`/ContextPath#Append().(i) |
| 297 | resultItemPath := resultFieldPath.Appendscip-go gomod github.com/coreos/vcontext f1dbbca7bef4 `github.com/coreos/vcontext/path`/ContextPath#Append().(resultField.Lenscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Len().()) |
| 298 | key := utilscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/util`/.CallKeyscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/util`/CallKey().(parentItem) |
| 299 | |
| 300 | if childItem, childList, childListIndex, ok := info.getChildEntryByKeyscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/structInfo#getChildEntryByKey().(fieldMeta.Namescip-go gomod github.com/golang/go/src go1.15 reflect/StructField#Name., key); ok { |
| 301 | if childList == fieldMeta.Namescip-go gomod github.com/golang/go/src go1.15 reflect/StructField#Name. { |
| 302 | // case 1: in child config in same list |
| 303 | childItemPath := childFieldPath.Appendscip-go gomod github.com/coreos/vcontext f1dbbca7bef4 `github.com/coreos/vcontext/path`/ContextPath#Append().(childListIndex) |
| 304 | // record the contribution of both parent and child, even if one wins |
| 305 | // or cancels the other |
| 306 | itemFromParent = true |
| 307 | itemFromChild = true |
| 308 | if childItem.Kindscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Kind().() == reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Structscip-go gomod github.com/golang/go/src go1.15 reflect/Struct. { |
| 309 | // If HTTP header Value is nil, it means that we should remove the |
| 310 | // parent header from the result. |
| 311 | if fieldMeta.Namescip-go gomod github.com/golang/go/src go1.15 reflect/StructField#Name. == "HTTPHeaders" && childItem.FieldByNamescip-go gomod github.com/golang/go/src go1.15 reflect/Value#FieldByName().("Value").IsNilscip-go gomod github.com/golang/go/src go1.15 reflect/Value#IsNil().() { |
| 312 | continue |
| 313 | } |
| 314 | appendToSlicescip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/appendToSlice().(resultField, mergeStructscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/mergeStruct().(parentItem, parentItemPath, childItem, childItemPath, resultItemPath, transcript)) |
| 315 | transcribeOnescip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/transcribeOne().(parentItemPath, resultItemPath, transcript) |
| 316 | transcribeOnescip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/transcribeOne().(childItemPath, resultItemPath, transcript) |
| 317 | } else if utilscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/util`/.IsPrimitivescip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/util`/IsPrimitive().(childItem.Kindscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Kind().()) { |
| 318 | appendToSlicescip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/appendToSlice().(resultField, childItem) |
| 319 | transcribescip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/transcribe().(childItemPath, resultItemPath, childItem, fieldMeta, transcript) |
| 320 | } else { |
| 321 | panic("List of pointers or slices or something else weird") |
| 322 | } |
| 323 | } else { // nolint:staticcheck |
| 324 | // case 2: in child config in different list. Do nothing since it'll be handled iterating over that list |
| 325 | } |
| 326 | } else { |
| 327 | // case 3: not in child config, append it |
| 328 | appendToSlicescip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/appendToSlice().(resultField, parentItem) |
| 329 | transcribescip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/transcribe().(parentItemPath, resultItemPath, parentItem, fieldMeta, transcript) |
| 330 | itemFromParent = true |
| 331 | } |
| 332 | } |
| 333 | // append child items not in parent |
| 334 | for i := 0; i < childField.Lenscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Len().(); i++ { |
| 335 | childItem := childField.Indexscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Index().(i) |
| 336 | childItemPath := childFieldPath.Appendscip-go gomod github.com/coreos/vcontext f1dbbca7bef4 `github.com/coreos/vcontext/path`/ContextPath#Append().(i) |
| 337 | resultItemPath := resultFieldPath.Appendscip-go gomod github.com/coreos/vcontext f1dbbca7bef4 `github.com/coreos/vcontext/path`/ContextPath#Append().(resultField.Lenscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Len().()) |
| 338 | key := utilscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/util`/.CallKeyscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/util`/CallKey().(childItem) |
| 339 | if _, alreadyMerged := parentKeys[key]; !alreadyMerged { |
| 340 | // We only check the parentMap for this field. If the parent had a matching entry in a different field |
| 341 | // then it would be skipped as case 2 above |
| 342 | appendToSlicescip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/appendToSlice().(resultField, childItem) |
| 343 | transcribescip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/transcribe().(childItemPath, resultItemPath, childItem, fieldMeta, transcript) |
| 344 | itemFromChild = true |
| 345 | } |
| 346 | } |
| 347 | if itemFromParent { |
| 348 | transcribeOnescip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/transcribeOne().(parentFieldPath, resultFieldPath, transcript) |
| 349 | } |
| 350 | if itemFromChild { |
| 351 | transcribeOnescip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/transcribeOne().(childFieldPath, resultFieldPath, transcript) |
| 352 | } |
| 353 | default: |
| 354 | panic("unreachable code reached") |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | return result |
| 359 | } |
| 360 | |
| 361 | // transcribe is called by mergeStruct when the latter decides to merge a |
| 362 | // subtree wholesale from either the parent or child, and thus loses |
| 363 | // interest in that subtree. transcribe descends the rest of that subtree, |
| 364 | // transcribing all of its populated leaves. It returns true if we |
| 365 | // transcribed anything. |
| 366 | func transcribescip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/transcribe().(fromPath pathscip-go gomod github.com/coreos/vcontext f1dbbca7bef4 `github.com/coreos/vcontext/path`/.ContextPathscip-go gomod github.com/coreos/vcontext f1dbbca7bef4 `github.com/coreos/vcontext/path`/ContextPath#, toPath pathscip-go gomod github.com/coreos/vcontext f1dbbca7bef4 `github.com/coreos/vcontext/path`/.ContextPathscip-go gomod github.com/coreos/vcontext f1dbbca7bef4 `github.com/coreos/vcontext/path`/ContextPath#, value reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Valuescip-go gomod github.com/golang/go/src go1.15 reflect/Value#, fieldMeta reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.StructFieldscip-go gomod github.com/golang/go/src go1.15 reflect/StructField#, transcript *Transcriptscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/Transcript#) bool { |
| 367 | kind := value.Kindscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Kind().() |
| 368 | switch { |
| 369 | case utilscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/util`/.IsPrimitivescip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/util`/IsPrimitive().(kind): |
| 370 | if value.IsZeroscip-go gomod github.com/golang/go/src go1.15 reflect/Value#IsZero().() { |
| 371 | return false |
| 372 | } |
| 373 | transcribeOnescip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/transcribeOne().(fromPath, toPath, transcript) |
| 374 | case kind == reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Ptrscip-go gomod github.com/golang/go/src go1.15 reflect/Ptr.: |
| 375 | if value.IsNilscip-go gomod github.com/golang/go/src go1.15 reflect/Value#IsNil().() { |
| 376 | return false |
| 377 | } |
| 378 | if value.Elemscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Elem().().Kindscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Kind().() == reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Structscip-go gomod github.com/golang/go/src go1.15 reflect/Struct. { |
| 379 | // we're not supposed to have struct pointers, but some |
| 380 | // ended up in the Clevis and Luks structs in spec 3.2.0 |
| 381 | // https://github.com/coreos/ignition/issues/1132 |
| 382 | return transcribescip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/transcribe().(fromPath, toPath, value.Elemscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Elem().(), fieldMeta, transcript) |
| 383 | } |
| 384 | transcribeOnescip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/transcribeOne().(fromPath, toPath, transcript) |
| 385 | case kind == reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Structscip-go gomod github.com/golang/go/src go1.15 reflect/Struct.: |
| 386 | var transcribed bool |
| 387 | for i := 0; i < value.NumFieldscip-go gomod github.com/golang/go/src go1.15 reflect/Value#NumField().(); i++ { |
| 388 | valueFieldMeta := value.Typescip-go gomod github.com/golang/go/src go1.15 reflect/Value#Type().().Fieldscip-go gomod github.com/golang/go/src go1.15 reflect/Type#Field().(i) |
| 389 | transcribed = transcribescip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/transcribe().(pathAppendFieldscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/pathAppendField().(fromPath, valueFieldMeta), pathAppendFieldscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/pathAppendField().(toPath, valueFieldMeta), value.Fieldscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Field().(i), valueFieldMeta, transcript) || transcribed |
| 390 | } |
| 391 | // embedded structs and empty structs should be invisible |
| 392 | if transcribed && !fieldMeta.Anonymousscip-go gomod github.com/golang/go/src go1.15 reflect/StructField#Anonymous. { |
| 393 | transcribeOnescip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/transcribeOne().(fromPath, toPath, transcript) |
| 394 | } |
| 395 | return transcribed |
| 396 | case kind == reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Slicescip-go gomod github.com/golang/go/src go1.15 reflect/Slice.: |
| 397 | var transcribed bool |
| 398 | for i := 0; i < value.Lenscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Len().(); i++ { |
| 399 | transcribed = transcribescip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/transcribe().(fromPath.Appendscip-go gomod github.com/coreos/vcontext f1dbbca7bef4 `github.com/coreos/vcontext/path`/ContextPath#Append().(i), toPath.Appendscip-go gomod github.com/coreos/vcontext f1dbbca7bef4 `github.com/coreos/vcontext/path`/ContextPath#Append().(i), value.Indexscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Index().(i), fieldMeta, transcript) || transcribed |
| 400 | } |
| 401 | if transcribed { |
| 402 | transcribeOnescip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/transcribeOne().(fromPath, toPath, transcript) |
| 403 | } |
| 404 | return transcribed |
| 405 | default: |
| 406 | panic("unreachable code reached") |
| 407 | } |
| 408 | return true |
| 409 | } |
| 410 | |
| 411 | // transcribeOne records one Mapping into a Transcript. |
| 412 | func transcribeOnescip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/transcribeOne().(from, to pathscip-go gomod github.com/coreos/vcontext f1dbbca7bef4 `github.com/coreos/vcontext/path`/.ContextPathscip-go gomod github.com/coreos/vcontext f1dbbca7bef4 `github.com/coreos/vcontext/path`/ContextPath#, transcript *Transcriptscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/Transcript#) { |
| 413 | transcript.Mappingsscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/Transcript#Mappings. = append(transcript.Mappingsscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/Transcript#Mappings., Mappingscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/Mapping#{ |
| 414 | Fromscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/Mapping#From.: from.Copyscip-go gomod github.com/coreos/vcontext f1dbbca7bef4 `github.com/coreos/vcontext/path`/ContextPath#Copy().(), |
| 415 | Toscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/Mapping#To.: to.Copyscip-go gomod github.com/coreos/vcontext f1dbbca7bef4 `github.com/coreos/vcontext/path`/ContextPath#Copy().(), |
| 416 | }) |
| 417 | } |
| 418 | |
| 419 | // getKeySet takes a value of a slice and returns the set of all the Key() values in that slice |
| 420 | func getKeySetscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/merge`/getKeySet().(list reflectscip-go gomod github.com/golang/go/src go1.15 reflect/.Valuescip-go gomod github.com/golang/go/src go1.15 reflect/Value#) map[string]struct{} { |
| 421 | m := map[string]struct{}{} |
| 422 | for i := 0; i < list.Lenscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Len().(); i++ { |
| 423 | m[utilscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/util`/.CallKeyscip-go gomod github.com/coreos/ignition/v2 . `github.com/coreos/ignition/v2/config/util`/CallKey().(list.Indexscip-go gomod github.com/golang/go/src go1.15 reflect/Value#Index().(i))] = struct{}{} |
| 424 | } |
| 425 | return m |
| 426 | } |