Skip to content

Commit 2ada482

Browse files
committed
makes GetRunningPodFromSelector return only Running pods on Podman
1 parent 852077f commit 2ada482

File tree

4 files changed

+3
-32
lines changed

4 files changed

+3
-32
lines changed

pkg/component/component.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,7 @@ func Log(platformClient platform.Client, componentName string, appName string, f
9494

9595
pod, err := platformClient.GetRunningPodFromSelector(odolabels.GetSelector(componentName, appName, odolabels.ComponentDevMode, false))
9696
if err != nil {
97-
return nil, fmt.Errorf("the component %s doesn't exist on the cluster", componentName)
98-
}
99-
100-
if pod.Status.Phase != corev1.PodRunning {
101-
return nil, fmt.Errorf("unable to show logs, component is not in running state. current status=%v", pod.Status.Phase)
97+
return nil, fmt.Errorf("a running component %s doesn't exist on the cluster: %w", componentName, err)
10298
}
10399

104100
containerName := command.Exec.Component

pkg/component/delete/delete.go

-6
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,6 @@ func (do *DeleteComponentClient) ExecutePreStopEvents(ctx context.Context, devfi
212212
return fmt.Errorf("unable to determine if component %s exists; cause: %v", componentName, err.Error())
213213
}
214214

215-
// do not fail Delete operation if if the pod is not running or if the event execution fails
216-
if pod.Status.Phase != corev1.PodRunning {
217-
klog.V(4).Infof("unable to execute preStop events, pod for component %q is not running", componentName)
218-
return nil
219-
}
220-
221215
klog.V(4).Infof("Executing %q event commands for component %q", libdevfile.PreStop, componentName)
222216
// ignore the failures if any; delete should not fail because preStop events failed to execute
223217
handler := component.NewRunHandler(

pkg/component/delete/delete_test.go

-19
Original file line numberDiff line numberDiff line change
@@ -700,25 +700,6 @@ func TestDeleteComponentClient_ExecutePreStopEvents(t *testing.T) {
700700
},
701701
wantErr: false,
702702
},
703-
{
704-
name: "did not execute PreStopEvents because the pod is not in the running state",
705-
fields: fields{
706-
kubeClient: func(ctrl *gomock.Controller) kclient.ClientInterface {
707-
client := kclient.NewMockClientInterface(ctrl)
708-
709-
selector := odolabels.GetSelector(componentName, "app", odolabels.ComponentDevMode, false)
710-
pod := odoTestingUtil.CreateFakePod(componentName, "mypod", "runtime")
711-
pod.Status.Phase = corev1.PodFailed
712-
client.EXPECT().GetRunningPodFromSelector(selector).Return(pod, nil)
713-
return client
714-
},
715-
},
716-
args: args{
717-
devfileObj: devfileObjWithPreStopEvents,
718-
appName: appName,
719-
},
720-
wantErr: false,
721-
},
722703
{
723704
name: "failed to execute PreStopEvents because it failed to execute the command inside the container, but no error returned",
724705
fields: fields{

pkg/podman/pods.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ func (o *PodmanCli) GetRunningPodFromSelector(selector string) (*corev1.Pod, err
9292
if err != nil {
9393
return nil, err
9494
}
95-
if inspect.State == "Running" {
96-
pod.Status.Phase = corev1.PodRunning
95+
if inspect.State != "Running" {
96+
return nil, fmt.Errorf("a pod exists but is not in Running state. Current status=%v", inspect.State)
9797
}
9898

9999
for _, container := range podReport.Containers {

0 commit comments

Comments
 (0)