Documentation ¶
Overview ¶
Package config provides functions for reading and writing client configuration.
Index ¶
- Constants
- Variables
- func AcquireTanzuConfigLock()
- func AddContext(c *configv1alpha1.Context, setCurrent bool) error
- func AddServer(s *configv1alpha1.Server, setCurrent bool) error
- func ClientConfigPath() (path string, err error)
- func ConfigureEnvVariables()
- func ContextExists(name string) (bool, error)
- func CopyLegacyConfigDir() error
- func DeleteClientConfig() error
- func EndpointFromContext(s *configv1alpha1.Context) (endpoint string, err error)
- func EndpointFromServer(s *configv1alpha1.Server) (endpoint string, err error)
- func GetClientConfig() (cfg *configv1alpha1.ClientConfig, err error)
- func GetClientConfigNoLock() (cfg *configv1alpha1.ClientConfig, err error)
- func GetCompatibilityFilePath() (string, error)
- func GetContext(name string) (*configv1alpha1.Context, error)
- func GetCurrentClusterConfig() (*rest.Config, error)
- func GetCurrentContext(ctxType configv1alpha1.ContextType) (c *configv1alpha1.Context, err error)
- func GetCurrentServer() (s *configv1alpha1.Server, err error)
- func GetDefaultRepo() (string, error)
- func GetDefaultStandaloneDiscoveryImage() string
- func GetDefaultStandaloneDiscoveryLocalPath() string
- func GetDefaultStandaloneDiscoveryType() string
- func GetDiscoverySources(serverName string) []configv1alpha1.PluginDiscovery
- func GetEdition() (string, error)
- func GetEnvConfigurations() map[string]string
- func GetServer(name string) (s *configv1alpha1.Server, err error)
- func GetTrustedArtifactLocations() []string
- func GetTrustedRegistries() []string
- func IsFeatureActivated(feature string) bool
- func IsTanzuConfigLockAcquired() bool
- func LocalDir() (path string, err error)
- func NewClientConfig() (*configv1alpha1.ClientConfig, error)
- func PutServer(s *configv1alpha1.Server, setCurrent bool) error
- func ReleaseTanzuConfigLock()
- func RemoveContext(name string) error
- func RemoveServer(name string) error
- func ServerExists(name string) (bool, error)
- func SetCurrentContext(name string) error
- func SetCurrentServer(name string) error
- func StoreClientConfig(cfg *configv1alpha1.ClientConfig) error
Constants ¶
const ( // FeatureContextAwareCLIForPlugins determines whether to use legacy way of discovering plugins or // to use the new context-aware Plugin API based plugin discovery mechanism // Users can set this featureflag so that we can have context-aware plugin discovery be opt-in for now. FeatureContextAwareCLIForPlugins = "features.global.context-aware-cli-for-plugins" // FeatureContextCommand determines whether to surface the context command. This is disabled by default. FeatureContextCommand = "features.global.context-target" // DualStack feature flags determine whether it is permitted to create // clusters with a dualstack TKG_IP_FAMILY. There are separate flags for // each primary, "ipv4,ipv6" vs "ipv6,ipv4", and flags for management vs // workload cluster plugins. FeatureFlagManagementClusterDualStackIPv4Primary = "features.management-cluster.dual-stack-ipv4-primary" FeatureFlagManagementClusterDualStackIPv6Primary = "features.management-cluster.dual-stack-ipv6-primary" FeatureFlagClusterDualStackIPv4Primary = "features.cluster.dual-stack-ipv4-primary" FeatureFlagClusterDualStackIPv6Primary = "features.cluster.dual-stack-ipv6-primary" // Custom Nameserver feature flags determine whether it is permitted to // provide the CONTROL_PLANE_NODE_NAMESERVERS and WORKER_NODE_NAMESERVERS // when creating a cluster. FeatureFlagManagementClusterCustomNameservers = "features.management-cluster.custom-nameservers" FeatureFlagClusterCustomNameservers = "features.cluster.custom-nameservers" // AWS Instance Types Exclude ARM feature flags determine whether instance types with processor architecture // support of ARM should be included when discovering available AWS instance types. Setting feature flag to true // filters out ARM supporting instance types; false allows ARM instance types to be included in results. FeatureFlagAwsInstanceTypesExcludeArm = "features.management-cluster.aws-instance-types-exclude-arm" // PackageBasedLCM feature flag determines whether to use package based lifecycle management of management component // or legacy way of managing management components. This is also used for clusterclass based management and workload // cluster provisioning FeatureFlagPackageBasedLCM = "features.global.package-based-lcm-beta" // TKR version v1alpha3 feature flag determines whether to use Tanzu Kubernetes Release API version v1alpha3. Setting // feature flag to true will allow to use the TKR version v1alpha3; false allows to use legacy TKR version v1alpha1 FeatureFlagTKRVersionV1Alpha3 = "features.global.tkr-version-v1alpha3-beta" // Package Plugin Kctrl Command Tree determines whether to use the command tree from kctrl. Setting feature flag to // true will allow to use the package command tree from kctrl for package plugin FeatureFlagPackagePluginKctrlCommandTree = "features.package.kctrl-package-command-tree" // FeatureFlagAutoApplyGeneratedClusterClassBasedConfiguration feature flag determines whether to auto-apply the generated ClusterClass // based configuration after converting legacy configration to ClusterClass based config or not // Note: This is a hidden feature-flag that doesn't get persisted to config.yaml by default FeatureFlagAutoApplyGeneratedClusterClassBasedConfiguration = "features.cluster.auto-apply-generated-clusterclass-based-configuration" // FeatureFlagForceDeployClusterWithClusterClass if this feature flag is set CLI will try to deploy ClusterClass // based cluster even if user has done any customization to the provider templates // Note: This is a hidden feature-flag that doesn't get persisted to config.yaml by default FeatureFlagForceDeployClusterWithClusterClass = "features.cluster.force-deploy-cluster-with-clusterclass" )
This block is for global feature constants, to allow them to be used more broadly
const ( // EnvConfigKey is the environment variable that points to a tanzu config. EnvConfigKey = "TANZU_CONFIG" // EnvEndpointKey is the environment variable that overrides the tanzu endpoint. EnvEndpointKey = "TANZU_ENDPOINT" //nolint:gosec // Avoid "hardcoded credentials" false positive. // EnvAPITokenKey is the environment variable that overrides the tanzu API token for global auth. EnvAPITokenKey = "TANZU_API_TOKEN" // ConfigName is the name of the config ConfigName = "config.yaml" )
const ( // NameHeader used by every client making an API call NameHeader = "x-client-name" // VersionHeader is the client version header. VersionHeader = "x-client-version" )
const AdvancedRepositoryName = "advanced"
AdvancedRepositoryName is the advanced repository name.
const CoreRepositoryName = "core"
CoreRepositoryName is the core repository name.
const DefaultEdition = "tkg"
DefaultEdition is the edition assumed when there is no value in the local config file
const DefaultTMCPluginsArtifactRepository = "https://tmc-cli.s3-us-west-2.amazonaws.com/plugins/artifacts"
DefaultTMCPluginsArtifactRepository is the S3 bucket repository for TMC plugins.
const DefaultVersionSelector = configv1alpha1.NoUnstableVersions
DefaultVersionSelector is to only use stable versions of plugins
Variables ¶
var ( // DefaultAllowedPluginRepositories this can be comma separated list of allowed registries DefaultAllowedPluginRepositories = "" DefaultStandaloneDiscoveryRepository = "" DefaultStandaloneDiscoveryImagePath = "" DefaultStandaloneDiscoveryImageTag = "" DefaultStandaloneDiscoveryName = "default" DefaultStandaloneDiscoveryNameLocal = "default-local" DefaultStandaloneDiscoveryType = common.DistributionTypeOCI DefaultStandaloneDiscoveryLocalPath = "" )
Default Standalone Discovery configuration Value of this variables gets assigned during build time
var AdvancedGCPBucketRepository = configv1alpha1.GCPPluginRepository{ BucketName: "tanzu-cli-advanced-plugins", Name: AdvancedRepositoryName, }
AdvancedGCPBucketRepository is the GCP bucket repository for advanced plugins.
var CoreBucketName = "tanzu-cli-framework"
CoreBucketName is the name of the core plugin repository bucket to use.
var CoreGCPBucketRepository = configv1alpha1.GCPPluginRepository{ BucketName: CoreBucketName, Name: CoreRepositoryName, }
CoreGCPBucketRepository is the default GCP bucket repository.
var ( DefaultCliFeatureFlags = map[string]bool{ FeatureContextAwareCLIForPlugins: common.ContextAwareDiscoveryEnabled(), FeatureContextCommand: false, "features.management-cluster.import": false, "features.management-cluster.export-from-confirm": true, "features.management-cluster.standalone-cluster-mode": false, FeatureFlagManagementClusterDualStackIPv4Primary: false, FeatureFlagManagementClusterDualStackIPv6Primary: false, FeatureFlagClusterDualStackIPv4Primary: false, FeatureFlagClusterDualStackIPv6Primary: false, FeatureFlagManagementClusterCustomNameservers: false, FeatureFlagClusterCustomNameservers: false, FeatureFlagAwsInstanceTypesExcludeArm: true, FeatureFlagTKRVersionV1Alpha3: false, FeatureFlagPackagePluginKctrlCommandTree: false, } )
DefaultCliFeatureFlags is used to populate an initially empty config file with default values for feature flags. The keys MUST be in the format "features.<plugin>.<feature>" or initialization will fail. Note that "global" is a special value for <plugin> to be used for CLI-wide features.
If a developer expects that their feature will be ready to release, they should create an entry here with a true value. If a developer has a beta feature they want to expose, but leave turned off by default, they should create an entry here with a false value. WE HIGHLY RECOMMEND the use of a SEPARATE flag for beta use; one that ends in "-beta". Thus, if you plan to eventually release a feature with a flag named "features.cluster.foo-bar", you should consider releasing the beta version with "features.cluster.foo-bar-beta". This will make it much easier when it comes time for mainstreaming the feature (with a default true value) under the flag name "features.cluster.foo-bar", as there will be no conflict with previous installs (that have a false value for the entry "features.cluster.foo-bar-beta").
var DefaultRepositories []configv1alpha1.PluginRepository = []configv1alpha1.PluginRepository{ { GCPPluginRepository: &CoreGCPBucketRepository, }, }
DefaultRepositories are the default repositories for the CLI.
var (
// LocalDirName is the name of the local directory in which tanzu state is stored.
LocalDirName = ".config/tanzu"
)
Functions ¶
func AcquireTanzuConfigLock ¶ added in v0.25.0
func AcquireTanzuConfigLock()
AcquireTanzuConfigLock tries to acquire lock to update tanzu config file with timeout
func AddContext ¶ added in v0.25.2
func AddContext(c *configv1alpha1.Context, setCurrent bool) error
AddContext adds a Context to the config.
func AddServer ¶
func AddServer(s *configv1alpha1.Server, setCurrent bool) error
AddServer adds a server to the config.
func ClientConfigPath ¶
ClientConfigPath returns the tanzu config path, checking for environment overrides.
func ConfigureEnvVariables ¶ added in v0.11.0
func ConfigureEnvVariables()
ConfigureEnvVariables reads and configures provided environment variables as part of tanzu configuration file
func ContextExists ¶ added in v0.25.2
ContextExists tells whether the Context by the given name exists.
func CopyLegacyConfigDir ¶
func CopyLegacyConfigDir() error
CopyLegacyConfigDir copies configuration files from legacy config dir to the new location. This is a no-op if the legacy dir does not exist or if the new config dir already exists.
func DeleteClientConfig ¶
func DeleteClientConfig() error
DeleteClientConfig deletes the config from the local directory.
func EndpointFromContext ¶ added in v0.25.2
func EndpointFromContext(s *configv1alpha1.Context) (endpoint string, err error)
EndpointFromContext returns the endpoint from context.
func EndpointFromServer ¶
func EndpointFromServer(s *configv1alpha1.Server) (endpoint string, err error)
EndpointFromServer returns the endpoint from server.
func GetClientConfig ¶
func GetClientConfig() (cfg *configv1alpha1.ClientConfig, err error)
GetClientConfig retrieves the config from the local directory with file lock
func GetClientConfigNoLock ¶ added in v0.25.2
func GetClientConfigNoLock() (cfg *configv1alpha1.ClientConfig, err error)
GetClientConfigNoLock retrieves the config from the local directory without acquiring the lock
func GetCompatibilityFilePath ¶ added in v0.17.0
GetCompatibilityFilePath returns the compatibilityPath set in the client configuration. If it cannot be resolved, the default path set at build time is returned along with an error describing why the path could not be resolved from the client configuration.
func GetContext ¶ added in v0.25.2
func GetContext(name string) (*configv1alpha1.Context, error)
GetContext by name.
func GetCurrentClusterConfig ¶ added in v0.17.0
GetCurrentClusterConfig gets the config of current logged in cluster
func GetCurrentContext ¶ added in v0.25.2
func GetCurrentContext(ctxType configv1alpha1.ContextType) (c *configv1alpha1.Context, err error)
GetCurrentContext gets the current context.
func GetCurrentServer ¶
func GetCurrentServer() (s *configv1alpha1.Server, err error)
GetCurrentServer gets the current server.
func GetDefaultRepo ¶ added in v0.17.0
GetDefaultRepo returns the bomRepo set in the client configuration. If it cannot be resolved, the default repo set at build time is returned along with an error describing why the bomRepo could not be resolved from the client configuration.
func GetDefaultStandaloneDiscoveryImage ¶ added in v0.11.0
func GetDefaultStandaloneDiscoveryImage() string
GetDefaultStandaloneDiscoveryImage returns the default Standalone Discovery image from the configured build time variables
func GetDefaultStandaloneDiscoveryLocalPath ¶ added in v0.11.0
func GetDefaultStandaloneDiscoveryLocalPath() string
GetDefaultStandaloneDiscoveryLocalPath returns default standalone discovery local path
func GetDefaultStandaloneDiscoveryType ¶ added in v0.11.0
func GetDefaultStandaloneDiscoveryType() string
GetDefaultStandaloneDiscoveryType returns the default standalone discovery type
func GetDiscoverySources ¶ added in v0.11.0
func GetDiscoverySources(serverName string) []configv1alpha1.PluginDiscovery
GetDiscoverySources returns all discovery sources Includes standalone discovery sources and if server is available it also includes context based discovery sources as well
func GetEdition ¶ added in v0.16.0
GetEdition returns the edition from the local configuration file
func GetEnvConfigurations ¶ added in v0.11.0
GetEnvConfigurations returns a map of configured environment variables to values as part of tanzu configuration file it returns nil if configuration is not yet defined
func GetServer ¶
func GetServer(name string) (s *configv1alpha1.Server, err error)
GetServer by name.
func GetTrustedArtifactLocations ¶ added in v0.17.0
func GetTrustedArtifactLocations() []string
GetTrustedArtifactLocations returns the list of trusted URI prefixes that can be trusted for downloading the CLIPlugins. Currently, this includes only the "tanzu-cli-advanced-plugins" GCP bucket where TMC plugins are stored. Other exceptions can be added as and when necessary.
func GetTrustedRegistries ¶ added in v0.11.2
func GetTrustedRegistries() []string
GetTrustedRegistries returns the list of trusted registries that can be used for downloading the CLIPlugins
func IsFeatureActivated ¶ added in v0.9.0
IsFeatureActivated returns true if the given feature is activated User can set this CLI feature flag using `tanzu config set features.global.<feature> true`
func IsTanzuConfigLockAcquired ¶ added in v0.25.0
func IsTanzuConfigLockAcquired() bool
IsTanzuConfigLockAcquired checks the lock status and returns true if the lock is acquired by the current process or returns false otherwise
func NewClientConfig ¶
func NewClientConfig() (*configv1alpha1.ClientConfig, error)
NewClientConfig returns a new config.
func PutServer ¶
func PutServer(s *configv1alpha1.Server, setCurrent bool) error
PutServer adds or updates the server.
func ReleaseTanzuConfigLock ¶ added in v0.25.0
func ReleaseTanzuConfigLock()
ReleaseTanzuConfigLock releases the lock if the tanzuConfigLock was acquired
func RemoveContext ¶ added in v0.25.2
RemoveContext removes a Context from the config.
func ServerExists ¶
ServerExists tells whether the server by the given name exists.
func SetCurrentContext ¶ added in v0.25.2
SetCurrentContext sets the current Context.
func SetCurrentServer ¶
SetCurrentServer sets the current server.
func StoreClientConfig ¶
func StoreClientConfig(cfg *configv1alpha1.ClientConfig) error
StoreClientConfig stores the config in the local directory. Make sure to Acquire and Release tanzu lock when reading/writing to the tanzu client configuration
Types ¶
This section is empty.