platform

package
v0.0.0-...-6c25587 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: Apache-2.0 Imports: 22 Imported by: 2

Documentation

Index

Constants

View Source
const (
	AWSRegion           = "aws_region"
	AWSAvailabilityZone = "aws_availability_zone"
	AWSInstanceID       = "aws_instance_id"
)
View Source
const (
	AzureMetadataEndpoint  = "http://169.254.169.254"
	AzureInstanceURL       = AzureMetadataEndpoint + "/metadata/instance"
	AzureDefaultAPIVersion = "2019-08-15"
	SysVendorPath          = "/sys/class/dmi/id/sys_vendor"
	MicrosoftIdentifier    = "Microsoft Corporation"
)
View Source
const (
	GCPProject           = "gcp_project"
	GCPProjectNumber     = "gcp_project_number"
	GCPCluster           = "gcp_gke_cluster_name"
	GCPClusterURL        = "gcp_gke_cluster_url"
	GCPLocation          = "gcp_location"
	GCEInstance          = "gcp_gce_instance"
	GCEInstanceID        = "gcp_gce_instance_id"
	GCEInstanceTemplate  = "gcp_gce_instance_template"
	GCEInstanceCreatedBy = "gcp_gce_instance_created_by"
	GCPQuotaProject      = "gcp_quota_project"
	GCPZone              = "gcp_zone"
)
View Source
const ComputeReadonlyScope = "https://www.googleapis.com/auth/compute.readonly"
View Source
const (
	KubernetesServiceHost = "KUBERNETES_SERVICE_HOST"
)

Variables

View Source
var CloudPlatform = env.Register("CLOUD_PLATFORM", "", "Cloud Platform on which proxy is running, if not specified, "+
	"Istio will try to discover the platform. Valid platform values are aws, azure, gcp, none").Get()
View Source
var GCPStaticMetadata = func() map[string]string {
	gcpm := env.Register("GCP_METADATA", "", "Pipe separated GCP metadata, schemed as PROJECT_ID|PROJECT_NUMBER|CLUSTER_NAME|CLUSTER_ZONE").Get()
	quota := env.Register("GCP_QUOTA_PROJECT", "", "Allows specification of a quota project to be used in requests to GCP APIs.").Get()
	zone := env.Register("GCP_ZONE", "", "GCP Zone where the workload is running on.").Get()
	if len(gcpm) == 0 {
		return map[string]string{}
	}
	md := map[string]string{}
	parts := strings.Split(gcpm, "|")
	if len(parts) == 4 {
		md[GCPProject] = parts[0]
		md[GCPProjectNumber] = parts[1]
		md[GCPCluster] = parts[2]
		md[GCPLocation] = parts[3]
	}

	if quota != "" {
		md[GCPQuotaProject] = quota
	}

	if clusterURL, err := constructGKEClusterURL(md); err == nil {
		md[GCPClusterURL] = clusterURL
	}

	if zone != "" {
		md[GCPZone] = zone
	}
	return md
}()

GCPStaticMetadata holds the statically defined GCP metadata

Functions

func IsAWS

func IsAWS(ipv6 bool) bool

IsAWS returns whether the platform for bootstrapping is Amazon Web Services.

func IsAzure

func IsAzure() bool

IsAzure returns whether the platform for bootstrapping is Azure Checks the system vendor file (similar to https://github.com/banzaicloud/satellite/blob/master/providers/azure.go)

func IsGCP

func IsGCP() bool

IsGCP returns whether or not the platform for bootstrapping is Google Cloud Platform.

Types

type Environment

type Environment interface {
	// Metadata returns a collection of environmental metadata, structured
	// as a map for metadata names to values. An example for GCP would be a
	// mapping from "gcp_project" to "2344534543". Keys should be prefixed
	// by the short name for the platform (example: "gcp_").
	Metadata() map[string]string

	// Locality returns the run location for the bootstrap transformed from the
	// platform-specific representation into the Envoy Locality schema.
	Locality() *core.Locality

	// Labels returns a collection of labels that exist on the underlying
	// instance, structured as a map for label name to values.
	Labels() map[string]string

	// IsKubernetes determines if running on Kubernetes
	IsKubernetes() bool
}

Environment provides information for the platform on which the bootstrapping is taking place.

func Discover

func Discover(ipv6 bool) Environment

Discover attempts to discover the host platform, defaulting to `Unknown` if a platform cannot be discovered.

func DiscoverWithTimeout

func DiscoverWithTimeout(timeout time.Duration, ipv6 bool) Environment

DiscoverWithTimeout attempts to discover the host platform, defaulting to `Unknown` after the provided timeout.

func NewAWS

func NewAWS(ipv6 bool) Environment

NewAWS returns a platform environment customized for AWS. Metadata returned by the AWS Environment is taken link-local address running on each node.

func NewAzure

func NewAzure() Environment

NewAzure returns a platform environment for Azure Default prefix is azure_

func NewAzureWithPrefix

func NewAzureWithPrefix(prefix string) Environment

func NewGCP

func NewGCP() Environment

NewGCP returns a platform environment customized for Google Cloud Platform. Metadata returned by the GCP Environment is taken from the GCE metadata service.

type GcpInstance

type GcpInstance struct {
	// Labels: Labels to apply to this instance.
	Labels map[string]string `json:"labels,omitempty"`
}

GcpInstance the instances response. Only contains fields we care about, rest are ignored

type Unknown

type Unknown struct{}

Unknown provides a default platform environment for cases in which the platform on which the bootstrapping is taking place cannot be determined.

func (*Unknown) IsKubernetes

func (*Unknown) IsKubernetes() bool

IsKubernetes is true to avoid label collisions

func (*Unknown) Labels

func (*Unknown) Labels() map[string]string

Labels returns an empty map.

func (*Unknown) Locality

func (*Unknown) Locality() *core.Locality

Locality returns an empty core.Locality struct.

func (*Unknown) Metadata

func (*Unknown) Metadata() map[string]string

Metadata returns an empty map.

Jump to

Keyboard shortcuts

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