make kubernetes plugin kubeconfig argument 'context' optional (#4451)

Signed-off-by: answer1991 <answer1991.chen@gmail.com>
This commit is contained in:
Jun Chen 2021-02-09 21:36:32 +08:00 committed by GitHub
parent 632463d3a9
commit a5bc3891e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 10 deletions

View file

@ -33,7 +33,7 @@ all the zones the plugin should be authoritative for.
kubernetes [ZONES...] {
endpoint URL
tls CERT KEY CACERT
kubeconfig KUBECONFIG CONTEXT
kubeconfig KUBECONFIG [CONTEXT]
namespaces NAMESPACE...
labels EXPRESSION
pods POD-MODE
@ -49,7 +49,10 @@ kubernetes [ZONES...] {
If omitted, it will connect to k8s in-cluster using the cluster service account.
* `tls` **CERT** **KEY** **CACERT** are the TLS cert, key and the CA cert file names for remote k8s connection.
This option is ignored if connecting in-cluster (i.e. endpoint is not specified).
* `kubeconfig` **KUBECONFIG** **CONTEXT** authenticates the connection to a remote k8s cluster using a kubeconfig file. It supports TLS, username and password, or token-based authentication. This option is ignored if connecting in-cluster (i.e., the endpoint is not specified).
* `kubeconfig` **KUBECONFIG [CONTEXT]** authenticates the connection to a remote k8s cluster using a kubeconfig file.
**[CONTEXT]** is optional, if not set, then the current context specified in kubeconfig will be used.
It supports TLS, username and password, or token-based authentication.
This option is ignored if connecting in-cluster (i.e., the endpoint is not specified).
* `namespaces` **NAMESPACE [NAMESPACE...]** only exposes the k8s namespaces listed.
If this option is omitted all namespaces are exposed
* `namespace_labels` **EXPRESSION** only expose the records for Kubernetes namespaces that match this label selector.

View file

@ -253,15 +253,18 @@ func ParseStanza(c *caddy.Controller) (*Kubernetes, error) {
}
case "kubeconfig":
args := c.RemainingArgs()
if len(args) == 2 {
config := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
&clientcmd.ClientConfigLoadingRules{ExplicitPath: args[0]},
&clientcmd.ConfigOverrides{CurrentContext: args[1]},
)
k8s.ClientConfig = config
continue
if len(args) != 1 && len(args) != 2 {
return nil, c.ArgErr()
}
return nil, c.ArgErr()
overrides := &clientcmd.ConfigOverrides{}
if len(args) == 2 {
overrides.CurrentContext = args[1]
}
config := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
&clientcmd.ClientConfigLoadingRules{ExplicitPath: args[0]},
overrides,
)
k8s.ClientConfig = config
default:
return nil, c.Errf("unknown property '%s'", c.Val())
}

View file

@ -329,6 +329,19 @@ kubernetes cluster.local`,
},
{
`kubernetes coredns.local {
kubeconfig file
}`,
false,
"",
1,
0,
"",
"",
podModeDisabled,
fall.Zero,
},
{
`kubernetes coredns.local {
kubeconfig file context
}`,
false,