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

Aggregate error messages from Pods on Job Read #831

Merged
merged 1 commit into from
Oct 8, 2019
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
- v1.15.x
- v1.14.x

### Improvements

- Aggregate error messages from Pods on Job Read. (https://github.com/pulumi/pulumi-kubernetes/pull/831).

## 1.2.0 (October 4, 2019)

### Supported Kubernetes versions
Expand Down
12 changes: 11 additions & 1 deletion pkg/await/batch_job.go → pkg/await/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,19 @@ func (jia *jobInitAwaiter) Read() error {
return nil
}

podAggregator, err := NewPodAggregator(ResourceIdFromUnstructured(jia.job), jia.config.clientSet)
if err != nil {
return errors.Wrapf(err, "Could not create PodAggregator for %s", jia.resource.GVKString())
}
messages := podAggregator.Read()
for _, message := range messages {
jia.errors.Add(message)
jia.config.logMessage(message)
}

return &initializationError{
subErrors: jia.errorMessages(),
object: job,
object: job,
}
}

Expand Down
29 changes: 29 additions & 0 deletions pkg/await/watchers.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,35 @@ func (pa *PodAggregator) run() {
}
}

// Read lists existing Pods and returns any related warning/error messages.
func (pa *PodAggregator) Read() logging.Messages {
var messages logging.Messages
checkPod := func(object runtime.Object) {
pod, err := clients.PodFromUnstructured(object.(*unstructured.Unstructured))
if err != nil {
glog.V(3).Infof("Failed to unmarshal Pod event: %v", err)
return
}
if relatedResource(pa.owner, pod) {
messages = append(messages, pa.checker.Update(pod).MessagesWithSeverity(diag.Warning, diag.Error)...)
}
}

// Get existing Pods.
pods, err := pa.client.List(metav1.ListOptions{})
if err != nil {
glog.V(3).Infof("Failed to list existing Pods: %v", err)
} else {
// Log errors and move on.
_ = pods.EachListItem(func(object runtime.Object) error {
checkPod(object)
return nil
})
}

return messages
}

// Stop safely stops a PodAggregator and underlying watch client.
func (pa *PodAggregator) Stop() {
pa.Lock()
Expand Down