Documentation
¶
Overview ¶
Package kubeconfig builds the kubeconfig entries nctl uses to talk to the Nine API and to Kubernetes clusters, and merges them into the user's kubeconfig.
Index ¶
- func Login(w format.Writer, newConfig *clientcmdapi.Config, ...) error
- func LoginCluster(ctx context.Context, client *api.Client, w format.Writer, ...) error
- func NewAPIConfig(apiURL, issuerURL *url.URL, command, clientID string, opts ...APIConfigOption) (*clientcmdapi.Config, error)
- func RemoveContext(configAccess clientcmd.ConfigAccess, name string) error
- type APIConfigOption
- func OverrideName(name string) APIConfigOption
- func UseClientCredentials(credentials ClientCredentials) APIConfigOption
- func UseStaticToken(token string) APIConfigOption
- func WithCACert(caCert []byte) APIConfigOption
- func WithOrganization(organization string) APIConfigOption
- func WithStorage(storage api.Storage) APIConfigOption
- type ClientCredentials
- type LoginOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Login ¶
func Login(w format.Writer, newConfig *clientcmdapi.Config, kubeconfigPath, userName string, toOrg string, opts ...LoginOption) error
Login merges newConfig into the kubeconfig at kubeconfigPath, creating the file if it does not exist, and reports the result to w. userName and toOrg are only used in the messages and may be empty.
func LoginCluster ¶
func LoginCluster(ctx context.Context, client *api.Client, w format.Writer, name types.NamespacedName, execPlugin bool) error
LoginCluster adds the KubernetesCluster name to the kubeconfig of client and switches the current context to it. If execPlugin is set, the OIDC exec plugin is run right away so the user is logged in and named in the output.
func NewAPIConfig ¶
func NewAPIConfig(apiURL, issuerURL *url.URL, command, clientID string, opts ...APIConfigOption) (*clientcmdapi.Config, error)
NewAPIConfig returns a kubeconfig with a single cluster, context and user for the API at apiURL. Unless a static token or client credentials are configured, the user authenticates through the OIDC exec plugin of the nctl binary at command.
func RemoveContext ¶ added in v1.22.0
func RemoveContext(configAccess clientcmd.ConfigAccess, name string) error
RemoveContext removes the context name and its user from the kubeconfig of configAccess. The cluster of the context is removed too unless another context uses it. Each entry is removed from the file that defines it. It returns fs.ErrNotExist if the kubeconfig has no context name.
Types ¶
type APIConfigOption ¶
type APIConfigOption func(*apiConfig)
APIConfigOption configures the kubeconfig built by NewAPIConfig.
func OverrideName ¶
func OverrideName(name string) APIConfigOption
OverrideName sets the name used for the cluster, context and user entry instead of the API URL host.
func UseClientCredentials ¶
func UseClientCredentials(credentials ClientCredentials) APIConfigOption
UseClientCredentials authenticates through the client-credentials exec plugin instead of the interactive OIDC one.
func UseStaticToken ¶
func UseStaticToken(token string) APIConfigOption
UseStaticToken authenticates with a static token instead of an exec plugin.
func WithCACert ¶
func WithCACert(caCert []byte) APIConfigOption
WithCACert sets the certificate authority data of the cluster entry.
func WithOrganization ¶
func WithOrganization(organization string) APIConfigOption
WithOrganization records the organization in the nctl context extension.
func WithStorage ¶ added in v1.22.0
func WithStorage(storage api.Storage) APIConfigOption
WithStorage sets where the exec plugin caches its tokens or reads its client secret, api.StorageKeyring by default.
type ClientCredentials ¶
ClientCredentials identify the APIServiceAccount the exec plugin obtains a token for. The client secret is not part of the kubeconfig, the exec plugin reads it with api.LookupClientSecret.
type LoginOption ¶
type LoginOption func(*loginConfig)
LoginOption configures Login.
func SwitchCurrentContext ¶
func SwitchCurrentContext() LoginOption
SwitchCurrentContext sets the current context of the merged kubeconfig to the one of the new config.
func WithProject ¶
func WithProject(project string) LoginOption
WithProject sets the project (namespace) of the new config's context.