Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract GVK more robustly when building applyset parent #368

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/patterns/declarative/pkg/applier/applylib.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/dynamic"
"k8s.io/klog/v2"
"sigs.k8s.io/kubebuilder-declarative-pattern/applylib/applyset"
Expand Down Expand Up @@ -125,8 +126,7 @@ func (a *ApplySetApplier) Apply(ctx context.Context, opt ApplierOptions) error {
}

// NewParentRef maps a declarative object's information to the ParentRef defined in the applyset library.
func NewParentRef(restMapper meta.RESTMapper, object runtime.Object, name, namespace string) (applyset.Parent, error) {
gvk := object.GetObjectKind().GroupVersionKind()
func NewParentRef(restMapper meta.RESTMapper, object runtime.Object, gvk schema.GroupVersionKind, name, namespace string) (applyset.Parent, error) {
restMapping, err := restMapper.RESTMapping(gvk.GroupKind(), gvk.Version)
if err != nil {
return nil, err
Expand Down
8 changes: 6 additions & 2 deletions pkg/patterns/declarative/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,13 @@ func (r *Reconciler) reconcileExists(ctx context.Context, name types.NamespacedN
}
}

parentRef, err := applier.NewParentRef(r.restMapper, instance, instance.GetName(), instance.GetNamespace())
gvk, err := apiutil.GVKForObject(instance, r.mgr.GetScheme())
if err != nil {
return statusInfo, err
return statusInfo, fmt.Errorf("getting GVK for %T: %w", instance, err)
}
parentRef, err := applier.NewParentRef(r.restMapper, instance, gvk, instance.GetName(), instance.GetNamespace())
if err != nil {
return statusInfo, fmt.Errorf("building applyset parent: %w", err)
}
applierOpt := applier.ApplierOptions{
RESTConfig: r.config,
Expand Down
Loading