Files
odo/pkg/dev/kubedev/kubedev.go
Philippe Martin b93a75c11a Move UI out of experimental mode (#7012)
* Make UI not experimental

* Display API and UI URLs

* Remove link to old sources

* Fix integration tests

* Add UI to Usage Data

* Add a "Using the GUI to edit the Devfile" page to doc

* Add link to odo.dev specific page

* Apply suggestions from code review

Co-authored-by: Armel Soro <armel@rm3l.org>

* Change favicon with odo logo

* Display web console URL as part of the Dev status

* Update UI static files

* Document that Comments not supported

* Add UI screenshots

---------

Co-authored-by: Armel Soro <armel@rm3l.org>
2023-08-04 13:02:34 +02:00

114 lines
3.6 KiB
Go

package kubedev
import (
"context"
"fmt"
devfilev1 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
"github.com/redhat-developer/odo/pkg/binding"
_delete "github.com/redhat-developer/odo/pkg/component/delete"
"github.com/redhat-developer/odo/pkg/configAutomount"
"github.com/redhat-developer/odo/pkg/dev"
"github.com/redhat-developer/odo/pkg/dev/common"
"github.com/redhat-developer/odo/pkg/devfile"
"github.com/redhat-developer/odo/pkg/devfile/location"
"github.com/redhat-developer/odo/pkg/exec"
"github.com/redhat-developer/odo/pkg/kclient"
"github.com/redhat-developer/odo/pkg/portForward"
"github.com/redhat-developer/odo/pkg/preference"
"github.com/redhat-developer/odo/pkg/sync"
"github.com/redhat-developer/odo/pkg/testingutil/filesystem"
"github.com/redhat-developer/odo/pkg/watch"
"k8s.io/klog"
)
type DevClient struct {
kubernetesClient kclient.ClientInterface
prefClient preference.Client
portForwardClient portForward.Client
watchClient watch.Client
bindingClient binding.Client
syncClient sync.Client
filesystem filesystem.Filesystem
execClient exec.Client
deleteClient _delete.Client
configAutomountClient configAutomount.Client
// deploymentExists is true when the deployment is already created when calling createComponents
deploymentExists bool
// portsChanged is true of ports have changed since the last call to createComponents
portsChanged bool
// portsToForward lists the port to forward during inner loop (TODO move port forward to createComponents)
portsToForward map[string][]devfilev1.Endpoint
}
var _ dev.Client = (*DevClient)(nil)
func NewDevClient(
kubernetesClient kclient.ClientInterface,
prefClient preference.Client,
portForwardClient portForward.Client,
watchClient watch.Client,
bindingClient binding.Client,
syncClient sync.Client,
filesystem filesystem.Filesystem,
execClient exec.Client,
deleteClient _delete.Client,
configAutomountClient configAutomount.Client,
) *DevClient {
return &DevClient{
kubernetesClient: kubernetesClient,
prefClient: prefClient,
portForwardClient: portForwardClient,
watchClient: watchClient,
bindingClient: bindingClient,
syncClient: syncClient,
filesystem: filesystem,
execClient: execClient,
deleteClient: deleteClient,
configAutomountClient: configAutomountClient,
}
}
func (o *DevClient) Start(
ctx context.Context,
options dev.StartOptions,
) error {
klog.V(4).Infoln("Creating new adapter")
var (
componentStatus = watch.ComponentStatus{
ImageComponentsAutoApplied: make(map[string]devfilev1.ImageComponent),
}
)
klog.V(4).Infoln("Creating inner-loop resources for the component")
watchParameters := watch.WatchParameters{
StartOptions: options,
DevfileWatchHandler: o.regenerateAdapterAndPush,
WatchCluster: true,
}
return o.watchClient.WatchAndPush(ctx, watchParameters, componentStatus)
}
// RegenerateAdapterAndPush get the new devfile and pushes the files to remote pod
func (o *DevClient) regenerateAdapterAndPush(ctx context.Context, pushParams common.PushParameters, componentStatus *watch.ComponentStatus) error {
devObj, err := devfile.ParseAndValidateFromFileWithVariables(location.DevfileLocation(o.filesystem, ""), pushParams.StartOptions.Variables, o.prefClient.GetImageRegistry(), true)
if err != nil {
return fmt.Errorf("unable to read devfile: %w", err)
}
pushParams.Devfile = devObj
err = o.reconcile(ctx, pushParams, componentStatus)
if err != nil {
return fmt.Errorf("watch command was unable to push component: %w", err)
}
return nil
}