@@ -186,14 +186,19 @@ func (r *ConfigReconciler) reconcileConfigTypes(inst *api.HNCConfiguration, allR
186186 }
187187
188188 // Look if the resource exists in the API server.
189- gvk , err := GVKFor (gr , allRes )
189+ gvk , namescoped , err := GVKNamescopedFor (gr , allRes )
190190 if err != nil {
191191 // If the type is not found, log error and write conditions but don't
192192 // early exit since the other types can still be reconciled.
193193 r .Log .Error (err , "while trying to reconcile the configuration" , "type" , gr , "mode" , rsc .Mode )
194194 r .writeCondition (inst , api .ConditionBadTypeConfiguration , api .ReasonResourceNotFound , err .Error ())
195195 continue
196196 }
197+ if ! namescoped {
198+ r .Log .Error (err , "while trying to reconcile the configuration" , "type" , gr , "mode" , rsc .Mode )
199+ r .writeCondition (inst , api .ConditionBadTypeConfiguration , api .ReasonResourceNotNamescoped , fmt .Sprintf ("type %s is not Namescoped" , gr ))
200+ continue
201+ }
197202 r .activeGVKMode [gr ] = gvkMode {gvk , rsc .Mode }
198203 r .activeGR [gvk ] = gr
199204 }
@@ -586,6 +591,13 @@ func GetAllResources(config *rest.Config) ([]*restmapper.APIGroupResources, erro
586591// GVKFor searches the GR in apiserver and returns the mapping GVK. If the GR
587592// doesn't exist, return an empty GVK and the error.
588593func GVKFor (gr schema.GroupResource , allRes []* restmapper.APIGroupResources ) (schema.GroupVersionKind , error ) {
594+ gvk , _ , err := GVKNamescopedFor (gr , allRes )
595+ return gvk , err
596+ }
597+
598+ // GVKNamescopedFor searches the GR in apiserver and returns the mapping GVK and whether it is namespaced. If the GR
599+ // doesn't exist, return an empty GVK and the error.
600+ func GVKNamescopedFor (gr schema.GroupResource , allRes []* restmapper.APIGroupResources ) (schema.GroupVersionKind , bool , error ) {
589601 // Look for a matching resource from all resources.
590602 for _ , groupedResources := range allRes {
591603 group := groupedResources .Group
@@ -608,10 +620,10 @@ func GVKFor(gr schema.GroupResource, allRes []*restmapper.APIGroupResources) (sc
608620 Version : version .Version ,
609621 Kind : resource .Kind ,
610622 }
611- return gvk , nil
623+ return gvk , resource . Namespaced , nil
612624 }
613625 }
614626 }
615627 }
616- return schema.GroupVersionKind {}, fmt .Errorf ("Resource %q not found" , gr )
628+ return schema.GroupVersionKind {}, false , fmt .Errorf ("Resource %q not found" , gr )
617629}
0 commit comments