Skip to content

Commit

Permalink
refactor obsolete plugin framework provider variables
Browse files Browse the repository at this point in the history
Signed-off-by: Erhan Cagirici <erhan@upbound.io>
  • Loading branch information
erhancagirici committed Jan 13, 2024
1 parent 3db611f commit 53763ea
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 14 deletions.
4 changes: 1 addition & 3 deletions pkg/config/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ func NewProvider(ctx context.Context, schema []byte, prefix string, modulePath s
}

p.skippedResourceNames = make([]string, 0, len(resourceMap))
terraformPluginFrameworkResourceFunctions := p.TerraformPluginFrameworkProvider.Resources(ctx)
for name, terraformResource := range resourceMap {
if len(terraformResource.Schema) == 0 {
// There are resources with no schema, that we will address later.
Expand Down Expand Up @@ -325,9 +326,6 @@ func NewProvider(ctx context.Context, schema []byte, prefix string, modulePath s
"but either config.Provider.TerraformProvider is not configured or the Go schema does not exist for the resource", name))
}

// TODO(cem): Consider creating a new context here, rather than getting one as input to this function.
// TODO(cem): Currently, terraformPluginFrameworkResourceFunctions is calculated for each plugin framework resource. Doing so is wasteful, because the result is independent of the resource. It should be called once, outside the loop.
terraformPluginFrameworkResourceFunctions := p.TerraformPluginFrameworkProvider.Resources(ctx)
for _, resourceFunc := range terraformPluginFrameworkResourceFunctions {
resource := resourceFunc()

Expand Down
4 changes: 1 addition & 3 deletions pkg/controller/external_async_terraform_plugin_framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/crossplane/crossplane-runtime/pkg/meta"
"github.com/crossplane/crossplane-runtime/pkg/reconciler/managed"
xpresource "github.com/crossplane/crossplane-runtime/pkg/resource"
"github.com/hashicorp/terraform-plugin-framework/provider"
"github.com/pkg/errors"
"sigs.k8s.io/controller-runtime/pkg/client"

Expand All @@ -35,10 +34,9 @@ func NewTerraformPluginFrameworkAsyncConnector(kube client.Client,
ots *OperationTrackerStore,
sf terraform.SetupFn,
cfg *config.Resource,
provider provider.Provider,
opts ...TerraformPluginFrameworkAsyncOption) *TerraformPluginFrameworkAsyncConnector {
nfac := &TerraformPluginFrameworkAsyncConnector{
TerraformPluginFrameworkConnector: NewTerraformPluginFrameworkConnector(kube, sf, cfg, ots, provider),
TerraformPluginFrameworkConnector: NewTerraformPluginFrameworkConnector(kube, sf, cfg, ots),
}
for _, f := range opts {
f(nfac)
Expand Down
11 changes: 5 additions & 6 deletions pkg/controller/external_terraform_plugin_framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,12 @@ func WithTerraformPluginFrameworkManagementPolicies(isManagementPoliciesEnabled
}
}

func NewTerraformPluginFrameworkConnector(kube client.Client, sf terraform.SetupFn, cfg *config.Resource, ots *OperationTrackerStore, terraformPluginFrameworkProvider fwprovider.Provider, opts ...TerraformPluginFrameworkConnectorOption) *TerraformPluginFrameworkConnector {
func NewTerraformPluginFrameworkConnector(kube client.Client, sf terraform.SetupFn, cfg *config.Resource, ots *OperationTrackerStore, opts ...TerraformPluginFrameworkConnectorOption) *TerraformPluginFrameworkConnector {
connector := &TerraformPluginFrameworkConnector{
getTerraformSetup: sf,
kube: kube,
config: cfg,
operationTrackerStore: ots,
terraformPluginFrameworkProvider: terraformPluginFrameworkProvider,
getTerraformSetup: sf,
kube: kube,
config: cfg,
operationTrackerStore: ots,
}
for _, f := range opts {
f(connector)
Expand Down
4 changes: 2 additions & 2 deletions pkg/pipeline/templates/controller.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func Setup(mgr ctrl.Manager, o tjcontroller.Options) error {
{{- end -}}
{{- else if .UseTerraformPluginFrameworkClient -}}
{{- if .UseAsync }}
tjcontroller.NewTerraformPluginFrameworkAsyncConnector(mgr.GetClient(), o.OperationTrackerStore, o.SetupFn, o.Provider.Resources["{{ .ResourceType }}"], o.Provider.TerraformPluginFrameworkProvider,
tjcontroller.NewTerraformPluginFrameworkAsyncConnector(mgr.GetClient(), o.OperationTrackerStore, o.SetupFn, o.Provider.Resources["{{ .ResourceType }}"],
tjcontroller.WithTerraformPluginFrameworkAsyncLogger(o.Logger),
tjcontroller.WithTerraformPluginFrameworkAsyncConnectorEventHandler(eventHandler),
tjcontroller.WithTerraformPluginFrameworkAsyncCallbackProvider(ac),
Expand All @@ -78,7 +78,7 @@ func Setup(mgr ctrl.Manager, o tjcontroller.Options) error {
{{- end -}}
)
{{- else }}
tjcontroller.NewTerraformPluginFrameworkConnector(mgr.GetClient(), o.SetupFn, o.Provider.Resources["{{ .ResourceType }}"], o.OperationTrackerStore, o.Provider.TerraformPluginFrameworkProvider,
tjcontroller.NewTerraformPluginFrameworkConnector(mgr.GetClient(), o.SetupFn, o.Provider.Resources["{{ .ResourceType }}"], o.OperationTrackerStore,
tjcontroller.WithTerraformPluginFrameworkLogger(o.Logger),
tjcontroller.WithTerraformPluginFrameworkMetricRecorder(metrics.NewMetricRecorder({{ .TypePackageAlias }}{{ .CRD.Kind }}_GroupVersionKind, mgr, o.PollInterval)),
{{if .FeaturesPackageAlias -}}
Expand Down

0 comments on commit 53763ea

Please sign in to comment.