@@ -141,12 +141,44 @@ func RunExport(f *clientcmd.Factory, exporter Exporter, in io.Reader, out io.Wri
141
141
newInfos := []* resource.Info {}
142
142
errs := []error {}
143
143
for _ , info := range infos {
144
+ converted := false
145
+
146
+ // convert unstructured object to runtime.Object
147
+ data , err := runtime .Encode (kapi .Codecs .LegacyCodec (), info .Object )
148
+ if err != nil {
149
+ errs = append (errs , err )
150
+ continue
151
+ }
152
+ decoded , err := runtime .Decode (f .Decoder (true ), data )
153
+ if err == nil {
154
+ // ignore error, if any, in order to allow resources
155
+ // not known by the client to still be exported
156
+ info .Object = decoded
157
+ converted = true
158
+ }
159
+
144
160
if err := exporter .Export (info .Object , exact ); err != nil {
145
161
if err == ErrExportOmit {
146
162
continue
147
163
}
148
164
errs = append (errs , err )
149
165
}
166
+
167
+ // if an unstructured resource was successfully converted by the universal decoder,
168
+ // re-convert that object once again into its external version.
169
+ // If object cannot be converted to an external version, ignore error and proceed with
170
+ // internal version.
171
+ if converted {
172
+ if data , err = runtime .Encode (kapi .Codecs .LegacyCodec (outputVersion ), info .Object ); err == nil {
173
+ external , err := runtime .Decode (f .Decoder (false ), data )
174
+ if err != nil {
175
+ errs = append (errs , fmt .Errorf ("error: failed to convert resource to external version: %v" , err ))
176
+ continue
177
+ }
178
+ info .Object = external
179
+ }
180
+ }
181
+
150
182
newInfos = append (newInfos , info )
151
183
}
152
184
if len (errs ) > 0 {
0 commit comments