Skip to content

Commit

Permalink
Reuse same volumes when devfile is modified, on podman (#6810)
Browse files Browse the repository at this point in the history
* Reuse same volumes when devfile is modified

* Fix doc /comment
  • Loading branch information
feloy committed May 11, 2023
1 parent da28e7d commit f491bcc
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ Podman is natively not able to port-forward to programs listening on localhost.
- you can change your application to listen on `0.0.0.0`. This will be necessary for the ports giving access to the application or, in Production, this port would not be available (this port will most probably be exposed through an Ingress or a Route in Production, and these methods need the port to be bound to `0.0.0.0`),
- you can keep the port bound to `localhost`. This is the best choice for the Debug port, to restrict access to this Debug port. In this case, you can use the flag `--forward-localhost` when running `odo dev` on Podman. This way, you keep the Debug port secure on cluster.

## Pod not updated when Devfile changes

When running `odo dev` on cluster, if you make changes to the Devfile affecting the definition of the deployed Pod (for example the memory or CPU requests or limits), the Pod will be recreated with its new definition. This behaviour is not supported yet for Podman.

## Pre-Stop events not supported

Pre-Stop events defined in the Devfile are not triggered when running `odo dev` on Podman.
Expand Down
2 changes: 1 addition & 1 deletion pkg/dev/podmandev/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ func (o *DevClient) CleanupResources(ctx context.Context, out io.Writer) error {
if o.deployedPod == nil {
return nil
}
return o.podmanClient.CleanupPodResources(o.deployedPod)
return o.podmanClient.CleanupPodResources(o.deployedPod, true)
}
14 changes: 7 additions & 7 deletions pkg/dev/podmandev/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,17 +226,17 @@ func (o *DevClient) deployPod(ctx context.Context, options dev.StartOptions, dev
return o.deployedPod, fwPorts, nil
}

// Delete previous volumes and pod, if running
// Delete previous pod, if running
if o.deployedPod != nil {
err = o.podmanClient.CleanupPodResources(o.deployedPod)
err = o.podmanClient.CleanupPodResources(o.deployedPod, false)
if err != nil {
return nil, nil, err
}
} else {
err = o.checkVolumesFree(pod)
if err != nil {
return nil, nil, err
}
}

err = o.checkVolumesFree(pod)
if err != nil {
return nil, nil, err
}

err = o.podmanClient.PlayKube(pod)
Expand Down
4 changes: 2 additions & 2 deletions pkg/odo/cli/delete/component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func (o *ComponentOptions) deleteNamedComponent(ctx context.Context) error {
if len(podmanResources) > 0 {
spinner := log.Spinnerf("Deleting resources from podman")
for _, pod := range podmanResources {
err = o.clientset.PodmanClient.CleanupPodResources(pod)
err = o.clientset.PodmanClient.CleanupPodResources(pod, true)
if err != nil {
log.Warningf("Failed to delete the pod %q from podman: %s\n", pod.GetName(), err)
}
Expand Down Expand Up @@ -359,7 +359,7 @@ func (o *ComponentOptions) deleteDevfileComponent(ctx context.Context) ([]unstru
_ = isPodmanInnerLoopDeployed
}
for _, pod := range podmanPods {
err = o.clientset.PodmanClient.CleanupPodResources(pod)
err = o.clientset.PodmanClient.CleanupPodResources(pod, true)
if err != nil {
log.Warningf("Failed to delete the pod %q from podman: %s\n", pod.GetName(), err)
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/odo/cli/delete/component/component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func TestComponentOptions_deleteNamedComponent(t *testing.T) {
},
podmanClient: func(ctrl *gomock.Controller) podman.Client {
client := podman.NewMockClient(ctrl)
client.EXPECT().CleanupPodResources(&pod1).Times(1)
client.EXPECT().CleanupPodResources(&pod1, true).Times(1)
return client
},
deleteComponentClient: func(ctrl *gomock.Controller) _delete.Client {
Expand All @@ -233,7 +233,7 @@ func TestComponentOptions_deleteNamedComponent(t *testing.T) {
},
podmanClient: func(ctrl *gomock.Controller) podman.Client {
client := podman.NewMockClient(ctrl)
client.EXPECT().CleanupPodResources(&pod1).Times(1)
client.EXPECT().CleanupPodResources(&pod1, true).Times(1)
return client
},
deleteComponentClient: func(ctrl *gomock.Controller) _delete.Client {
Expand All @@ -255,7 +255,7 @@ func TestComponentOptions_deleteNamedComponent(t *testing.T) {
},
podmanClient: func(ctrl *gomock.Controller) podman.Client {
client := podman.NewMockClient(ctrl)
client.EXPECT().CleanupPodResources(&pod1).Times(0)
client.EXPECT().CleanupPodResources(&pod1, true).Times(0)
return client
},
deleteComponentClient: func(ctrl *gomock.Controller) _delete.Client {
Expand All @@ -278,7 +278,7 @@ func TestComponentOptions_deleteNamedComponent(t *testing.T) {
},
podmanClient: func(ctrl *gomock.Controller) podman.Client {
client := podman.NewMockClient(ctrl)
client.EXPECT().CleanupPodResources(&pod1).Times(1)
client.EXPECT().CleanupPodResources(&pod1, true).Times(1)
return client
},
deleteComponentClient: func(ctrl *gomock.Controller) _delete.Client {
Expand Down Expand Up @@ -309,7 +309,7 @@ func TestComponentOptions_deleteNamedComponent(t *testing.T) {
},
podmanClient: func(ctrl *gomock.Controller) podman.Client {
client := podman.NewMockClient(ctrl)
client.EXPECT().CleanupPodResources(&pod1).Times(1)
client.EXPECT().CleanupPodResources(&pod1, true).Times(1)
return client
},
deleteComponentClient: func(ctrl *gomock.Controller) _delete.Client {
Expand Down Expand Up @@ -344,7 +344,7 @@ func TestComponentOptions_deleteNamedComponent(t *testing.T) {
},
podmanClient: func(ctrl *gomock.Controller) podman.Client {
client := podman.NewMockClient(ctrl)
client.EXPECT().CleanupPodResources(&pod1).Times(0)
client.EXPECT().CleanupPodResources(&pod1, true).Times(0)
return client
},
deleteComponentClient: func(ctrl *gomock.Controller) _delete.Client {
Expand Down
2 changes: 1 addition & 1 deletion pkg/podman/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type Client interface {
VolumeRm(volumeName string) error

// CleanupPodResources stops and removes a pod and its associated resources (volumes)
CleanupPodResources(pod *corev1.Pod) error
CleanupPodResources(pod *corev1.Pod, cleanVolumes bool) error

ListAllComponents() ([]api.ComponentAbstract, error)

Expand Down
8 changes: 4 additions & 4 deletions pkg/podman/mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion pkg/podman/podman.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func (o *PodmanCli) VolumeLs() (map[string]bool, error) {
return SplitLinesAsSet(string(out)), nil
}

func (o *PodmanCli) CleanupPodResources(pod *corev1.Pod) error {
func (o *PodmanCli) CleanupPodResources(pod *corev1.Pod, cleanupVolumes bool) error {
err := o.PodStop(pod.GetName())
if err != nil {
return err
Expand All @@ -216,6 +216,10 @@ func (o *PodmanCli) CleanupPodResources(pod *corev1.Pod) error {
return err
}

if !cleanupVolumes {
return nil
}

for _, volume := range pod.Spec.Volumes {
if volume.PersistentVolumeClaim == nil {
continue
Expand Down

0 comments on commit f491bcc

Please sign in to comment.