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

fix: deployment and pod status for Lens #53

Merged
merged 2 commits into from
Sep 16, 2023
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
31 changes: 31 additions & 0 deletions internal/adapter/converter/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,38 @@ func (converter *DockerAPIConverter) UpdateDeploymentFromContainerInfo(deploymen
deployment.Status.UpdatedReplicas = 1
deployment.Status.ReadyReplicas = 1
deployment.Status.AvailableReplicas = 1

// set the deployment conditions to available and progressing
// if the container is running
deployment.Status.Conditions = []apps.DeploymentCondition{
{
Type: apps.DeploymentAvailable,
Status: "True",
Message: "Deployment is available",
Reason: "MinimumReplicasAvailable",
LastTransitionTime: metav1.NewTime(time.Now()),
},
{
Type: apps.DeploymentProgressing,
Status: "True",
Message: "NewReplicaSetAvailable",
Reason: "NewReplicaSetAvailable",
LastTransitionTime: metav1.NewTime(time.Now()),
},
}
} else {
deployment.Status.UnavailableReplicas = 1

// set the deployment conditions to unavailable and progressing
// if the container is not running
deployment.Status.Conditions = []apps.DeploymentCondition{
{
Type: apps.DeploymentAvailable,
Status: "False",
Message: "Deployment is not available",
Reason: "MinimumReplicasUnavailable",
LastTransitionTime: metav1.NewTime(time.Now()),
},
}
}
}
39 changes: 39 additions & 0 deletions internal/adapter/converter/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,47 @@ func (converter *DockerAPIConverter) ConvertContainerToPod(container types.Conta
pod.Status.ContainerStatuses[0].State.Running = &core.ContainerStateRunning{
StartedAt: metav1.NewTime(time.Unix(container.Created, 0)),
}

// the conditions block with PodReady, PodScheduled, PodInitialized, and ContainersReady
// are required for the pod to be considered ready
pod.Status.Conditions = []core.PodCondition{
{
Type: core.PodReady,
Status: "True",
Message: "Pod is ready",
LastTransitionTime: metav1.NewTime(time.Now()),
},
{
Type: core.PodScheduled,
Status: "True",
Message: "Pod is scheduled",
LastTransitionTime: metav1.NewTime(time.Now()),
},
{
Type: core.PodInitialized,
Status: "True",
Message: "Pod has been initialized",
LastTransitionTime: metav1.NewTime(time.Now()),
},
{
Type: core.ContainersReady,
Status: "True",
Message: "Containers are ready",
LastTransitionTime: metav1.NewTime(time.Now()),
},
}
} else {
pod.Status.Phase = core.PodUnknown

// this is to mark the pod's condition as unknown
pod.Status.Conditions = []core.PodCondition{
{
Type: core.PodConditionType(core.PodUnknown),
Status: "False",
Message: "Pod is not running",
LastTransitionTime: metav1.NewTime(time.Now()),
},
}
}

return pod
Expand Down