infraflow

package
v1.43.3 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ChildKeyIDs is the prefix key for all ids.
	ChildKeyIDs = "ids"
	// ChildKeyInventory is the prefix key for for the inventory struct.
	ChildKeyInventory = "inventory"
	// CreatedResourcesExistKey is a marker for the Terraform migration case. If the TF state is not empty
	// we inject this marker into the state to block the deletion without having first a successful reconciliation.
	CreatedResourcesExistKey = "resources_exist"

	// KeyManagedIdentityClientId is a key for the MI's client ID.
	KeyManagedIdentityClientId = "managed_identity_client_id"
	// KeyManagedIdentityId is a key for the MI's identity ID.
	KeyManagedIdentityId = "managed_identity_id"
)
View Source
const (
	// TemplateAvailabilitySet the template for the ID of an availability set.
	TemplateAvailabilitySet = "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Compute/availabilitySets/%s"
	// TemplateNatGateway the template for the id of a NAT Gateway.
	TemplateNatGateway = "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/natGateways/%s"
	// TemplatePublicIP the template for the id of a public IP.
	TemplatePublicIP = "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/publicIPAddresses/%s"
	// TemplateResourceGroup is the template for the id of a resource group.
	TemplateResourceGroup = "/subscriptions/%s/resourceGroups/%s"
	// TemplateRouteTable is the template for the id of a route table.
	TemplateRouteTable = "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/routeTables/%s"
	// TemplateSecurityGroup is the template for the id of a security group.
	TemplateSecurityGroup = "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/networkSecurityGroups/%s"
	// TemplateVirtualNetwork is the template for the id of a virtual network.
	TemplateVirtualNetwork = "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/virtualNetworks/%s"
	// TemplateSubnet is the template for the id of a subnet.
	TemplateSubnet = "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/virtualNetworks/%s/subnets/%s"
)

Variables

This section is empty.

Functions

func Filter

func Filter[T any](arr []T, fs ...func(T) bool) []T

Filter filters the given array based on the provided functions.

func ForceNewIp

func ForceNewIp(current, target *armnetwork.PublicIPAddress) (bool, string, any)

ForceNewIp checks if the resource can be reconciled. If not, returns the name of the field and value that couldn't be updated.

func ForceNewNat

func ForceNewNat(current, target *armnetwork.NatGateway) (bool, string, any)

ForceNewNat checks if the resource can be reconciled. If not, returns the name of the field and value that couldn't be updated.

func ForceNewSubnet

func ForceNewSubnet(_, _ *armnetwork.Subnet) (bool, string, any)

ForceNewSubnet checks if the resource can be reconciled. If not, returns the name of the field and value that couldn't be updated.

func GetIdFromTemplate

func GetIdFromTemplate(template, subscription, rgName, name string) string

GetIdFromTemplate returns the ID of a resource based on the target template.

func GetIdFromTemplateWithParent

func GetIdFromTemplateWithParent(template, subscription, rgName, parent, name string) string

GetIdFromTemplateWithParent returns the ID of a resource based on the target template.

func GetObject

func GetObject[T any](wb shared.Whiteboard, key string) T

GetObject returns the object and attempts to cast it to the specified type.

func Join

func Join[K comparable, V any](m1, m2 map[K]V) map[K]V

Join merges maps by appending m2 to m1.

func ResourceGroupIdFromTemplate

func ResourceGroupIdFromTemplate(subscription, name string) string

ResourceGroupIdFromTemplate returns the id of a resource group.

func ToMap

func ToMap[T comparable, Y comparable](arr []T, f func(T) Y) map[Y]T

ToMap converts an array into a map. The key is provided by applying "f" to the array objects and the value are the objects.

Types

type Access

type Access interface {
	// DeletePublicIP deletes a public IP after disassociating it from the NAT Gateway if necessary.
	DeletePublicIP(ctx context.Context, rgName, pipName string) error
	// DisassociatePublicIP from the NAT Gateway it is attached.
	DisassociatePublicIP(ctx context.Context, rgName, natName, pipId string) error
	// DeleteNatGateway deletes a NAT Gateway after disassociating from all subnets attached to it.
	DeleteNatGateway(ctx context.Context, rgName, natName string) error
	// DisassociateNatGateway disassociates the NAT Gateway from attached subnets.
	DisassociateNatGateway(ctx context.Context, rgName, natName string) error
}

Access provides additional methods that are build on top of the azure client primitives.

type AvailabilitySetConfig

type AvailabilitySetConfig struct {
	AzureResourceMetadata
	// countFaultDomains is the fault domain count for the AV set.
	CountFaultDomains *int32
	// countFaultDomains is the update domain count for the AV set.
	CountUpdateDomains *int32
	Location           string
}

AvailabilitySetConfig contains the configuration for the shoot's availability set.

type AzureResourceKind

type AzureResourceKind string

AzureResourceKind is a string describing the resource type.

const (
	// KindAvailabilitySet is the kind for an availability set.
	KindAvailabilitySet AzureResourceKind = "Microsoft.Compute/availabilitySets"
	// KindNatGateway is the kind for a NAT Gateway.
	KindNatGateway AzureResourceKind = "Microsoft.Network/natGateways"
	// KindPublicIP is the kind for a public ip.
	KindPublicIP AzureResourceKind = "Microsoft.Network/publicIPAddresses"
	// KindResourceGroup is the kind for a resource group.
	KindResourceGroup AzureResourceKind = "Microsoft.Resources/resourceGroups"
	// KindRouteTable is the kind for a route table.
	KindRouteTable AzureResourceKind = "Microsoft.Network/routeTables"
	// KindSecurityGroup is the kind for a security group.
	KindSecurityGroup AzureResourceKind = "Microsoft.Network/networkSecurityGroups"
	// KindSubnet is the kind for a subnet
	KindSubnet AzureResourceKind = "Microsoft.Network/virtualNetworks/subnets"
	// KindVirtualNetwork is the kind for a virtual network.
	KindVirtualNetwork AzureResourceKind = "Microsoft.Network/virtualNetworks"
)

func (AzureResourceKind) String

func (a AzureResourceKind) String() string

type AzureResourceMetadata

type AzureResourceMetadata struct {
	ResourceGroup string
	Name          string
	Parent        string
	Kind          AzureResourceKind
}

AzureResourceMetadata is able to uniquely identify a resource.

type FlowContext

type FlowContext struct {
	*shared.BasicFlowContext
	// contains filtered or unexported fields
}

FlowContext is the reconciler for all managed resources

func NewFlowContext

func NewFlowContext(factory client.Factory,
	auth *internal.ClientAuth,
	logger logr.Logger,
	infra *extensionsv1alpha1.Infrastructure,
	cluster *controller.Cluster,
	state *azure.InfrastructureState,
	persistFunc PersistStateFunc,
) (*FlowContext, error)

NewFlowContext creates a new FlowContext.

func (*FlowContext) Delete

func (f *FlowContext) Delete(ctx context.Context) error

Delete deletes all resources managed by the reconciler

func (*FlowContext) DeleteResourceGroup

func (f *FlowContext) DeleteResourceGroup(ctx context.Context) error

DeleteResourceGroup deletes the shoot's resource group.

func (*FlowContext) DeleteSubnetsInForeignGroup

func (f *FlowContext) DeleteSubnetsInForeignGroup(ctx context.Context) error

DeleteSubnetsInForeignGroup deletes all managed subnets in a foreign resource group

func (*FlowContext) EnsureAvailabilitySet

func (f *FlowContext) EnsureAvailabilitySet(ctx context.Context) error

EnsureAvailabilitySet creates or updates an KindAvailabilitySet

func (*FlowContext) EnsureManagedIdentity

func (f *FlowContext) EnsureManagedIdentity(ctx context.Context) (err error)

EnsureManagedIdentity reconciles the managed identity specificed in the config.

func (*FlowContext) EnsureNatGateways

func (f *FlowContext) EnsureNatGateways(ctx context.Context) error

EnsureNatGateways reconciles all the NAT Gateways for the shoot.

func (*FlowContext) EnsurePublicIps

func (f *FlowContext) EnsurePublicIps(ctx context.Context) error

EnsurePublicIps reconciles the public IPs for the shoot.

func (*FlowContext) EnsureResourceGroup

func (f *FlowContext) EnsureResourceGroup(ctx context.Context) error

EnsureResourceGroup creates or updates the shoot's resource group.

func (*FlowContext) EnsureRouteTable

func (f *FlowContext) EnsureRouteTable(ctx context.Context) error

EnsureRouteTable creates or updates the route table

func (*FlowContext) EnsureSecurityGroup

func (f *FlowContext) EnsureSecurityGroup(ctx context.Context) error

EnsureSecurityGroup creates or updates a KindSecurityGroup

func (*FlowContext) EnsureSubnets

func (f *FlowContext) EnsureSubnets(ctx context.Context) error

EnsureSubnets creates or updates subnets.

func (*FlowContext) EnsureVirtualNetwork

func (f *FlowContext) EnsureVirtualNetwork(ctx context.Context) error

EnsureVirtualNetwork reconciles the shoot's virtual network. At the end of the step the VNet should be created or in the case of user-provided vnet verify that it exists.

func (*FlowContext) GetInfrastructureState

func (f *FlowContext) GetInfrastructureState() (*runtime.RawExtension, error)

GetInfrastructureState returns tha shoot's infrastructure state.

func (*FlowContext) GetInfrastructureStatus

func (f *FlowContext) GetInfrastructureStatus(_ context.Context) (*v1alpha1.InfrastructureStatus, error)

GetInfrastructureStatus returns the infrastructure status.

func (*FlowContext) Reconcile

Reconcile reconciles target infrastructure.

type InfrastructureAdapter

type InfrastructureAdapter struct {
	// contains filtered or unexported fields
}

InfrastructureAdapter contains information about the infrastructure resources that are either static, or otherwise inferable based on the shoot configuration. It acts as an intermediate step to make the configuration easier to process for the ensurer step.

func NewInfrastructureAdapter

NewInfrastructureAdapter returns a new instance of the InfrastructureAdapter.

func (*InfrastructureAdapter) AvailabilitySetConfig

func (ia *InfrastructureAdapter) AvailabilitySetConfig() *AvailabilitySetConfig

AvailabilitySetConfig returns the configuration for the shoot's availability set.

func (*InfrastructureAdapter) HasShootPrefix

func (ia *InfrastructureAdapter) HasShootPrefix(name *string) bool

HasShootPrefix returns true if the target resource's name is prefixed with the shoot's canonical name.

func (*InfrastructureAdapter) IpConfigs

func (ia *InfrastructureAdapter) IpConfigs() []PublicIPConfig

IpConfigs is the configuration for the desired public IPs.

func (*InfrastructureAdapter) ManagedIpConfigs

func (ia *InfrastructureAdapter) ManagedIpConfigs() map[string]PublicIPConfig

ManagedIpConfigs returns a filtered list of only the public IPs that are managed by gardener.

func (*InfrastructureAdapter) NatGatewayConfigs

func (ia *InfrastructureAdapter) NatGatewayConfigs() map[string]NatGatewayConfig

NatGatewayConfigs is the configuration for the desired NAT Gateways.

func (*InfrastructureAdapter) Region

func (ia *InfrastructureAdapter) Region() string

Region is the region of the shoot.

func (*InfrastructureAdapter) ResourceGroup

func (ia *InfrastructureAdapter) ResourceGroup() ResourceGroupConfig

ResourceGroup returns the configuration for the shoot's resource group.

func (*InfrastructureAdapter) ResourceGroupName

func (ia *InfrastructureAdapter) ResourceGroupName() string

ResourceGroupName returns the shoot's resource group's name.

func (*InfrastructureAdapter) RouteTableConfig

func (ia *InfrastructureAdapter) RouteTableConfig() RouteTableConfig

RouteTableConfig returns configuration for the shoot's route table.

func (*InfrastructureAdapter) SecurityGroupConfig

func (ia *InfrastructureAdapter) SecurityGroupConfig() SecurityGroupConfig

SecurityGroupConfig returns the configuration for our desired security group.

func (*InfrastructureAdapter) TechnicalName

func (ia *InfrastructureAdapter) TechnicalName() string

TechnicalName the cluster's "base" name. Used as a name or as a prefix by other resources.

func (*InfrastructureAdapter) VirtualNetworkConfig

func (ia *InfrastructureAdapter) VirtualNetworkConfig() VirtualNetworkConfig

VirtualNetworkConfig returns the virtual network configuration.

func (*InfrastructureAdapter) Zones

func (ia *InfrastructureAdapter) Zones() []ZoneConfig

Zones returns the target specification for the zones that need to be reconciled.

type Inventory

type Inventory struct {
	shared.Whiteboard
}

Inventory is responsible for managing a list of all infrastructure created objects.

func NewSimpleInventory

func NewSimpleInventory(wb shared.Whiteboard) *Inventory

NewSimpleInventory returns a new instance of Inventory.

func (*Inventory) ByKind

func (i *Inventory) ByKind(kind AzureResourceKind) []string

ByKind returns a list of all the IDs of stored objects of a particular kind.

func (*Inventory) Delete

func (i *Inventory) Delete(id string)

Delete deletes the item with ID==id from the inventory and any children it may have. That means that it deletes any ID prefixed by id, since azure IDs are hierarchical.

func (*Inventory) Get

func (i *Inventory) Get(id string) *arm.ResourceID

Get gets the item from the inventory.

func (*Inventory) Insert

func (i *Inventory) Insert(id string) error

Insert inserts the id to the inventory.

func (*Inventory) ToList

func (i *Inventory) ToList() []v1alpha1.AzureResource

ToList returns a list of v1alpha1 API objects that correspond to the current inventory list.

type NatGatewayConfig

type NatGatewayConfig struct {
	AzureResourceMetadata
	Location     string
	Zone         *string
	IdleTimeout  *int32
	PublicIPList []PublicIPConfig
}

NatGatewayConfig contains configuration for a NAT Gateway.

func (*NatGatewayConfig) ToProvider

func (nat *NatGatewayConfig) ToProvider(base *armnetwork.NatGateway) *armnetwork.NatGateway

ToProvider translates the config into the actual provider object.

type PersistStateFunc

type PersistStateFunc func(ctx context.Context, state *runtime.RawExtension) error

PersistStateFunc is a callback function that is used to persist the state during the reconciliation.

type PublicIPConfig

type PublicIPConfig struct {
	AzureResourceMetadata
	Zones    []string
	Location string
	Managed  bool
}

PublicIPConfig contains configuration for a public IP resource.

func (*PublicIPConfig) ToProvider

func (ip *PublicIPConfig) ToProvider(base *armnetwork.PublicIPAddress) *armnetwork.PublicIPAddress

ToProvider translates the config into the actual provider object.

type ResourceGroupConfig

type ResourceGroupConfig struct {
	AzureResourceMetadata
	Location string
}

ResourceGroupConfig contains the configuration for a resource group.

type RouteTableConfig

type RouteTableConfig struct {
	AzureResourceMetadata
	Location string
}

RouteTableConfig is the desired configuration for a route table.

func (*RouteTableConfig) ToProvider

func (r *RouteTableConfig) ToProvider(base *armnetwork.RouteTable) *armnetwork.RouteTable

ToProvider translates the config into the actual provider object.

type SecurityGroupConfig

type SecurityGroupConfig struct {
	AzureResourceMetadata
	Location string
}

SecurityGroupConfig is the desired configuration for a security group.

func (*SecurityGroupConfig) ToProvider

func (r *SecurityGroupConfig) ToProvider(base *armnetwork.SecurityGroup) *armnetwork.SecurityGroup

ToProvider translates the config into the actual provider object.

type SpecMismatchError

type SpecMismatchError struct {
	// AzureResourceMetadata describe uniquely an Azure resource
	AzureResourceMetadata
	// Field is the name of field that could not be reconciled.
	Field string
	// Expected is the value of the field that was expected.
	Expected any
	// Found is the actual value of Field.
	Found any
	// Info contains additional information or instruction to the user.
	Info *string
}

SpecMismatchError is an error to indicate that the reconciliation cannot proceed or the operation requested is not supported.

func NewSpecMismatchError

func NewSpecMismatchError(identifier AzureResourceMetadata, offender string, expected, found any, info *string) *SpecMismatchError

NewSpecMismatchError creates a TerminalSpecMismatch error.

func (*SpecMismatchError) Error

func (t *SpecMismatchError) Error() string

type SubnetConfig

type SubnetConfig struct {
	AzureResourceMetadata
	// contains filtered or unexported fields
}

SubnetConfig is the specification for a subnet

func (*SubnetConfig) ToProvider

func (s *SubnetConfig) ToProvider(base *armnetwork.Subnet) *armnetwork.Subnet

ToProvider translates the config into the actual provider object.

type TerminalConditionError

type TerminalConditionError struct {
	AzureResourceMetadata
	// contains filtered or unexported fields
}

TerminalConditionError is an error to mark cases where the reconciliation cannot continue.

func NewTerminalConditionError

func NewTerminalConditionError(identifier AzureResourceMetadata, err error) *TerminalConditionError

NewTerminalConditionError creates a TerminalConditionError.

func (*TerminalConditionError) Error

func (t *TerminalConditionError) Error() string

func (*TerminalConditionError) Unwrap

func (t *TerminalConditionError) Unwrap() error

type VirtualNetworkConfig

type VirtualNetworkConfig struct {
	AzureResourceMetadata
	// Managed is true if the vnet is managed by gardener.
	Managed bool
	// Location is a reference to the region.
	Location string
	// Cidr is the vnet's CIDR.
	CIDR *string
	// DDoSPlanID is the ID reference of the DDoS protection plan.
	DDoSPlanID *string
}

VirtualNetworkConfig contains configuration for the virtual network

func (*VirtualNetworkConfig) ToProvider

func (v *VirtualNetworkConfig) ToProvider(base *armnetwork.VirtualNetwork) *armnetwork.VirtualNetwork

ToProvider translates the config into the actual provider object.

type ZoneConfig

type ZoneConfig struct {
	Subnet     SubnetConfig
	NatGateway *NatGatewayConfig
	Migrated   bool
}

ZoneConfig is the specification for a zone.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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