runtime

package
v0.33.0 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: Apache-2.0 Imports: 43 Imported by: 233

README

pkg/runtime

This package contains a set of concrete structs and helper functions that provide a common controller implementation for an AWS service.

The top-level container struct in the package is ServiceController. A single instance of ServiceController is created (using NewServiceController()) from the cmd/controller/main.go file that contains the ACK controller entrypoint for a specific AWS service API.

ServiceController primarily serves as a way to glue the upstream sigs.k8s.io/controller-runtime (here on called ctrlrt for short since that alias we use in the ACK codebase to refer to that upstream repository) machinery together with ACK types that handle communication with the AWS service API.

The main ctrlrt types that ServiceController glues together are the ctrlrt.Manager and ctrlrt.Reconciler types. The ctrlrt.Manager type is used to bind a bunch of sigs.k8s.io/client-go and sigs.k8s.io/apimachinery infrastructure together into a common network server/listener structure. The ctrlrt.Reconciler type is an interface that provides a single Reconcile() method whose job is to reconcile the state of a single custom resource (CR) object.

The ServiceController.BindControllerManager() method accepts a ctrlrt.Manager object and is responsible for creating a reconciler for each kind of CR that the service controller will handle.

But how does the ServiceController know what kinds of CRs that it will handle?

There is a ServiceController.WithResourceManagerFactories() method that sets the ServiceController's collection of objects that implement the types.AWSResourceManagerFactory interface.

These resource manager factories produce objects that implement the types.AWSResourceManager interface, which is basic CRUD+L operations for a particular AWS resource against the backend AWS service API. The types.AWSResourceManagerFactory.For() method returns a types.AWSResourceManager object that has been created to handle a specific AWS service API resources for one AWS account. In this way, the single service controller can manage resources across multiple AWS accounts.

Resource manager factories are registered with a Registry object that is package-scoped to the individual service controller's services/{service}/pkg/resource package. See the example service's pkg/resource/registry.go file for how this package-scoped registry works. Individual resource manager factories are registered with this package-scoped Registry object using an init() call within a file named {resource}_manager_factory.go. For example, the Book resource in the example service's pkg/resource package has its resource manager factory registered in the init() function in the pkg/resource/book_resource_manager_factory.go file.

Documentation

Index

Constants

View Source
const (
	// NamespaceKubeNodeLease is the name of the Kubernetes namespace that
	// contains the kube-node-lease resources (used for node hearthbeats)
	NamespaceKubeNodeLease = "kube-node-lease"
	// NamespacePublic is the name of the Kubernetes namespace that contains
	// the public info (ConfigMaps)
	NamespaceKubePublic = "kube-public"
	// NamespaceSystem is the name of the Kubernetes namespace where we place
	// system components.
	NamespaceKubeSystem = "kube-system"
)
View Source
const (
	// MissingImageTagValue is the placeholder value when ACK controller
	// image tag(release semver) cannot be determined.
	MissingImageTagValue = "unknown"
)

Variables

View Source
var ACKResourceTagFormats = map[string]resolveTagFormat{
	acktags.ServiceAliasTagFormat: func(
		obj rtclient.Object,
		md acktypes.ServiceControllerMetadata,
	) string {
		return md.ServiceAlias
	},

	acktags.ControllerVersionTagFormat: func(
		obj rtclient.Object,
		md acktypes.ServiceControllerMetadata,
	) string {
		controllerImageTag := md.GitVersion

		if controllerImageTag == "" {
			controllerImageTag = MissingImageTagValue
		}
		return controllerImageTag
	},

	acktags.NamespaceTagFormat: func(
		obj rtclient.Object,
		md acktypes.ServiceControllerMetadata,
	) string {
		return obj.GetNamespace()
	},

	acktags.ResourceNameTagFormat: func(
		obj rtclient.Object,
		md acktypes.ServiceControllerMetadata,
	) string {
		return obj.GetName()
	},
}

ACKResourceTagFormats is map of ACK resource tag formats to it's resolveTagFormat function.

To add a new ACKResourceTag format, include it in this map, along with the resolveTagFormat function and expandTagValue() method will start expanding the new resource tag format.

Localise the global to make it easier to mock

Functions

func GetDefaultTags

func GetDefaultTags(
	config *ackconfig.Config,
	obj rtclient.Object,
	md acktypes.ServiceControllerMetadata,
) acktags.Tags

GetDefaultTags provides Default tags (key value pairs) for given resource

func IsAdopted

func IsAdopted(res acktypes.AWSResource) bool

IsAdopted returns true if the supplied AWSResource was created with a non-nil ARN annotation, which indicates that the Kubernetes user who created the CR for the resource expects the ACK service controller to "adopt" a pre-existing resource and bring it under ACK management.

func IsSynced

func IsSynced(res acktypes.AWSResource) bool

IsSynced returns true if the supplied AWSResource's CR and associated backend AWS service API resource are in sync.

func NewAdoptionReconciler added in v0.1.0

NewAdoptionReconciler returns a new adoptionReconciler object

func NewAdoptionReconcilerWithClient added in v0.14.1

func NewAdoptionReconcilerWithClient(
	sc acktypes.ServiceController,
	log logr.Logger,
	cfg ackcfg.Config,
	metrics *ackmetrics.Metrics,
	cache ackrtcache.Caches,
	kc client.Client,
	apiReader client.Reader,
) acktypes.AdoptedResourceReconciler

NewAdoptionReconcilerWithClient returns a new adoptionReconciler object with specified k8s client and Reader. Currently this function is used for testing purpose only because "adoptionReconciler" struct is not available outside 'runtime' package for dependency injection.

func NewFieldExportReconcilerForAWSResource added in v0.18.0

func NewFieldExportReconcilerForAWSResource(
	sc acktypes.ServiceController,
	log logr.Logger,
	cfg ackcfg.Config,
	metrics *ackmetrics.Metrics,
	cache ackrtcache.Caches,
	rd acktypes.AWSResourceDescriptor,
) acktypes.FieldExportReconciler

NewFieldExportReconcilerForAWSResource returns a new FieldExportReconciler object

func NewFieldExportReconcilerForFieldExport added in v0.18.0

func NewFieldExportReconcilerForFieldExport(
	sc acktypes.ServiceController,
	log logr.Logger,
	cfg ackcfg.Config,
	metrics *ackmetrics.Metrics,
	cache ackrtcache.Caches,
) acktypes.FieldExportReconciler

NewFieldExportReconcilerForFieldExport returns a new FieldExportReconciler object

func NewFieldExportReconcilerWithClient added in v0.18.0

func NewFieldExportReconcilerWithClient(
	sc acktypes.ServiceController,
	log logr.Logger,
	cfg ackcfg.Config,
	metrics *ackmetrics.Metrics,
	cache ackrtcache.Caches,
	kc client.Client,
	apiReader client.Reader,
) acktypes.FieldExportReconciler

NewFieldExportReconcilerWithClient returns a new FieldExportReconciler object with specified k8s client and Reader. Currently this function is used for testing purpose only because "FieldExportReconciler" struct is not available outside 'runtime' package for dependency injection.

func NewFieldExportResourceReconcilerWithClient added in v0.18.0

func NewFieldExportResourceReconcilerWithClient(
	sc acktypes.ServiceController,
	log logr.Logger,
	cfg ackcfg.Config,
	metrics *ackmetrics.Metrics,
	cache ackrtcache.Caches,
	kc client.Client,
	apiReader client.Reader,
	rd acktypes.AWSResourceDescriptor,
) acktypes.FieldExportReconciler

NewFieldExportResourceReconcilerWithClient returns a new FieldExportReconciler object with specified k8s client and Reader. Currently this function is used for testing purpose only because "FieldExportReconciler" struct is not available outside 'runtime' package for dependency injection.

func NewReconciler

NewReconciler returns a new reconciler object

func NewReconcilerWithClient added in v0.7.0

NewReconcilerWithClient returns a new reconciler object with Client(controller-runtime/pkg/client) already set.

func NewServiceController

func NewServiceController(
	svcAlias string,
	svcAPIGroup string,
	svcEndpointsID string,
	versionInfo acktypes.VersionInfo,
) acktypes.ServiceController

NewServiceController returns a new serviceController instance

Types

type Registry

type Registry struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewRegistry

func NewRegistry() *Registry

NewRegistry returns a thread-safe Registry object

func (*Registry) GetResourceManagerFactories

func (r *Registry) GetResourceManagerFactories() []types.AWSResourceManagerFactory

GetResourceManagerFactories returns AWSResourceManagerFactories that are registered with the RegistryA

func (*Registry) RegisterResourceManagerFactory

func (r *Registry) RegisterResourceManagerFactory(f types.AWSResourceManagerFactory)

RegisterResourceManagerFactory registers a resource manager factory with the package's registry

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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