2 Copyright 2014 The Kubernetes Authors.
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
20 "k8s.io/apimachinery/pkg/runtime"
23 // Where possible, json tags match the cli argument names.
24 // Top level config objects and all values required for proper functioning are not "omitempty". Any truly optional piece of config is allowed to be omitted.
26 // Config holds the information needed to build connect to remote kubernetes clusters as a given user
27 // IMPORTANT if you add fields to this struct, please update IsConfigEmpty()
28 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
30 // Legacy field from pkg/api/types.go TypeMeta.
31 // TODO(jlowdermilk): remove this after eliminating downstream dependencies.
33 Kind string `json:"kind,omitempty"`
34 // Legacy field from pkg/api/types.go TypeMeta.
35 // TODO(jlowdermilk): remove this after eliminating downstream dependencies.
37 APIVersion string `json:"apiVersion,omitempty"`
38 // Preferences holds general information to be use for cli interactions
39 Preferences Preferences `json:"preferences"`
40 // Clusters is a map of referencable names to cluster configs
41 Clusters map[string]*Cluster `json:"clusters"`
42 // AuthInfos is a map of referencable names to user configs
43 AuthInfos map[string]*AuthInfo `json:"users"`
44 // Contexts is a map of referencable names to context configs
45 Contexts map[string]*Context `json:"contexts"`
46 // CurrentContext is the name of the context that you would like to use by default
47 CurrentContext string `json:"current-context"`
48 // Extensions holds additional information. This is useful for extenders so that reads and writes don't clobber unknown fields
50 Extensions map[string]runtime.Object `json:"extensions,omitempty"`
53 // IMPORTANT if you add fields to this struct, please update IsConfigEmpty()
54 type Preferences struct {
56 Colors bool `json:"colors,omitempty"`
57 // Extensions holds additional information. This is useful for extenders so that reads and writes don't clobber unknown fields
59 Extensions map[string]runtime.Object `json:"extensions,omitempty"`
62 // Cluster contains information about how to communicate with a kubernetes cluster
64 // LocationOfOrigin indicates where this object came from. It is used for round tripping config post-merge, but never serialized.
65 LocationOfOrigin string
66 // Server is the address of the kubernetes cluster (https://hostname:port).
67 Server string `json:"server"`
68 // InsecureSkipTLSVerify skips the validity check for the server's certificate. This will make your HTTPS connections insecure.
70 InsecureSkipTLSVerify bool `json:"insecure-skip-tls-verify,omitempty"`
71 // CertificateAuthority is the path to a cert file for the certificate authority.
73 CertificateAuthority string `json:"certificate-authority,omitempty"`
74 // CertificateAuthorityData contains PEM-encoded certificate authority certificates. Overrides CertificateAuthority
76 CertificateAuthorityData []byte `json:"certificate-authority-data,omitempty"`
77 // Extensions holds additional information. This is useful for extenders so that reads and writes don't clobber unknown fields
79 Extensions map[string]runtime.Object `json:"extensions,omitempty"`
82 // AuthInfo contains information that describes identity information. This is use to tell the kubernetes cluster who you are.
83 type AuthInfo struct {
84 // LocationOfOrigin indicates where this object came from. It is used for round tripping config post-merge, but never serialized.
85 LocationOfOrigin string
86 // ClientCertificate is the path to a client cert file for TLS.
88 ClientCertificate string `json:"client-certificate,omitempty"`
89 // ClientCertificateData contains PEM-encoded data from a client cert file for TLS. Overrides ClientCertificate
91 ClientCertificateData []byte `json:"client-certificate-data,omitempty"`
92 // ClientKey is the path to a client key file for TLS.
94 ClientKey string `json:"client-key,omitempty"`
95 // ClientKeyData contains PEM-encoded data from a client key file for TLS. Overrides ClientKey
97 ClientKeyData []byte `json:"client-key-data,omitempty"`
98 // Token is the bearer token for authentication to the kubernetes cluster.
100 Token string `json:"token,omitempty"`
101 // TokenFile is a pointer to a file that contains a bearer token (as described above). If both Token and TokenFile are present, Token takes precedence.
103 TokenFile string `json:"tokenFile,omitempty"`
104 // Impersonate is the username to act-as.
106 Impersonate string `json:"act-as,omitempty"`
107 // ImpersonateGroups is the groups to imperonate.
109 ImpersonateGroups []string `json:"act-as-groups,omitempty"`
110 // ImpersonateUserExtra contains additional information for impersonated user.
112 ImpersonateUserExtra map[string][]string `json:"act-as-user-extra,omitempty"`
113 // Username is the username for basic authentication to the kubernetes cluster.
115 Username string `json:"username,omitempty"`
116 // Password is the password for basic authentication to the kubernetes cluster.
118 Password string `json:"password,omitempty"`
119 // AuthProvider specifies a custom authentication plugin for the kubernetes cluster.
121 AuthProvider *AuthProviderConfig `json:"auth-provider,omitempty"`
122 // Exec specifies a custom exec-based authentication plugin for the kubernetes cluster.
124 Exec *ExecConfig `json:"exec,omitempty"`
125 // Extensions holds additional information. This is useful for extenders so that reads and writes don't clobber unknown fields
127 Extensions map[string]runtime.Object `json:"extensions,omitempty"`
130 // Context is a tuple of references to a cluster (how do I communicate with a kubernetes cluster), a user (how do I identify myself), and a namespace (what subset of resources do I want to work with)
131 type Context struct {
132 // LocationOfOrigin indicates where this object came from. It is used for round tripping config post-merge, but never serialized.
133 LocationOfOrigin string
134 // Cluster is the name of the cluster for this context
135 Cluster string `json:"cluster"`
136 // AuthInfo is the name of the authInfo for this context
137 AuthInfo string `json:"user"`
138 // Namespace is the default namespace to use on unspecified requests
140 Namespace string `json:"namespace,omitempty"`
141 // Extensions holds additional information. This is useful for extenders so that reads and writes don't clobber unknown fields
143 Extensions map[string]runtime.Object `json:"extensions,omitempty"`
146 // AuthProviderConfig holds the configuration for a specified auth provider.
147 type AuthProviderConfig struct {
148 Name string `json:"name"`
150 Config map[string]string `json:"config,omitempty"`
153 // ExecConfig specifies a command to provide client credentials. The command is exec'd
154 // and outputs structured stdout holding credentials.
156 // See the client.authentiction.k8s.io API group for specifications of the exact input
158 type ExecConfig struct {
159 // Command to execute.
160 Command string `json:"command"`
161 // Arguments to pass to the command when executing it.
163 Args []string `json:"args"`
164 // Env defines additional environment variables to expose to the process. These
165 // are unioned with the host's environment, as well as variables client-go uses
166 // to pass argument to the plugin.
168 Env []ExecEnvVar `json:"env"`
170 // Preferred input version of the ExecInfo. The returned ExecCredentials MUST use
171 // the same encoding version as the input.
172 APIVersion string `json:"apiVersion,omitempty"`
175 // ExecEnvVar is used for setting environment variables when executing an exec-based
176 // credential plugin.
177 type ExecEnvVar struct {
178 Name string `json:"name"`
179 Value string `json:"value"`
182 // NewConfig is a convenience function that returns a new Config object with non-nil maps
183 func NewConfig() *Config {
185 Preferences: *NewPreferences(),
186 Clusters: make(map[string]*Cluster),
187 AuthInfos: make(map[string]*AuthInfo),
188 Contexts: make(map[string]*Context),
189 Extensions: make(map[string]runtime.Object),
193 // NewContext is a convenience function that returns a new Context
194 // object with non-nil maps
195 func NewContext() *Context {
196 return &Context{Extensions: make(map[string]runtime.Object)}
199 // NewCluster is a convenience function that returns a new Cluster
200 // object with non-nil maps
201 func NewCluster() *Cluster {
202 return &Cluster{Extensions: make(map[string]runtime.Object)}
205 // NewAuthInfo is a convenience function that returns a new AuthInfo
206 // object with non-nil maps
207 func NewAuthInfo() *AuthInfo {
209 Extensions: make(map[string]runtime.Object),
210 ImpersonateUserExtra: make(map[string][]string),
214 // NewPreferences is a convenience function that returns a new
215 // Preferences object with non-nil maps
216 func NewPreferences() *Preferences {
217 return &Preferences{Extensions: make(map[string]runtime.Object)}