Skip to content

Commit

Permalink
Move handler to pkg/component package
Browse files Browse the repository at this point in the history
  • Loading branch information
feloy committed May 24, 2023
1 parent 4ca7421 commit 18ebc5a
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 20 deletions.
3 changes: 1 addition & 2 deletions pkg/component/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (

"github.com/redhat-developer/odo/pkg/component"
"github.com/redhat-developer/odo/pkg/configAutomount"
"github.com/redhat-developer/odo/pkg/dev/common"
"github.com/redhat-developer/odo/pkg/exec"
"github.com/redhat-developer/odo/pkg/kclient"
odolabels "github.com/redhat-developer/odo/pkg/labels"
Expand Down Expand Up @@ -221,7 +220,7 @@ func (do *DeleteComponentClient) ExecutePreStopEvents(ctx context.Context, devfi

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 := common.NewRunHandler(
handler := component.NewRunHandler(
ctx,
do.kubeClient,
do.execClient,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package common
package component

/*
var (
Expand Down
15 changes: 7 additions & 8 deletions pkg/dev/common/handler.go → pkg/component/handler.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package common
package component

import (
"context"
Expand All @@ -8,7 +8,6 @@ import (
"github.com/devfile/library/v2/pkg/devfile/parser"
"k8s.io/klog"

"github.com/redhat-developer/odo/pkg/component"
envcontext "github.com/redhat-developer/odo/pkg/config/context"
"github.com/redhat-developer/odo/pkg/configAutomount"
"github.com/redhat-developer/odo/pkg/devfile/image"
Expand Down Expand Up @@ -94,7 +93,7 @@ func (a *runHandler) ApplyKubernetes(kubernetes devfilev1.Component, kind v1alph
}
switch platform := a.platformClient.(type) {
case kclient.ClientInterface:
return component.ApplyKubernetes(mode, appName, componentName, a.devfile, kubernetes, platform, a.path)
return ApplyKubernetes(mode, appName, componentName, a.devfile, kubernetes, platform, a.path)
default:
klog.V(4).Info("apply kubernetes commands are not implemented on podman")
log.Warningf("Apply Kubernetes components are not supported on Podman. Skipping: %v.", kubernetes.Name)
Expand All @@ -113,7 +112,7 @@ func (a *runHandler) ApplyOpenShift(openshift devfilev1.Component, kind v1alpha2
}
switch platform := a.platformClient.(type) {
case kclient.ClientInterface:
return component.ApplyKubernetes(mode, appName, componentName, a.devfile, openshift, platform, a.path)
return ApplyKubernetes(mode, appName, componentName, a.devfile, openshift, platform, a.path)
default:
klog.V(4).Info("apply OpenShift commands are not implemented on podman")
log.Warningf("Apply OpenShift components are not supported on Podman. Skipping: %v.", openshift.Name)
Expand All @@ -127,11 +126,11 @@ func (a *runHandler) ExecuteNonTerminatingCommand(ctx context.Context, command d
appName = odocontext.GetApplication(a.ctx)
)
if isContainerRunning(command.Exec.Component, a.containersRunning) {
return component.ExecuteRunCommand(ctx, a.execClient, a.platformClient, command, a.ComponentExists, a.podName, appName, componentName)
return ExecuteRunCommand(ctx, a.execClient, a.platformClient, command, a.ComponentExists, a.podName, appName, componentName)
}
switch platform := a.platformClient.(type) {
case kclient.ClientInterface:
return component.ExecuteInNewContainer(ctx, platform, a.configAutomountClient, a.devfile, componentName, appName, command)
return ExecuteInNewContainer(ctx, platform, a.configAutomountClient, a.devfile, componentName, appName, command)
default:
klog.V(4).Info("executing a command in a new container is not implemented on podman")
log.Warningf("executing a command in a new container is not implemented on podman. Skipping: %v.", command.Id)
Expand All @@ -145,11 +144,11 @@ func (a *runHandler) ExecuteTerminatingCommand(ctx context.Context, command devf
appName = odocontext.GetApplication(a.ctx)
)
if isContainerRunning(command.Exec.Component, a.containersRunning) {
return component.ExecuteTerminatingCommand(ctx, a.execClient, a.platformClient, command, a.ComponentExists, a.podName, appName, componentName, a.msg, false)
return ExecuteTerminatingCommand(ctx, a.execClient, a.platformClient, command, a.ComponentExists, a.podName, appName, componentName, a.msg, false)
}
switch platform := a.platformClient.(type) {
case kclient.ClientInterface:
return component.ExecuteInNewContainer(ctx, platform, a.configAutomountClient, a.devfile, componentName, appName, command)
return ExecuteInNewContainer(ctx, platform, a.configAutomountClient, a.devfile, componentName, appName, command)
default:
klog.V(4).Info("executing a command in a new container is not implemented on podman")
log.Warningf("executing a command in a new container is not implemented on podman. Skipping: %v.", command.Id)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package common
package component

import (
"context"
Expand Down
4 changes: 2 additions & 2 deletions pkg/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
"github.com/devfile/library/v2/pkg/devfile/parser"

"github.com/redhat-developer/odo/pkg/component"
"github.com/redhat-developer/odo/pkg/configAutomount"
"github.com/redhat-developer/odo/pkg/dev/common"
"github.com/redhat-developer/odo/pkg/devfile/image"
"github.com/redhat-developer/odo/pkg/kclient"
"github.com/redhat-developer/odo/pkg/libdevfile"
Expand Down Expand Up @@ -39,7 +39,7 @@ func (o *DeployClient) Deploy(ctx context.Context) error {
path = filepath.Dir(devfilePath)
)

handler := common.NewRunHandler(
handler := component.NewRunHandler(
ctx,
o.kubeClient,
nil,
Expand Down
6 changes: 3 additions & 3 deletions pkg/dev/kubedev/innerloop.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (o *DevClient) innerloop(ctx context.Context, parameters common.PushParamet
if !componentStatus.PostStartEventsDone && libdevfile.HasPostStartEvents(parameters.Devfile) {
// PostStart events from the devfile will only be executed when the component
// didn't previously exist
handler := common.NewRunHandler(
handler := component.NewRunHandler(
ctx,
o.kubernetesClient,
o.execClient,
Expand Down Expand Up @@ -122,7 +122,7 @@ func (o *DevClient) innerloop(ctx context.Context, parameters common.PushParamet
var running bool
var isComposite bool

cmdHandler := common.NewRunHandler(
cmdHandler := component.NewRunHandler(
ctx,
o.kubernetesClient,
o.execClient,
Expand Down Expand Up @@ -161,7 +161,7 @@ func (o *DevClient) innerloop(ctx context.Context, parameters common.PushParamet
// Invoke the build command once (before calling libdevfile.ExecuteCommandByNameAndKind), as, if cmd is a composite command,
// the handler we pass will be called for each command in that composite command.
doExecuteBuildCommand := func() error {
execHandler := common.NewRunHandler(
execHandler := component.NewRunHandler(
ctx,
o.kubernetesClient,
o.execClient,
Expand Down
6 changes: 3 additions & 3 deletions pkg/dev/podmandev/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (o *DevClient) reconcile(
// PostStart events from the devfile will only be executed when the component
// didn't previously exist
if !componentStatus.PostStartEventsDone && libdevfile.HasPostStartEvents(devfileObj) {
execHandler := common.NewRunHandler(
execHandler := component.NewRunHandler(
ctx,
o.podmanClient,
o.execClient,
Expand All @@ -86,7 +86,7 @@ func (o *DevClient) reconcile(

if execRequired {
doExecuteBuildCommand := func() error {
execHandler := common.NewRunHandler(
execHandler := component.NewRunHandler(
ctx,
o.podmanClient,
o.execClient,
Expand Down Expand Up @@ -114,7 +114,7 @@ func (o *DevClient) reconcile(
cmdName = options.DebugCommand
}

cmdHandler := common.NewRunHandler(
cmdHandler := component.NewRunHandler(
ctx,
o.podmanClient,
o.execClient,
Expand Down

0 comments on commit 18ebc5a

Please sign in to comment.