func getProjectAndZone()

in pkg/cloud_provider/lustre/cloud.go [149:179]


func getProjectAndZone(ctx context.Context, config *ConfigFile) (string, string, error) {
	var err error
	var zone string
	if config == nil || config.Global.Zone == "" {
		zone, err = metadata.ZoneWithContext(ctx)
		if err != nil {
			return "", "", err
		}
		klog.Infof("Using GCP zone from the Metadata server: %q", zone)
	} else {
		zone = config.Global.Zone
		klog.Infof("Using GCP zone from the local GCE cloud provider config file: %q", zone)
	}

	var projectID string
	if config == nil || config.Global.ProjectID == "" {
		// Project ID is not available from the local GCE cloud provider config file.
		// This could happen if the driver is not running in the master VM.
		// Defaulting to project ID from the Metadata server.
		projectID, err = metadata.ProjectIDWithContext(ctx)
		if err != nil {
			return "", "", err
		}
		klog.Infof("Using GCP project ID %q from the Metadata server", projectID)
	} else {
		projectID = config.Global.ProjectID
		klog.Infof("Using GCP project ID %q from the local GCE cloud provider config file: %#v", projectID, config)
	}

	return projectID, zone, nil
}