Skip to content

Commit

Permalink
makes GetRunningPodFromSelector return only Running pods on Podman
Browse files Browse the repository at this point in the history
  • Loading branch information
feloy committed Jun 2, 2023
1 parent 852077f commit 2ada482
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 32 deletions.
6 changes: 1 addition & 5 deletions pkg/component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,7 @@ func Log(platformClient platform.Client, componentName string, appName string, f

pod, err := platformClient.GetRunningPodFromSelector(odolabels.GetSelector(componentName, appName, odolabels.ComponentDevMode, false))
if err != nil {
return nil, fmt.Errorf("the component %s doesn't exist on the cluster", componentName)
}

if pod.Status.Phase != corev1.PodRunning {
return nil, fmt.Errorf("unable to show logs, component is not in running state. current status=%v", pod.Status.Phase)
return nil, fmt.Errorf("a running component %s doesn't exist on the cluster: %w", componentName, err)
}

containerName := command.Exec.Component
Expand Down
6 changes: 0 additions & 6 deletions pkg/component/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,6 @@ func (do *DeleteComponentClient) ExecutePreStopEvents(ctx context.Context, devfi
return fmt.Errorf("unable to determine if component %s exists; cause: %v", componentName, err.Error())
}

// do not fail Delete operation if if the pod is not running or if the event execution fails
if pod.Status.Phase != corev1.PodRunning {
klog.V(4).Infof("unable to execute preStop events, pod for component %q is not running", componentName)
return nil
}

klog.V(4).Infof("Executing %q event commands for component %q", libdevfile.PreStop, componentName)
// ignore the failures if any; delete should not fail because preStop events failed to execute
handler := component.NewRunHandler(
Expand Down
19 changes: 0 additions & 19 deletions pkg/component/delete/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -700,25 +700,6 @@ func TestDeleteComponentClient_ExecutePreStopEvents(t *testing.T) {
},
wantErr: false,
},
{
name: "did not execute PreStopEvents because the pod is not in the running state",
fields: fields{
kubeClient: func(ctrl *gomock.Controller) kclient.ClientInterface {
client := kclient.NewMockClientInterface(ctrl)

selector := odolabels.GetSelector(componentName, "app", odolabels.ComponentDevMode, false)
pod := odoTestingUtil.CreateFakePod(componentName, "mypod", "runtime")
pod.Status.Phase = corev1.PodFailed
client.EXPECT().GetRunningPodFromSelector(selector).Return(pod, nil)
return client
},
},
args: args{
devfileObj: devfileObjWithPreStopEvents,
appName: appName,
},
wantErr: false,
},
{
name: "failed to execute PreStopEvents because it failed to execute the command inside the container, but no error returned",
fields: fields{
Expand Down
4 changes: 2 additions & 2 deletions pkg/podman/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ func (o *PodmanCli) GetRunningPodFromSelector(selector string) (*corev1.Pod, err
if err != nil {
return nil, err
}
if inspect.State == "Running" {
pod.Status.Phase = corev1.PodRunning
if inspect.State != "Running" {
return nil, fmt.Errorf("a pod exists but is not in Running state. Current status=%v", inspect.State)
}

for _, container := range podReport.Containers {
Expand Down

0 comments on commit 2ada482

Please sign in to comment.