modeldefaults

package
v0.0.0-...-b9bb202 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 20, 2024 License: AGPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ApplyStrategy

type ApplyStrategy interface {
	// Apply evaluates both the model config default value and that of the
	// already set value on model config and returns the resultant value that
	// should be set on model config.
	Apply(defaultVal, setVal any) any
}

ApplyStrategy describes a strategy for how default values should be applied to model config.

type AttributeDefaultValues

type AttributeDefaultValues struct {
	// Default and Controller represent the values as set at those levels.
	Default    any
	Controller any
	// Regions is a slice of Region representing the values as set in each
	// region.
	Regions []RegionDefaultValue
}

AttributeDefaultValues represents all the default values at each level for a given setting.

type CloudDefaultValues

type CloudDefaultValues struct {
	// Default and Controller represent the values as set at those levels.
	Default    any
	Controller any
}

CloudDefaultValues represents the default values for a given config attribute.

type DefaultAttributeValue

type DefaultAttributeValue struct {
	// These attributes are set according to what
	// defaults have been defined for an attribute.
	Default    any
	Controller any
	Region     any

	// Strategy is the ApplyStrategy that should be used when deciding how to
	// integrate this default value. If Strategy is the zero value then consult
	// [DefaultAttributeValue.ApplyStrategy] for expected behaviour.
	Strategy ApplyStrategy
}

DefaultAttributeValue represents a model config default attribute value and the hierarchical nature of where defaults can come from within Juju.

Because model defaults and the respective sources which defaults come from all have their own opinions on how the default will get applied. DefaultAttributeValue provides the mechanism for sources to place their opinions in one place and for the consuming side (model config) to use the default sources opinion.

func (DefaultAttributeValue) ApplyStrategy

func (d DefaultAttributeValue) ApplyStrategy(setVal any) any

ApplyStrategy runs the ApplyStrategy attached to this default value. The returned value is the result of what the ApplyStrategy has deemed is the value that should be set on the model config. If this DefaultAttributeValue has no ApplyStrategy set then by default we pass the decision to PreferSetApplyStrategy.

func (DefaultAttributeValue) Value

func (d DefaultAttributeValue) Value() any

Value returns the most relevant default value. eg if region is set, prefer the region value.

func (DefaultAttributeValue) ValueSource

func (d DefaultAttributeValue) ValueSource(val any) (bool, string)

ValueSource reports if the current DefaultAttributeValue.Value is equal to the value passed in. The source of the default value is also returned when the values are equal. If the current value of DefaultAttributeValue.Value or val is nil then false and empty string for source is returned.

For legacy reasons we have worked with types of "any" for model config values and trying to apply comparison logic over these types is hard to get right. For this reason this function only considers values to be equal if their types are comparable via == and or the type of Value is of []any, in which case we will defer to the reflect package for DeepEqual.

This is carry over logic from legacy Juju. Over time we can look at removing the use of any for more concrete types.

type Defaults

type Defaults map[string]DefaultAttributeValue

Defaults represents a set of default values for a given attribute. Defaults should be used to describe the full set of defaults that a model should consider for its config.

type ModelCloudDefaultAttributes

type ModelCloudDefaultAttributes map[string]CloudDefaultValues

ModelCloudDefaultAttributes represents a set of default values for a given attribute. The values contain the schema default value and any controller default value.

type ModelDefaultAttributes

type ModelDefaultAttributes map[string]AttributeDefaultValues

ModelDefaultAttributes represents a set of default values for a given attribute. The values contain the schema default value, any controller default value, and values set for cloud regions.

type PreferDefaultApplyStrategy

type PreferDefaultApplyStrategy struct{}

PreferDefaultApplyStrategy is an ApplyStrategy implementation that will always prefer the value set in the model default value. If the value for the model default is nil then the model config set value will be chosen.

func (*PreferDefaultApplyStrategy) Apply

func (*PreferDefaultApplyStrategy) Apply(defaultVal, setVal any) any

Apply implements ApplyStrategy interface for PreferDefaultApplyStrategy

type PreferSetApplyStrategy

type PreferSetApplyStrategy struct{}

PreferSetApplyStrategy is an ApplyStrategy implementation that will always prefer the value set in model config before the value being offered by the model default. If the set value for model config is nil then the default value will be returned. If both values are nil then nil will be returned.

The zero value of this type is safe to use as an ApplyStrategy.

func (*PreferSetApplyStrategy) Apply

func (*PreferSetApplyStrategy) Apply(defaultVal, setVal any) any

Apply implements ApplyStrategy interface for PreferSetApplyStrategy.

type RegionDefaultValue

type RegionDefaultValue struct {
	// Name represents the region name for this specific setting.
	Name string
	// Value is the value of the setting this represents in the named region.
	Value any
}

RegionDefaultValue holds the region information for each region in DefaultSetting.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL