@@ -278,10 +278,16 @@ func renderCRDs(options *CRDInstallOptions) ([]runtime.Object, error) {
278278 var (
279279 err error
280280 info os.FileInfo
281- crds []* unstructured.Unstructured
282281 files []os.FileInfo
283282 )
284283
284+ type GVKN struct {
285+ GVK schema.GroupVersionKind
286+ Name string
287+ }
288+
289+ crds := map [GVKN ]* unstructured.Unstructured {}
290+
285291 for _ , path := range options .Paths {
286292 var filePath = path
287293
@@ -294,7 +300,7 @@ func renderCRDs(options *CRDInstallOptions) ([]runtime.Object, error) {
294300 }
295301
296302 if ! info .IsDir () {
297- filePath , files = filepath .Dir (path ), append ( files , info )
303+ filePath , files = filepath .Dir (path ), []os. FileInfo { info }
298304 } else {
299305 if files , err = ioutil .ReadDir (path ); err != nil {
300306 return nil , err
@@ -307,14 +313,23 @@ func renderCRDs(options *CRDInstallOptions) ([]runtime.Object, error) {
307313 return nil , err
308314 }
309315
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 ]
313324 }
314- crds = append (crds , crdList ... )
315325 }
316326
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
318333}
319334
320335// readCRDs reads the CRDs from files and Unmarshals them into structs
0 commit comments