Skip to content

Commit

Permalink
Merge pull request #367 from justinsb/allow_dynamic_client
Browse files Browse the repository at this point in the history
Allow dynamic client to be set
  • Loading branch information
k8s-ci-robot committed Jan 10, 2024
2 parents d0f7229 + b286d70 commit 8e6cf52
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pkg/patterns/declarative/pkg/applier/applylib.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,13 @@ func (a *ApplySetApplier) Apply(ctx context.Context, opt ApplierOptions) error {

patchOptions.Force = &opt.Force

dynamicClient, err := dynamic.NewForConfig(opt.RESTConfig)
if err != nil {
return fmt.Errorf("error building dynamic client: %w", err)
dynamicClient := opt.DynamicClient
if dynamicClient == nil {
d, err := dynamic.NewForConfig(opt.RESTConfig)
if err != nil {
return fmt.Errorf("error building dynamic client: %w", err)
}
dynamicClient = d
}

restMapper := opt.RESTMapper
Expand Down
5 changes: 5 additions & 0 deletions pkg/patterns/declarative/pkg/applier/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

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

ParentRef applyset.Parent
Client client.Client

// DynamicClient, if set, will be used for applying additional objects.
// If not set, a dynamic client will be built from RESTConfig.
DynamicClient dynamic.Interface
}

0 comments on commit 8e6cf52

Please sign in to comment.