Skip to content
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

r/kubernetes_pod: Add timeout to pod resource #151

Merged
merged 2 commits into from
Apr 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions kubernetes/resource_kubernetes_pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ func resourceKubernetesPod() *schema.Resource {
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(5 * time.Minute),
Delete: schema.DefaultTimeout(5 * time.Minute),
},

Schema: map[string]*schema.Schema{
"metadata": namespacedMetadataSchema("pod", true),
"spec": {
Expand Down Expand Up @@ -67,7 +73,7 @@ func resourceKubernetesPodCreate(d *schema.ResourceData, meta interface{}) error
stateConf := &resource.StateChangeConf{
Target: []string{"Running"},
Pending: []string{"Pending"},
Timeout: 5 * time.Minute,
Timeout: d.Timeout(schema.TimeoutCreate),
Refresh: func() (interface{}, string, error) {
out, err := conn.CoreV1().Pods(metadata.Namespace).Get(metadata.Name, metav1.GetOptions{})
if err != nil {
Expand Down Expand Up @@ -174,7 +180,7 @@ func resourceKubernetesPodDelete(d *schema.ResourceData, meta interface{}) error
return err
}

err = resource.Retry(5*time.Minute, func() *resource.RetryError {
err = resource.Retry(d.Timeout(schema.TimeoutDelete), func() *resource.RetryError {
out, err := conn.CoreV1().Pods(namespace).Get(name, metav1.GetOptions{})
if err != nil {
if statusErr, ok := err.(*errors.StatusError); ok && statusErr.ErrStatus.Code == 404 {
Expand Down
8 changes: 8 additions & 0 deletions website/docs/r/pod.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ The following arguments are supported:
* `name` - (Optional) Name of the pod, must be unique. Cannot be updated. More info: http://kubernetes.io/docs/user-guide/identifiers#names
* `namespace` - (Optional) Namespace defines the space within which name of the pod must be unique.

### Timeouts

`kubernetes_pod` provides the following
[Timeouts](/docs/configuration/resources.html#timeouts) configuration options:

- `create` - (Default `5 minutes`) Used for Creating Pods.
- `delete` - (Default `5 minutes`) Used for Destroying Pods.

#### Attributes

* `generation` - A sequence number representing a specific generation of the desired state.
Expand Down