make kubernetes plugin kubeconfig argument 'context' optional (#4451)
Signed-off-by: answer1991 <answer1991.chen@gmail.com>
This commit is contained in:
parent
632463d3a9
commit
a5bc3891e8
3 changed files with 29 additions and 10 deletions
|
@ -33,7 +33,7 @@ all the zones the plugin should be authoritative for.
|
||||||
kubernetes [ZONES...] {
|
kubernetes [ZONES...] {
|
||||||
endpoint URL
|
endpoint URL
|
||||||
tls CERT KEY CACERT
|
tls CERT KEY CACERT
|
||||||
kubeconfig KUBECONFIG CONTEXT
|
kubeconfig KUBECONFIG [CONTEXT]
|
||||||
namespaces NAMESPACE...
|
namespaces NAMESPACE...
|
||||||
labels EXPRESSION
|
labels EXPRESSION
|
||||||
pods POD-MODE
|
pods POD-MODE
|
||||||
|
@ -49,7 +49,10 @@ kubernetes [ZONES...] {
|
||||||
If omitted, it will connect to k8s in-cluster using the cluster service account.
|
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.
|
* `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).
|
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.
|
* `namespaces` **NAMESPACE [NAMESPACE...]** only exposes the k8s namespaces listed.
|
||||||
If this option is omitted all namespaces are exposed
|
If this option is omitted all namespaces are exposed
|
||||||
* `namespace_labels` **EXPRESSION** only expose the records for Kubernetes namespaces that match this label selector.
|
* `namespace_labels` **EXPRESSION** only expose the records for Kubernetes namespaces that match this label selector.
|
||||||
|
|
|
@ -253,15 +253,18 @@ func ParseStanza(c *caddy.Controller) (*Kubernetes, error) {
|
||||||
}
|
}
|
||||||
case "kubeconfig":
|
case "kubeconfig":
|
||||||
args := c.RemainingArgs()
|
args := c.RemainingArgs()
|
||||||
if len(args) == 2 {
|
if len(args) != 1 && len(args) != 2 {
|
||||||
config := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
|
return nil, c.ArgErr()
|
||||||
&clientcmd.ClientConfigLoadingRules{ExplicitPath: args[0]},
|
|
||||||
&clientcmd.ConfigOverrides{CurrentContext: args[1]},
|
|
||||||
)
|
|
||||||
k8s.ClientConfig = config
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
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:
|
default:
|
||||||
return nil, c.Errf("unknown property '%s'", c.Val())
|
return nil, c.Errf("unknown property '%s'", c.Val())
|
||||||
}
|
}
|
||||||
|
|
|
@ -329,6 +329,19 @@ kubernetes cluster.local`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
`kubernetes coredns.local {
|
`kubernetes coredns.local {
|
||||||
|
kubeconfig file
|
||||||
|
}`,
|
||||||
|
false,
|
||||||
|
"",
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
podModeDisabled,
|
||||||
|
fall.Zero,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
`kubernetes coredns.local {
|
||||||
kubeconfig file context
|
kubeconfig file context
|
||||||
}`,
|
}`,
|
||||||
false,
|
false,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue