Correct ContainerStatus of Notebook CR (kubeflow/kubeflow#5314)
* Correct ContainerStatus of Notebook CR The Notebook Controller doesn't set the State of the CR correctly. In some cases the first container is the istio-sidecar which results in an incorrect state being shown to the Notebook CR. This is fix now by showing the Notebook container ContainerState to the Notebook CR ContainerState * Changed log statement and added a comment Implemented remarks of @yanniszark and @kimwnasptd * Small reorganization of some if statements
This commit is contained in:
parent
7badb2b424
commit
82c04b3be1
|
|
@ -206,23 +206,42 @@ func (r *NotebookReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
|
||||||
} else {
|
} else {
|
||||||
// Got the pod
|
// Got the pod
|
||||||
podFound = true
|
podFound = true
|
||||||
if len(pod.Status.ContainerStatuses) > 0 &&
|
|
||||||
pod.Status.ContainerStatuses[0].State != instance.Status.ContainerState {
|
// Update status of the CR using the ContainerState of
|
||||||
log.Info("Updating container state: ", "namespace", instance.Namespace, "name", instance.Name)
|
// the container that has the same name as the CR.
|
||||||
cs := pod.Status.ContainerStatuses[0].State
|
// If no container of same name is found, the state of the CR is not updated.
|
||||||
instance.Status.ContainerState = cs
|
if len(pod.Status.ContainerStatuses) > 0 {
|
||||||
oldConditions := instance.Status.Conditions
|
notebookContainerFound := false
|
||||||
newCondition := getNextCondition(cs)
|
for i := range pod.Status.ContainerStatuses {
|
||||||
// Append new condition
|
if pod.Status.ContainerStatuses[i].Name != instance.Name {
|
||||||
if len(oldConditions) == 0 || oldConditions[0].Type != newCondition.Type ||
|
continue
|
||||||
oldConditions[0].Reason != newCondition.Reason ||
|
}
|
||||||
oldConditions[0].Message != newCondition.Message {
|
if pod.Status.ContainerStatuses[i].State == instance.Status.ContainerState {
|
||||||
log.Info("Appending to conditions: ", "namespace", instance.Namespace, "name", instance.Name, "type", newCondition.Type, "reason", newCondition.Reason, "message", newCondition.Message)
|
continue
|
||||||
instance.Status.Conditions = append([]v1beta1.NotebookCondition{newCondition}, oldConditions...)
|
}
|
||||||
|
|
||||||
|
log.Info("Updating Notebook CR state: ", "namespace", instance.Namespace, "name", instance.Name)
|
||||||
|
cs := pod.Status.ContainerStatuses[i].State
|
||||||
|
instance.Status.ContainerState = cs
|
||||||
|
oldConditions := instance.Status.Conditions
|
||||||
|
newCondition := getNextCondition(cs)
|
||||||
|
// Append new condition
|
||||||
|
if len(oldConditions) == 0 || oldConditions[0].Type != newCondition.Type ||
|
||||||
|
oldConditions[0].Reason != newCondition.Reason ||
|
||||||
|
oldConditions[0].Message != newCondition.Message {
|
||||||
|
log.Info("Appending to conditions: ", "namespace", instance.Namespace, "name", instance.Name, "type", newCondition.Type, "reason", newCondition.Reason, "message", newCondition.Message)
|
||||||
|
instance.Status.Conditions = append([]v1beta1.NotebookCondition{newCondition}, oldConditions...)
|
||||||
|
}
|
||||||
|
err = r.Status().Update(ctx, instance)
|
||||||
|
if err != nil {
|
||||||
|
return ctrl.Result{}, err
|
||||||
|
}
|
||||||
|
notebookContainerFound = true
|
||||||
|
break
|
||||||
|
|
||||||
}
|
}
|
||||||
err = r.Status().Update(ctx, instance)
|
if !notebookContainerFound {
|
||||||
if err != nil {
|
log.Error(nil, "Could not find the Notebook container, will not update the status of the CR. No container has the same name as the CR.", "CR name:", instance.Name)
|
||||||
return ctrl.Result{}, err
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue