infracommon

package
v1.2.5 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2024 License: Apache-2.0 Imports: 37 Imported by: 0

README

edge-cloud-infra interface

mexos package contains a library abstraction of interacting with different underlying cloudlet platforms as well as different target cluster/app deployment variants

Below is a high level overview of the organization of the code here.

  • cloudletinfra.go - contains a set of functions to initialize and manage different cloudlet infra. The cloudlet we deal with is described in edgeproto.CloudletInfraProperties. It provides the abstraction for the different platforms(azure, gcp, dind, etc) on which mobiledgex cloudlet is deployed
  • appinst.go - add/delete app apis for the different underlying cluster types(helm, k8s, kvm, etc.)
  • cluster.go - abstraction for creation/deletion of cluster instances based on the platform(k8s, gcp, azure, swarm(future), etc)
  • const.go - common names and other constants. In particular it contains names for the supported edgeproto.ConfigFile.Kind strings. Currently supported:
    • AppConfigHemYaml - yaml file with helm chart customizations
    • AppConfigEnvYaml - yaml file with environment variables that need to be added to the application that will be deployed. For example if a deployment that is expected of this application is Kubernetes the structure of this yaml file is assumed to be an array of k8s.io/api/core/v1.EnvVar objects.

NOTE

This organization of the mexos package has grown organically, hence there is a fair bit of redundant code. Hence a refactor will eventually need to happen which will affect the content of this README

Documentation

Index

Constants

View Source
const (
	NumIPTypes = 2
	IndexIPV4  = 0
	IndexIPV6  = 1
)
View Source
const (
	IPTablesBin         = "iptables"
	IP6TablesBin        = "ip6tables"
	IPTablesSaveBin     = "iptables-save"
	IP6TablesSaveBin    = "ip6tables-save"
	IPTablesPersistCmd  = "iptables-save > /etc/iptables/rules.v4"
	IP6TablesPersistCmd = "ip6tables-save > /etc/iptables/rules.v6"
)
View Source
const ManifestTypeCommand = "command"
View Source
const NetplanFileNotFound = "netplan file not found"
View Source
const RemoteCidrAll = "0.0.0.0/0"
View Source
const RemoteCidrAllIPV6 = "::/0"
View Source
const RemoteCidrNone = "0.0.0.0/32"
View Source
const TrustPolicySecGrpNameLabel string = "trust-policy"

Variables

View Source
var ClientVersion = "SSH-2.0-mobiledgex-ssh-client-1.0"
View Source
var CloudletPlatformActive = "CloudletPlatformActive"
View Source
var DefaultConnectTimeout time.Duration = 30 * time.Second
View Source
var DefaultMetalLbNamespace = "metallb-system"

metalLb usually installs here but can be configured in a different NS

View Source
var DestIPUnspecified = IPs{}
View Source
var InfraCommonProps = map[string]*edgeproto.PropertyInfo{

	"MEX_EXTERNAL_IP_MAP": &edgeproto.PropertyInfo{
		Name:        "External IP Map",
		Description: "External IP Map",
	},
	"FLAVOR_MATCH_PATTERN": &edgeproto.PropertyInfo{
		Name:        "Flavor Match Pattern",
		Description: "Flavors matching this pattern will be used by Cloudlet to bringup VMs",
		Value:       ".*",
	},
	"SKIP_INSTALL_RESOURCE_TRACKER": &edgeproto.PropertyInfo{
		Name:        "Skip Install Resource Tracker",
		Description: "If set to true, the resource tracker is not installed to save time. For test only",
		Internal:    true,
	},
	"MEX_CRM_GATEWAY_ADDR": {
		Name:        "CRM Gateway Address",
		Description: "Required if infra API endpoint is completely isolated from external network",
	},
	"MEX_PLATFORM_STATS_MAX_CACHE_TIME": {
		Name:        "Platform Stats Max Cache Time",
		Description: "Maximum time to used cached platform stats if nothing changed, in seconds",
		Internal:    true,
		Value:       "3600",
	},
	"MEX_SHARED_ROOTLB_NAME": {
		Name:        "Shared rootLB name",
		Description: "Used for backwards compatibility if appDnsRoot changes",
	},
}

Cloudlet Infra Common Properties

View Source
var MetalLbAddressPool = `` /* 332-byte string literal not displayed */
View Source
var NoDnsOverride = ""
View Source
var SSHOpts = []string{"StrictHostKeyChecking=no", "UserKnownHostsFile=/dev/null", "LogLevel=ERROR"}
View Source
var SSHUser = "ubuntu"

Functions

func AddDefaultIptablesRules

func AddDefaultIptablesRules(ctx context.Context, client ssh.Client, ipversion IPVersion) error

AddDefaultIptablesRules adds the default set of rules which are always needed

func AddIngressIptablesRules

func AddIngressIptablesRules(ctx context.Context, client ssh.Client, label string, cidrs, destIp IPs, ports []dme.AppPort) error

AddIngressIptablesRules adds rules using a CIDR and AppPorts as input

func AddIptablesRules

func AddIptablesRules(ctx context.Context, client ssh.Client, label string, rules *FirewallRules) error

AddIptablesRules adds a set of rules

func BackupKubeconfig

func BackupKubeconfig(ctx context.Context, client ssh.Client)

func ConfigureMetalLb

func ConfigureMetalLb(ctx context.Context, client ssh.Client, clusterInst *edgeproto.ClusterInst, addressRanges []string) error

func CopyFile

func CopyFile(src string, dst string) error

func CopyKubeConfig

func CopyKubeConfig(ctx context.Context, rootLBClient ssh.Client, clusterInst *edgeproto.ClusterInst, rootLBName, masterIP string) error

CopyKubeConfig copies over kubeconfig from the cluster

func CreateCloudletNode

func CreateCloudletNode(ctx context.Context, config *confignode.ConfigureNodeVars, accessApi platform.AccessApi) error

CreateCloudletNode requests the Controller via the accessApi to register a new cloudlet node, and stores the new password into ConfigureNodeVars.

func CreateClusterConfigMap

func CreateClusterConfigMap(ctx context.Context, client ssh.Client, clusterInst *edgeproto.ClusterInst) error

ConfigMap of cluster instance details such as cluster name, cloudlet name, and operator name

func CreateDockerRegistrySecret

func CreateDockerRegistrySecret(ctx context.Context, client ssh.Client, kconf string, imagePath string, authApi cloudcommon.RegistryAuthApi, names *k8smgmt.KubeNames, existingCreds *cloudcommon.RegistryAuth) error

func DefaultKubeconfig

func DefaultKubeconfig() string

func DeleteDataFromVault

func DeleteDataFromVault(config *vault.Config, path string) error

func DeleteDockerRegistrySecret

func DeleteDockerRegistrySecret(ctx context.Context, client ssh.Client, kconf string, imagePath string, authApi cloudcommon.RegistryAuthApi, names *k8smgmt.KubeNames, existingCreds *cloudcommon.RegistryAuth) error

func DeleteIptablesRules

func DeleteIptablesRules(ctx context.Context, client ssh.Client, label string, rules *FirewallRules) error

DeleteIptablesRules deletes a set of rules

func DoIptablesCommand

func DoIptablesCommand(ctx context.Context, client ssh.Client, rule string, ruleExists bool, action *InterfaceActionsOp, ipversion IPVersion) error

DoIptablesCommand runs an iptables add or delete conditionally based on whether the entry already exists or not

func ExecTemplate

func ExecTemplate(templateName, templateString string, templateData interface{}) (*bytes.Buffer, error)

func FormatDuration

func FormatDuration(dur time.Duration, digIdx int) string

round the given field denoted by digIdx, we mostly want seconds rounded to two digits

func GenerateNetworkFileDetailsForIP

func GenerateNetworkFileDetailsForIP(ctx context.Context, portName string, ifName string, ipAddr string, maskbits uint32, ipv6Addr string) (string, string, string, error)

GenerateNetworkFileDetailsForIP returns interfaceFileName, fileMatchPattern, contents based on whether netplan is enabled Deprecated: should instead use GetNetworkConfig

func GetAppWhitelistRulesLabel

func GetAppWhitelistRulesLabel(app *edgeproto.App) string

func GetDockerCrtFile

func GetDockerCrtFile(crtFilePath string) (string, error)

func GetEnvVarsFromVault

func GetEnvVarsFromVault(ctx context.Context, config *vault.Config, path string) (map[string]string, error)

GetEnvVarsFromVault is deprecated, use accessvars.GetCloudletAccessVars instead.

func GetHTTPFile

func GetHTTPFile(ctx context.Context, uri string) ([]byte, error)

func GetMacAddrToInterfaceNames

func GetMacAddrToInterfaceNames(ctx context.Context, client ssh.Client) (map[string]string, map[string]string, error)

func GetNetplanFilename

func GetNetplanFilename(portName string) string

func GetPlatformConfig

func GetPlatformConfig(cloudlet *edgeproto.Cloudlet, pfConfig *edgeproto.PlatformConfig, pfInitConfig *pf.PlatformInitConfig) *pf.PlatformConfig

GetPlatformConfig builds a platform.PlatformConfig from a cloudlet and an edgeproto.PlatformConfig

func GetReqErr

func GetReqErr(reqBody io.ReadCloser) error

for reading errors from an http response

func GetServerSecurityGroupName

func GetServerSecurityGroupName(serverName string) string

GetServerSecurityGroupName gets the secgrp name based on the server name

func GetSvcExternalIpOrHost

func GetSvcExternalIpOrHost(ctx context.Context, client ssh.Client, kubeNames *k8smgmt.KubeNames, name string) (string, string, error)

GetSvcExternalIpOrHost returns ipaddr, hostname. Either the IP or the DNS will be blank depending on whether the service has an IP address or a name.

func GetUniqueLoopbackIp

func GetUniqueLoopbackIp(ctx context.Context, ports []dme.AppPort) string

GetUniqueLoopbackIp returns an IP on the loopback interface, which is anything in the 127.0.0.0/8 subnet. The purpose is to have a unique loopback IP which can be used for the envoy metrics port. The IP returned is derived from the highest number app port as follows First octet: 127 Second octet: 1 if highest port is TCP, 2 if highest port is UDP Third and fourth octets: highest port number

func GetUrlInfo

func GetUrlInfo(ctx context.Context, accessApi platform.AccessApi, fileUrlPath string) (time.Time, string, error)

func GetVaultCloudletCommonPath

func GetVaultCloudletCommonPath(filePath string) string

func GetVaultDataString

func GetVaultDataString(ctx context.Context, config *vault.Config, path string) ([]byte, error)

Get data from Vault as a string

func GetVaultDataToFile

func GetVaultDataToFile(config *vault.Config, path, fileName string) error

func HandlePlatformSwitchToActive

func HandlePlatformSwitchToActive(ctx context.Context,
	cloudletKey *edgeproto.CloudletKey,
	caches *pf.Caches,
	clusterInstCleanupFunc func(ctx context.Context, clusterInst *edgeproto.ClusterInst, updateCallback edgeproto.CacheUpdateCallback) error,
	appInstCleanupFunc func(ctx context.Context, clusterInst *edgeproto.ClusterInst, app *edgeproto.App, appInst *edgeproto.AppInst, updateCallback edgeproto.CacheUpdateCallback) error)

HandlePlatformSwitchToActive handles the case when a formerly standby CRM becomes active, including in-progress provisioning requests which must be cleaned using the provided functions

func IPIndexOf

func IPIndexOf(ipType IPVersion) int

func IncrIP

func IncrIP(ip net.IP)

func InstallAndConfigMetalLbIfNotInstalled

func InstallAndConfigMetalLbIfNotInstalled(ctx context.Context, client ssh.Client, clusterInst *edgeproto.ClusterInst, addressRanges []string) error

func InstallMetalLb

func InstallMetalLb(ctx context.Context, client ssh.Client, clusterInst *edgeproto.ClusterInst) error

func InternEnv

func InternEnv(envs map[string]string) error

func IsMetalLbInstalled

func IsMetalLbInstalled(ctx context.Context, client ssh.Client, clusterInst *edgeproto.ClusterInst, metalLbNameSpace string) (bool, error)

func KubePatchServiceIP

func KubePatchServiceIP(ctx context.Context, client ssh.Client, kubeNames *k8smgmt.KubeNames, servicename, ipaddr, ipv6Addr, namespace string) error

KubePatchServiceIP updates the service to have the given external ip. This is done locally and not thru an ssh client

func ParseIpRanges

func ParseIpRanges(ipranges string) ([]string, error)

ParseIpRanges takes a list of comma-separated IP ranges such as 139.178.83.27/29-139.178.83.30/29,139.178.87.10/29-139.178.87.14/29 and returns a slice of all the IP addresses

func PersistIptablesRules

func PersistIptablesRules(ctx context.Context, client ssh.Client, ipversion IPVersion) error

func PutDataToVault

func PutDataToVault(config *vault.Config, path string, data map[string]interface{}) error

func RemoveIngressIptablesRules

func RemoveIngressIptablesRules(ctx context.Context, client ssh.Client, label string, cidrs, destIP IPs, ports []dme.AppPort) error

RemoveIngressIptablesRules removes rules using a CIDR and AppPorts as input

func RemoveRulesForLabel

func RemoveRulesForLabel(ctx context.Context, client ssh.Client, label string) error

func SCPFilePath

func SCPFilePath(sshClient ssh.Client, srcPath, dstPath string) error

func ServerIsNetplanEnabled

func ServerIsNetplanEnabled(ctx context.Context, client ssh.Client) bool

The base image currently only supports netplan.

func SetEdgeboxMode

func SetEdgeboxMode(mode bool)

func SetTestMode

func SetTestMode(tMode bool)

func Sh

func Sh(envVars map[string]string) *sh.Session

func VerifyMetalLbRunning

func VerifyMetalLbRunning(ctx context.Context, client ssh.Client, clusterInst *edgeproto.ClusterInst, metalLbNameSpace string) error

func WriteTemplateFile

func WriteTemplateFile(filename string, buf *bytes.Buffer) error

Types

type CloudletManifest

type CloudletManifest struct {
	ManifestItems []CloudletManifestItem
}

func (*CloudletManifest) AddItem

func (m *CloudletManifest) AddItem(title string, contentType ManifestContentType, contentSubType ManifestContentSubType, content string)

func (*CloudletManifest) AddSubItem

func (m *CloudletManifest) AddSubItem(title string, contentType ManifestContentType, contentSubType ManifestContentSubType, content string)

func (*CloudletManifest) ToString

func (m *CloudletManifest) ToString() (string, error)

type CloudletManifestItem

type CloudletManifestItem struct {
	Id             uint32
	Title          string
	ContentType    ManifestContentType
	ContentSubType ManifestContentSubType
	Content        string
	SubManifests   []CloudletManifestItem
}

type CommonEmbedded

type CommonEmbedded struct{}

func (*CommonEmbedded) GetVersionProperties

func (c *CommonEmbedded) GetVersionProperties(ctx context.Context) map[string]string

type CommonPlatform

type CommonPlatform struct {
	Properties        InfraProperties
	PlatformConfig    *pf.PlatformConfig
	MappedExternalIPs map[string]string
	DeploymentTag     string
}

func (*CommonPlatform) ActivateFQDN

func (c *CommonPlatform) ActivateFQDN(ctx context.Context, fqdn, addr string, ipversion IPVersion) error

ActivateFQDN updates and ensures Fqdn is registered properly

func (*CommonPlatform) AddProxySecurityRulesAndPatchDNS

func (c *CommonPlatform) AddProxySecurityRulesAndPatchDNS(ctx context.Context, client ssh.Client, kubeNames *k8smgmt.KubeNames, app *edgeproto.App, appInst *edgeproto.AppInst, getDnsSvcAction GetDnsSvcActionFunc, whiteListAdd WhiteListFunc, wlParams *WhiteListParams, proxyConfig *proxy.ProxyConfig, ops ProxyDnsSecOpts, proxyops ...proxy.Op) error

AddProxySecurityRulesAndPatchDNS Adds security rules and dns records in parallel

func (*CommonPlatform) CreateAppDNSAndPatchKubeSvc

func (c *CommonPlatform) CreateAppDNSAndPatchKubeSvc(ctx context.Context, client ssh.Client, kubeNames *k8smgmt.KubeNames, overrideDns string, getSvcAction GetDnsSvcActionFunc) error

Register DNS entries for externally visible services. The passed in GetDnsSvcActionFunc function should provide this function with the actions to perform for each service, since different platforms will use different IPs and patching.

func (*CommonPlatform) DeleteAppDNS

func (c *CommonPlatform) DeleteAppDNS(ctx context.Context, client ssh.Client, kubeNames *k8smgmt.KubeNames, overrideDns string) error

func (*CommonPlatform) DeleteCloudletFirewallRules

func (c *CommonPlatform) DeleteCloudletFirewallRules(ctx context.Context, client ssh.Client) error

DeleteCloudletFirewallRules deletes cloudlet-wide rules based on properties

func (*CommonPlatform) DeleteDNSRecords

func (c *CommonPlatform) DeleteDNSRecords(ctx context.Context, fqdn string) error

func (*CommonPlatform) DeleteIptableRulesForCloudletWideLabel

func (c *CommonPlatform) DeleteIptableRulesForCloudletWideLabel(ctx context.Context, client ssh.Client) error

func (*CommonPlatform) DeleteProxySecurityGroupRules

func (c *CommonPlatform) DeleteProxySecurityGroupRules(ctx context.Context, client ssh.Client, proxyName string, whiteListDel WhiteListFunc, wlParams *WhiteListParams) error

func (*CommonPlatform) GetCloudletDNSZone

func (c *CommonPlatform) GetCloudletDNSZone() string

func (*CommonPlatform) GetMappedExternalIP

func (c *CommonPlatform) GetMappedExternalIP(ip string) string

GetMappedExternalIP returns the IP that the input IP should be mapped to. This is used for environments which used NATted external IPs

func (*CommonPlatform) GetSSHClientFromIPAddr

func (cp *CommonPlatform) GetSSHClientFromIPAddr(ctx context.Context, ipaddr string, ops ...pc.SSHClientOp) (ssh.Client, error)

GetSSHClientFromIPAddr returns ssh client handle for the given IP.

func (*CommonPlatform) InitInfraCommon

func (c *CommonPlatform) InitInfraCommon(ctx context.Context, platformConfig *pf.PlatformConfig, platformSpecificProps map[string]*edgeproto.PropertyInfo, ops ...InitOp) error

func (*CommonPlatform) ValidateExternalIPMapping

func (c *CommonPlatform) ValidateExternalIPMapping(ctx context.Context, ip string) error

ValidateExternalIPMapping checjs mapped IPs are defined but there is no entry for this particular IP, then it may indicate a provisioning error in which the external range is not matched with the internal range

type DnsSvcAction

type DnsSvcAction struct {
	// if non-empty string, DNS entry will be created against this IP
	// for the service. The DNS name is derived from App parameters.
	ExternalIP string
	// IPv6 external IP
	ExternalIPV6 string
	// AWS uses hostname for service
	Hostname string
	// True to patch the kubernetes service with the Patch IP.
	PatchKube bool
	// IP to patch the kubernetes service with. If empty, will use
	// ExternalIP instead.
	PatchIP string
	// IPv6 to patch the kubernetes service with. If empty, will use
	// ExternalIPV6 instead.
	PatchIPV6 string
	// Should we add DNS, or not
	AddDNS bool
}

type EnvData

type EnvData struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

type ErrorResp

type ErrorResp struct {
	Error  string   `json:"error,omitempty"`
	Errors []string `json:"errors,omitempty"`
}

type FirewallRule

type FirewallRule struct {
	IPVersion    IPVersion
	Protocol     string
	RemoteCidr   string
	PortRange    string
	InterfaceIn  string
	InterfaceOut string
	PortEndpoint PortSourceOrDestChoice
	Conntrack    string
	DestIP       string
}

type FirewallRules

type FirewallRules struct {
	EgressRules  []FirewallRule
	IngressRules []FirewallRule
}

func GetFirewallRulesFromAppPorts

func GetFirewallRulesFromAppPorts(ctx context.Context, cidr string, destIp string, ports []dme.AppPort, ipversion IPVersion) (*FirewallRules, error)

GetFirewallRulesFromAppPorts accepts a CIDR and a set of AppPorts and converts to a set of rules

type GetDnsSvcActionFunc

type GetDnsSvcActionFunc func(svc v1.Service) (*DnsSvcAction, error)

Callback function for callers to control the behavior of DNS changes.

type IPVersion

type IPVersion string
const (
	IPV4 IPVersion = "ipv4"
	IPV6 IPVersion = "ipv6"
)

func GetAddrIPVersion

func GetAddrIPVersion(ctx context.Context, addr string) (IPVersion, error)

func GetCIDRIPVersion

func GetCIDRIPVersion(ctx context.Context, cidr string) (IPVersion, error)

type IPs

type IPs [NumIPTypes]string

IPs is a fixed length array of IP addresses based on type.

func GetAllowedClientCIDR

func GetAllowedClientCIDR() IPs

func GetExternalPublicAddr

func GetExternalPublicAddr(ctx context.Context, types ...IPVersion) (IPs, error)

GetExternalPublicAddr gets the externally visible public IP address

func GetIPAddressFromNetplan

func GetIPAddressFromNetplan(ctx context.Context, client ssh.Client, portName string) (IPs, error)

GetIPAddressFromNetplan returns the ipv4 and ipv6 addr Deprecated: should instead use GetNetworkConfig.

func (IPs) IPV4

func (s IPs) IPV4() string

func (IPs) IPV6

func (s IPs) IPV6() string

func (IPs) IsSet

func (s IPs) IsSet() bool

func (IPs) Matches

func (s IPs) Matches(z IPs) bool

func (IPs) NetIPs

func (s IPs) NetIPs() (NetIPs, error)

func (IPs) Sanitize

func (s IPs) Sanitize(sanitizeFunc func(string) string) IPs

type ImageCategoryType

type ImageCategoryType string
const ImageCategoryPlatform ImageCategoryType = "platform"
const ImageCategoryVmApp ImageCategoryType = "vmapp"

type ImageInfo

type ImageInfo struct {
	Md5sum          string
	LocalImageName  string
	SourceImageTime time.Time
	OsType          edgeproto.VmAppOsType
	ImageType       edgeproto.ImageType
	ImagePath       string
	ImageCategory   ImageCategoryType
	Flavor          string
	VmName          string // for use only if the image is to be imported directly into a VM
}

type InfraProperties

type InfraProperties struct {
	Properties map[string]*edgeproto.PropertyInfo
	Mux        sync.Mutex // protects local properties cache which only changes on init
}

func (*InfraProperties) GetCloudletCRMGatewayIPAndPort

func (ip *InfraProperties) GetCloudletCRMGatewayIPAndPort() (string, int)

func (*InfraProperties) GetPlatformStatsMaxCacheTime

func (ip *InfraProperties) GetPlatformStatsMaxCacheTime() (uint64, error)

func (*InfraProperties) GetValue

func (p *InfraProperties) GetValue(key string) (string, bool)

func (*InfraProperties) Init

func (p *InfraProperties) Init()

func (*InfraProperties) SetProperties

func (p *InfraProperties) SetProperties(props map[string]*edgeproto.PropertyInfo)

func (*InfraProperties) SetPropsFromVars

func (p *InfraProperties) SetPropsFromVars(ctx context.Context, vars map[string]string)

func (*InfraProperties) SetValue

func (p *InfraProperties) SetValue(key, value string)

func (*InfraProperties) UpdatePropsFromVars

func (p *InfraProperties) UpdatePropsFromVars(ctx context.Context, vars map[string]string)

type InitOp

type InitOp func(opts *InitOptions)

type InitOptions

type InitOptions struct {
}

type InterfaceActionsOp

type InterfaceActionsOp struct {
	AddInterface    bool
	DeleteInterface bool
	CreateIptables  bool
	DeleteIptables  bool
}

type IptablesChanges

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

func (*IptablesChanges) PersistRules

func (s *IptablesChanges) PersistRules(ctx context.Context, client ssh.Client) error

type IptablesRules

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

type ManifestContentSubType

type ManifestContentSubType string
const ManifestSubTypeBash ManifestContentSubType = "bash"
const ManifestSubTypeNone ManifestContentSubType = "none"
const ManifestSubTypePython ManifestContentSubType = "python"
const ManifestSubTypeYaml ManifestContentSubType = "yaml"

type ManifestContentType

type ManifestContentType string
const ManifestTypeCode ManifestContentType = "code"
const ManifestTypeNone ManifestContentType = "none"
const ManifestTypeURL ManifestContentType = "url"

type MetalConfigmapParams

type MetalConfigmapParams struct {
	AddressRanges []string
}

type NetIPs

type NetIPs [NumIPTypes]netip.Addr

NetIPs is a fixed length array of IP addresses based on type.

type NetplanDevice

type NetplanDevice struct {
	Addresses   []string           `yaml:"addresses,omitempty"`
	DHCP4       bool               `yaml:"dhcp4,omitempty"`
	DHCP6       bool               `yaml:"dhcp6,omitempty"`
	IPV6MTU     int                `yaml:"ipv6-mtu,omitempty"`
	IPV6Privacy bool               `yaml:"ipv6-privacy,omitempty"`
	LinkLocal   []string           `yaml:"link-local,omitempty"`
	Nameservers NetplanNameservers `yaml:"nameservers,omitempty"`
	MTU         int                `yaml:"mtu,omitempty"`
	Routes      []*NetplanRoute    `yaml:"routes,omitempty"`
}

type NetplanDeviceMatch

type NetplanDeviceMatch struct {
	Name       string   `yaml:"name,omitempty"`
	MACAddress string   `yaml:"macaddress,omitempty"`
	Driver     []string `yaml:"driver,omitempty"`
}

type NetplanEthernet

type NetplanEthernet struct {
	NetplanDevice `yaml:",inline"`
	Match         NetplanDeviceMatch `yaml:"match,omitempty"`
}

type NetplanFile

type NetplanFile struct {
	FileName     string
	Netplan      NetplanInfo
	FileContents string
}

type NetplanInfo

type NetplanInfo struct {
	Network NetplanNetwork `yaml:"network"`
}

type NetplanNameservers

type NetplanNameservers struct {
	Addresses []string `yaml:"addresses,omitempty"`
	Search    []string `yaml:"search,omitempty"`
}

type NetplanNetwork

type NetplanNetwork struct {
	Version   int                         `yaml:"version"`
	Ethernets map[string]*NetplanEthernet `yaml:"ethernets,omitempty"`
}

type NetplanRoute

type NetplanRoute struct {
	From   string `yaml:"from,omitempty"`
	To     string `yaml:"to,omitempty"`
	Via    string `yaml:"via,omitempty"`
	OnLink bool   `yaml:"on-link,omitempty"`
	Metric int    `yaml:"metric,omitempty"`
	Type   string `yaml:"type,omitempty"`
	Scope  string `yaml:"scope,omitempty"`
	MTU    int    `yaml:"mtu,omitempty"`
}

func (*NetplanRoute) ChangeDefaultToIPSpecific

func (s *NetplanRoute) ChangeDefaultToIPSpecific() error

ChangeDefaultToIPSpecific changes the "to" field if it is set to "default" to the IP-specific default route, i.e. 0.0.0.0/0 for IPv4 or ::/0 for IPv6. If the route is the default for both IPv4 and IPv6, it should be "default", but if the system has separate gateways for IPv4 and IPv6, neither should use "default", but instead should use the IP-specific CIDRs.

type NetworkConfig

type NetworkConfig struct {
	NetplanFiles []*NetplanFile
	// contains filtered or unexported fields
}

func GetNetworkConfig

func GetNetworkConfig(ctx context.Context, client ssh.Client) (*NetworkConfig, error)

GetNetworkConfig reads the network configuration from all netplan files. Interfaces may be defined in any netplan file. Ubuntu cloud-init puts all interfaces it detects into 50-network-config.yaml, and we have traditionally put additional port interfaces into separate files. However, depending upon if cloud-init detects ports or not, additional ports may also end up in 50-network-config.yaml. So we need to read all netplan yaml files to really understand the network config.

func (*NetworkConfig) Apply

func (s *NetworkConfig) Apply(ctx context.Context, client ssh.Client) (bool, error)

Apply writes changed netplan files to the system and applies the changes, if any. It returns true if there were any changes applied. Note that file changes are based on file content string comparison, so formatting, comments, etc in the initial cloud-init config file may trigger a no-op apply. "netplan apply" itself also only applies what it determines as network configuration changes, so there is no harm in this.

func (*NetworkConfig) GetInterface

func (s *NetworkConfig) GetInterface(ifaceName string, portName string) *NetplanEthernet

GetInterface returns the ethernet object for the given interface name. The object is created if it does not already exist, and is put into a new netplan file whose name is derived from the portName.

type PortSourceOrDestChoice

type PortSourceOrDestChoice string

PortSourceOrDestChoice indicates whether the port(s) are the source or destination ports

const DestPort PortSourceOrDestChoice = "dport"
const SourcePort PortSourceOrDestChoice = "sport"

type ProxyDnsSecOpts

type ProxyDnsSecOpts struct {
	AddProxy              bool
	AddDnsAndPatchKubeSvc bool
	AddSecurityRules      bool
	ProxyNamePrefix       string
}

type VaultData

type VaultData struct {
	Data string `json:"data"`
}

type VaultEnvData

type VaultEnvData struct {
	Env []EnvData `json:"env"`
}

type WhiteListFunc

type WhiteListFunc func(ctx context.Context, client ssh.Client, wlParams *WhiteListParams) error

type WhiteListParams

type WhiteListParams struct {
	SecGrpName  string
	ServerName  string
	Label       string
	AllowedCIDR IPs
	DestIP      IPs
	Ports       []dme.AppPort
}

Jump to

Keyboard shortcuts

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