controller

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2023 License: MPL-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultPartition is the name of the default Consul partition.
	DefaultPartition = "default"
	// DefaultNamespace is the name of the default Consul namespace.
	DefaultNamespace = "default"
)
View Source
const DefaultPollingInterval = 10 * time.Second

Variables

This section is empty.

Functions

func IsACLNotFoundError added in v0.4.0

func IsACLNotFoundError(err error) bool

IsACLNotFoundError returns true if the ACL is not found.

func PartitionsEnabled added in v0.4.0

func PartitionsEnabled(p string) bool

PartitionsEnabled indicates if support for partitions and namespaces is enabled.

Types

type Controller

type Controller struct {
	// Resources lists resources for Controller to reconcile.
	Resources ResourceLister
	// PollingInterval is an interval that Controller will use to reconcile all Resources.
	PollingInterval time.Duration
	// Log is the logger used by the Controller.
	Log hclog.Logger
}

Controller is a generic controller implementation. It periodically polls for Resources and reconciles them by calling Resource's Upsert or Delete function accordingly.

func (*Controller) Run

func (c *Controller) Run(ctx context.Context)

Run starts the Controller loop. The loop will exit when ctx is canceled.

type Resource

type Resource interface {
	// Namespace indicates the namespace that this resource belongs to [Consul Enterprise].
	// It returns the empty string if namespaces are not enabled.
	Namespace() string

	// Reconcile offers functions to reconcile itself with an external state.
	Reconcile() error
}

Resource is a generic type that needs to be reconciled by the Controller.

type ResourceLister

type ResourceLister interface {
	// List all Resources.
	List() ([]Resource, error)

	// ReconcileNamespaces ensures that all requisite namespaces exist.
	ReconcileNamespaces([]Resource) error
}

ResourceLister is an interface for listing Resources.

type TaskID added in v0.5.0

type TaskID string

type TaskState added in v0.5.0

type TaskState struct {
	ConsulClient *api.Client

	// TaskID is the id of the ECS task.
	TaskID TaskID
	// ClusterARN is the ECS cluster.
	ClusterARN string
	// Partition that the task belongs to [Consul Enterprise].
	Partition string
	// Namespace that the task belongs to [Consul Enterprise].
	NS string

	// ECSTaskFound indicates whether an ECS task was found for this task id.
	ECSTaskFound bool
	// ACLTokens are the Consul ACL tokens found for this task id.
	ACLTokens []*api.ACLTokenListEntry

	Log hclog.Logger
}

TaskState contains the information needed to reconcile a task.

func (*TaskState) Delete added in v0.5.0

func (t *TaskState) Delete() error

Delete removes the service token for the given ServiceInfo.

func (*TaskState) Namespace added in v0.5.0

func (t *TaskState) Namespace() string

Namespace returns the namespace that the service belongs to. It returns the empty string if namespaces are not enabled.

func (*TaskState) Reconcile added in v0.5.0

func (t *TaskState) Reconcile() error

Reconcile deletes ACL tokens based on their ServiceState.

type TaskStateLister added in v0.5.0

type TaskStateLister struct {
	// ECSClient is the AWS ECS client to be used by the ServiceStateLister.
	ECSClient ecsiface.ECSAPI

	// ConsulClient is the Consul client to be used by the ServiceStateLister.
	ConsulClient *api.Client

	// ClusterARN is the name or the ARN of the ECS cluster.
	ClusterARN string

	// Partition is the partition that is used by the ServiceStateLister [Consul Enterprise].
	// If partition and namespace support are not enabled then this is set to the empty string.
	Partition string

	// Log is the logger for the ServiceStateLister.
	Log hclog.Logger
}

TaskStateLister is an implementation of ResourceLister.

func (TaskStateLister) List added in v0.5.0

func (s TaskStateLister) List() ([]Resource, error)

List returns resources to be reconciled. - Namespaces which may need to be created - Tokens whcih may need to be cleaned up

func (TaskStateLister) ReconcileNamespaces added in v0.5.0

func (s TaskStateLister) ReconcileNamespaces(resources []Resource) error

ReconcileNamespaces ensures that for every service in the cluster the namespace exists and the cross-partition/cross-namespace read policy exists.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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