This repository was archived by the owner on Apr 1, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 244
Expand file tree
/
Copy pathkubedev.go
More file actions
113 lines (96 loc) · 3.65 KB
/
kubedev.go
File metadata and controls
113 lines (96 loc) · 3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
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/v2"
)
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
}