blob: 1391df7021bddbb657cf35ecf95e68c161b2ce4a [file] [log] [blame]
sslobodrd046be82019-01-16 10:02:22 -05001/*
2Copyright 2014 The Kubernetes Authors.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17package api
18
19import (
20 "k8s.io/apimachinery/pkg/runtime"
21)
22
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.
25
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
29type Config struct {
30 // Legacy field from pkg/api/types.go TypeMeta.
31 // TODO(jlowdermilk): remove this after eliminating downstream dependencies.
32 // +optional
33 Kind string `json:"kind,omitempty"`
34 // Legacy field from pkg/api/types.go TypeMeta.
35 // TODO(jlowdermilk): remove this after eliminating downstream dependencies.
36 // +optional
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
49 // +optional
50 Extensions map[string]runtime.Object `json:"extensions,omitempty"`
51}
52
53// IMPORTANT if you add fields to this struct, please update IsConfigEmpty()
54type Preferences struct {
55 // +optional
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
58 // +optional
59 Extensions map[string]runtime.Object `json:"extensions,omitempty"`
60}
61
62// Cluster contains information about how to communicate with a kubernetes cluster
63type Cluster struct {
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.
69 // +optional
70 InsecureSkipTLSVerify bool `json:"insecure-skip-tls-verify,omitempty"`
71 // CertificateAuthority is the path to a cert file for the certificate authority.
72 // +optional
73 CertificateAuthority string `json:"certificate-authority,omitempty"`
74 // CertificateAuthorityData contains PEM-encoded certificate authority certificates. Overrides CertificateAuthority
75 // +optional
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
78 // +optional
79 Extensions map[string]runtime.Object `json:"extensions,omitempty"`
80}
81
82// AuthInfo contains information that describes identity information. This is use to tell the kubernetes cluster who you are.
83type 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.
87 // +optional
88 ClientCertificate string `json:"client-certificate,omitempty"`
89 // ClientCertificateData contains PEM-encoded data from a client cert file for TLS. Overrides ClientCertificate
90 // +optional
91 ClientCertificateData []byte `json:"client-certificate-data,omitempty"`
92 // ClientKey is the path to a client key file for TLS.
93 // +optional
94 ClientKey string `json:"client-key,omitempty"`
95 // ClientKeyData contains PEM-encoded data from a client key file for TLS. Overrides ClientKey
96 // +optional
97 ClientKeyData []byte `json:"client-key-data,omitempty"`
98 // Token is the bearer token for authentication to the kubernetes cluster.
99 // +optional
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.
102 // +optional
103 TokenFile string `json:"tokenFile,omitempty"`
104 // Impersonate is the username to act-as.
105 // +optional
106 Impersonate string `json:"act-as,omitempty"`
107 // ImpersonateGroups is the groups to imperonate.
108 // +optional
109 ImpersonateGroups []string `json:"act-as-groups,omitempty"`
110 // ImpersonateUserExtra contains additional information for impersonated user.
111 // +optional
112 ImpersonateUserExtra map[string][]string `json:"act-as-user-extra,omitempty"`
113 // Username is the username for basic authentication to the kubernetes cluster.
114 // +optional
115 Username string `json:"username,omitempty"`
116 // Password is the password for basic authentication to the kubernetes cluster.
117 // +optional
118 Password string `json:"password,omitempty"`
119 // AuthProvider specifies a custom authentication plugin for the kubernetes cluster.
120 // +optional
121 AuthProvider *AuthProviderConfig `json:"auth-provider,omitempty"`
122 // Exec specifies a custom exec-based authentication plugin for the kubernetes cluster.
123 // +optional
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
126 // +optional
127 Extensions map[string]runtime.Object `json:"extensions,omitempty"`
128}
129
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)
131type 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
139 // +optional
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
142 // +optional
143 Extensions map[string]runtime.Object `json:"extensions,omitempty"`
144}
145
146// AuthProviderConfig holds the configuration for a specified auth provider.
147type AuthProviderConfig struct {
148 Name string `json:"name"`
149 // +optional
150 Config map[string]string `json:"config,omitempty"`
151}
152
153// ExecConfig specifies a command to provide client credentials. The command is exec'd
154// and outputs structured stdout holding credentials.
155//
156// See the client.authentiction.k8s.io API group for specifications of the exact input
157// and output format
158type ExecConfig struct {
159 // Command to execute.
160 Command string `json:"command"`
161 // Arguments to pass to the command when executing it.
162 // +optional
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.
167 // +optional
168 Env []ExecEnvVar `json:"env"`
169
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"`
173}
174
175// ExecEnvVar is used for setting environment variables when executing an exec-based
176// credential plugin.
177type ExecEnvVar struct {
178 Name string `json:"name"`
179 Value string `json:"value"`
180}
181
182// NewConfig is a convenience function that returns a new Config object with non-nil maps
183func NewConfig() *Config {
184 return &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),
190 }
191}
192
193// NewContext is a convenience function that returns a new Context
194// object with non-nil maps
195func NewContext() *Context {
196 return &Context{Extensions: make(map[string]runtime.Object)}
197}
198
199// NewCluster is a convenience function that returns a new Cluster
200// object with non-nil maps
201func NewCluster() *Cluster {
202 return &Cluster{Extensions: make(map[string]runtime.Object)}
203}
204
205// NewAuthInfo is a convenience function that returns a new AuthInfo
206// object with non-nil maps
207func NewAuthInfo() *AuthInfo {
208 return &AuthInfo{
209 Extensions: make(map[string]runtime.Object),
210 ImpersonateUserExtra: make(map[string][]string),
211 }
212}
213
214// NewPreferences is a convenience function that returns a new
215// Preferences object with non-nil maps
216func NewPreferences() *Preferences {
217 return &Preferences{Extensions: make(map[string]runtime.Object)}
218}