controller

package
v0.27.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultAsyncOperationTimeout is the default timeout duration of async operation.
	DefaultAsyncOperationTimeout = time.Duration(120) * time.Second
)

Functions

This section is empty.

Types

type BaseController

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

BaseController is the base struct of async operation controller.

func NewBaseAsyncController

func NewBaseAsyncController(options Options) BaseController

NewBaseAsyncController creates a new BaseController instance with the given Options for Async Operation.

func (*BaseController) DataProvider

DataProvider gets data storage provider for this controller.

func (*BaseController) DeploymentProcessor

func (b *BaseController) DeploymentProcessor() deployment.DeploymentProcessor

DeploymentProcessor gets the core rp deployment processor for this controller.

func (*BaseController) KubeClient

func (b *BaseController) KubeClient() runtimeclient.Client

KubeClient gets Kubernetes client for this controller.

func (*BaseController) ResourceType

func (b *BaseController) ResourceType() string

ResourceType gets the resource type for this controller.

func (*BaseController) StorageClient

func (b *BaseController) StorageClient() store.StorageClient

StorageClient gets storage client for this controller.

type Controller

type Controller interface {
	// Run runs async request operation.
	Run(ctx context.Context, request *Request) (Result, error)

	// StorageClient gets the storage client for resource type.
	StorageClient() store.StorageClient
}

Controller is an interface to implement async operation controller.

type Options

type Options struct {
	// StorageClient is the data storage client.
	StorageClient store.StorageClient

	// DataProvider is the data storage provider.
	DataProvider dataprovider.DataStorageProvider

	// KubeClient is the Kubernetes controller runtime client.
	KubeClient runtimeclient.Client

	// ResourceType is the string that represents the resource type.
	ResourceType string

	// GetDeploymentProcessor is the factory function to create core rp DeploymentProcessor instance.
	GetDeploymentProcessor func() deployment.DeploymentProcessor
}

Options represents controller options.

type Request

type Request struct {
	// APIVersion represents the api-version of operation request.
	APIVersion string `json:"apiVersion"`

	// OperationID represents the unique id of the async operation.
	OperationID uuid.UUID `json:"asyncOperationID"`
	// OperationType represents the type of operation.
	OperationType string `json:"operationType"`
	// ResourceID represents the id of the resource which requires async operation.
	ResourceID string `json:"resourceID"`

	// CorrelationID represents the correlation ID of async operation.
	CorrelationID string `json:"correlationID,omitempty"`
	// TraceparentID represents W3C trace parent ID of async operation.
	TraceparentID string `json:"traceparent,omitempty"`
	// AcceptLanguage represents the locale of operation request.
	AcceptLanguage string `json:"language,omitempty"`

	// HomeTenantID represents the home tenant id of caller.
	HomeTenantID string `json:"homeTenantID,omitempty"`
	// ClientObjectID represents the client object id of caller.
	ClientObjectID string `json:"clientObjectID,omitempty"`

	// OperationTimeout represents the timeout duration of async operation.
	OperationTimeout *time.Duration `json:"asyncOperationTimeout"`
}

Request is a message used for async request queue message broker.

func (*Request) ARMRequestContext

func (r *Request) ARMRequestContext() (*v1.ARMRequestContext, error)

ARMRequestContext creates v1.ARMRequestContext object from async operation request. It returns error if the given resource id is invalid.

func (*Request) Timeout

func (r *Request) Timeout() time.Duration

Timeout gets the operation timeout and returns the default timeout unless it specifies.

type Result

type Result struct {
	// Requeue tells the Controller to requeue the reconcile key. Defaults to false.
	Requeue bool

	// Error represents the error when status is Cancelled or Failed.
	Error *v1.ErrorDetails
	// contains filtered or unexported fields
}

Result is the response of async operation controller.

func NewCanceledResult

func NewCanceledResult(message string) Result

NewCanceledResult creates a new Result object with a canceled status and the given message.

func NewFailedResult

func NewFailedResult(err v1.ErrorDetails) Result

NewFailedResult creates a new Result object with the given error details and sets the failed flag to true.

func (*Result) ProvisioningState

func (r *Result) ProvisioningState() v1.ProvisioningState

ProvisioningState returns the provisioning state of the request object, which is either v1.ProvisioningStateSucceeded or the value of the state field if it is not nil.

func (*Result) SetCanceled

func (r *Result) SetCanceled(message string)

SetCanceled sets the Result's Requeue field to false, sets the ProvisioningState to Canceled and sets the Error field to an ErrorDetails object with the given message.

func (*Result) SetFailed

func (r *Result) SetFailed(err v1.ErrorDetails, requeue bool)

SetFailed sets the error response with Failed status.

func (*Result) SetProvisioningState

func (r *Result) SetProvisioningState(s v1.ProvisioningState)

SetProvisioningState sets the state of a Result object to the given ProvisioningState.

Jump to

Keyboard shortcuts

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