github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/worker/storageprovisioner/config.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package storageprovisioner
     5  
     6  import (
     7  	"github.com/juju/clock"
     8  	"github.com/juju/errors"
     9  	"github.com/juju/names/v5"
    10  
    11  	"github.com/juju/juju/storage"
    12  	"github.com/juju/juju/worker/common"
    13  )
    14  
    15  // Logger represents the methods used by the worker to log details.
    16  type Logger interface {
    17  	Tracef(string, ...interface{})
    18  	Debugf(string, ...interface{})
    19  	Warningf(string, ...interface{})
    20  	Errorf(string, ...interface{})
    21  }
    22  
    23  // Config holds configuration and dependencies for a storageprovisioner worker.
    24  type Config struct {
    25  	Model                names.ModelTag
    26  	Scope                names.Tag
    27  	StorageDir           string
    28  	Applications         ApplicationWatcher
    29  	Volumes              VolumeAccessor
    30  	Filesystems          FilesystemAccessor
    31  	Life                 LifecycleManager
    32  	Registry             storage.ProviderRegistry
    33  	Machines             MachineAccessor
    34  	Status               StatusSetter
    35  	Clock                clock.Clock
    36  	Logger               Logger
    37  	CloudCallContextFunc common.CloudCallContextFunc
    38  }
    39  
    40  // Validate returns an error if the config cannot be relied upon to start a worker.
    41  func (config Config) Validate() error {
    42  	switch config.Scope.(type) {
    43  	case nil:
    44  		return errors.NotValidf("nil Scope")
    45  	case names.ModelTag:
    46  		if config.StorageDir != "" {
    47  			return errors.NotValidf("environ Scope with non-empty StorageDir")
    48  		}
    49  	case names.MachineTag:
    50  		if config.StorageDir == "" {
    51  			return errors.NotValidf("machine Scope with empty StorageDir")
    52  		}
    53  		if config.Machines == nil {
    54  			return errors.NotValidf("nil Machines")
    55  		}
    56  	case names.ApplicationTag:
    57  		if config.StorageDir != "" {
    58  			return errors.NotValidf("application Scope with StorageDir")
    59  		}
    60  		if config.Applications == nil {
    61  			return errors.NotValidf("nil Applications")
    62  		}
    63  	default:
    64  		return errors.NotValidf("%T Scope", config.Scope)
    65  	}
    66  	if config.Volumes == nil {
    67  		return errors.NotValidf("nil Volumes")
    68  	}
    69  	if config.Filesystems == nil {
    70  		return errors.NotValidf("nil Filesystems")
    71  	}
    72  	if config.Life == nil {
    73  		return errors.NotValidf("nil Life")
    74  	}
    75  	if config.Registry == nil {
    76  		return errors.NotValidf("nil Registry")
    77  	}
    78  	if config.Status == nil {
    79  		return errors.NotValidf("nil Status")
    80  	}
    81  	if config.Clock == nil {
    82  		return errors.NotValidf("nil Clock")
    83  	}
    84  	if config.Logger == nil {
    85  		return errors.NotValidf("nil Logger")
    86  	}
    87  	if config.CloudCallContextFunc == nil {
    88  		return errors.NotValidf("nil CloudCallContextFunc")
    89  	}
    90  	return nil
    91  }