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

resource/kubernetes_persistent_volume_claim: Improve event log polling for warns #125

Merged
merged 1 commit into from
Feb 26, 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
18 changes: 12 additions & 6 deletions kubernetes/event_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ import (
)

func getLastWarningsForObject(conn *kubernetes.Clientset, metadata meta_v1.ObjectMeta, kind string, limit int) ([]api.Event, error) {
fs := fields.Set(map[string]string{
"involvedObject.name": metadata.Name,
"involvedObject.namespace": metadata.Namespace,
"involvedObject.kind": kind,
}).String()
m := map[string]string{
"involvedObject.name": metadata.Name,
"involvedObject.kind": kind,
}
if metadata.Namespace != "" {
m["involvedObject.namespace"] = metadata.Namespace
}

fs := fields.Set(m).String()
log.Printf("[DEBUG] Looking up events via this selector: %q", fs)
out, err := conn.CoreV1().Events(metadata.Namespace).List(meta_v1.ListOptions{
FieldSelector: fs,
Expand Down Expand Up @@ -61,7 +65,9 @@ func getLastWarningsForObject(conn *kubernetes.Clientset, metadata meta_v1.Objec
func stringifyEvents(events []api.Event) string {
var output string
for _, e := range events {
output += fmt.Sprintf("\n * %s: %s", e.Reason, e.Message)
output += fmt.Sprintf("\n * %s (%s): %s: %s",
e.InvolvedObject.Name, e.InvolvedObject.Kind,
e.Reason, e.Message)
}
return output
}
15 changes: 14 additions & 1 deletion kubernetes/resource_kubernetes_persistent_volume_claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,23 @@ func resourceKubernetesPersistentVolumeClaimCreate(d *schema.ResourceData, meta
}
_, err = stateConf.WaitForState()
if err != nil {
lastWarnings, wErr := getLastWarningsForObject(conn, out.ObjectMeta, "PersistentVolumeClaim", 3)
var lastWarnings []api.Event
var wErr error

lastWarnings, wErr = getLastWarningsForObject(conn, out.ObjectMeta, "PersistentVolumeClaim", 3)
if wErr != nil {
return wErr
}

if len(lastWarnings) == 0 {
lastWarnings, wErr = getLastWarningsForObject(conn, meta_v1.ObjectMeta{
Name: out.Spec.VolumeName,
}, "PersistentVolume", 3)
if wErr != nil {
return wErr
}
}

return fmt.Errorf("%s%s", err, stringifyEvents(lastWarnings))
}
}
Expand Down