func GetConfig()

in pkg/common/config.go [135:176]


func GetConfig() Config {
	mode := os.Getenv("PROBER_MODE")
	if mode == "" {
		mode = DefaultMode
	}
	nodeIP := os.Getenv("NODE_IP")
	if mode == ModeNode && nodeIP == "" {
		panic(errors.New("can't determine node IP for node mode"))
	}
	hostNetwork := os.Getenv("POD_IP") == nodeIP
	reportInterval, _ := time.ParseDuration(os.Getenv("REPORT_INTERVAL"))
	if reportInterval == 0 {
		reportInterval = DefaultReportInterval
	}

	// Enable Cluster Prober to probe the cluster-wide addon services like metrics-server, kube-dns and so on
	clusterProbes := os.Getenv("ENABLE_CLUSTER_PROBES") == "true"
	nodeProbes := os.Getenv("ENABLE_NODE_PROBES") == "true"
	connProbes := os.Getenv("ENABLE_CONNECTIVITY_PROBES") == "true"
	projectID, location, clusterName, nodeName := getMetadata(mode)

	pool := strings.TrimPrefix(nodeName, fmt.Sprintf("gke-%s-", clusterName))
	// Strip off ending node identifiers ("-13a25f43-chwu")
	pool = pool[:len(pool)-14]

	return Config{
		ProjectID:      projectID,
		Location:       location,
		Cluster:        clusterName,
		Mode:           mode,
		NodeName:       nodeName,
		NodeIP:         nodeIP,
		Nodepool:       pool,
		HostNetwork:    hostNetwork,
		ReportInterval: reportInterval,
		ConnProbes:     connProbes,
		ClusterProbes:  clusterProbes,
		NodeProbes:     nodeProbes,
		UserAgent:      UserAgent,
		MetricPrefix:   MetricPrefix,
	}
}