forked from redhat-developer/odo
/
adapter.go
71 lines (54 loc) · 1.76 KB
/
adapter.go
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
package kubernetes
import (
"io"
"github.com/openshift/odo/pkg/devfile/adapters/common"
"github.com/openshift/odo/pkg/devfile/adapters/kubernetes/component"
"github.com/openshift/odo/pkg/kclient"
"github.com/pkg/errors"
)
// Adapter maps Devfiles to Kubernetes resources and actions
type Adapter struct {
componentAdapter common.ComponentAdapter
}
type KubernetesContext struct {
Namespace string
}
// New instantiates a kubernetes adapter
func New(adapterContext common.AdapterContext, client kclient.Client) Adapter {
compAdapter := component.New(adapterContext, client)
return Adapter{
componentAdapter: compAdapter,
}
}
// Push creates Kubernetes resources that correspond to the devfile if they don't already exist
func (k Adapter) Push(parameters common.PushParameters) error {
err := k.componentAdapter.Push(parameters)
if err != nil {
return errors.Wrap(err, "Failed to create the component")
}
return nil
}
// DoesComponentExist returns true if a component with the specified name exists
func (k Adapter) DoesComponentExist(cmpName string) (bool, error) {
return k.componentAdapter.DoesComponentExist(cmpName)
}
// Delete deletes the Kubernetes resources that correspond to the devfile
func (k Adapter) Delete(labels map[string]string) error {
err := k.componentAdapter.Delete(labels)
if err != nil {
return err
}
return nil
}
// Test runs the devfile test command
func (k Adapter) Test(testCmd string, show bool) error {
return k.componentAdapter.Test(testCmd, show)
}
// Log shows log from component
func (k Adapter) Log(follow, debug bool) (io.ReadCloser, error) {
return k.componentAdapter.Log(follow, debug)
}
// Exec executes a command in the component
func (d Adapter) Exec(command []string) error {
return d.componentAdapter.Exec(command)
}