@@ -98,17 +98,18 @@ func createCRDs(ctx context.Context, config *rest.Config, crds []*apiextensionsv
9898}
9999
100100func waitForDiscovery (ctx context.Context , config * rest.Config , crds []* apiextensionsv1.CustomResourceDefinition ) error {
101- gvrs := map [schema. GroupVersionResource ] struct {}{}
101+ resourcesByGV := make ( map [string ] map [ string ] struct {}, 0 )
102102 for _ , crd := range crds {
103103 for _ , version := range crd .Spec .Versions {
104104 if ! version .Served {
105105 continue
106106 }
107- gvrs [schema.GroupVersionResource {
108- Group : crd .Spec .Group ,
109- Version : version .Name ,
110- Resource : crd .Spec .Names .Plural ,
111- }] = struct {}{}
107+ gv := schema.GroupVersion {Version : version .Name , Group : crd .Spec .Group }.String ()
108+ _ , ok := resourcesByGV [gv ]
109+ if ! ok {
110+ resourcesByGV [gv ] = make (map [string ]struct {}, 0 )
111+ }
112+ resourcesByGV [gv ][crd .Spec .Names .Plural ] = struct {}{}
112113 }
113114 }
114115 discoveryClient , err := discovery .NewDiscoveryClientForConfig (config )
@@ -123,15 +124,17 @@ func waitForDiscovery(ctx context.Context, config *rest.Config, crds []*apiexten
123124 }
124125
125126 for _ , gv := range serverGVRs {
127+ if _ , ok := resourcesByGV [gv .GroupVersion ]; ! ok {
128+ continue
129+ }
126130 for _ , r := range gv .APIResources {
127- delete (gvrs , schema.GroupVersionResource {
128- Group : r .Group ,
129- Version : r .Version ,
130- Resource : r .Name ,
131- })
131+ delete (resourcesByGV [gv .GroupVersion ], r .Name )
132+ }
133+ if len (resourcesByGV [gv .GroupVersion ]) == 0 {
134+ delete (resourcesByGV , gv .GroupVersion )
132135 }
133136 }
134137
135- return len (gvrs ) == 0 , nil
138+ return len (resourcesByGV ) == 0 , nil
136139 })
137140}
0 commit comments