controller

package
v0.2.0-beta2 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2021 License: MPL-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultPollingInterval = 10 * time.Second

Variables

This section is empty.

Functions

func UpsertConsulClientToken

func UpsertConsulClientToken(consulClient *api.Client, smClient secretsmanageriface.SecretsManagerAPI, secretARN, secretPrefix string, log hclog.Logger) error

UpsertConsulClientToken creates or updates ACL policy and token for the Consul client in Consul. It then saves the created token in AWS Secrets Manager in the secret provided by secretARN.

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
	// contains filtered or unexported fields
}

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 {
	ID() (ResourceID, error)
	Upsert() error
	Delete() error
}

Resource is a generic type that needs to be reconciled by the Controller. It offers Upsert and Delete functions to reconcile itself with an external state.

type ResourceID

type ResourceID string

ResourceID represents the ID of the resource.

type ResourceLister

type ResourceLister interface {
	List() ([]Resource, error)
}

ResourceLister is an interface for listing Resources.

type Task

type Task struct {
	SecretsManagerClient secretsmanageriface.SecretsManagerAPI
	ConsulClient         *api.Client

	Cluster      string
	SecretPrefix string
	Task         ecs.Task

	Log hclog.Logger
}

func (*Task) Delete

func (t *Task) Delete() error

func (*Task) ID

func (t *Task) ID() (ResourceID, error)

ID returns Task definition ARN or error if it cannot be determined from the Task. We're using task definition ARN instead of the Task ARN because we consider tasks for the same definition to be equivalent in terms of their Upsert and Delete behavior, and so there's no reason to process subsequent tasks with the same task definition.

func (*Task) Upsert

func (t *Task) Upsert() error

Upsert creates a token for the task if one doesn't already exist and updates the secret with the contents of the token.

type TaskLister

type TaskLister struct {
	// ECSClient is the AWS ECS client to be used by the TaskLister.
	ECSClient ecsiface.ECSAPI
	// SecretsManagerClient is the AWS Secrets Manager client to be used by the TaskLister.
	SecretsManagerClient secretsmanageriface.SecretsManagerAPI
	// ConsulClient is the Consul client to be used by the TaskLister.
	// TaskLister doesn't need to talk to Consul, but it passes this client
	// to each Resource it creates.
	ConsulClient *api.Client

	// Cluster is the name or the ARN of the ECS cluster.
	Cluster string
	// SecretPrefix is the prefix to determine names of resources in Consul or AWS.
	SecretPrefix string

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

TaskLister is an implementation of ResourceLister that lists ECS tasks.

func (TaskLister) List

func (t TaskLister) List() ([]Resource, error)

List lists all tasks for the Cluster.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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