Skip to content

Commit d0f7229

Browse files
authored
Merge pull request #368 from justinsb/extract_gvk_more_robustly
Extract GVK more robustly when building applyset parent
2 parents 6f37936 + 94acf17 commit d0f7229

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

pkg/patterns/declarative/pkg/applier/applylib.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"k8s.io/apimachinery/pkg/api/meta"
99
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1010
"k8s.io/apimachinery/pkg/runtime"
11+
"k8s.io/apimachinery/pkg/runtime/schema"
1112
"k8s.io/client-go/dynamic"
1213
"k8s.io/klog/v2"
1314
"sigs.k8s.io/kubebuilder-declarative-pattern/applylib/applyset"
@@ -125,8 +126,7 @@ func (a *ApplySetApplier) Apply(ctx context.Context, opt ApplierOptions) error {
125126
}
126127

127128
// NewParentRef maps a declarative object's information to the ParentRef defined in the applyset library.
128-
func NewParentRef(restMapper meta.RESTMapper, object runtime.Object, name, namespace string) (applyset.Parent, error) {
129-
gvk := object.GetObjectKind().GroupVersionKind()
129+
func NewParentRef(restMapper meta.RESTMapper, object runtime.Object, gvk schema.GroupVersionKind, name, namespace string) (applyset.Parent, error) {
130130
restMapping, err := restMapper.RESTMapping(gvk.GroupKind(), gvk.Version)
131131
if err != nil {
132132
return nil, err

pkg/patterns/declarative/reconciler.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,9 +370,13 @@ func (r *Reconciler) reconcileExists(ctx context.Context, name types.NamespacedN
370370
}
371371
}
372372

373-
parentRef, err := applier.NewParentRef(r.restMapper, instance, instance.GetName(), instance.GetNamespace())
373+
gvk, err := apiutil.GVKForObject(instance, r.mgr.GetScheme())
374374
if err != nil {
375-
return statusInfo, err
375+
return statusInfo, fmt.Errorf("getting GVK for %T: %w", instance, err)
376+
}
377+
parentRef, err := applier.NewParentRef(r.restMapper, instance, gvk, instance.GetName(), instance.GetNamespace())
378+
if err != nil {
379+
return statusInfo, fmt.Errorf("building applyset parent: %w", err)
376380
}
377381
applierOpt := applier.ApplierOptions{
378382
RESTConfig: r.config,

0 commit comments

Comments
 (0)