forked from redhat-developer/odo
/
adapter.go
54 lines (41 loc) · 1.33 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
package kubernetes
import (
"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 {
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
}