Skip to content

Commit b286d70

Browse files
committed
Allow dynamic client to be set
This allows us to override the dynamic client, useful for tests or if we want to intercept and track all the calls (for automatic dependency tracking).
1 parent 6f37936 commit b286d70

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

pkg/patterns/declarative/pkg/applier/applylib.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,13 @@ func (a *ApplySetApplier) Apply(ctx context.Context, opt ApplierOptions) error {
5454

5555
patchOptions.Force = &opt.Force
5656

57-
dynamicClient, err := dynamic.NewForConfig(opt.RESTConfig)
58-
if err != nil {
59-
return fmt.Errorf("error building dynamic client: %w", err)
57+
dynamicClient := opt.DynamicClient
58+
if dynamicClient == nil {
59+
d, err := dynamic.NewForConfig(opt.RESTConfig)
60+
if err != nil {
61+
return fmt.Errorf("error building dynamic client: %w", err)
62+
}
63+
dynamicClient = d
6064
}
6165

6266
restMapper := opt.RESTMapper

pkg/patterns/declarative/pkg/applier/type.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"k8s.io/apimachinery/pkg/api/meta"
77
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
8+
"k8s.io/client-go/dynamic"
89
"k8s.io/client-go/rest"
910
"sigs.k8s.io/controller-runtime/pkg/client"
1011
"sigs.k8s.io/kubebuilder-declarative-pattern/applylib/applyset"
@@ -39,4 +40,8 @@ type ApplierOptions struct {
3940

4041
ParentRef applyset.Parent
4142
Client client.Client
43+
44+
// DynamicClient, if set, will be used for applying additional objects.
45+
// If not set, a dynamic client will be built from RESTConfig.
46+
DynamicClient dynamic.Interface
4247
}

0 commit comments

Comments
 (0)