controller

package
v0.0.0-...-4e01cd4 Latest Latest
Warning

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

Go to latest
Published: May 23, 2025 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

func IsACLNotFoundError(err error) bool

IsACLNotFoundError returns true if the ACL is not found.

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

	// IsPresent checks if the given resource is found in the response
	// returned by ECS
	IsPresent() bool

	// ID returns the taskID of the resource
	ID() TaskID

	// 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

type TaskID string

type TaskState

type TaskState struct {
	// SetupConsulClientFn sets up a consul client on demand.
	SetupConsulClientFn func() (*api.Client, error)

	// 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
	// Service and the sidecar proxy registrations associated with this ECS task
	Services []*api.AgentService

	Log hclog.Logger
}

TaskState contains the information needed to reconcile a task.

func (*TaskState) Delete

func (t *TaskState) Delete(consulClient *api.Client) error

Delete removes the service token for the given ServiceInfo.

func (*TaskState) DeregisterServices

func (t *TaskState) DeregisterServices(consulClient *api.Client) error

DeregisterServices removes the service and proxy registrations from the Consul catalog

func (*TaskState) ID

func (t *TaskState) ID() TaskID

ID returns the taskID of the resource

func (*TaskState) IsPresent

func (t *TaskState) IsPresent() bool

func (*TaskState) Namespace

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

func (t *TaskState) Reconcile() error

Reconcile deletes ACL tokens and removes the service from Catalog based on the TaskState.

type TaskStateLister

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

	// SetupConsulClientFn sets up a consul client on demand.
	SetupConsulClientFn func() (*api.Client, error)

	// 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

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

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

func (TaskStateLister) ReconcileNamespaces

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