Skip to content

Commit 8e6cf52

Browse files
authored
Merge pull request #367 from justinsb/allow_dynamic_client
Allow dynamic client to be set
2 parents d0f7229 + b286d70 commit 8e6cf52

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
@@ -55,9 +55,13 @@ func (a *ApplySetApplier) Apply(ctx context.Context, opt ApplierOptions) error {
5555

5656
patchOptions.Force = &opt.Force
5757

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

6367
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)