config

package
v0.35.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2022 License: Apache-2.0 Imports: 16 Imported by: 25

Documentation

Overview

Copyright © 2020 Portworx

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	AuthKeyToken                     = "token"
	AuthKeyName                      = "name"
	AuthKeyKubernetesSecret          = "kube-secret-name"
	AuthKeyKubernetesSecretNamespace = "kube-secret-namespace"

	DefaultClusterTunnelServiceNamespace = "kube-system"
	DefaultClusterTunnelServiceName      = "portworx-api"
	DefaultClusterTunnelServicePort      = "9020"
)
View Source
const (
	SpecifiedContext    = "cfgcontext"
	File                = "cfgfile"
	PxDefaultDir        = ".pxc"
	PxDefaultConfigName = "config.yml"
)
View Source
const (
	KubeconfigUserPrefix = "pxc@"
)

Variables

This section is empty.

Functions

func Get

func Get(k string) string

func Set

func Set(k, v string)

func SetCM added in v0.31.1

func SetCM(c *ConfigManager)

func SetKM added in v0.31.1

func SetKM(k *KubernetesConfigManager)

Types

type AuthInfo added in v0.23.0

type AuthInfo struct {
	Name               string              `json:"name,omitempty" yaml:"name,omitempty"`
	Token              string              `json:"token,omitempty" yaml:"token,omitempty"`
	KubernetesAuthInfo *KubernetesAuthInfo `json:"kubernetes,omitempty" yaml:"kubernetes,omitempty"`
}

AuthInfo provides authentication information about the user

func NewAuthInfo added in v0.23.0

func NewAuthInfo() *AuthInfo

NewAuthInfo returns an empty pxc Authinfo

func NewAuthInfoFromMap added in v0.23.0

func NewAuthInfoFromMap(m map[string]string) *AuthInfo

NewAuthInfoFromMap returns a new pxc AuthInfo from a map. Normally used to create an object from the information saved in Kubeconfig

type Cluster added in v0.23.0

type Cluster struct {
	Name       string `json:"name,omitempty" yaml:"name,omitempty"`
	CACert     string `json:"cacert,omitempty" yaml:"cacert,omitempty"`
	CACertData []byte `json:"cacert-data,omitempty" yaml:"cacert-data,omitempty"`
	Endpoint   string `json:"endpoint,omitempty" yaml:"endpoint,omitempty"`
	Secure     bool   `json:"secure,omitempty" yaml:"secure,omitempty"`

	TunnelServiceNamespace string `json:"tunnelServiceNamespace,omitempty" yaml:"tunnelServiceNamespace,omitempty"`
	TunnelServiceName      string `json:"tunnelServiceName,omitempty" yaml:"tunnelServiceName,omitempty"`
	TunnelServicePort      string `json:"tunnelServicePort,omitempty" yaml:"tunnelServicePort,omitempty"`
}

Cluster provides information on how to connect to Portworx

func NewCluster added in v0.23.0

func NewCluster() *Cluster

func NewClusterFromEncodedString added in v0.23.0

func NewClusterFromEncodedString(encodedString string) (*Cluster, error)

func NewDefaultCluster added in v0.23.0

func NewDefaultCluster() *Cluster

type Config added in v0.23.0

type Config struct {
	Preferences    Preferences          `json:"global" yaml:"global"`
	Clusters       map[string]*Cluster  `json:"clusters,omitempty" yaml:"clusters,omitempty"`
	AuthInfos      map[string]*AuthInfo `json:"users,omitempty" yaml:"users,omitempty"`
	Contexts       map[string]*Context  `json:"contexts,omitempty" yaml:"contexts,omitempty"`
	CurrentContext string               `json:"current-context,omitempty" yaml:"current-context,omitempty"`
}

Config is a a model to store information about the authentication and connection to a Portworx system. The design is to enable an easy extension of a Kubernetes configuration.

type ConfigFlags added in v0.23.0

type ConfigFlags struct {
	ConfigDir       string
	ConfigFile      string
	Context         string
	SecretNamespace string
	SecretName      string
	Token           string
	Verbosity       int32
}

func (*ConfigFlags) AddFlags added in v0.23.0

func (c *ConfigFlags) AddFlags(flags *pflag.FlagSet)

AddFlags adds the appropriate global flags for non-kubectl plugin mode

func (*ConfigFlags) AddFlagsPluginMode added in v0.23.0

func (c *ConfigFlags) AddFlagsPluginMode(flags *pflag.FlagSet)

AddFlagsPluginMode adds the appropriate global flags when running as a kubectl plugin

func (*ConfigFlags) GetConfigFile added in v0.23.0

func (c *ConfigFlags) GetConfigFile() string

type ConfigManager added in v0.23.0

type ConfigManager struct {
	Config *Config
	Flags  *ConfigFlags
	// contains filtered or unexported fields
}

func CM added in v0.23.0

func CM() *ConfigManager

CM returns the instance to the config manager

func NewConfigManagerForContext added in v0.31.1

func NewConfigManagerForContext(context string) (*ConfigManager, error)

func (*ConfigManager) ConfigDeleteAuthInfo added in v0.25.0

func (cm *ConfigManager) ConfigDeleteAuthInfo(name string) error

ConfigDeleteAuthInfo deletes credentials from disk

func (*ConfigManager) ConfigDeleteCluster added in v0.25.0

func (cm *ConfigManager) ConfigDeleteCluster(name string) error

ConfigDeleteCluster deletes the cluster configuration from disk

func (*ConfigManager) ConfigDeleteContext added in v0.25.0

func (cm *ConfigManager) ConfigDeleteContext(name string) error

ConfigDeleteContext deletes context from disk

func (*ConfigManager) ConfigGetCurrentContext added in v0.25.0

func (cm *ConfigManager) ConfigGetCurrentContext() (string, error)

ConfigGetCurrentContext returns the current context set by kubectl

func (*ConfigManager) ConfigLoad added in v0.25.0

func (cm *ConfigManager) ConfigLoad() (*Config, error)

ConfigLoad loads the configuration from disk

func (*ConfigManager) ConfigSaveAuthInfo added in v0.25.0

func (cm *ConfigManager) ConfigSaveAuthInfo(a *AuthInfo) error

ConfigSaveAuthInfo saves user configuration to disk

func (*ConfigManager) ConfigSaveCluster added in v0.25.0

func (cm *ConfigManager) ConfigSaveCluster(c *Cluster) error

ConfigSaveCluster saves the cluster configuration to disk

func (*ConfigManager) ConfigSaveContext added in v0.25.0

func (cm *ConfigManager) ConfigSaveContext(c *Context) error

ConfigSaveContext saves a context to disk

func (*ConfigManager) ConfigUseContext added in v0.25.0

func (cm *ConfigManager) ConfigUseContext(name string) error

ConfigUseContext is not supported by kubectl plugin

func (*ConfigManager) ForEachContext added in v0.31.1

func (cm *ConfigManager) ForEachContext(
	handler func(context, clusterName string) error,
)

func (*ConfigManager) GetConfigFile added in v0.23.0

func (cm *ConfigManager) GetConfigFile() string

GetConfigFile returns the current config file used

func (*ConfigManager) GetCurrentAuthInfo added in v0.23.0

func (cm *ConfigManager) GetCurrentAuthInfo() *AuthInfo

GetCurrentAuthInfo returns configuration information about the current user

func (*ConfigManager) GetCurrentCluster added in v0.23.0

func (cm *ConfigManager) GetCurrentCluster() *Cluster

GetCurrentCluster returns configuration information about the current cluster

func (*ConfigManager) GetEndpoint added in v0.23.0

func (cm *ConfigManager) GetEndpoint() string

GetEndpoint returns either the saved endpoint in the config file or the tunneled local endpoint

func (*ConfigManager) GetFlags added in v0.23.0

func (cm *ConfigManager) GetFlags() *ConfigFlags

GetFlags returns all the pxc persistent flags

func (*ConfigManager) Load added in v0.23.0

func (cm *ConfigManager) Load() error

func (*ConfigManager) RunInNamedContext added in v0.32.0

func (cm *ConfigManager) RunInNamedContext(contextName string, handler func() error) error

func (*ConfigManager) SetTunnelEndpoint added in v0.23.0

func (cm *ConfigManager) SetTunnelEndpoint(tunnelEndpoint string)

SetTunnelEndpoint sets the local endpoint when a tunnel is used

type ConfigReaderWriter added in v0.25.0

type ConfigReaderWriter interface {
	ConfigSaveCluster(*Cluster) error
	ConfigDeleteCluster(string) error
	ConfigLoad() (*Config, error)
	ConfigSaveAuthInfo(*AuthInfo) error
	ConfigSaveContext(*Context) error
	ConfigDeleteAuthInfo(string) error
	ConfigDeleteContext(string) error
	ConfigUseContext(string) error
	ConfigGetCurrentContext() (string, error)
}

type Context added in v0.23.0

type Context struct {
	Name     string `json:"name,omitempty" yaml:"name,omitempty"`
	AuthInfo string `json:"user,omitempty" yaml:"user,omitempty"`
	Cluster  string `json:"cluster,omitempty" yaml:"cluster,omitempty"`
}

Context provides information on who is trying to connect to a specific cluster

func NewContext added in v0.25.0

func NewContext() *Context

type KubernetesAuthInfo added in v0.23.0

type KubernetesAuthInfo struct {
	SecretName      string `json:"secretName,omitempty" yaml:"secretName,omitempty"`
	SecretNamespace string `json:"secretNamespace,omitempty" yaml:"secretNamespace,omitempty"`
}

KubernetesAuthInfo provides information on where to access the token in Kubernetes

type KubernetesConfigManager added in v0.24.0

type KubernetesConfigManager struct {
	// contains filtered or unexported fields
}

KubernetesConfigManager contains all the Kubernetes configuration

func KM added in v0.23.0

KM returns the Kubernetes configuration flags and settings

func NewKubernetesConfigManagerForContext added in v0.31.1

func NewKubernetesConfigManagerForContext(context string) *KubernetesConfigManager

func (*KubernetesConfigManager) ConfigDeleteAuthInfo added in v0.25.0

func (k *KubernetesConfigManager) ConfigDeleteAuthInfo(name string) error

ConfigDeleteAuthInfo deletes auth information for the current context

func (*KubernetesConfigManager) ConfigDeleteCluster added in v0.25.0

func (k *KubernetesConfigManager) ConfigDeleteCluster(name string) error

func (*KubernetesConfigManager) ConfigDeleteContext added in v0.25.0

func (k *KubernetesConfigManager) ConfigDeleteContext(name string) error

ConfigDeleteContext deletes auth information for the current context

func (*KubernetesConfigManager) ConfigFlags added in v0.24.0

ConfigFlags returns the kubernetes raw configuration object

func (*KubernetesConfigManager) ConfigGetCurrentContext added in v0.25.0

func (k *KubernetesConfigManager) ConfigGetCurrentContext() (string, error)

ConfigGetCurrentContext returns the current context set by kubectl

func (*KubernetesConfigManager) ConfigLoad added in v0.25.0

func (k *KubernetesConfigManager) ConfigLoad() (*Config, error)

func (*KubernetesConfigManager) ConfigSaveAuthInfo added in v0.25.0

func (k *KubernetesConfigManager) ConfigSaveAuthInfo(authInfo *AuthInfo) error

func (*KubernetesConfigManager) ConfigSaveCluster added in v0.25.0

func (k *KubernetesConfigManager) ConfigSaveCluster(clusterInfo *Cluster) error

ConfigSaveCluster saves the cluster configuration as part of an extension to the current context cluster in the Kubeconfig

func (*KubernetesConfigManager) ConfigSaveContext added in v0.25.0

func (k *KubernetesConfigManager) ConfigSaveContext(c *Context) error

ConfigSaveContext does not do anything in kubectl plugin mode because it is managed by kubectl

func (*KubernetesConfigManager) ConfigUseContext added in v0.25.0

func (k *KubernetesConfigManager) ConfigUseContext(name string) error

ConfigUseContext is not supported by kubectl plugin

func (*KubernetesConfigManager) DeleteAuthInfoInKubeconfig added in v0.25.0

func (k *KubernetesConfigManager) DeleteAuthInfoInKubeconfig(authInfoName string) error

DeleteAuthInfoInKubeconfig deletes the saved Portworx configuration in the kubeconfig

func (*KubernetesConfigManager) DeleteClusterInKubeconfig added in v0.24.0

func (k *KubernetesConfigManager) DeleteClusterInKubeconfig(clusterName string) error

DeleteClusterInKubeconfig deletes the saved Portworx configuration in the kubeconfig

func (*KubernetesConfigManager) GetCurrentAuthInfo added in v0.28.0

func (k *KubernetesConfigManager) GetCurrentAuthInfo() (*clientcmdapi.AuthInfo, error)

GetCurrentAuthInfo returns configuration information about the current user

func (*KubernetesConfigManager) GetCurrentCluster added in v0.28.0

func (k *KubernetesConfigManager) GetCurrentCluster() (*clientcmdapi.Cluster, error)

GetCurrentCluster returns configuration information about the current cluster

func (*KubernetesConfigManager) GetKubernetesCurrentContext added in v0.24.0

func (k *KubernetesConfigManager) GetKubernetesCurrentContext() (string, error)

GetKubernetesCurrentContext returns the context currently selected by either the config file or from the command line

func (*KubernetesConfigManager) GetStartingKubeconfig added in v0.24.0

func (k *KubernetesConfigManager) GetStartingKubeconfig() (*clientcmdapi.Config, error)

GetStartingKubeconfig is used to adjust the current Kubernetes config. You can then call ModifyKubeconfig() with the modified configuration

func (*KubernetesConfigManager) KubectlFlagsToCliArgs added in v0.24.0

func (k *KubernetesConfigManager) KubectlFlagsToCliArgs() string

KubectlFlagsToCliArgs rebuilds the flags as cli args

func (*KubernetesConfigManager) ModifyKubeconfig added in v0.24.0

func (k *KubernetesConfigManager) ModifyKubeconfig(newConfig *clientcmdapi.Config) error

ModifyKubeconfig takes a modified configuration and seves it to disk

func (*KubernetesConfigManager) Namespace added in v0.24.0

func (k *KubernetesConfigManager) Namespace() (string, bool, error)

Namespace returns the namespace resulting from the merged result of all overrides and a boolean indicating if it was overridden

func (*KubernetesConfigManager) SaveAuthInfoForKubeUser added in v0.24.0

func (k *KubernetesConfigManager) SaveAuthInfoForKubeUser(user, locationOfOrigin string, a *AuthInfo) error

SaveAuthInfoForKubeUser saves the pxc configuration in the kubeconfig file as a new user entry. Supply locationOfOrigin so that the Kubernetes saves the object with the appropriate user. LocationOfOrigin is found in each of the user objects in the kubernetes Config object.

func (*KubernetesConfigManager) SaveClusterInKubeconfig added in v0.24.0

func (k *KubernetesConfigManager) SaveClusterInKubeconfig(clusterName, location string, c *Cluster) error

SaveClusterInKubeconfig stores pxc cluster configuration information in Kubeconfig

func (*KubernetesConfigManager) ToRESTConfig added in v0.24.0

func (k *KubernetesConfigManager) ToRESTConfig() (*rest.Config, error)

ToRESTConfig implements RESTClientGetter. Returns a REST client configuration based on a provided path to a .kubeconfig file, loading rules, and config flag overrides. Expects the AddFlags method to have been called. comment from k8s.io/cli-runtime

func (*KubernetesConfigManager) ToRawKubeConfigLoader added in v0.24.0

func (k *KubernetesConfigManager) ToRawKubeConfigLoader() clientcmd.ClientConfig

ToRawKubeConfigLoader binds config flag values to config overrides Returns an interactive clientConfig if the password flag is enabled, or a non-interactive clientConfig otherwise. comment from k8s.io/cli-runtime

type Preferences added in v0.23.0

type Preferences struct {
}

Preferences provides any pxc specific configuration

Jump to

Keyboard shortcuts

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