/
installer.go
58 lines (51 loc) · 1.58 KB
/
installer.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
package resources
import (
"github.com/jenkins-x/jx/pkg/util"
)
const kubeCtlBinary = "kubectl"
// Installer provides support for installing Kuberntes resources directly from files
//go:generate pegomock generate github.com/jenkins-x/jx/pkg/kube/resources Installer -o mocks/installer.go
type Installer interface {
// Install installs the Kubernetes resources provided in the file
Install(file string) (string, error)
// InstallDir installs the Kubernetes resources provided in the directory
InstallDir(dir string) (string, error)
}
// KubeCtlInstaller kubectl based resources installer
type KubeCtlInstaller struct {
runner util.Commander
}
// NewKubeCtlInstaller creates a new kubectl installer
func NewKubeCtlInstaller(cwd string, wait, validate bool) *KubeCtlInstaller {
args := []string{"apply"}
if wait {
args = append(args, "--wait")
}
if validate {
args = append(args, "--validate=true")
} else {
args = append(args, "--validate=false")
}
runner := &util.Command{
Name: kubeCtlBinary,
Args: args,
Dir: cwd,
}
return &KubeCtlInstaller{
runner: runner,
}
}
// Install installs the resources provided in the file
func (i *KubeCtlInstaller) Install(file string) (string, error) {
args := i.runner.CurrentArgs()
args = append(args, "-f", file)
i.runner.SetArgs(args)
return i.runner.RunWithoutRetry()
}
// InstallDir installs the resources provided in the directory
func (i *KubeCtlInstaller) InstallDir(dir string) (string, error) {
args := i.runner.CurrentArgs()
args = append(args, "--recursive", "-f", dir)
i.runner.SetArgs(args)
return i.runner.RunWithoutRetry()
}