From afae24de0d72d16f8603cd1f71df600e1f99c62f Mon Sep 17 00:00:00 2001 From: Bartosz Majsak Date: Wed, 21 Aug 2024 12:17:31 +0200 Subject: [PATCH] refactor: moves unstruct funcs to its own pkg (#60) Operations on unstructured k8s objects should be kept in its own pkg for better code organization. We use this struct to dynamically handle watched CRs as we do not want to import types of every component for which we provide platform capabilites. Often such types might not exist as as a dedicated client-go library with generated stubs. This change creates new `pkg/unstruct` where we should start organizing helper functions. --- controllers/routing/routing_reconcile_resources.go | 3 ++- pkg/{cluster/unstruct.go => unstruct/funcs.go} | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) rename pkg/{cluster/unstruct.go => unstruct/funcs.go} (99%) diff --git a/controllers/routing/routing_reconcile_resources.go b/controllers/routing/routing_reconcile_resources.go index e46451c..938a7db 100644 --- a/controllers/routing/routing_reconcile_resources.go +++ b/controllers/routing/routing_reconcile_resources.go @@ -11,6 +11,7 @@ import ( "github.com/opendatahub-io/odh-platform/pkg/metadata/annotations" "github.com/opendatahub-io/odh-platform/pkg/metadata/labels" "github.com/opendatahub-io/odh-platform/pkg/spi" + "github.com/opendatahub-io/odh-platform/pkg/unstruct" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "sigs.k8s.io/controller-runtime/pkg/client" @@ -78,7 +79,7 @@ func (r *PlatformRoutingController) exportService(ctx context.Context, target *u return fmt.Errorf("could not load templates for type %s: %w", exportMode, err) } - if errApply := cluster.Apply(ctx, r.Client, resources, ownershipLabels...); errApply != nil { + if errApply := unstruct.Apply(ctx, r.Client, resources, ownershipLabels...); errApply != nil { return fmt.Errorf("could not apply routing resources for type %s: %w", exportMode, errApply) } } diff --git a/pkg/cluster/unstruct.go b/pkg/unstruct/funcs.go similarity index 99% rename from pkg/cluster/unstruct.go rename to pkg/unstruct/funcs.go index 201a53f..b49c656 100644 --- a/pkg/cluster/unstruct.go +++ b/pkg/unstruct/funcs.go @@ -1,4 +1,4 @@ -package cluster +package unstruct import ( "context"