Skip to content

Commit 04018b4

Browse files
committed
Replace component.execHandler by common.runHandler
1 parent 4fcf81d commit 04018b4

File tree

4 files changed

+86
-15
lines changed

4 files changed

+86
-15
lines changed

pkg/component/delete/delete.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
1515
"k8s.io/klog"
1616

17-
"github.com/redhat-developer/odo/pkg/component"
17+
"github.com/redhat-developer/odo/pkg/dev/common"
1818
"github.com/redhat-developer/odo/pkg/exec"
1919
"github.com/redhat-developer/odo/pkg/kclient"
2020
odolabels "github.com/redhat-developer/odo/pkg/labels"
@@ -216,7 +216,19 @@ func (do *DeleteComponentClient) ExecutePreStopEvents(ctx context.Context, devfi
216216

217217
klog.V(4).Infof("Executing %q event commands for component %q", libdevfile.PreStop, componentName)
218218
// ignore the failures if any; delete should not fail because preStop events failed to execute
219-
err = libdevfile.ExecPreStopEvents(ctx, devfileObj, component.NewExecHandler(do.kubeClient, do.execClient, appName, componentName, pod.Name, "Executing pre-stop command in container", false, false))
219+
handler := common.NewRunHandler(
220+
do.kubeClient,
221+
do.execClient,
222+
appName,
223+
componentName,
224+
pod.Name,
225+
false,
226+
"Executing pre-stop command in container",
227+
228+
// TODO(feloy) set these values when we want to support Apply Image/Kubernetes/OpenShift commands for PreStop events
229+
nil, nil, nil, parser.DevfileObj{}, "",
230+
)
231+
err = libdevfile.ExecPreStopEvents(ctx, devfileObj, handler)
220232
if err != nil {
221233
klog.V(4).Infof("Failed to execute %q event commands for component %q, cause: %v", libdevfile.PreStop, componentName, err.Error())
222234
}

pkg/dev/common/handler.go

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,45 @@ type RunHandler struct {
3333
PodName string
3434

3535
Ctx context.Context
36+
Msg string
3637
}
3738

3839
var _ libdevfile.Handler = (*RunHandler)(nil)
3940

41+
func NewRunHandler(
42+
platformClient platform.Client,
43+
execClient exec.Client,
44+
appName string,
45+
componentName string,
46+
podName string,
47+
componentExists bool,
48+
msg string,
49+
50+
// For building images
51+
fs filesystem.Filesystem,
52+
imageBackend image.Backend,
53+
ctx context.Context,
54+
55+
// For apply Kubernetes / Openshift
56+
devfile parser.DevfileObj,
57+
path string,
58+
59+
) *RunHandler {
60+
return &RunHandler{
61+
FS: fs,
62+
ExecClient: execClient,
63+
AppName: appName,
64+
ComponentName: componentName,
65+
Devfile: devfile,
66+
PlatformClient: platformClient,
67+
ImageBackend: imageBackend,
68+
Path: path,
69+
ComponentExists: componentExists,
70+
PodName: podName,
71+
Ctx: ctx,
72+
}
73+
}
74+
4075
func (a *RunHandler) ApplyImage(img devfilev1.Component) error {
4176
return image.BuildPushSpecificImage(a.Ctx, a.ImageBackend, a.FS, img, envcontext.GetEnvConfig(a.Ctx).PushImages)
4277
}
@@ -68,8 +103,7 @@ func (a *RunHandler) ExecuteNonTerminatingCommand(ctx context.Context, command d
68103
}
69104

70105
func (a *RunHandler) ExecuteTerminatingCommand(ctx context.Context, command devfilev1.Command) error {
71-
panic("handler: ExecuteRunCommand in ExecuteTerminatingCommand")
72-
//return component.ExecuteRunCommand(ctx, a.ExecClient, a.PlatformClient, command, a.ComponentExists, a.PodName, a.AppName, a.ComponentName)
106+
return component.ExecuteTerminatingCommand(ctx, a.ExecClient, a.PlatformClient, command, a.ComponentExists, a.PodName, a.AppName, a.ComponentName, a.Msg, false)
73107
}
74108

75109
// IsRemoteProcessForCommandRunning returns true if the command is running

pkg/dev/kubedev/innerloop.go

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import (
77
"time"
88

99
devfilev1 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
10+
"github.com/devfile/library/v2/pkg/devfile/parser"
1011
parsercommon "github.com/devfile/library/v2/pkg/devfile/parser/data/v2/common"
1112

12-
"github.com/redhat-developer/odo/pkg/component"
1313
"github.com/redhat-developer/odo/pkg/dev/common"
1414
"github.com/redhat-developer/odo/pkg/devfile/image"
1515
"github.com/redhat-developer/odo/pkg/libdevfile"
@@ -89,8 +89,20 @@ func (o *DevClient) innerloop(ctx context.Context, parameters common.PushParamet
8989

9090
// PostStart events from the devfile will only be executed when the component
9191
// didn't previously exist
92+
handler := common.NewRunHandler(
93+
o.kubernetesClient,
94+
o.execClient,
95+
appName,
96+
componentName,
97+
pod.Name,
98+
false,
99+
"Executing post-start command in container",
100+
101+
// TODO(feloy) set these values when we want to support Apply Image/Kubernetes/OpenShift commands for PostStart commands
102+
nil, nil, nil, parser.DevfileObj{}, "",
103+
)
92104
if !componentStatus.PostStartEventsDone && libdevfile.HasPostStartEvents(parameters.Devfile) {
93-
err = libdevfile.ExecPostStartEvents(ctx, parameters.Devfile, component.NewExecHandler(o.kubernetesClient, o.execClient, appName, componentName, pod.Name, "Executing post-start command in container", parameters.Show, false))
105+
err = libdevfile.ExecPostStartEvents(ctx, parameters.Devfile, handler)
94106
if err != nil {
95107
return err
96108
}
@@ -145,8 +157,18 @@ func (o *DevClient) innerloop(ctx context.Context, parameters common.PushParamet
145157
// Invoke the build command once (before calling libdevfile.ExecuteCommandByNameAndKind), as, if cmd is a composite command,
146158
// the handler we pass will be called for each command in that composite command.
147159
doExecuteBuildCommand := func() error {
148-
execHandler := component.NewExecHandler(o.kubernetesClient, o.execClient, appName, componentName, pod.Name,
149-
"Building your application in container", parameters.Show, running)
160+
execHandler := common.NewRunHandler(
161+
o.kubernetesClient,
162+
o.execClient,
163+
appName,
164+
componentName,
165+
pod.Name,
166+
running,
167+
"Building your application in container",
168+
169+
// TODO(feloy) set these values when we want to support Apply Image/Kubernetes/OpenShift commands for PostStart commands
170+
nil, nil, nil, parser.DevfileObj{}, "",
171+
)
150172
return libdevfile.Build(ctx, parameters.Devfile, parameters.StartOptions.BuildCommand, execHandler)
151173
}
152174
if err = doExecuteBuildCommand(); err != nil {

pkg/dev/podmandev/reconcile.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"github.com/fatih/color"
1414

1515
"github.com/redhat-developer/odo/pkg/api"
16-
"github.com/redhat-developer/odo/pkg/component"
1716
envcontext "github.com/redhat-developer/odo/pkg/config/context"
1817
"github.com/redhat-developer/odo/pkg/dev"
1918
"github.com/redhat-developer/odo/pkg/dev/common"
@@ -65,15 +64,17 @@ func (o *DevClient) reconcile(
6564
// PostStart events from the devfile will only be executed when the component
6665
// didn't previously exist
6766
if !componentStatus.PostStartEventsDone && libdevfile.HasPostStartEvents(devfileObj) {
68-
execHandler := component.NewExecHandler(
67+
execHandler := common.NewRunHandler(
6968
o.podmanClient,
7069
o.execClient,
7170
appName,
7271
componentName,
7372
pod.Name,
74-
"Executing post-start command in container",
75-
false, /* TODO */
7673
false,
74+
"Executing post-start command in container",
75+
76+
// TODO(feloy) set these values when we want to support Apply Image/Kubernetes/OpenShift commands for PostStart commands
77+
nil, nil, nil, parser.DevfileObj{}, "",
7778
)
7879
err = libdevfile.ExecPostStartEvents(ctx, devfileObj, execHandler)
7980
if err != nil {
@@ -84,15 +85,17 @@ func (o *DevClient) reconcile(
8485

8586
if execRequired {
8687
doExecuteBuildCommand := func() error {
87-
execHandler := component.NewExecHandler(
88+
execHandler := common.NewRunHandler(
8889
o.podmanClient,
8990
o.execClient,
9091
appName,
9192
componentName,
9293
pod.Name,
94+
false,
9395
"Building your application in container",
94-
false, /* TODO */
95-
componentStatus.RunExecuted,
96+
97+
// TODO(feloy) set these values when we want to support Apply Image/Kubernetes/OpenShift commands for PreStop events
98+
nil, nil, nil, parser.DevfileObj{}, "",
9699
)
97100
return libdevfile.Build(ctx, devfileObj, options.BuildCommand, execHandler)
98101
}

0 commit comments

Comments
 (0)