processors

package
v0.26.5 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2023 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Overview

processors contains the shared logic and interfaces for implementing a resource processor.

Resource processors are responsible for processing the results of recipe execution or any other change to the lifecycle of a portable resource.

For example a mongo processor might take the results of executing a recipe and compute and store the connection string as part of the resource data model.

Package processors is a generated GoMock package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetOutputResourcesFromRecipe

func GetOutputResourcesFromRecipe(output *recipes.RecipeOutput) ([]rpv1.OutputResource, error)

GetOutputResourcesFromRecipe parses the output resources from a recipe and returns a slice of OutputResource objects, returning an error if any of the resources are invalid.

func GetOutputResourcesFromResourcesField

func GetOutputResourcesFromResourcesField(field []*portableresources.ResourceReference) ([]rpv1.OutputResource, error)

GetOutputResourcesFromResourcesField parses a slice of resource references and converts each resource into an OutputResource. It returns a slice of output resources and an error if any of the resource references are invalid. This should be used for processing the '.properties.resources' field of a resource.

func NewResourceClient

func NewResourceClient(arm *armauth.ArmConfig, connection sdk.Connection, k8sClient runtime_client.Client, k8sDiscoveryClient discovery.ServerResourcesInterface) *resourceClient

NewResourceClient creates a new resourceClient instance with the given parameters.

Types

type MockResourceClient

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

MockResourceClient is a mock of ResourceClient interface.

func NewMockResourceClient

func NewMockResourceClient(ctrl *gomock.Controller) *MockResourceClient

NewMockResourceClient creates a new mock instance.

func (*MockResourceClient) Delete

func (m *MockResourceClient) Delete(arg0 context.Context, arg1 string) error

Delete mocks base method.

func (*MockResourceClient) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

type MockResourceClientMockRecorder

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

MockResourceClientMockRecorder is the mock recorder for MockResourceClient.

func (*MockResourceClientMockRecorder) Delete

func (mr *MockResourceClientMockRecorder) Delete(arg0, arg1 interface{}) *gomock.Call

Delete indicates an expected call of Delete.

type Options

type Options struct {
	// RuntimeConfiguration represents the configuration of the target runtime.
	RuntimeConfiguration recipes.RuntimeConfiguration

	// RecipeOutput represents the output of executing a recipe (may be nil).
	RecipeOutput *recipes.RecipeOutput
}

Options defines the options passed to the resource processor.

type ResourceClient

type ResourceClient interface {
	// Delete deletes a resource by id.
	//
	// If the API version is omitted, then an attempt will be made to look up the API version.
	Delete(ctx context.Context, id string) error
}

ResourceClient is a client used by resource processors for interacting with UCP resources.

type ResourceError

type ResourceError struct {
	ID    string
	Inner error
}

ResourceError represents an error that occured while processing a resource.

func (*ResourceError) Error

func (e *ResourceError) Error() string

Error returns a string describing the error that occurred when attempting to delete a resource.

func (*ResourceError) Unwrap

func (e *ResourceError) Unwrap() error

Unwrap returns the underlying error of ResourceError.

type ResourceProcessor

type ResourceProcessor[P interface {
	*T
	rpv1.RadiusResourceModel
}, T any] interface {
	// Process is called to process the results of recipe execution or any other changes to the resource
	// data model. Process should modify the datamodel in place to perform updates.
	Process(ctx context.Context, resource P, options Options) error

	// Delete is called to delete all the resources created by the resource processor.
	Delete(ctx context.Context, resource P, options Options) error
}

ResourceProcessor is responsible for processing the results of recipe execution or any other change to the lifecycle of a portable resource. Each resource processor supports a single Radius resource type (eg: RedisCache).

type ValidationError

type ValidationError struct {
	Message string
}

ValidationError represents a user-facing validation message reported by the processor.

func (*ValidationError) Error

func (e *ValidationError) Error() string

Error returns a string containing the error message for ValidationError.

type Validator

type Validator struct {

	// ConnectionValues stores the connection values extracted from the data model and recipe output.
	ConnectionValues map[string]any

	// ConnectionSecrets stores the connection secrets extracted from the data model and recipe output.
	ConnectionSecrets map[string]rpv1.SecretValueReference

	// OutputResources stores the output resources extracted from the data model and recipe output.
	OutputResources *[]rpv1.OutputResource
	// contains filtered or unexported fields
}

Validator provides validation support to be used with the data model of a resource type that supports recipes.

The Validator can be used to:

- Extract output resources from a `resource` field - Extract output resources from the recipe out - Extract connection values and connection secrets from the recipe output - Apply values and secrets from the recipe output to the resource data model.

func NewValidator

func NewValidator(connectionValues *map[string]any, connectionSecrets *map[string]rpv1.SecretValueReference, outputResources *[]rpv1.OutputResource) *Validator

NewValidator initializes and returns a new Validator instance with empty data structures for connection values, connection secrets and output resources. Use the parameters to pass in pointers to the corresponding fields on the resource data model.

func (*Validator) AddComputedBoolField

func (v *Validator) AddComputedBoolField(name string, ref *bool, compute func() (bool, *ValidationError))

AddComputedBoolField registers a field containing a computed boolean connection value. The false value will be treated as an "unset" value.

The compute function will be called if the value is not already set or provided by the recipe. Inside the compute function it is safe to assume that other non-computed fields have been populated already.

The compute function will not be called if a validation error has previously occurred.

func (*Validator) AddComputedSecretField

func (v *Validator) AddComputedSecretField(name string, ref *string, compute func() (string, *ValidationError))

AddComputedSecretField registers a field containing a computed string connection secret. The empty string will be treated as an "unset" value.

The compute function will be called if the secret is not already set or provided by the recipe. Inside the compute function it is safe to assume that other non-computed fields have been populated already.

The compute function will not be called if a validation error has previously occurred.

func (*Validator) AddComputedStringField

func (v *Validator) AddComputedStringField(name string, ref *string, compute func() (string, *ValidationError))

AddComputedStringField registers a field containing a computed string connection value. The empty string will be treated as an "unset" value.

The compute function will be called if the value is not already set or provided by the recipe. Inside the compute function it is safe to assume that other non-computed fields have been populated already.

The compute function will not be called if a validation error has previously occurred.

func (*Validator) AddOptionalAnyField

func (v *Validator) AddOptionalAnyField(name string, ref any)

AddOptionalAnyField registers a field containing any property value. The empty property will be treated as an "unset" value.

func (*Validator) AddOptionalInt32Field

func (v *Validator) AddOptionalInt32Field(name string, ref *int32)

AddOptionalInt32Field registers a field containing an optional int32 connection value. The zero value will be treated as an "unset" value.

func (*Validator) AddOptionalSecretField

func (v *Validator) AddOptionalSecretField(name string, ref *string)

AddRequiredSecretField registers a field containing an optional string connection secret. The empty string will be treated as an "unset" value.

func (*Validator) AddOptionalStringField

func (v *Validator) AddOptionalStringField(name string, ref *string)

AddOptionalStringField registers a field containing an optional string connection value. The empty string will be treated as an "unset" value.

func (*Validator) AddRequiredInt32Field

func (v *Validator) AddRequiredInt32Field(name string, ref *int32)

AddRequiredInt32Field registers a field containing a required int32 connection value. The zero value will be treated as an "unset" value.

func (*Validator) AddRequiredSecretField

func (v *Validator) AddRequiredSecretField(name string, ref *string)

AddRequiredSecretField registers a field containing a required string connection secret. The empty string will be treated as an "unset" value.

func (*Validator) AddRequiredStringField

func (v *Validator) AddRequiredStringField(name string, ref *string)

AddRequiredStringField registers a field containing a required string connection value. The empty string will be treated as an "unset" value.

func (*Validator) AddResourcesField

func (v *Validator) AddResourcesField(ref *[]*portableresources.ResourceReference)

AddResourceField registers a field containing a resource ID with the validator.

func (*Validator) SetAndValidate

func (v *Validator) SetAndValidate(output *recipes.RecipeOutput) error

SetAndValidate will bind fields from the recipe output, populate output resources, and populate connection values/secrets.

This function returns *ValidationError for validation failures.

After calling SetAndValidate, the connection values/secrets and output resources will be populated.

Jump to

Keyboard shortcuts

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