Documentation
¶
Index ¶
- Variables
- func Filter(data []string, regex string) ([]string, error)
- func GetClosestRegions(origin openmcpv1alpha1.RegionSpecification, ...) ([]string, error)
- func SortByProximity(start openmcpv1alpha1.RegionSpecification, preferSameRegion bool) [][]openmcpv1alpha1.RegionSpecification
- type BasicRegionMapper
- type GenericToSpecificRegionMapper
- type Geography
- type Location
Constants ¶
This section is empty.
Variables ¶
var AWSRegions = []string{
"us-east-2",
"us-east-1",
"us-west-1",
"us-west-2",
"af-south-1",
"ap-east-1",
"ap-south-2",
"ap-southeast-3",
"ap-southeast-4",
"ap-south-1",
"ap-northeast-3",
"ap-northeast-2",
"ap-southeast-1",
"ap-southeast-2",
"ap-northeast-1",
"ca-central-1",
"ca-west-1",
"eu-central-1",
"eu-west-1",
"eu-west-2",
"eu-south-1",
"eu-west-3",
"eu-south-2",
"eu-north-1",
"eu-central-2",
"il-central-1",
"me-south-1",
"me-central-1",
"sa-east-1",
"us-gov-east-1",
"us-gov-west-1",
}
AWSRegions contains a list of all known AWS regions. May not be up-to-date.
var AWSZones = []string{
"us-east-2a",
"us-east-2b",
"us-east-2c",
"us-east-1a",
"us-east-1b",
"us-east-1c",
"us-east-1d",
"us-east-1e",
"us-east-1f",
"us-west-1a",
"us-west-1b",
"us-west-2a",
"us-west-2b",
"us-west-2c",
"us-west-2d",
"ap-south-1a",
"ap-south-1b",
"ap-south-1c",
"ap-northeast-3a",
"ap-northeast-3b",
"ap-northeast-3c",
"ap-northeast-2a",
"ap-northeast-2b",
"ap-northeast-2c",
"ap-northeast-2d",
"ap-southeast-1a",
"ap-southeast-1b",
"ap-southeast-1c",
"ap-southeast-2a",
"ap-southeast-2b",
"ap-southeast-2c",
"ap-northeast-1a",
"ap-northeast-1c",
"ap-northeast-1d",
"ca-central-1a",
"ca-central-1b",
"ca-central-1d",
"eu-central-1a",
"eu-central-1b",
"eu-central-1c",
"eu-west-1a",
"eu-west-1b",
"eu-west-1c",
"eu-west-2a",
"eu-west-2b",
"eu-west-2c",
"eu-west-3a",
"eu-west-3b",
"eu-west-3c",
"eu-north-1a",
"eu-north-1b",
"eu-north-1c",
"sa-east-1a",
"sa-east-1b",
"sa-east-1c",
}
AWSZones contains a list of all known AWS availability zones. May not be up-to-date. Note that special zones or zones belonging to special regions are excluded, so not every region from the AWSRegions list has matching zones in here.
var DefaultRegion = openmcpv1alpha1.RegionSpecification{ Name: openmcpv1alpha1.EUROPE, Direction: openmcpv1alpha1.CENTRAL, }
var DirectionOppositeMapping = map[openmcpv1alpha1.Direction]openmcpv1alpha1.Direction{ openmcpv1alpha1.NORTH: openmcpv1alpha1.SOUTH, openmcpv1alpha1.EAST: openmcpv1alpha1.WEST, openmcpv1alpha1.SOUTH: openmcpv1alpha1.NORTH, openmcpv1alpha1.WEST: openmcpv1alpha1.EAST, }
var DirectionProximityMapping = map[openmcpv1alpha1.Direction][]openmcpv1alpha1.Direction{ openmcpv1alpha1.CENTRAL: {openmcpv1alpha1.NORTH, openmcpv1alpha1.EAST, openmcpv1alpha1.SOUTH, openmcpv1alpha1.WEST}, openmcpv1alpha1.NORTH: {openmcpv1alpha1.CENTRAL, openmcpv1alpha1.WEST, openmcpv1alpha1.EAST}, openmcpv1alpha1.EAST: {openmcpv1alpha1.CENTRAL, openmcpv1alpha1.NORTH, openmcpv1alpha1.SOUTH}, openmcpv1alpha1.SOUTH: {openmcpv1alpha1.CENTRAL, openmcpv1alpha1.EAST, openmcpv1alpha1.WEST}, openmcpv1alpha1.WEST: {openmcpv1alpha1.CENTRAL, openmcpv1alpha1.SOUTH, openmcpv1alpha1.NORTH}, }
DirectionProximityMapping maps directions to lists of neighboring directions. The lists are considered to be ordered. By default, all directions (except CENTRAL) are considered to be neighbored to CENTRAL first and their respective two non-opposite directions second. CENTRAL is neighbored to all other directions.
var GCPRegions = []string{
"asia-east1",
"asia-east2",
"asia-northeast1",
"asia-northeast2",
"asia-northeast3",
"asia-south1",
"asia-south2",
"asia-southeast1",
"asia-southeast2",
"australia-southeast1",
"australia-southeast2",
"europe-central2",
"europe-north1",
"europe-southwest1",
"europe-west1",
"europe-west10",
"europe-west12",
"europe-west2",
"europe-west3",
"europe-west4",
"europe-west6",
"europe-west8",
"europe-west9",
"me-central1",
"me-central2",
"me-west1",
"northamerica-northeast1",
"northamerica-northeast2",
"southamerica-east1",
"southamerica-west1",
"us-central1",
"us-east1",
"us-east4",
"us-east5",
"us-south1",
"us-west1",
"us-west2",
"us-west3",
"us-west4",
}
GCPRegions contains a list of all known GCP regions. May not be up-to-date.
var GCPZones = []string{}/* 118 elements not displayed */
GCPZones contains a list of all known GCP availability zones. May not be up-to-date.
Functions ¶
func Filter ¶
Filter filters a list of strings and returns a new list containing only the elements which are matched by the given regular expression. Returns an error if the regular expression cannot be compiled.
func GetClosestRegions ¶
func GetClosestRegions(origin openmcpv1alpha1.RegionSpecification, mapper GenericToSpecificRegionMapper, availableRegions []string, preferSameRegion bool) ([]string, error)
GetClosestRegion tries to find the region(s) that are closest to the origin region. First, the SortByProximity function is used to generate multiple lists of generic regions, ordered by their 'distance' to the origin region. Then, for each of these lists, all of its entries are mapped using the specified mapper and extended with the specified pre- and suffix. For each string generated this way, the list of available regions is filtered for entries that match the resulting regular expression. If any matches are found, the function is aborted and returns only the matches found for the current list. If no match is found for any list, nil is returned. An error is only returned if the generated regular expression is invalid.
The idea is, that all returned specific regions are considered to have the same minimal distance to the specified origin.
The preferSameRegion field controls whether other directions within the same region should be prioritized over neighboring directions of neighboring regions. For example: GCP currently only has regions in the south(east) of Australia, so there is no exact match for the generic region specification (AUSTRALIA, NORTH). With preferSameRegion set to false, the function returns GCPs asia-south* regions because Asia's south is considered only one step away from Australia's north, opposed to Australia's south, which is considered to be two steps away. With preferSameRegion set to true, the function returns GCPs australia-south* regions because even though it is the opposite direction, they still share the same region and are therefore preferred. If GCP had zones in central, east, or west of Australia, all of these would be considered one step away from (AUSTRALIA, NORTH). In this case, with preferSameRegion set to true, only these regions would be returned, neither asia-south*, nor australia-south*. With preferSameRegion set to false, the returned selection would contain australia-central*, -east*, and -west*, as well as asia-south*, because all of them are considered the same distance away from (AUSTRALIA, NORTH).
The returned list is sorted alphabetically to ensure consistent results.
func SortByProximity ¶
func SortByProximity(start openmcpv1alpha1.RegionSpecification, preferSameRegion bool) [][]openmcpv1alpha1.RegionSpecification
Types ¶
type BasicRegionMapper ¶
type BasicRegionMapper struct { // In format string, %R will be replaced by the region and %D will be replaced by the direction. Format string RegionGenericToSpecific map[openmcpv1alpha1.Region]string DirectionGenericToSpecific map[openmcpv1alpha1.Direction]string DefaultMissingDirection bool }
BasicRegionMapper is a basic implementation of the GenericToSpecificRegionMapper interface.
func AWSMapper ¶
func AWSMapper() *BasicRegionMapper
AWSMapper returns a pre-configured mapper for AWS regions.
func GCPMapper ¶
func GCPMapper() *BasicRegionMapper
GCPMapper returns a pre-configured mapper for GCP regions.
func NewRegionMapper ¶
func NewRegionMapper(format string, regionMapping map[openmcpv1alpha1.Region]string, directionMapping map[openmcpv1alpha1.Direction]string, defaultMissingDirection bool) *BasicRegionMapper
NewRegionMapper creates a new BasicRegionMapper. format is a regex string where %R represents the region and %D represents the direction. The mappings map from generic regions and directions to the specific ones. If defaultMissingDirection is set to true, the direction is defaulted to CENTRAL if not specified. Otherwise, it is kept empty. The region is always defaulted to the value from DefaultRegion if left empty.
Example: If EUROPE maps to 'eu' and CENTRAL maps to 'central' and the format string is '%R-%D-[0-9]+', the mapper would map (EUROPE, CENTRAL) to 'eu-central-[0-9]+'. This regex could then be used to filter e.g. ['eu-central-1', 'eu-central-2', 'eu-central-3'] out of a list of available specific regions.
func (*BasicRegionMapper) MapGenericToSpecific ¶
func (m *BasicRegionMapper) MapGenericToSpecific(reg openmcpv1alpha1.Region, dir openmcpv1alpha1.Direction) string
type GenericToSpecificRegionMapper ¶
type GenericToSpecificRegionMapper interface { // MapGenericToSpecific takes a generic region and direction and maps them to an implementation-specific regex string. // This regex can be used to filter a list of existing regions for matches. // The behavior if (parts of) the arguments are empty or no mapping can be found depends on the implementation of the interface. MapGenericToSpecific(openmcpv1alpha1.Region, openmcpv1alpha1.Direction) string }
GenericToSpecificRegionMapper maps between the generic region specification and a specific implementation.
func GetPredefinedMapperByCloudprovider ¶
func GetPredefinedMapperByCloudprovider(provider string) GenericToSpecificRegionMapper
GetPredefinedMapperByCloudprovider returns a predefined mapper for the specified cloud provider, if any exists. Otherwise, nil is returned. The name of the cloudprovider is case-insensitive.
Currently supported: aws, gcp
type Geography ¶
type Geography map[openmcpv1alpha1.Region]*Location
var World Geography = Geography{ openmcpv1alpha1.AFRICA: {Region: openmcpv1alpha1.AFRICA, Neighbor: map[openmcpv1alpha1.Direction]*Location{}}, openmcpv1alpha1.ASIA: {Region: openmcpv1alpha1.ASIA, Neighbor: map[openmcpv1alpha1.Direction]*Location{}}, openmcpv1alpha1.AUSTRALIA: {Region: openmcpv1alpha1.AUSTRALIA, Neighbor: map[openmcpv1alpha1.Direction]*Location{}}, openmcpv1alpha1.EUROPE: {Region: openmcpv1alpha1.EUROPE, Neighbor: map[openmcpv1alpha1.Direction]*Location{}}, openmcpv1alpha1.NORTHAMERICA: {Region: openmcpv1alpha1.NORTHAMERICA, Neighbor: map[openmcpv1alpha1.Direction]*Location{}}, openmcpv1alpha1.SOUTHAMERICA: {Region: openmcpv1alpha1.SOUTHAMERICA, Neighbor: map[openmcpv1alpha1.Direction]*Location{}}, }
func (Geography) SortByProximity ¶
func (g Geography) SortByProximity(start openmcpv1alpha1.RegionSpecification, preferSameRegion bool) [][]openmcpv1alpha1.RegionSpecification
SortByProximity basically sorts the elements of this Geography based on a breadth-first search starting from the given element. The returned list is two-dimensional, where the index of the outer elements corresponds to the relative distance of all corrensponding inner elements. If preferSameRegion is set to true, the result list is ordered in a way that other regions only appear after all combinations of the start region with all directions.
type Location ¶
type Location struct { Region openmcpv1alpha1.Region Neighbor map[openmcpv1alpha1.Direction]*Location }