@@ -278,10 +278,16 @@ func renderCRDs(options *CRDInstallOptions) ([]runtime.Object, error) {
278
278
var (
279
279
err error
280
280
info os.FileInfo
281
- crds []* unstructured.Unstructured
282
281
files []os.FileInfo
283
282
)
284
283
284
+ type GVKN struct {
285
+ GVK schema.GroupVersionKind
286
+ Name string
287
+ }
288
+
289
+ crds := map [GVKN ]* unstructured.Unstructured {}
290
+
285
291
for _ , path := range options .Paths {
286
292
var filePath = path
287
293
@@ -294,7 +300,7 @@ func renderCRDs(options *CRDInstallOptions) ([]runtime.Object, error) {
294
300
}
295
301
296
302
if ! info .IsDir () {
297
- filePath , files = filepath .Dir (path ), append ( files , info )
303
+ filePath , files = filepath .Dir (path ), []os. FileInfo { info }
298
304
} else {
299
305
if files , err = ioutil .ReadDir (path ); err != nil {
300
306
return nil , err
@@ -307,14 +313,23 @@ func renderCRDs(options *CRDInstallOptions) ([]runtime.Object, error) {
307
313
return nil , err
308
314
}
309
315
310
- // If CRD already in the list, skip it.
311
- if existsUnstructured (crds , crdList ) {
312
- continue
316
+ for i , crd := range crdList {
317
+ gvkn := GVKN {GVK : crd .GroupVersionKind (), Name : crd .GetName ()}
318
+ if _ , found := crds [gvkn ]; found {
319
+ // Currently, we only print a log when there are duplicates. We may want to error out if that makes more sense.
320
+ log .Info ("there are more than one CRD definitions with the same <Group, Version, Kind, Name>" , "GVKN" , gvkn )
321
+ }
322
+ // We always use the CRD definition that we found last.
323
+ crds [gvkn ] = crdList [i ]
313
324
}
314
- crds = append (crds , crdList ... )
315
325
}
316
326
317
- return unstructuredCRDListToRuntime (crds ), nil
327
+ // Converting map to a list to return
328
+ var res []runtime.Object
329
+ for _ , obj := range crds {
330
+ res = append (res , obj )
331
+ }
332
+ return res , nil
318
333
}
319
334
320
335
// readCRDs reads the CRDs from files and Unmarshals them into structs
0 commit comments