-
Notifications
You must be signed in to change notification settings - Fork 984
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support of client-go credential plugins in auth #396
Conversation
This looks like this would close #161 so I have edited the PR description to automatically close it. I cannot provide a full review of this enhancement, but can provide some review of the Go/Terraform Provider SDK code. 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking care of this issue. Change mostly looks good.
I've one suggestion about the type of structure used to model it. See below.
@bflad Happy to have your eyes on it too and please add any suggestions you might have.
kubernetes/provider.go
Outdated
@@ -101,6 +101,33 @@ func Provider() terraform.ResourceProvider { | |||
DefaultFunc: schema.EnvDefaultFunc("KUBE_LOAD_CONFIG_FILE", true), | |||
Description: "Load local kubeconfig.", | |||
}, | |||
"exec": { | |||
Type: schema.TypeSet, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please make this a TypeList instead?
I've found that in Terraform 0.12+ a TypeList works best for modeling a complex block, such as this.
kubernetes/provider.go
Outdated
@@ -101,6 +101,33 @@ func Provider() terraform.ResourceProvider { | |||
DefaultFunc: schema.EnvDefaultFunc("KUBE_LOAD_CONFIG_FILE", true), | |||
Description: "Load local kubeconfig.", | |||
}, | |||
"exec": { | |||
Type: schema.TypeSet, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With MaxItems: 1
configurations blocks, it is generally preferred to use Type: schema.TypeList
to simplify handling. 👍
website/docs/index.html.markdown
Outdated
@@ -109,4 +109,4 @@ The following arguments are supported: | |||
* `config_context_cluster` - (Optional) Cluster context of the kube config (name of the kubeconfig cluster, `--cluster` flag in `kubectl`). Can be sourced from `KUBE_CTX_CLUSTER`. | |||
* `token` - (Optional) Token of your service account. Can be sourced from `KUBE_TOKEN`. | |||
* `load_config_file` - (Optional) By default the local config (~/.kube/config) is loaded when you use this provider. This option at false disable this behaviour. Can be sourced from `KUBE_LOAD_CONFIG_FILE`. | |||
|
|||
* `exec` - (Optional) Exec-based client auth provider (https://kubernetes.io/docs/reference/access-authn-authz/authentication/#client-go-credential-plugins) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we are adding a new configuration block with nested arguments, we should appropriately document everything here. 👍
* `exec` - (Optional) Exec-based client auth provider (https://kubernetes.io/docs/reference/access-authn-authz/authentication/#client-go-credential-plugins) | |
* `exec` - (Optional) Configuration block to use an [exec-based credential plugin](https://kubernetes.io/docs/reference/access-authn-authz/authentication/#client-go-credential-plugins), e.g. call an external command to receive user credentials. | |
* `api_version` - (Required) API version to use when decoding the ExecCredentials resource, e.g. `client.authentication.k8s.io/v1beta1`. | |
* `command` - (Required) Command to execute. | |
* `args` - (Optional) List of arguments to pass when executing the plugin. | |
* `env` - (Optional) Map of environment variables to set when executing the plugin. |
kubernetes/provider.go
Outdated
@@ -181,6 +208,18 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) { | |||
cfg.BearerToken = v.(string) | |||
} | |||
|
|||
if v, ok := d.GetOk("exec"); ok { | |||
exec := &clientcmdapi.ExecConfig{} | |||
spec := v.(*schema.Set).List()[0].(map[string]interface{}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, would you mind breaking down this line into multiple steps and check for errors and nils on the type assertions. This looks like it has the potential to panic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In theory, it should pass by the schema checker, but I've added an extra check to avoid the panic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -101,6 +101,34 @@ func Provider() terraform.ResourceProvider { | |||
DefaultFunc: schema.EnvDefaultFunc("KUBE_LOAD_CONFIG_FILE", true), | |||
Description: "Load local kubeconfig.", | |||
}, | |||
"exec": { | |||
Type: schema.TypeList, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why wasn't this done as TypeMap
?
Is this in a release? The code is in available at least in 1.10.0, but I'm getting:
|
Ah, it's a block. I see.
|
@chancez did the block above work for you ? what versions are you using ?
|
It did.
|
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks! |
Closes #161