@@ -78,6 +78,15 @@ type gr2gvkMode map[schema.GroupResource]gvkMode
7878// gvk2gr keeps track of a group of unique GVKs with the mapping GRs.
7979type gvk2gr map [schema.GroupVersionKind ]schema.GroupResource
8080
81+ type GVKErr struct {
82+ Reason string
83+ Msg string
84+ }
85+
86+ func (e * GVKErr ) Error () string {
87+ return e .Msg
88+ }
89+
8190// checkPeriod is the period that the config reconciler checks if it needs to reconcile the
8291// `config` singleton.
8392const checkPeriod = 3 * time .Second
@@ -188,10 +197,12 @@ func (r *ConfigReconciler) reconcileConfigTypes(inst *api.HNCConfiguration, allR
188197 // Look if the resource exists in the API server.
189198 gvk , err := GVKFor (gr , allRes )
190199 if err != nil {
191- // If the type is not found, log error and write conditions but don't
200+ // If the type is not found or namespaced , log error and write conditions but don't
192201 // early exit since the other types can still be reconciled.
193202 r .Log .Error (err , "while trying to reconcile the configuration" , "type" , gr , "mode" , rsc .Mode )
194- r .writeCondition (inst , api .ConditionBadTypeConfiguration , api .ReasonResourceNotFound , err .Error ())
203+ if gvkerr , ok := err .(* GVKErr ); ok {
204+ r .writeCondition (inst , api .ConditionBadTypeConfiguration , gvkerr .Reason , gvkerr .Msg )
205+ }
195206 continue
196207 }
197208 r .activeGVKMode [gr ] = gvkMode {gvk , rsc .Mode }
@@ -599,6 +610,9 @@ func GVKFor(gr schema.GroupResource, allRes []*restmapper.APIGroupResources) (sc
599610 for _ , version := range group .Versions {
600611 for _ , resource := range groupedResources .VersionedResources [version .Version ] {
601612 if resource .Name == gr .Resource {
613+ if ! resource .Namespaced {
614+ return schema.GroupVersionKind {}, & GVKErr {api .ReasonResourceNotNamespaced , fmt .Sprintf ("Resource %q is not namespaced" , gr )}
615+ }
602616 // Please note that we cannot use resource.group or resource.version
603617 // here because they are preferred group/version and they are default
604618 // to empty to imply this current containing group/version. Therefore,
@@ -613,5 +627,5 @@ func GVKFor(gr schema.GroupResource, allRes []*restmapper.APIGroupResources) (sc
613627 }
614628 }
615629 }
616- return schema.GroupVersionKind {}, fmt .Errorf ("Resource %q not found" , gr )
630+ return schema.GroupVersionKind {}, & GVKErr { api . ReasonResourceNotFound , fmt .Sprintf ("Resource %q not found" , gr )}
617631}
0 commit comments