Skip to content

Commit

Permalink
refactor: Use IsGVKNamespaced instead of plain RESTMapper
Browse files Browse the repository at this point in the history
  • Loading branch information
codablock committed Jul 19, 2024
1 parent fa84cf9 commit 1564170
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions controllers/objecttemplate_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/log"
Expand Down Expand Up @@ -234,11 +235,11 @@ func (r *ObjectTemplateReconciler) doReconcile(ctx context.Context, rt *template
}

for _, x := range allResources {
rm, err := r.Client.RESTMapper().RESTMapping(x.GroupVersionKind().GroupKind(), x.GroupVersionKind().Version)
isNs, err := apiutil.IsGVKNamespaced(x.GroupVersionKind(), objClient.RESTMapper())
if err != nil {
return err
}
if rm.Scope.Name() == apimeta.RESTScopeNameNamespace && x.GetNamespace() == "" {
if isNs && x.GetNamespace() == "" {
x.SetNamespace(rt.Namespace)
}
}
Expand Down

0 comments on commit 1564170

Please sign in to comment.