Skip to content

Recognize component-level failure for batch/v1 Jobs #165

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

Merged
merged 1 commit into from
Jun 24, 2024
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
45 changes: 24 additions & 21 deletions internal/controller/appwrapper/appwrapper_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"strconv"
"time"

batchv1 "k8s.io/api/batch/v1"
v1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
Expand Down Expand Up @@ -515,8 +516,8 @@ func (r *AppWrapperReconciler) getComponentStatus(ctx context.Context, aw *workl

for componentIdx := range aw.Status.ComponentStatus {
cs := &aw.Status.ComponentStatus[componentIdx]
switch cs.Kind {
case "PyTorchJob":
switch cs.APIVersion + ":" + cs.Kind {
case "kubeflow.org/v1:PyTorchJob":
obj := &unstructured.Unstructured{}
obj.SetAPIVersion(cs.APIVersion)
obj.SetKind(cs.Kind)
Expand Down Expand Up @@ -547,16 +548,26 @@ func (r *AppWrapperReconciler) getComponentStatus(ctx context.Context, aw *workl
}
}
}
} else {
if apierrors.IsNotFound(err) {
meta.SetStatusCondition(&aw.Status.ComponentStatus[componentIdx].Conditions, metav1.Condition{
Type: string(workloadv1beta2.Unhealthy),
Status: metav1.ConditionTrue,
Reason: "ComponentNotFound",
})
} else {
return nil, err
} else if !apierrors.IsNotFound(err) {
return nil, err
}

case "batch/v1:Job":
obj := &batchv1.Job{}
if err := r.Get(ctx, types.NamespacedName{Name: cs.Name, Namespace: aw.Namespace}, obj); err == nil {
if obj.GetDeletionTimestamp().IsZero() {
summary.deployed += 1

// batch/v1 Jobs are failed when status.Conditions contains an entry with type "Failed" and status "True"
for _, jc := range obj.Status.Conditions {
if jc.Type == batchv1.JobFailed && jc.Status == v1.ConditionTrue {
summary.failed += 1
}
}
}

} else if !apierrors.IsNotFound(err) {
return nil, err
}

default:
Expand All @@ -565,16 +576,8 @@ func (r *AppWrapperReconciler) getComponentStatus(ctx context.Context, aw *workl
if obj.GetDeletionTimestamp().IsZero() {
summary.deployed += 1
}
} else {
if apierrors.IsNotFound(err) {
meta.SetStatusCondition(&aw.Status.ComponentStatus[componentIdx].Conditions, metav1.Condition{
Type: string(workloadv1beta2.Unhealthy),
Status: metav1.ConditionTrue,
Reason: "ComponentNotFound",
})
} else {
return nil, err
}
} else if !apierrors.IsNotFound(err) {
return nil, err
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions samples/wrapped-failing-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ spec:
metadata:
name: sample-failing-job
spec:
backoffLimit: 1
completions: 1
template:
spec:
restartPolicy: Never
Expand Down