Skip to content

Commit

Permalink
Merge pull request #151 from appilon/91-k8s-pod-timeout
Browse files Browse the repository at this point in the history
r/kubernetes_pod: Add timeout to pod resource
  • Loading branch information
appilon authored Apr 9, 2018
2 parents d310211 + 1227610 commit ea3b56c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
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

0 comments on commit ea3b56c

Please sign in to comment.