-
Notifications
You must be signed in to change notification settings - Fork 104
/
install.go
100 lines (81 loc) · 2.62 KB
/
install.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
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
package install
import (
"fmt"
"time"
"github.com/spf13/afero"
"github.com/kudobuilder/kudo/pkg/kudoctl/clog"
"github.com/kudobuilder/kudo/pkg/kudoctl/env"
"github.com/kudobuilder/kudo/pkg/kudoctl/packages/install"
pkgresolver "github.com/kudobuilder/kudo/pkg/kudoctl/packages/resolver"
"github.com/kudobuilder/kudo/pkg/kudoctl/util/repo"
)
// RepositoryOptions defines the options necessary for any cmd working with repository
type RepositoryOptions struct {
RepoName string
}
// Options defines configuration options for the install command
type Options struct {
RepositoryOptions
InstanceName string
Parameters map[string]string
AppVersion string
OperatorVersion string
SkipInstance bool
RequestTimeout int64
Wait bool
WaitTime int64
CreateNameSpace bool
}
// DefaultOptions initializes the install command options to its defaults
var DefaultOptions = &Options{}
// Run returns the errors associated with cmd env
func Run(args []string, options *Options, fs afero.Fs, settings *env.Settings) error {
err := validate(args)
if err != nil {
return err
}
err = installOperator(args[0], options, fs, settings)
return err
}
func validate(args []string) error {
if len(args) != 1 {
return clog.Errorf("expecting exactly one argument - name of the package or path to install")
}
return nil
}
// installOperator is installing single operator into cluster and returns error in case of error
func installOperator(operatorArgument string, options *Options, fs afero.Fs, settings *env.Settings) error {
repository, err := repo.ClientFromSettings(fs, settings.Home, options.RepoName)
if err != nil {
return fmt.Errorf("could not build operator repository: %w", err)
}
clog.V(4).Printf("repository used %s", repository)
kc, err := env.GetClient(settings)
clog.V(3).Printf("acquiring kudo client")
if err != nil {
clog.V(3).Printf("failed to acquire client")
return fmt.Errorf("creating kudo client: %w", err)
}
clog.V(3).Printf("getting operator package")
resolver := pkgresolver.New(repository)
pkg, err := resolver.Resolve(operatorArgument, options.AppVersion, options.OperatorVersion)
if err != nil {
return fmt.Errorf("failed to resolve operator package for: %s %w", operatorArgument, err)
}
installOpts := install.Options{
SkipInstance: options.SkipInstance,
CreateNamespace: options.CreateNameSpace,
}
if options.Wait {
waitDuration := time.Duration(options.WaitTime) * time.Second
installOpts.Wait = &waitDuration
}
return install.Package(
kc,
options.InstanceName,
settings.Namespace,
*pkg.Resources,
options.Parameters,
resolver,
installOpts)
}