Repository: grpc/grpc-go
File: internal/xds/xdsclient/pool.go (Go)

Code before:
		return config, nil
	}
	return p.getBootstrapConfiguration()
}

// NewClientWithConfig returns an xDS client with the given name from the pool.
// If the client doesn't already exist, it creates a new xDS client using the
// provided config and adds it to the pool. The provided config takes precedence
// over any config passed during pool creation. This should be used when a
// non-default config is required. If the provided config is nil, it attempts
// to load the configuration from the environment variables.
//
// The second return value represents a close function which the caller is
// expected to invoke once they are done using the client.  It is safe for the
// caller to invoke this close function multiple times.
func (p *Pool) NewClientWithConfig(name string, metricsRecorder estats.MetricsRecorder, config *bootstrap.Config) (XDSClient, func(), error) {
	config, err := p.getConfig(config)
	if err != nil {
		return nil, nil, err
	}
	return p.newRefCounted(name, metricsRecorder, defaultWatchExpiryTimeout, config)
}

// NewClient returns an xDS client with the given name from the pool. If the
// client doesn't already exist, it loads the configuration from the
// environment variables, creates a new xDS client and adds it to the pool.
//
// The second return value represents a close function which the caller is
// expected to invoke once they are done using the client.  It is safe for the
// caller to invoke this close function multiple times.
func (p *Pool) NewClient(name string, metricsRecorder estats.MetricsRecorder) (XDSClient, func(), error) {
	config, err := p.getConfig(nil)
	if err != nil {
		return nil, nil, err
	}
	return p.newRefCounted(name, metricsRecorder, defaultWatchExpiryTimeout, config)
}

// NewClientForTesting returns an xDS client configured with the provided
// options from the pool. If the client doesn't already exist, it creates a new
// xDS client and adds it to the pool.
// If the config in options is nil, it attempts to load the configuration from
// the environment variables.
//
// The second return value represents a close function which the caller is
// expected to invoke once they are done using the client.  It is safe for the
// caller to invoke this close function multiple times.
//
// # Testing Only
//
// This function should ONLY be used for testing purposes.

Review comment (suggestion):
Again, this *need not* load from environment variables. It *could* simply use the configuration provided at pool creation time. The only time configuration is loaded from env vars is for the default pool.

Code after:
		return config, nil
	}
	return p.getBootstrapConfiguration()
}

// NewClientWithConfig returns an xDS client with the given name from the pool.
// If the client doesn't already exist, it creates a new xDS client using the
// provided config and adds it to the pool. The provided config takes precedence
// over any config passed during pool creation. This should be used when a
// non-default config is required. If the provided config is nil, it attempts
// to load the configuration provided at pool creation time.
//
// The second return value represents a close function which the caller is
// expected to invoke once they are done using the client.  It is safe for the
// caller to invoke this close function multiple times.
func (p *Pool) NewClientWithConfig(name string, metricsRecorder estats.MetricsRecorder, config *bootstrap.Config) (XDSClient, func(), error) {
	config, err := p.getConfig(config)
	if err != nil {
		return nil, nil, err
	}
	return p.newRefCounted(name, metricsRecorder, defaultWatchExpiryTimeout, config)
}

// NewClient returns an xDS client with the given name from the pool. If the
// client doesn't already exist, it loads the configuration and creates a new
// xDS client and adds it to the pool.
//
// The second return value represents a close function which the caller is
// expected to invoke once they are done using the client.  It is safe for the
// caller to invoke this close function multiple times.
func (p *Pool) NewClient(name string, metricsRecorder estats.MetricsRecorder) (XDSClient, func(), error) {
	config, err := p.getConfig(nil)
	if err != nil {
		return nil, nil, err
	}
	return p.newRefCounted(name, metricsRecorder, defaultWatchExpiryTimeout, config)
}

// NewClientForTesting returns an xDS client configured with the provided
// options from the pool. If the client doesn't already exist, it creates a new
// xDS client and adds it to the pool.
//
// If the config in options is nil, it attempts to load the configuration
// provided at the time of pool creation.
//
// The second return value represents a close function which the caller is
// expected to invoke once they are done using the client.  It is safe for the
// caller to invoke this close function multiple times.
//
// # Testing Only
//