configflags

package
v1.1.6 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AllowListLocalPathsFlags = []Definition{
	{
		FlagName:     "allow-listed-local-paths",
		ConfigPath:   types.NodeAllowListedLocalPaths,
		DefaultValue: Default.Node.AllowListedLocalPaths,
		Description:  "Local paths that are allowed to be mounted into jobs",
	},
}
View Source
var CapacityFlags = []Definition{
	{
		FlagName:             "ignore-physical-resource-limits",
		ConfigPath:           types.NodeComputeCapacityIgnorePhysicalResourceLimits,
		DefaultValue:         Default.Node.Compute.Capacity.IgnorePhysicalResourceLimits,
		Description:          `When set the compute node will ignore is physical resource limits`,
		EnvironmentVariables: []string{"BACALHAU_CAPACITY_MANAGER_OVER_COMMIT"},
	},
	{
		FlagName:     "limit-total-cpu",
		ConfigPath:   types.NodeComputeCapacityTotalResourceLimitsCPU,
		DefaultValue: Default.Node.Compute.Capacity.TotalResourceLimits.CPU,
		Description:  `Total CPU core limit to run all jobs (e.g. 500m, 2, 8).`,
	},
	{
		FlagName:     "limit-total-memory",
		ConfigPath:   types.NodeComputeCapacityTotalResourceLimitsMemory,
		DefaultValue: Default.Node.Compute.Capacity.TotalResourceLimits.Memory,
		Description:  `Total Memory limit to run all jobs  (e.g. 500Mb, 2Gb, 8Gb).`,
	},
	{
		FlagName:     "limit-total-gpu",
		ConfigPath:   types.NodeComputeCapacityTotalResourceLimitsGPU,
		DefaultValue: Default.Node.Compute.Capacity.TotalResourceLimits.GPU,
		Description:  `Total GPU limit to run all jobs (e.g. 1, 2, or 8).`,
	},
	{
		FlagName:     "limit-job-cpu",
		ConfigPath:   types.NodeComputeCapacityJobResourceLimitsCPU,
		DefaultValue: Default.Node.Compute.Capacity.JobResourceLimits.CPU,
		Description:  `Job CPU core limit to run all jobs (e.g. 500m, 2, 8).`,
	},
	{
		FlagName:     "limit-job-memory",
		ConfigPath:   types.NodeComputeCapacityDefaultJobResourceLimitsMemory,
		DefaultValue: Default.Node.Compute.Capacity.JobResourceLimits.Memory,
		Description:  `Job Memory limit to run all jobs  (e.g. 500Mb, 2Gb, 8Gb).`,
	},
	{
		FlagName:     "limit-job-gpu",
		ConfigPath:   types.NodeComputeCapacityJobResourceLimitsGPU,
		DefaultValue: Default.Node.Compute.Capacity.JobResourceLimits.GPU,
		Description:  `Job GPU limit to run all jobs (e.g. 1, 2, or 8).`,
	},
}
View Source
var ClientAPIFlags = []Definition{
	{
		FlagName:     "api-host",
		DefaultValue: Default.Node.ClientAPI.Host,
		ConfigPath:   types.NodeClientAPIHost,
		Description: `The host for the client and server to communicate on (via REST).
Ignored if BACALHAU_API_HOST environment variable is set.`,
		EnvironmentVariables: []string{"BACALHAU_API_HOST"},
	},
	{
		FlagName:     "api-port",
		DefaultValue: Default.Node.ClientAPI.Port,
		ConfigPath:   types.NodeClientAPIPort,
		Description: `The port for the client and server to communicate on (via REST).
Ignored if BACALHAU_API_PORT environment variable is set.`,
		EnvironmentVariables: []string{"BACALHAU_API_PORT"},
	},
}
View Source
var ComputeStorageFlags = []Definition{
	{
		FlagName:             "compute-execution-store-type",
		ConfigPath:           types.NodeComputeExecutionStoreType,
		DefaultValue:         Default.Node.Compute.ExecutionStore.Type,
		Description:          "The type of store used by the compute node (BoltDB or InMemory)",
		EnvironmentVariables: []string{"BACALHAU_COMPUTE_STORE_TYPE"},
	},
	{
		FlagName:             "compute-execution-store-path",
		ConfigPath:           types.NodeComputeExecutionStorePath,
		DefaultValue:         Default.Node.Compute.ExecutionStore.Path,
		Description:          "The path used for the compute execution store when using BoltDB",
		EnvironmentVariables: []string{"BACALHAU_COMPUTE_STORE_PATH"},
	},
}
View Source
var ComputeTimeoutFlags = []Definition{
	{
		FlagName:     "job-execution-timeout-bypass-client-id",
		ConfigPath:   types.NodeComputeJobTimeoutsJobExecutionTimeoutClientIDBypassList,
		DefaultValue: Default.Node.Compute.JobTimeouts.JobExecutionTimeoutClientIDBypassList,
		Description:  `List of IDs of clients that are allowed to bypass the job execution timeout check`,
	},
	{
		FlagName:     "job-negotiation-timeout",
		ConfigPath:   types.NodeComputeJobTimeoutsJobNegotiationTimeout,
		DefaultValue: Default.Node.Compute.JobTimeouts.JobNegotiationTimeout,
		Description:  `Timeout value to hold a bid for a job.`,
	},
	{
		FlagName:     "min-job-execution-timeout",
		ConfigPath:   types.NodeComputeJobTimeoutsMinJobExecutionTimeout,
		DefaultValue: Default.Node.Compute.JobTimeouts.MinJobExecutionTimeout,
		Description:  `The minimum execution timeout this compute node supports. Jobs with lower timeout requirements will not be bid on.`,
	},
	{
		FlagName:     "max-job-execution-timeout",
		ConfigPath:   types.NodeComputeJobTimeoutsMaxJobExecutionTimeout,
		DefaultValue: Default.Node.Compute.JobTimeouts.MaxJobExecutionTimeout,
		Description:  `The maximum execution timeout this compute node supports. Jobs with higher timeout requirements will not be bid on.`,
	},
	{
		FlagName:     "default-job-execution-timeout",
		ConfigPath:   types.NodeComputeJobTimeoutsJobExecutionTimeoutClientIDBypassList,
		DefaultValue: Default.Node.Compute.JobTimeouts.DefaultJobExecutionTimeout,
		Description:  `default value for the execution timeout this compute node will assign to jobs with no timeout requirement defined.`,
	},
}

Default is the default value used by flags. It will be overridden by any values in the config file. We can configure the default flag values by setting `Default` to a different config environment.

View Source
var DisabledFeatureFlags = []Definition{
	{
		FlagName:     "disable-engine",
		ConfigPath:   types.NodeDisabledFeaturesEngines,
		DefaultValue: Default.Node.DisabledFeatures.Engines,
		Description:  "Engine types to disable",
	},
	{
		FlagName:     "disabled-publisher",
		ConfigPath:   types.NodeDisabledFeaturesPublishers,
		DefaultValue: Default.Node.DisabledFeatures.Publishers,
		Description:  "Publisher types to disable",
	},
	{
		FlagName:     "disable-storage",
		ConfigPath:   types.NodeDisabledFeaturesStorages,
		DefaultValue: Default.Node.DisabledFeatures.Storages,
		Description:  "Storage types to disable",
	},
}
View Source
var IPFSFlags = []Definition{
	{
		FlagName:             "ipfs-swarm-addrs",
		ConfigPath:           types.NodeIPFSSwarmAddresses,
		DefaultValue:         Default.Node.IPFS.SwarmAddresses,
		Description:          "IPFS multiaddress to connect the in-process IPFS node to - cannot be used with --ipfs-connect.",
		EnvironmentVariables: []string{"BACALHAU_IPFS_SWARM_ADDRESSES"},
	},
	{
		FlagName:             "ipfs-swarm-key",
		ConfigPath:           types.NodeIPFSSwarmKeyPath,
		DefaultValue:         Default.Node.IPFS.SwarmKeyPath,
		Description:          "Optional IPFS swarm key required to connect to a private IPFS swarm",
		EnvironmentVariables: []string{"BACALHAU_IPFS_SWARM_KEY"},
	},
	{
		FlagName:     "ipfs-connect",
		ConfigPath:   types.NodeIPFSConnect,
		DefaultValue: Default.Node.IPFS.Connect,
		Description:  "The ipfs host multiaddress to connect to, otherwise an in-process IPFS node will be created if not set.",
	},
	{
		FlagName:     "private-internal-ipfs",
		ConfigPath:   types.NodeIPFSPrivateInternal,
		DefaultValue: Default.Node.IPFS.PrivateInternal,
		Description: "Whether the in-process IPFS node should auto-discover other nodes, including the public IPFS network - " +
			"cannot be used with --ipfs-connect. " +
			"Use \"--private-internal-ipfs=false\" to disable. " +
			"To persist a local Ipfs node, set BACALHAU_SERVE_IPFS_PATH to a valid path.",
	},
	{
		FlagName:             "ipfs-serve-path",
		ConfigPath:           types.NodeIPFSServePath,
		DefaultValue:         Default.Node.IPFS.ServePath,
		Description:          "path local Ipfs node will persist data to",
		EnvironmentVariables: []string{"BACALHAU_SERVE_IPFS_PATH"},
	},
}
View Source
var JobSelectionFlags = []Definition{
	{
		FlagName:     "job-selection-data-locality",
		ConfigPath:   types.NodeComputeJobSelectionLocality,
		DefaultValue: Default.Node.Compute.JobSelection.Locality,
		Description:  `Only accept jobs that reference data we have locally ("local") or anywhere ("anywhere").`,
	},
	{
		FlagName:     "job-selection-reject-stateless",
		ConfigPath:   types.NodeComputeJobSelectionRejectStatelessJobs,
		DefaultValue: Default.Node.Compute.JobSelection.RejectStatelessJobs,
		Description:  `Reject jobs that don't specify any data.`,
	},
	{
		FlagName:     "job-selection-accept-networked",
		ConfigPath:   types.NodeComputeJobSelectionAcceptNetworkedJobs,
		DefaultValue: Default.Node.Compute.JobSelection.AcceptNetworkedJobs,
		Description:  `Accept jobs that require network access.`,
	},
	{
		FlagName:     "job-selection-probe-http",
		ConfigPath:   types.NodeComputeJobSelectionProbeHTTP,
		DefaultValue: Default.Node.Compute.JobSelection.ProbeHTTP,
		Description:  `Use the result of a HTTP POST to decide if we should take on the job.`,
	},
	{
		FlagName:     "job-selection-probe-exec",
		ConfigPath:   types.NodeComputeJobSelectionProbeExec,
		DefaultValue: Default.Node.Compute.JobSelection.ProbeExec,
		Description:  `Use the result of a exec an external program to decide if we should take on the job.`,
	},
}
View Source
var LabelFlags = []Definition{
	{
		FlagName:     "labels",
		ConfigPath:   types.NodeLabels,
		DefaultValue: Default.Node.Labels,

		Description: `Labels to be associated with the node that can be used for node selection and filtering. (e.g. --labels key1=value1,key2=value2)`,
	},
}
View Source
var Libp2pFlags = []Definition{
	{
		FlagName:     "peer",
		ConfigPath:   types.NodeLibp2pPeerConnect,
		DefaultValue: Default.Node.Libp2p.PeerConnect,
		Description: `A comma-separated list of libp2p multiaddress to connect to. ` +
			`Use "none" to avoid connecting to any peer, ` +
			`"env" to connect to the default peer list of your active environment (see BACALHAU_ENVIRONMENT env var).`,
	},
	{
		FlagName:     "swarm-port",
		ConfigPath:   types.NodeLibp2pSwarmPort,
		DefaultValue: Default.Node.Libp2p.SwarmPort,
		Description:  `The port to listen on for swarm connections.`,
	},
}
View Source
var LogFlags = []Definition{
	{
		FlagName:     "log-mode",
		DefaultValue: logger.LogModeDefault,
		ConfigPath:   types.NodeLoggingMode,
		Description:  `Log format: 'default','station','json','combined','event'`,
	},
}
View Source
var NodeTypeFlags = []Definition{
	{
		FlagName:     "node-type",
		ConfigPath:   types.NodeType,
		DefaultValue: Default.Node.Type,
		Description:  `Whether the node is a compute, requester or both.`,
	},
}
View Source
var RequesterJobStorageFlags = []Definition{
	{
		FlagName:             "requester-job-store-type",
		ConfigPath:           types.NodeRequesterJobStoreType,
		DefaultValue:         Default.Node.Requester.JobStore.Type,
		Description:          "The type of job store used by the requester node (BoltDB or InMemory)",
		EnvironmentVariables: []string{"BACALHAU_JOB_STORE_TYPE"},
	},
	{
		FlagName:             "requester-job-store-path",
		ConfigPath:           types.NodeRequesterJobStorePath,
		DefaultValue:         Default.Node.Requester.JobStore.Path,
		Description:          "The path used for the requester job store store when using BoltDB",
		EnvironmentVariables: []string{"BACALHAU_JOB_STORE_PATH"},
	},
}
View Source
var RequesterTLSFlags = []Definition{
	{
		FlagName:     "autocert",
		DefaultValue: Default.Node.ServerAPI.TLS.AutoCert,
		ConfigPath:   types.NodeServerAPITLSAutoCert,
		Description: `Specifies a host name for which ACME is used to obtain a TLS Certificate.
Using this option results in the API serving over HTTPS`,
		EnvironmentVariables: []string{"BACALHAU_AUTO_TLS"},
	},
	{
		FlagName:             "tlscert",
		DefaultValue:         Default.Node.ServerAPI.TLS.ServerCertificate,
		ConfigPath:           types.NodeServerAPITLSServerCertificate,
		Description:          `Specifies a TLS certificate file to be used by the requester node`,
		EnvironmentVariables: []string{"BACALHAU_TLS_CERT"},
	},
	{
		FlagName:             "tlskey",
		DefaultValue:         Default.Node.ServerAPI.TLS.ServerKey,
		ConfigPath:           types.NodeServerAPITLSServerKey,
		Description:          `Specifies a TLS key file matching the certificate to be used by the requester node`,
		EnvironmentVariables: []string{"BACALHAU_TLS_KEY"},
	},
}
View Source
var ServerAPIFlags = []Definition{
	{
		FlagName:             "port",
		DefaultValue:         Default.Node.ServerAPI.Port,
		ConfigPath:           types.NodeServerAPIPort,
		Description:          `The port to server on.`,
		EnvironmentVariables: []string{"BACALHAU_SERVER_PORT"},
	},
	{
		FlagName:             "host",
		DefaultValue:         Default.Node.ServerAPI.Host,
		ConfigPath:           types.NodeServerAPIHost,
		Description:          `The host to serve on.`,
		EnvironmentVariables: []string{"BACALHAU_SERVER_HOST"},
	},
}

Functions

func BindFlags

func BindFlags(cmd *cobra.Command, register map[string][]Definition) error

BindFlags binds flags from a command to Viper using the provided definitions. This method should be called in command `PreRun`

func FlagNameForKey added in v1.1.0

func FlagNameForKey(key string, def ...Definition) string

FlagNameForKey accepts a configuration key and slice of Definition's containing the key. It returns the name of the flag corresponding to the key prefixed with `--`, or panics if the key is not part of the definition.

func PreRun added in v1.1.2

func PreRun(flags map[string][]Definition) func(*cobra.Command, []string) error

PreRun returns a run hook that binds the passed flag sets onto the command.

func RegisterFlags

func RegisterFlags(cmd *cobra.Command, register map[string][]Definition) error

RegisterFlags adds flags to the command based on provided definitions. This method should be called before the command runs to register flags accordingly.

Types

type Definition

type Definition struct {
	FlagName             string
	ConfigPath           string
	DefaultValue         interface{}
	Description          string
	EnvironmentVariables []string
}

Definition serves as a bridge between Cobra's command-line flags and Viper's configuration management. Each instance of `Definition` maps a flag (as presented to the user via the CLI) to its corresponding configuration setting in Viper. Here's a breakdown:

  • FlagName: The name of the flag as it appears on the command line.
  • ConfigPath: The path/key used by Viper to store and retrieve the flag's value. This path can represent nested configuration settings. It is also the environment variable (replace '.' with '_')
  • DefaultValue: The default value for the flag, used both in Cobra (when the flag is not explicitly provided) and in Viper (as the initial configuration value).
  • Description: A human-readable description of the flag's purpose, shown in help messages and documentation.

By defining flags in this manner, we establish a clear and consistent pattern for integrating Cobra and Viper, ensuring that command-line interactions seamlessly reflect and influence the underlying configuration state.

func FlagDefForKey added in v1.1.0

func FlagDefForKey(key string, def ...Definition) Definition

FlagDefForKey accepts a configuration key and slice of Definition's containing the key. It returns the Definition for the specific key or panics if the key is not part of the definition.

Jump to

Keyboard shortcuts

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