registry

package
v0.14.2 Latest Latest
Warning

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

Go to latest
Published: May 13, 2024 License: MIT Imports: 5 Imported by: 16

Documentation

Overview

Package registry provides a way to register resources and their listers and obtain them after the fact. The registry is currently deeply embedded with the other packages and how they access specific aspects of a resource.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearRegistry

func ClearRegistry()

ClearRegistry clears the registry of all registrations Designed for use for unit tests, not for production code. Only use if you know what you are doing.

func GetAlternativeResourceTypeMapping

func GetAlternativeResourceTypeMapping() map[string]string

GetAlternativeResourceTypeMapping returns a map of resource types to their alternative resource type. The primary use case is used to map resource types to their alternative AWS Cloud Control resource type. This allows each resource to define what it's alternative resource type is instead of trying to track them in a single place.

func GetDeprecatedResourceTypeMapping

func GetDeprecatedResourceTypeMapping() map[string]string

GetDeprecatedResourceTypeMapping returns a map of deprecated resource types to their replacement. The primary use case is used to map deprecated resource types to their replacement in the config package. This allows us to provide notifications to the user that they are using a deprecated resource type and should update their config. This allow allows each resource to define it's DeprecatedAliases instead of trying to track them in a single place.

func GetNames

func GetNames() []string

GetNames provides a string slice of all lister names that have been registered

func GetNamesForScope

func GetNamesForScope(scope Scope) []string

GetNamesForScope provides a string slice of all listers for a particular scope

func Register

func Register(r *Registration)

Register registers a resource lister with the registry

Types

type Lister

type Lister interface {
	List(ctx context.Context, opts interface{}) ([]resource.Resource, error)
}

Lister is an interface that represents a resource that can be listed

func GetLister

func GetLister(name string) Lister

GetLister gets a specific lister by name

type Listers

type Listers map[string]Lister

Listers is a map of resource type to lister

func GetListers

func GetListers() (listers Listers)

func GetListersForScope

func GetListersForScope(scope Scope) (listers Listers)

GetListersForScope returns a map of listers for a particular scope that they've been grouped by

func GetListersV2

func GetListersV2() (listers Listers)

GetListersV2 returns a map of listers based on graph top sort order

type RegisterOption

type RegisterOption func(name string, lister Lister)

RegisterOption is a function that can be used to manipulate the lister for a given resource type at registration time

type Registration

type Registration struct {
	// Name is the name of the resource type
	Name string

	// Scope is the scope of the resource type, if left empty it'll default to DefaultScope. It's simple a string
	// designed to group resource types together. The primary use case is for Azure, it needs resources scoped to
	// different levels, whereas AWS has simply Account level.
	Scope Scope

	// Resource is the resource type that the lister is going to list. This is a struct that implements the Resource
	// interface. This is primarily used to generate documentation by parsing the structs properties and generating
	// markdown documentation.
	// Note: it is a interface{} because we are going to inspect it, we do not need to actually call any methods on it.
	Resource interface{}

	// Lister is the lister for the resource type, it is a struct with a method called List that returns a slice
	// of resources. The lister is responsible for filtering out any resources that should not be deleted because they
	// are ineligible for deletion. For example, built in resources that cannot be deleted.
	Lister Lister

	// Settings allows for resources to define settings that can be configured by the calling tool to change the
	// behavior of the resource. For example, EC2 and RDS Instances have Deletion Protection, this allows the resource
	// to define a setting that can be configured by the calling tool to enable/disable deletion protection.
	Settings []string

	// DependsOn is a list of resource types that this resource type depends on. This is used to determine
	// the order in which resources are deleted. For example, a VPC depends on subnets, so we want to delete
	// the subnets before we delete the VPC. This is a Resource level dependency, not a resource instance (i.e. all
	// subnets must be deleted before any VPC can be deleted, not just the subnets that are associated with the VPC).
	DependsOn []string

	// DeprecatedAliases is a list of deprecated aliases for the resource type, usually misspellings or old names
	// that have been replaced with a new resource type. This is used to map the old resource type to the new
	// resource type. This is used in the config package to resolve any deprecated resource types and provide
	// notifications to the user.
	DeprecatedAliases []string

	// AlternativeResource is used to determine if there's an alternative resource type to use. The primary use case
	// for this is AWS Cloud Control API, where we want to use the Cloud Control API resource type instead of the
	// default resource type. However, any resource that uses a different API to manage the same resource can use this
	// field.
	AlternativeResource string
}

Registration is a struct that contains the information needed to register a resource lister

func GetRegistration

func GetRegistration(name string) *Registration

GetRegistration returns the registration for the given resource type

type Registrations

type Registrations map[string]*Registration

Registrations is a map of resource type to registration

func GetRegistrations added in v0.14.0

func GetRegistrations() Registrations

GetRegistrations returns all registrations

type Scope

type Scope string

Scope is a string in which resources are grouped against, this is meant for upstream tools to define their own scopes if the DefaultScope is not sufficient. For example Azure has multiple levels of scoping for resources, whereas AWS does not.

const DefaultScope Scope = "default"

DefaultScope is the default scope which resources are registered against if no other scope is provided

Jump to

Keyboard shortcuts

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