Documentation ¶
Overview ¶
workspaces contains functionality for using the workspace concept of the CLI to store data related to the remote endpoints that are described by the workspace concept (Radius control plane, environment, et al).
Index ¶
- Constants
- Variables
- type ConnectionConfig
- type EditableWorkspaceRequiredError
- type KubernetesConnectionConfig
- type KubernetesConnectionOverrides
- type NamedWorkspaceRequiredError
- type Source
- type Workspace
- func (ws Workspace) Connect() (sdk.Connection, error)
- func (ws Workspace) ConnectionConfig() (ConnectionConfig, error)
- func (ws Workspace) ConnectionConfigEquals(other ConnectionConfig) bool
- func (ws Workspace) FmtConnection() string
- func (w Workspace) IsEditableWorkspace() bool
- func (w Workspace) IsNamedWorkspace() bool
- func (ws Workspace) IsSameKubernetesContext(kubeContext string) bool
- func (ws Workspace) KubernetesContext() (string, bool)
Constants ¶
const ( // SourceFallback indicates that the workspace was not loaded from config, and is using default settings. SourceFallback = "fallback" // SourceLocalDirectory indicates that the workspace was loaded from the users working directory. SourceLocalDirectory = "localdirectory" // SourceUserConfig indicates that the workspace was loaded from per-user config. SourceUserConfig = "userconfig" )
const KindKubernetes string = "kubernetes"
Variables ¶
var ErrEditableWorkspaceRequired error = &EditableWorkspaceRequiredError{}
ErrNamedWorkspaceRequired is a value of EditableWorkspaceRequiredError.
var ErrNamedWorkspaceRequired error = &NamedWorkspaceRequiredError{}
ErrNamedWorkspaceRequired is a value of NamedWorkspaceRequiredError.
Functions ¶
This section is empty.
Types ¶
type ConnectionConfig ¶
type EditableWorkspaceRequiredError ¶
type EditableWorkspaceRequiredError struct { }
EditableWorkspaceRequiredError is an error used when an editable workspace must be specified by the user.
func (*EditableWorkspaceRequiredError) Error ¶
func (*EditableWorkspaceRequiredError) Error() string
Error() returns an message describing EditableWorkspaceRequiredError.
type KubernetesConnectionConfig ¶
type KubernetesConnectionConfig struct { // Kind specifies the kind of connection. For KubernetesConnectionConfig this is always 'kubernetes'. Kind string `json:"kind" mapstructure:"kind" yaml:"kind"` // Context is the kubernetes kubeconfig context used to connect. The empty string is allowed as it // maps to the current kubeconfig context. Context string `json:"context" mapstructure:"context" yaml:"context"` // Overrides describes local overrides for testing purposes. This field is optional. Overrides KubernetesConnectionOverrides `json:"overrides,omitempty" mapstructure:"overrides" yaml:"overrides,omitempty"` }
func (*KubernetesConnectionConfig) Connect ¶
func (c *KubernetesConnectionConfig) Connect() (sdk.Connection, error)
Connect() checks if a URL is provided in the Overrides field, and if so, creates a direct connection to the URL. If no URL is provided, it creates a connection to Kubernetes using the provided context. If an error occurs, an error is returned.
func (*KubernetesConnectionConfig) GetKind ¶
func (c *KubernetesConnectionConfig) GetKind() string
GetKind() returns the string "KindKubernetes" for a KubernetesConnectionConfig object.
func (*KubernetesConnectionConfig) String ¶
func (c *KubernetesConnectionConfig) String() string
String() returns a string that describes the Kubernetes connection configuration.
type KubernetesConnectionOverrides ¶
type KubernetesConnectionOverrides struct { // UCP describes an override for testing UCP. this field is optional. UCP string `json:"ucp" mapstructure:"ucp" yaml:"ucp"` }
type NamedWorkspaceRequiredError ¶
type NamedWorkspaceRequiredError struct { }
NamedWorkspaceRequiredError is an error used when a named workspace must be specified by the user.
func (*NamedWorkspaceRequiredError) Error ¶
func (*NamedWorkspaceRequiredError) Error() string
Error() returns a string describing NamedWorkspaceRequiredError.
type Workspace ¶
type Workspace struct { // Source indicates how the workspace was loaded. Source Source `json:"-" mapstructure:"-" yaml:"-"` // Directory config contains per-directory overrides and settings that affect the behavior of `rad`. // This is not stored in the `~/.rad/config.yaml`. DirectoryConfig config.DirectoryConfig `json:"-" mapstructure:"-" yaml:"-"` // Name is the name of the workspace. The name is not stored as part of the workspace entry but is populated // by the configuration APIs in this package. // // Will be set if the Source == SourceUserConfig, otherwise will be empty. Name string `json:"-" mapstructure:"-" yaml:"-"` // Connection represents the connection to the workspace. The details required by the connection are different // depending on the kind of connection. For example a Kubernetes connection requires a valid kubeconfig context // entry and a namespace. Connection map[string]any `json:"connection" mapstructure:"connection" yaml:"connection" validate:"required"` // Environment represents the default environment used for deployments of applications. This field is optional. Environment string `json:"environment,omitempty" mapstructure:"environment" yaml:"environment,omitempty"` // Scope represents the default scope used for deployments of Radius resources. This field is optional. Scope string `json:"scope,omitempty" mapstructure:"scope" yaml:"scope,omitempty"` }
Workspace represents configuration for the rad CLI.
Workspaces may:
- be stored in per-user config (~/.rad/config.yaml) OR
- be stored in the user's working directory `$pwd/.rad/rad.yaml` OR
- may represent the rad CLI's fallback configuration when no configuration is present
func MakeFallbackWorkspace ¶
func MakeFallbackWorkspace() *Workspace
MakeFallbackWorkspace() creates a Workspace struct with a SourceFallback source and a Kubernetes connection with an empty context. It returns a pointer to the Workspace struct.
func (Workspace) Connect ¶
func (ws Workspace) Connect() (sdk.Connection, error)
Connect attempts to create a connection to the workspace using the connection configuration and returns the connection and an error if one occurs.
func (Workspace) ConnectionConfig ¶
func (ws Workspace) ConnectionConfig() (ConnectionConfig, error)
ConnectionConfig() checks the "kind" field of the workspace's Connection object and returns a ConnectionConfig object based on the kind, or an error if the kind is unsupported.
func (Workspace) ConnectionConfigEquals ¶
func (ws Workspace) ConnectionConfigEquals(other ConnectionConfig) bool
ConnectionConfigEquals() checks if the given ConnectionConfig is of type Kubernetes and if the Kubernetes context is the same as the one stored in the Workspace, and returns a boolean value accordingly.
func (Workspace) FmtConnection ¶
FmtConnection can safely format connection info for display to users.
func (Workspace) IsEditableWorkspace ¶
IsEditableWorkspace returns true for workspaces stored in per-user or directory-based configuration. These workspaces have configuration files and thus can have their settings updated.
func (Workspace) IsNamedWorkspace ¶
IsNamedWorkspace returns true for workspaces stored in per-user configuration. These workspaces have names that can be referenced in commands with the `--workspace` flag.
func (Workspace) IsSameKubernetesContext ¶
IsSameKubernetesContext checks if the "context" field of the "Connection" map of the "Workspace" struct is equal to the given "kubeContext" string and returns a boolean value accordingly.
func (Workspace) KubernetesContext ¶
KubernetesContext checks if the workspace connection is of type Kubernetes and returns the context string if it exists, otherwise it returns an empty string and false.