Skip to content

Commit

Permalink
Merge pull request #370 from justinsb/automated-cherry-pick-of-#368-r…
Browse files Browse the repository at this point in the history
…elease-0.15

Automated cherry pick of #368: Extract GVK more robustly when building applyset parent
  • Loading branch information
k8s-ci-robot committed Jan 12, 2024
2 parents aae728e + 7879245 commit fb5a6a4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
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

0 comments on commit fb5a6a4

Please sign in to comment.