Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for exec command for odo deploy #6047

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 38 additions & 4 deletions pkg/deploy/deploy.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package deploy

import (
"errors"

"github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
"github.com/devfile/library/pkg/devfile/parser"

"github.com/devfile/library/pkg/devfile/parser/data/v2/common"
"github.com/redhat-developer/odo/pkg/devfile/adapters/kubernetes/component"
"github.com/redhat-developer/odo/pkg/devfile/image"
"github.com/redhat-developer/odo/pkg/kclient"
Expand Down Expand Up @@ -69,5 +67,41 @@ func (o *deployHandler) Execute(command v1alpha2.Command) error {
// TODO:
// * Make sure we inject the "deploy" mode label once we implement exec in `odo deploy`
// * Make sure you inject the "component type" label once we implement exec.
return errors.New("exec command is not implemented for Deploy")

// get the containers matching the command
containers, err := libdevfile.GetContainerComponentsForCommand(o.devfileObj, command)
if err != nil {
return err
}
if len(containers) != 1 {
return libdevfile.NewNotExactlyOneContainer()
}
containerName := containers[0]

// get all the container components from the devfile and find the one we are interested in
devfileContainers, err := o.devfileObj.Data.GetComponents(common.DevfileOptions{
ComponentOptions: common.ComponentOptions{v1alpha2.ContainerComponentType},
})
if err != nil {
return err
}
var devfileContainer v1alpha2.Component
var found bool
for _, dc := range devfileContainers {
if dc.Name == containerName {
found = true
devfileContainer = dc
}
}
if !found {
return libdevfile.NewNotExactlyOneContainer()
}

job, err := libdevfile.GetJobFromContainerWithCommand(devfileContainer, command)
if err != nil {
return err
}
job.Labels = odolabels.GetLabels(o.devfileObj.GetMetadataName(), "app", "", odolabels.ComponentDeployMode, false)

return o.kubeClient.CreateJob(job)
}
4 changes: 4 additions & 0 deletions pkg/kclient/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package kclient
import (
"context"
"io"
batchv1 "k8s.io/api/batch/v1"
"time"

"github.com/go-openapi/spec"
Expand Down Expand Up @@ -67,6 +68,9 @@ type ClientInterface interface {
// events.go
PodWarningEventWatcher(ctx context.Context) (result watch.Interface, isForbidden bool, err error)

// jobs.go
CreateJob(job batchv1.Job) error

// kclient.go
GetClient() kubernetes.Interface
GetConfig() clientcmd.ClientConfig
Expand Down
15 changes: 15 additions & 0 deletions pkg/kclient/jobs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package kclient

import (
"context"
batchv1 "k8s.io/api/batch/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func (c *Client) CreateJob(job batchv1.Job) error {
_, err := c.KubeClient.BatchV1().Jobs(c.Namespace).Create(context.TODO(), &job, metav1.CreateOptions{})
if err != nil {
return err
}
return nil
}
Loading