@@ -78,6 +78,15 @@ type gr2gvkMode map[schema.GroupResource]gvkMode
78
78
// gvk2gr keeps track of a group of unique GVKs with the mapping GRs.
79
79
type gvk2gr map [schema.GroupVersionKind ]schema.GroupResource
80
80
81
+ type GVKErr struct {
82
+ Reason string
83
+ Msg string
84
+ }
85
+
86
+ func (e * GVKErr ) Error () string {
87
+ return e .Msg
88
+ }
89
+
81
90
// checkPeriod is the period that the config reconciler checks if it needs to reconcile the
82
91
// `config` singleton.
83
92
const checkPeriod = 3 * time .Second
@@ -188,10 +197,12 @@ func (r *ConfigReconciler) reconcileConfigTypes(inst *api.HNCConfiguration, allR
188
197
// Look if the resource exists in the API server.
189
198
gvk , err := GVKFor (gr , allRes )
190
199
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
192
201
// early exit since the other types can still be reconciled.
193
202
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
+ }
195
206
continue
196
207
}
197
208
r .activeGVKMode [gr ] = gvkMode {gvk , rsc .Mode }
@@ -599,6 +610,9 @@ func GVKFor(gr schema.GroupResource, allRes []*restmapper.APIGroupResources) (sc
599
610
for _ , version := range group .Versions {
600
611
for _ , resource := range groupedResources .VersionedResources [version .Version ] {
601
612
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
+ }
602
616
// Please note that we cannot use resource.group or resource.version
603
617
// here because they are preferred group/version and they are default
604
618
// to empty to imply this current containing group/version. Therefore,
@@ -613,5 +627,5 @@ func GVKFor(gr schema.GroupResource, allRes []*restmapper.APIGroupResources) (sc
613
627
}
614
628
}
615
629
}
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 )}
617
631
}
0 commit comments