controller

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 25, 2024 License: Apache-2.0 Imports: 53 Imported by: 373

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Base64DecodeFunc = function.New(&function.Spec{
	Params: []function.Parameter{
		{
			Name:        "str",
			Type:        cty.String,
			AllowMarked: true,
		},
	},
	Type: function.StaticReturnType(cty.String),
	Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
		str, strMarks := args[0].Unmark()
		s := str.AsString()
		sDec, err := base64.StdEncoding.DecodeString(s)
		if err != nil {
			return cty.UnknownVal(cty.String), fmt.Errorf("failed to decode base64 data %s", s)
		}
		if !utf8.Valid(sDec) {
			log.Printf("[DEBUG] the result of decoding the provided string is not valid UTF-8: %s", s)
			return cty.UnknownVal(cty.String), fmt.Errorf("the result of decoding the provided string is not valid UTF-8")
		}
		return cty.StringVal(string(sDec)).WithMarks(strMarks), nil
	},
})
View Source
var Base64EncodeFunc = function.New(&function.Spec{
	Params: []function.Parameter{
		{
			Name: "str",
			Type: cty.String,
		},
	},
	Type: function.StaticReturnType(cty.String),
	Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
		return cty.StringVal(base64.StdEncoding.EncodeToString([]byte(args[0].AsString()))), nil
	},
})

Functions

This section is empty.

Types

type APICallbacks

type APICallbacks struct {
	// contains filtered or unexported fields
}

APICallbacks providers callbacks that work on API resources.

func NewAPICallbacks

func NewAPICallbacks(m ctrl.Manager, of xpresource.ManagedKind, opts ...APICallbacksOption) *APICallbacks

NewAPICallbacks returns a new APICallbacks.

func (*APICallbacks) Create

func (ac *APICallbacks) Create(name string) terraform.CallbackFn

Create makes sure the error is saved in async operation condition.

func (*APICallbacks) Destroy

func (ac *APICallbacks) Destroy(name string) terraform.CallbackFn

Destroy makes sure the error is saved in async operation condition.

func (*APICallbacks) Update

func (ac *APICallbacks) Update(name string) terraform.CallbackFn

Update makes sure the error is saved in async operation condition.

type APICallbacksOption

type APICallbacksOption func(callbacks *APICallbacks)

APICallbacksOption represents a configurable option for the APICallbacks

func WithEventHandler

func WithEventHandler(e *handler.EventHandler) APICallbacksOption

WithEventHandler sets the EventHandler for the APICallbacks so that the APICallbacks instance can requeue reconcile requests in the context of the asynchronous operations.

func WithStatusUpdates

func WithStatusUpdates(enabled bool) APICallbacksOption

WithStatusUpdates sets whether the LastAsyncOperation status condition is enabled. If set to false, APICallbacks will not use the LastAsyncOperation status condition for reporting ongoing async operations or errors. Error conditions will still be reported as usual in the `Synced` status condition.

type APISecretClient

type APISecretClient struct {
	// contains filtered or unexported fields
}

APISecretClient is a client for getting k8s secrets

func (*APISecretClient) GetSecretData

func (a *APISecretClient) GetSecretData(ctx context.Context, ref *xpv1.SecretReference) (map[string][]byte, error)

GetSecretData gets and returns data for the referenced secret

func (*APISecretClient) GetSecretValue

func (a *APISecretClient) GetSecretValue(ctx context.Context, sel xpv1.SecretKeySelector) ([]byte, error)

GetSecretValue gets and returns value for key of the referenced secret

type AsyncTracker

type AsyncTracker struct {
	// LastOperation holds information about the most recent operation.
	// Consumers are responsible for managing the last operation by starting,
	// ending and flushing it when done with processing the results.
	// Designed to allow only one ongoing operation at a given time.
	LastOperation *terraform.Operation
	// contains filtered or unexported fields
}

AsyncTracker holds information for a managed resource to track the async Terraform operations and the Terraform state (TF SDKv2 or TF Plugin Framework) of the external resource

The typical usage is to instantiate an AsyncTracker for a managed resource, and store in a global OperationTrackerStore, to carry information between reconciliation scopes.

When an asynchronous Terraform operation is started for the resource in a reconciliation (e.g. with a goroutine), consumers can mark an operation start on the LastOperation field, then access the operation status in the forthcoming reconciliation cycles, and act upon (e.g. hold further actions if there is an ongoing operation, mark the end when underlying Terraform operation is completed, save the resulting terraform state etc.)

When utilized without the LastOperation usage, it can act as a Terraform state cache for synchronous reconciliations

func NewAsyncTracker

func NewAsyncTracker(opts ...AsyncTrackerOption) *AsyncTracker

NewAsyncTracker initializes an AsyncTracker with given options

func (*AsyncTracker) GetFrameworkTFState added in v1.1.0

func (a *AsyncTracker) GetFrameworkTFState() *tfprotov5.DynamicValue

GetFrameworkTFState returns the stored Terraform Plugin Framework external resource state in this AsyncTracker as *tfprotov5.DynamicValue MUST be used only for Terraform Plugin Framework resources

func (*AsyncTracker) GetTfID

func (a *AsyncTracker) GetTfID() string

GetTfID returns the Terraform ID of the external resource currently stored in this AsyncTracker's SDKv2 instance state. MUST be only used for SDKv2 resources.

func (*AsyncTracker) GetTfState

func (a *AsyncTracker) GetTfState() *tfsdk.InstanceState

GetTfState returns the stored Terraform Plugin SDKv2 InstanceState for SDKv2 Terraform resources MUST be only used for SDKv2 resources.

func (*AsyncTracker) HasFrameworkTFState added in v1.1.0

func (a *AsyncTracker) HasFrameworkTFState() bool

HasFrameworkTFState returns whether this AsyncTracker has a Terraform Plugin Framework state stored. MUST be used only for Terraform Plugin Framework resources

func (*AsyncTracker) HasState

func (a *AsyncTracker) HasState() bool

HasState returns whether the AsyncTracker has a SDKv2 state stored. MUST be only used for SDKv2 resources.

func (*AsyncTracker) IsDeleted

func (a *AsyncTracker) IsDeleted() bool

IsDeleted returns whether the associated external resource has logically been deleted.

func (*AsyncTracker) SetDeleted

func (a *AsyncTracker) SetDeleted(deleted bool)

SetDeleted sets the logical deletion status of the associated external resource.

func (*AsyncTracker) SetFrameworkTFState added in v1.1.0

func (a *AsyncTracker) SetFrameworkTFState(state *tfprotov5.DynamicValue)

SetFrameworkTFState stores the given *tfprotov5.DynamicValue Terraform Plugin Framework external resource state into this AsyncTracker's fwstate MUST be used only for Terraform Plugin Framework resources

func (*AsyncTracker) SetTfState

func (a *AsyncTracker) SetTfState(state *tfsdk.InstanceState)

SetTfState stores the given SDKv2 Terraform InstanceState into the AsyncTracker MUST be only used for SDKv2 resources.

type AsyncTrackerOption

type AsyncTrackerOption func(manager *AsyncTracker)

func WithAsyncTrackerLogger

func WithAsyncTrackerLogger(l logging.Logger) AsyncTrackerOption

WithAsyncTrackerLogger sets the logger of AsyncTracker.

type CallbackFn

type CallbackFn func(error, context.Context) error

type CallbackProvider

type CallbackProvider interface {
	Create(name string) terraform.CallbackFn
	Update(name string) terraform.CallbackFn
	Destroy(name string) terraform.CallbackFn
}

CallbackProvider provides functions that can be called with the result of async operations.

type Connector

type Connector struct {
	// contains filtered or unexported fields
}

Connector initializes the external client with credentials and other configuration parameters.

func NewConnector

func NewConnector(kube client.Client, ws Store, sf terraform.SetupFn, cfg *config.Resource, opts ...Option) *Connector

NewConnector returns a new Connector object.

func (*Connector) Connect

Connect makes sure the underlying client is ready to issue requests to the provider API.

type ESSOptions

type ESSOptions struct {
	TLSConfig     *tls.Config
	TLSSecretName *string
}

ESSOptions for External Secret Stores.

type OperationTrackerFinalizer added in v1.1.0

type OperationTrackerFinalizer struct {
	xpresource.Finalizer
	OperationStore TrackerCleaner
}

OperationTrackerFinalizer removes the operation tracker from the workspace store and only then calls RemoveFinalizer of the underlying Finalizer.

func NewOperationTrackerFinalizer added in v1.1.0

func NewOperationTrackerFinalizer(tc TrackerCleaner, af xpresource.Finalizer) *OperationTrackerFinalizer

NewOperationTrackerFinalizer returns a new OperationTrackerFinalizer.

func (*OperationTrackerFinalizer) AddFinalizer added in v1.1.0

func (nf *OperationTrackerFinalizer) AddFinalizer(ctx context.Context, obj xpresource.Object) error

AddFinalizer to the supplied Managed resource.

func (*OperationTrackerFinalizer) RemoveFinalizer added in v1.1.0

func (nf *OperationTrackerFinalizer) RemoveFinalizer(ctx context.Context, obj xpresource.Object) error

RemoveFinalizer removes the workspace from workspace store before removing the finalizer.

type OperationTrackerStore

type OperationTrackerStore struct {
	// contains filtered or unexported fields
}

OperationTrackerStore stores the AsyncTracker instances associated with the managed resource instance.

func NewOperationStore

func NewOperationStore(l logging.Logger) *OperationTrackerStore

NewOperationStore returns a new OperationTrackerStore instance

func (*OperationTrackerStore) RemoveTracker

func (ops *OperationTrackerStore) RemoveTracker(obj xpresource.Object) error

RemoveTracker will remove the stored AsyncTracker of the given managed resource from this OperationTrackerStore.

func (*OperationTrackerStore) Tracker

Tracker returns the associated *AsyncTracker stored in this OperationTrackerStore for the given managed resource. If there is no tracker stored previously, a new AsyncTracker is created and stored for the specified managed resource. Subsequent calls with the same managed resource will return the previously instantiated and stored AsyncTracker for that managed resource

type Option

type Option func(*Connector)

Option allows you to configure Connector.

func WithCallbackProvider

func WithCallbackProvider(ac CallbackProvider) Option

WithCallbackProvider configures the controller to use async variant of the functions of the Terraform client and run given callbacks once those operations are completed.

func WithConnectorEventHandler

func WithConnectorEventHandler(e *handler.EventHandler) Option

WithConnectorEventHandler configures the EventHandler so that the external clients can requeue reconciliation requests.

func WithLogger

func WithLogger(l logging.Logger) Option

WithLogger configures a logger for the Connector.

type Options

type Options struct {
	controller.Options

	// Provider contains all resource configurations of the provider which can
	// be used to pick the related one. Since the selection is done in runtime,
	// we need to pass everything and generated code will pick the one.
	Provider *config.Provider

	// WorkspaceStore will be used to pick/initialize the workspace the specific CR
	// instance should use.
	WorkspaceStore *terraform.WorkspaceStore

	OperationTrackerStore *OperationTrackerStore

	// SetupFn contains the provider-specific initialization logic, such as
	// preparing the auth token for Terraform CLI.
	SetupFn terraform.SetupFn

	// SecretStoreConfigGVK is the GroupVersionKind for the Secret StoreConfig
	// resource. Setting this enables External Secret Stores for the controller
	// by adding connection.DetailsManager as a ConnectionPublisher.
	SecretStoreConfigGVK *schema.GroupVersionKind

	// ESSOptions for External Secret Stores.
	ESSOptions *ESSOptions

	// PollJitter adds the specified jitter to the configured reconcile period
	// of the up-to-date resources in managed.Reconciler.
	PollJitter time.Duration

	// StartWebhooks enables starting of the conversion webhooks by the
	// provider's controllerruntime.Manager.
	StartWebhooks bool
}

Options contains incriminating options for a given Upjet controller instance.

type ProviderSharer

type ProviderSharer interface {
	UseProvider(inuse terraform.InUse, attachmentConfig string)
}

ProviderSharer shares a native provider process with the receiver.

type Resource

type Resource interface {
	Apply(ctx context.Context, s *tf.InstanceState, d *tf.InstanceDiff, meta interface{}) (*tf.InstanceState, tfdiag.Diagnostics)
	RefreshWithoutUpgrade(ctx context.Context, s *tf.InstanceState, meta interface{}) (*tf.InstanceState, tfdiag.Diagnostics)
}

type Store

type Store interface {
	Workspace(ctx context.Context, c resource.SecretClient, tr resource.Terraformed, ts terraform.Setup, cfg *config.Resource) (*terraform.Workspace, error)
}

Store is where we can get access to the Terraform workspace of given resource.

type TerraformPluginFrameworkAsyncConnector added in v1.1.0

type TerraformPluginFrameworkAsyncConnector struct {
	*TerraformPluginFrameworkConnector
	// contains filtered or unexported fields
}

TerraformPluginFrameworkAsyncConnector is a managed reconciler Connecter implementation for reconciling Terraform plugin framework based resources.

func (*TerraformPluginFrameworkAsyncConnector) Connect added in v1.1.0

type TerraformPluginFrameworkAsyncOption added in v1.1.0

type TerraformPluginFrameworkAsyncOption func(connector *TerraformPluginFrameworkAsyncConnector)

TerraformPluginFrameworkAsyncOption represents a configuration option for a TerraformPluginFrameworkAsyncConnector object.

func WithTerraformPluginFrameworkAsyncCallbackProvider added in v1.1.0

func WithTerraformPluginFrameworkAsyncCallbackProvider(ac CallbackProvider) TerraformPluginFrameworkAsyncOption

WithTerraformPluginFrameworkAsyncCallbackProvider configures the controller to use async variant of the functions of the Terraform client and run given callbacks once those operations are completed.

func WithTerraformPluginFrameworkAsyncConnectorEventHandler added in v1.1.0

func WithTerraformPluginFrameworkAsyncConnectorEventHandler(e *handler.EventHandler) TerraformPluginFrameworkAsyncOption

WithTerraformPluginFrameworkAsyncConnectorEventHandler configures the EventHandler so that the Terraform Plugin Framework external clients can requeue reconciliation requests.

func WithTerraformPluginFrameworkAsyncLogger added in v1.1.0

func WithTerraformPluginFrameworkAsyncLogger(l logging.Logger) TerraformPluginFrameworkAsyncOption

WithTerraformPluginFrameworkAsyncLogger configures a logger for the TerraformPluginFrameworkAsyncConnector.

func WithTerraformPluginFrameworkAsyncManagementPolicies added in v1.1.0

func WithTerraformPluginFrameworkAsyncManagementPolicies(isManagementPoliciesEnabled bool) TerraformPluginFrameworkAsyncOption

WithTerraformPluginFrameworkAsyncManagementPolicies configures whether the client should handle management policies.

func WithTerraformPluginFrameworkAsyncMetricRecorder added in v1.1.0

func WithTerraformPluginFrameworkAsyncMetricRecorder(r *metrics.MetricRecorder) TerraformPluginFrameworkAsyncOption

WithTerraformPluginFrameworkAsyncMetricRecorder configures a metrics.MetricRecorder for the TerraformPluginFrameworkAsyncConnector.

type TerraformPluginFrameworkConnector added in v1.1.0

type TerraformPluginFrameworkConnector struct {
	// contains filtered or unexported fields
}

TerraformPluginFrameworkConnector is an external client, with credentials and other configuration parameters, for Terraform Plugin Framework resources. You can use NewTerraformPluginFrameworkConnector to construct.

func NewTerraformPluginFrameworkConnector added in v1.1.0

NewTerraformPluginFrameworkConnector creates a new TerraformPluginFrameworkConnector with given options.

func (*TerraformPluginFrameworkConnector) Connect added in v1.1.0

Connect makes sure the underlying client is ready to issue requests to the provider API.

type TerraformPluginFrameworkConnectorOption added in v1.1.0

type TerraformPluginFrameworkConnectorOption func(connector *TerraformPluginFrameworkConnector)

TerraformPluginFrameworkConnectorOption allows you to configure TerraformPluginFrameworkConnector.

func WithTerraformPluginFrameworkLogger added in v1.1.0

func WithTerraformPluginFrameworkLogger(l logging.Logger) TerraformPluginFrameworkConnectorOption

WithTerraformPluginFrameworkLogger configures a logger for the TerraformPluginFrameworkConnector.

func WithTerraformPluginFrameworkManagementPolicies added in v1.1.0

func WithTerraformPluginFrameworkManagementPolicies(isManagementPoliciesEnabled bool) TerraformPluginFrameworkConnectorOption

WithTerraformPluginFrameworkManagementPolicies configures whether the client should handle management policies.

func WithTerraformPluginFrameworkMetricRecorder added in v1.1.0

func WithTerraformPluginFrameworkMetricRecorder(r *metrics.MetricRecorder) TerraformPluginFrameworkConnectorOption

WithTerraformPluginFrameworkMetricRecorder configures a metrics.MetricRecorder for the TerraformPluginFrameworkConnectorOption.

type TerraformPluginSDKAsyncConnector added in v1.1.0

type TerraformPluginSDKAsyncConnector struct {
	*TerraformPluginSDKConnector
	// contains filtered or unexported fields
}

TerraformPluginSDKAsyncConnector is a managed reconciler Connecter implementation for reconciling Terraform plugin SDK v2 based resources.

func NewTerraformPluginSDKAsyncConnector added in v1.1.0

func NewTerraformPluginSDKAsyncConnector(kube client.Client, ots *OperationTrackerStore, sf terraform.SetupFn, cfg *config.Resource, opts ...TerraformPluginSDKAsyncOption) *TerraformPluginSDKAsyncConnector

NewTerraformPluginSDKAsyncConnector initializes a new TerraformPluginSDKAsyncConnector.

func (*TerraformPluginSDKAsyncConnector) Connect added in v1.1.0

type TerraformPluginSDKAsyncOption added in v1.1.0

type TerraformPluginSDKAsyncOption func(connector *TerraformPluginSDKAsyncConnector)

TerraformPluginSDKAsyncOption represents a configuration option for a TerraformPluginSDKAsyncConnector object.

func WithTerraformPluginSDKAsyncCallbackProvider added in v1.1.0

func WithTerraformPluginSDKAsyncCallbackProvider(ac CallbackProvider) TerraformPluginSDKAsyncOption

WithTerraformPluginSDKAsyncCallbackProvider configures the controller to use async variant of the functions of the Terraform client and run given callbacks once those operations are completed.

func WithTerraformPluginSDKAsyncConnectorEventHandler added in v1.1.0

func WithTerraformPluginSDKAsyncConnectorEventHandler(e *handler.EventHandler) TerraformPluginSDKAsyncOption

WithTerraformPluginSDKAsyncConnectorEventHandler configures the EventHandler so that the Terraform plugin SDK external clients can requeue reconciliation requests.

func WithTerraformPluginSDKAsyncLogger added in v1.1.0

func WithTerraformPluginSDKAsyncLogger(l logging.Logger) TerraformPluginSDKAsyncOption

WithTerraformPluginSDKAsyncLogger configures a logger for the TerraformPluginSDKAsyncConnector.

func WithTerraformPluginSDKAsyncManagementPolicies added in v1.1.0

func WithTerraformPluginSDKAsyncManagementPolicies(isManagementPoliciesEnabled bool) TerraformPluginSDKAsyncOption

WithTerraformPluginSDKAsyncManagementPolicies configures whether the client should handle management policies.

func WithTerraformPluginSDKAsyncMetricRecorder added in v1.1.0

func WithTerraformPluginSDKAsyncMetricRecorder(r *metrics.MetricRecorder) TerraformPluginSDKAsyncOption

WithTerraformPluginSDKAsyncMetricRecorder configures a metrics.MetricRecorder for the TerraformPluginSDKAsyncConnector.

type TerraformPluginSDKConnector added in v1.1.0

type TerraformPluginSDKConnector struct {
	// contains filtered or unexported fields
}

func NewTerraformPluginSDKConnector added in v1.1.0

func NewTerraformPluginSDKConnector(kube client.Client, sf terraform.SetupFn, cfg *config.Resource, ots *OperationTrackerStore, opts ...TerraformPluginSDKOption) *TerraformPluginSDKConnector

NewTerraformPluginSDKConnector initializes a new TerraformPluginSDKConnector

func (*TerraformPluginSDKConnector) Connect added in v1.1.0

type TerraformPluginSDKOption added in v1.1.0

type TerraformPluginSDKOption func(connector *TerraformPluginSDKConnector)

TerraformPluginSDKOption allows you to configure TerraformPluginSDKConnector.

func WithTerraformPluginSDKLogger added in v1.1.0

func WithTerraformPluginSDKLogger(l logging.Logger) TerraformPluginSDKOption

WithTerraformPluginSDKLogger configures a logger for the TerraformPluginSDKConnector.

func WithTerraformPluginSDKManagementPolicies added in v1.1.0

func WithTerraformPluginSDKManagementPolicies(isManagementPoliciesEnabled bool) TerraformPluginSDKOption

WithTerraformPluginSDKManagementPolicies configures whether the client should handle management policies.

func WithTerraformPluginSDKMetricRecorder added in v1.1.0

func WithTerraformPluginSDKMetricRecorder(r *metrics.MetricRecorder) TerraformPluginSDKOption

WithTerraformPluginSDKMetricRecorder configures a metrics.MetricRecorder for the TerraformPluginSDKConnector.

type TrackerCleaner

type TrackerCleaner interface {
	RemoveTracker(obj xpresource.Object) error
}

TrackerCleaner is the interface for the common finalizer of both Terraform plugin SDK and framework managed resources.

type Workspace

Workspace is the set of methods that are needed for the controller to work.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL