@@ -21,57 +21,29 @@ import (
2121 "errors"
2222 "strings"
2323
24- "github.com/kcp-dev/init-agent/internal/kcp"
2524 "github.com/kcp-dev/init-agent/internal/log"
2625
27- "github.com/kcp-dev/logicalcluster/v3"
28-
2926 apierrors "k8s.io/apimachinery/pkg/api/errors"
3027 "k8s.io/apimachinery/pkg/api/meta"
3128 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
3229 ctrlruntimeclient "sigs.k8s.io/controller-runtime/pkg/client"
3330)
3431
35- type ClusterApplier interface {
36- Cluster (cluster logicalcluster.Name ) (Applier , error )
37- }
38-
3932type Applier interface {
40- Apply (ctx context.Context , objs []* unstructured.Unstructured ) (requeue bool , err error )
33+ Apply (ctx context.Context , client ctrlruntimeclient. Client , objs []* unstructured.Unstructured ) (requeue bool , err error )
4134}
4235
43- type clusterApplier struct {
44- cc kcp.ClusterClient
45- }
36+ type applier struct {}
4637
47- func NewClusterApplier (cc kcp.ClusterClient ) ClusterApplier {
48- return & clusterApplier {cc : cc }
49- }
50-
51- func (a * clusterApplier ) Cluster (cluster logicalcluster.Name ) (Applier , error ) {
52- client , err := a .cc .Cluster (cluster , nil ) // using unstructured, no scheme needed
53- if err != nil {
54- return nil , err
55- }
56-
57- return & applier {client : client }, nil
58- }
59-
60- type applier struct {
61- client ctrlruntimeclient.Client
62- }
63-
64- func NewApplier (client ctrlruntimeclient.Client ) Applier {
65- return & applier {
66- client : client ,
67- }
38+ func NewApplier () Applier {
39+ return & applier {}
6840}
6941
70- func (a * applier ) Apply (ctx context.Context , objs []* unstructured.Unstructured ) (requeue bool , err error ) {
42+ func (a * applier ) Apply (ctx context.Context , client ctrlruntimeclient. Client , objs []* unstructured.Unstructured ) (requeue bool , err error ) {
7143 SortObjectsByHierarchy (objs )
7244
7345 for _ , object := range objs {
74- err := a .applyObject (ctx , object )
46+ err := a .applyObject (ctx , client , object )
7547 if err != nil {
7648 if errors .Is (err , & meta.NoKindMatchError {}) {
7749 return true , nil
@@ -84,7 +56,7 @@ func (a *applier) Apply(ctx context.Context, objs []*unstructured.Unstructured)
8456 return false , nil
8557}
8658
87- func (a * applier ) applyObject (ctx context.Context , obj * unstructured.Unstructured ) error {
59+ func (a * applier ) applyObject (ctx context.Context , client ctrlruntimeclient. Client , obj * unstructured.Unstructured ) error {
8860 gvk := obj .GroupVersionKind ()
8961
9062 key := ctrlruntimeclient .ObjectKeyFromObject (obj ).String ()
@@ -94,7 +66,7 @@ func (a *applier) applyObject(ctx context.Context, obj *unstructured.Unstructure
9466 logger := log .FromContext (ctx )
9567 logger .Debugw ("Applying object" , "obj-key" , key , "obj-gvk" , gvk )
9668
97- if err := a . client .Create (ctx , obj ); err != nil {
69+ if err := client .Create (ctx , obj ); err != nil {
9870 if ! apierrors .IsAlreadyExists (err ) {
9971 return err
10072 }
0 commit comments