Repository: moby/moby
File: daemon/volume/drivers/adapter.go (Go)

Code before:

func (a *volumeDriverAdapter) getCapabilities() volume.Capability {
	if a.capabilities != nil {
		return *a.capabilities
	}
	capabilities, err := a.proxy.Capabilities()
	if err != nil {
		// `GetCapabilities` is a not a required endpoint.
		// On error assume it's a local-only driver
		log.G(context.TODO()).WithFields(log.Fields{
			"error":  err,
			"driver": a.name,
		}).Debug("Volume driver returned an error while trying to query its capabilities, using default capabilities")
		return volume.Capability{Scope: volume.LocalScope}
	}

	// don't spam the warn log below just because the plugin didn't provide a scope
	if capabilities.Scope == "" {
		capabilities.Scope = volume.LocalScope
	}

	capabilities.Scope = strings.ToLower(capabilities.Scope)
	if capabilities.Scope != volume.LocalScope && capabilities.Scope != volume.GlobalScope {
		log.G(context.TODO()).WithFields(log.Fields{
			"driver": a.name,
			"scope":  a.Scope(),
		}).Warn("Volume driver returned an invalid scope")
		capabilities.Scope = volume.LocalScope
	}

	a.capabilities = &capabilities
	return capabilities
}

type volumeAdapter struct {
	proxy      volumeDriver
	name       string
	scopePath  func(string) string
	driverName string
	eMount     string    // ephemeral host volume path
	createdAt  time.Time // time the directory was created
	status     map[string]any
}

type proxyVolume struct {
	Name       string
	Mountpoint string
	CreatedAt  time.Time
	Status     map[string]any
}


Review comment (suggestion):
Just to be sure this was not intentional; before this patch, this would pass  `a.Scope` as argument, i.e., pass the _function_ / _method_), instead of the _result_ of the function. Not sure even if that really worked, and if that was intentional.

Code after:

func (a *volumeDriverAdapter) getCapabilities() volume.Capability {
	if a.capabilities != nil {
		return *a.capabilities
	}
	capabilities, err := a.proxy.Capabilities()
	if err != nil {
		// `GetCapabilities` is a not a required endpoint.
		// On error assume it's a local-only driver
		log.G(context.TODO()).WithFields(log.Fields{
			"error":  err,
			"driver": a.name,
		}).Debug("Volume driver returned an error while trying to query its capabilities, using default capabilities")
		return volume.Capability{Scope: volume.LocalScope}
	}

	// don't spam the warn log below just because the plugin didn't provide a scope
	if capabilities.Scope == "" {
		capabilities.Scope = volume.LocalScope
	}

	capabilities.Scope = strings.ToLower(capabilities.Scope)
	if capabilities.Scope != volume.LocalScope && capabilities.Scope != volume.GlobalScope {
		log.G(context.TODO()).WithFields(log.Fields{
			"driver": a.name,
			"scope":  capabilities.Scope,
		}).Warn("Volume driver returned an invalid scope")
		capabilities.Scope = volume.LocalScope
	}

	a.capabilities = &capabilities
	return capabilities
}

type volumeAdapter struct {
	proxy      volumeDriver
	name       string
	scopePath  func(string) string
	driverName string
	eMount     string    // ephemeral host volume path
	createdAt  time.Time // time the directory was created
	status     map[string]any
}

type proxyVolume struct {
	Name       string
	Mountpoint string
	CreatedAt  time.Time
	Status     map[string]any
}