@@ -20,6 +20,7 @@ import (
20
20
"context"
21
21
"errors"
22
22
"fmt"
23
+ "net/http"
23
24
"path/filepath"
24
25
"reflect"
25
26
"strings"
@@ -41,6 +42,7 @@ import (
41
42
"sigs.k8s.io/controller-runtime/pkg/reconcile"
42
43
"sigs.k8s.io/kustomize/kyaml/filesys"
43
44
45
+ "sigs.k8s.io/kubebuilder-declarative-pattern/commonclient"
44
46
"sigs.k8s.io/kubebuilder-declarative-pattern/pkg/patterns/addon/pkg/utils"
45
47
"sigs.k8s.io/kubebuilder-declarative-pattern/pkg/patterns/declarative/kustomize"
46
48
"sigs.k8s.io/kubebuilder-declarative-pattern/pkg/patterns/declarative/pkg/applier"
@@ -51,18 +53,20 @@ var _ reconcile.Reconciler = &Reconciler{}
51
53
52
54
type Reconciler struct {
53
55
prototype DeclarativeObject
54
- client client.Client
55
- config * rest.Config
56
+
57
+ client client.Client
58
+ restConfig * rest.Config
59
+ httpClient * http.Client
60
+ dynamicClient dynamic.Interface
61
+ restMapper meta.RESTMapper
56
62
57
63
metrics reconcileMetrics
58
64
mgr manager.Manager
59
65
60
66
// recorder is the EventRecorder for creating k8s events
61
- recorder recorder.EventRecorder
62
- dynamicClient dynamic.Interface
67
+ recorder recorder.EventRecorder
63
68
64
- restMapper meta.RESTMapper
65
- options reconcilerParams
69
+ options reconcilerParams
66
70
}
67
71
68
72
type DeclarativeObject interface {
@@ -105,11 +109,17 @@ func (r *Reconciler) Init(mgr manager.Manager, prototype DeclarativeObject, opts
105
109
r .recorder = mgr .GetEventRecorderFor (controllerName )
106
110
107
111
r .client = mgr .GetClient ()
108
- r .config = mgr .GetConfig ()
112
+ r .restConfig = mgr .GetConfig ()
113
+ httpClient , err := commonclient .GetHTTPClient (mgr )
114
+ if err != nil {
115
+ return fmt .Errorf ("getting HTTP client: %w" , err )
116
+ }
117
+ r .httpClient = httpClient
118
+
109
119
r .mgr = mgr
110
120
globalObjectTracker .mgr = mgr
111
121
112
- d , err := dynamic .NewForConfig (r .config )
122
+ d , err := dynamic .NewForConfigAndClient (r .restConfig , r . httpClient )
113
123
if err != nil {
114
124
return err
115
125
}
@@ -379,7 +389,7 @@ func (r *Reconciler) reconcileExists(ctx context.Context, name types.NamespacedN
379
389
return statusInfo , fmt .Errorf ("building applyset parent: %w" , err )
380
390
}
381
391
applierOpt := applier.ApplierOptions {
382
- RESTConfig : r .config ,
392
+ RESTConfig : r .restConfig ,
383
393
RESTMapper : r .restMapper ,
384
394
Namespace : ns ,
385
395
ParentRef : parentRef ,
@@ -389,6 +399,7 @@ func (r *Reconciler) reconcileExists(ctx context.Context, name types.NamespacedN
389
399
Force : true ,
390
400
CascadingStrategy : r .options .cascadingStrategy ,
391
401
Client : r .client ,
402
+ DynamicClient : r .dynamicClient ,
392
403
}
393
404
394
405
applyOperation := & ApplyOperation {
0 commit comments