-
Notifications
You must be signed in to change notification settings - Fork 73
minor errors in pod.go #100
base: master
Are you sure you want to change the base?
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@@ -24,7 +24,7 @@ import ( | |||
"github.com/prometheus/client_golang/prometheus" | |||
"github.com/prometheus/client_golang/prometheus/promauto" | |||
log "github.com/sirupsen/logrus" | |||
"k8s.io/api/core/v1" | |||
v1 "k8s.io/api/core/v1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is unnecessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is created by gofmt I think, maybe we can keep it.
@@ -392,9 +392,9 @@ func (jc *JobController) ReconcilePods( | |||
} | |||
// Check if the pod is retryable. | |||
if spec.RestartPolicy == apiv1.RestartPolicyExitCode { | |||
if pod.Status.Phase == v1.PodFailed && trainutil.IsRetryableExitCode(exitCode) { | |||
if pod.Status.Phase == v1.PodFailed && !trainutil.IsRetryableExitCode(exitCode) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this was intended and correct but we probably need to improve the log message here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original logic here is to provide flexibility to define your own retryable exit code. This should not be changed.
Since kubernetes doesn't have restart method, That's the reason we delete
the pod, and wait for next reconcile
loop to create a new one. It's asynchronous so restart
here may be confused to users.
@@ -86,7 +86,7 @@ func (jc *JobController) AddPod(obj interface{}) { | |||
logger := commonutil.LoggerForPod(pod, jc.Controller.GetAPIGroupVersionKind().Kind) | |||
|
|||
if job == nil { | |||
if pod.Labels[apiv1.GroupNameLabel] == jc.Controller.GetGroupNameLabelValue() { | |||
if pod.Labels[apiv1.GroupNameLabel] != jc.Controller.GetGroupNameLabelValue() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch up
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check logics here.
common/pkg/controller.v1/common/job_controller.go
Lines 321 to 336 in ac0c6e1
func (jc *JobController) resolveControllerRef(namespace string, controllerRef *metav1.OwnerReference) metav1.Object { | |
// We can't look up by UID, so look up by Name and then verify UID. | |
// Don't even try to look up by Name if it's the wrong Kind. | |
if controllerRef.Kind != jc.Controller.GetAPIGroupVersionKind().Kind { | |
return nil | |
} | |
job, err := jc.Controller.GetJobFromInformerCache(namespace, controllerRef.Name) | |
if err != nil { | |
return nil | |
} | |
if job.GetUID() != controllerRef.UID { | |
// The controller we found with this Name is not the same one that the | |
// ControllerRef points to. | |
return nil | |
} | |
return job |
If we can not find the job, we will end reconcile loop and directly return
. The only thing matters is if we want to have some meaningful log.
There're several reason job == nil
here
- Kind doesn't match
- GroupNameLabel doesn't match
- Job doesn't exist. In this case, the pod is an orphan pod.
the 3rd one is the only case we want to persist the log. Does it make sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Jeffwan
Thank you so much Jeff. Much clearer after your patient explanation.
But I am still a little confused
I think the three cases should be:
1.Kind doesn't match
2.Name unmatched
3. Name matched but UID unmatched
My understanding is that third case cannot prove this pod is an orphan pod. It can only prove that the controllerRef point s to a different job.
Thank you again. Really appreciate your help
Thank you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xfate123 You are right. I didn't follow logic in resolveControllerRef
. UID mismatch is one of the cases. We check GroupNameLabel
again in caller side which I think is unnecessary. We use fixed value kubeflow.org
for most of the operators.
My understanding is that third case cannot prove this pod is an orphan pod. It can only prove that the controllerRef point s to a different job.
I may not explain this clearly. you are right. It could be an orphan pod (job has been deleted - case 2) or a pod point to different job (UID mismatch - case 3). case 1 seems match the criterion as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Jeffwan Thank you so much for your clear explanation
@@ -392,9 +392,9 @@ func (jc *JobController) ReconcilePods( | |||
} | |||
// Check if the pod is retryable. | |||
if spec.RestartPolicy == apiv1.RestartPolicyExitCode { | |||
if pod.Status.Phase == v1.PodFailed && trainutil.IsRetryableExitCode(exitCode) { | |||
if pod.Status.Phase == v1.PodFailed && !trainutil.IsRetryableExitCode(exitCode) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original logic here is to provide flexibility to define your own retryable exit code. This should not be changed.
Since kubernetes doesn't have restart method, That's the reason we delete
the pod, and wait for next reconcile
loop to create a new one. It's asynchronous so restart
here may be confused to users.
@@ -86,7 +86,7 @@ func (jc *JobController) AddPod(obj interface{}) { | |||
logger := commonutil.LoggerForPod(pod, jc.Controller.GetAPIGroupVersionKind().Kind) | |||
|
|||
if job == nil { | |||
if pod.Labels[apiv1.GroupNameLabel] == jc.Controller.GetGroupNameLabelValue() { | |||
if pod.Labels[apiv1.GroupNameLabel] != jc.Controller.GetGroupNameLabelValue() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check logics here.
common/pkg/controller.v1/common/job_controller.go
Lines 321 to 336 in ac0c6e1
func (jc *JobController) resolveControllerRef(namespace string, controllerRef *metav1.OwnerReference) metav1.Object { | |
// We can't look up by UID, so look up by Name and then verify UID. | |
// Don't even try to look up by Name if it's the wrong Kind. | |
if controllerRef.Kind != jc.Controller.GetAPIGroupVersionKind().Kind { | |
return nil | |
} | |
job, err := jc.Controller.GetJobFromInformerCache(namespace, controllerRef.Name) | |
if err != nil { | |
return nil | |
} | |
if job.GetUID() != controllerRef.UID { | |
// The controller we found with this Name is not the same one that the | |
// ControllerRef points to. | |
return nil | |
} | |
return job |
If we can not find the job, we will end reconcile loop and directly return
. The only thing matters is if we want to have some meaningful log.
There're several reason job == nil
here
- Kind doesn't match
- GroupNameLabel doesn't match
- Job doesn't exist. In this case, the pod is an orphan pod.
the 3rd one is the only case we want to persist the log. Does it make sense?
Co-authored-by: depfu[bot] <23717796+depfu[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
just some minor errors I found when I studied the code