Merge pull request #15019 from hashicorp/f-k8s-pvc-unbound-reason
provider/kubernetes: Provide more details about why PVC failed to bind
This commit is contained in:
commit
a4c9c40c32
|
@ -9,6 +9,7 @@ import (
|
|||
"github.com/hashicorp/terraform/helper/schema"
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/fields"
|
||||
pkgApi "k8s.io/apimachinery/pkg/types"
|
||||
api "k8s.io/kubernetes/pkg/api/v1"
|
||||
kubernetes "k8s.io/kubernetes/pkg/client/clientset_generated/clientset"
|
||||
|
@ -165,6 +166,7 @@ func resourceKubernetesPersistentVolumeClaimCreate(d *schema.ResourceData, meta
|
|||
name := out.ObjectMeta.Name
|
||||
|
||||
if d.Get("wait_until_bound").(bool) {
|
||||
var lastEvent api.Event
|
||||
stateConf := &resource.StateChangeConf{
|
||||
Target: []string{"Bound"},
|
||||
Pending: []string{"Pending"},
|
||||
|
@ -176,6 +178,20 @@ func resourceKubernetesPersistentVolumeClaimCreate(d *schema.ResourceData, meta
|
|||
return out, "", err
|
||||
}
|
||||
|
||||
events, err := conn.CoreV1().Events(metadata.Namespace).List(meta_v1.ListOptions{
|
||||
FieldSelector: fields.Set(map[string]string{
|
||||
"involvedObject.name": metadata.Name,
|
||||
"involvedObject.namespace": metadata.Namespace,
|
||||
"involvedObject.kind": "PersistentVolumeClaim",
|
||||
}).String(),
|
||||
})
|
||||
if err != nil {
|
||||
return out, "", err
|
||||
}
|
||||
if len(events.Items) > 0 {
|
||||
lastEvent = events.Items[0]
|
||||
}
|
||||
|
||||
statusPhase := fmt.Sprintf("%v", out.Status.Phase)
|
||||
log.Printf("[DEBUG] Persistent volume claim %s status received: %#v", out.Name, statusPhase)
|
||||
return out, statusPhase, nil
|
||||
|
@ -183,7 +199,11 @@ func resourceKubernetesPersistentVolumeClaimCreate(d *schema.ResourceData, meta
|
|||
}
|
||||
_, err = stateConf.WaitForState()
|
||||
if err != nil {
|
||||
return err
|
||||
reason := ""
|
||||
if lastEvent.Reason != "" {
|
||||
reason = fmt.Sprintf(". Reason: %s: %s", lastEvent.Reason, lastEvent.Message)
|
||||
}
|
||||
return fmt.Errorf("%s%s", err, reason)
|
||||
}
|
||||
}
|
||||
log.Printf("[INFO] Persistent volume claim %s created", out.Name)
|
||||
|
|
Loading…
Reference in New Issue