Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow dynamic client to be set #367

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -54,9 +54,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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason not to set opt.DynamicClient to d in this case? Could save us need to repeatedly generating dynamicClients during repeated reconciles.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question, I'll take a look! I don't think dynamic client caches any server-generated state, so it's "just memory", but I'll chekc!

}

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
}
Loading