func getMetadata()

in pkg/common/config.go [179:199]


func getMetadata(mode string) (project, location, cluster, nodename string) {
	project, _ = metadata.ProjectID()
	location = "local"
	switch mode {
	case ModeCluster:
		// For regional clusters, this will be a region rather than zone
		location, _ = metadata.InstanceAttributeValue("cluster-location")
	case ModeNode:
		location, _ = metadata.Zone()
	}
	cluster, _ = metadata.InstanceAttributeValue("cluster-name")
	// We would normally use metadata.InstanceName() but alas,
	// that is not available via the GKE metadata server
	var err error
	if nodename, err = metadata.Hostname(); err != nil {
		panic(fmt.Errorf("can't determine hostname from metadata server: %v\n", err))
	}
	// Remove domain portions
	nodename = strings.Split(nodename, ".")[0]
	return
}