@@ -146,6 +146,7 @@ func (r *Reconciler) ensureEnforcedTypes(inst *api.HNCConfiguration) error {
146
146
// to retry but only set conditions since the configuration may be incorrect.
147
147
func (r * Reconciler ) reconcileConfigTypes (inst * api.HNCConfiguration ) {
148
148
// Get valid settings in the spec.resources of the `config` singleton.
149
+ gvkChecker := newGVKChecker (r .resourceMapper )
149
150
for _ , rsc := range inst .Spec .Resources {
150
151
gr := schema.GroupResource {Group : rsc .Group , Resource : rsc .Resource }
151
152
// Look if the resource exists in the API server.
@@ -164,7 +165,7 @@ func (r *Reconciler) reconcileConfigTypes(inst *api.HNCConfiguration) {
164
165
log := r .Log .WithValues ("resource" , gr , "appliedMode" , rsc .Mode )
165
166
msg := ""
166
167
// Set a different message if the type is enforced by HNC.
167
- if api . IsEnforcedType ( rsc ) {
168
+ if gvkChecker . isEnforced ( gvk ) {
168
169
msg = fmt .Sprintf ("The sync mode for %q is enforced by HNC as %q and cannot be overridden" , gr , api .Propagate )
169
170
log .Info ("The sync mode for this resource is enforced by HNC and cannot be overridden" )
170
171
} else {
@@ -541,3 +542,32 @@ func reasonForGVKError(err error) string {
541
542
}
542
543
return reason
543
544
}
545
+
546
+ // gvkChecker checks if a GVK is an enforced type.
547
+ // It is needed to check duplicated types in ResourceSpec using GVK instead of GR,
548
+ // since the user-given GRs might include some ambiguity.
549
+ // (e.g. singular/plural, empty group is handled as corev1).
550
+ type gvkChecker struct {
551
+ enforcedGVKs []schema.GroupVersionKind
552
+ }
553
+
554
+ func newGVKChecker (mapper resourceMapper ) * gvkChecker {
555
+ var enforcedGVKs []schema.GroupVersionKind
556
+ for _ , enforcedType := range api .EnforcedTypes {
557
+ enforcedGVK , _ := mapper .NamespacedKindFor (schema.GroupResource {
558
+ Group : enforcedType .Group ,
559
+ Resource : enforcedType .Resource ,
560
+ })
561
+ enforcedGVKs = append (enforcedGVKs , enforcedGVK )
562
+ }
563
+ return & gvkChecker {enforcedGVKs }
564
+ }
565
+
566
+ func (c * gvkChecker ) isEnforced (gvk schema.GroupVersionKind ) bool {
567
+ for _ , enforcedGVK := range c .enforcedGVKs {
568
+ if gvk == enforcedGVK {
569
+ return true
570
+ }
571
+ }
572
+ return false
573
+ }
0 commit comments