-
Notifications
You must be signed in to change notification settings - Fork 6
/
service.go
107 lines (88 loc) · 2.56 KB
/
service.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
101
102
103
104
105
106
107
package app
import (
"github.com/giantswarm/app/v7/pkg/values"
"github.com/giantswarm/k8sclient/v7/pkg/k8sclient"
"github.com/giantswarm/microerror"
"github.com/giantswarm/micrologger"
"sigs.k8s.io/controller-runtime/pkg/client"
appdata "github.com/giantswarm/kubectl-gs/v3/pkg/data/domain/app"
catalogdata "github.com/giantswarm/kubectl-gs/v3/pkg/data/domain/catalog"
"github.com/giantswarm/kubectl-gs/v3/pkg/helmbinary"
)
var _ Interface = &Service{}
// Config represents the values that New() needs in order to create a valid app service.
type Config struct {
Client k8sclient.Interface
Logger micrologger.Logger
}
// Service represents an instance of the App service.
type Service struct {
Client client.Client
AppDataService appdata.Interface
CatalogDataService catalogdata.Interface
HelmbinaryService helmbinary.Interface
ValuesService *values.Values
CatalogFetchResults map[string]CatalogFetchResult
SchemaFetchResults map[string]SchemaFetchResult
}
// New returns an app service given a certain Config.
func New(config Config) (Interface, error) {
var err error
if config.Client == nil {
return nil, microerror.Maskf(invalidConfigError, "%T.Client must not be empty", config)
}
if config.Logger == nil {
return nil, microerror.Maskf(invalidConfigError, "%T.Logger must not be empty", config)
}
var appDataService appdata.Interface
{
c := appdata.Config{
Client: config.Client.CtrlClient(),
}
appDataService, err = appdata.New(c)
if err != nil {
return nil, microerror.Mask(err)
}
}
var catalogDataService catalogdata.Interface
{
c := catalogdata.Config{
Client: config.Client.CtrlClient(),
}
catalogDataService, err = catalogdata.New(c)
if err != nil {
return nil, microerror.Mask(err)
}
}
var helmbinaryService helmbinary.Interface
{
c := helmbinary.Config{
Client: config.Client.CtrlClient(),
}
helmbinaryService, err = helmbinary.New(c)
if err != nil {
return nil, microerror.Mask(err)
}
}
var valuesService *values.Values
{
c := values.Config{
K8sClient: config.Client.K8sClient(),
Logger: config.Logger,
}
valuesService, err = values.New(c)
if err != nil {
return nil, microerror.Mask(err)
}
}
s := &Service{
Client: config.Client.CtrlClient(),
AppDataService: appDataService,
CatalogDataService: catalogDataService,
HelmbinaryService: helmbinaryService,
ValuesService: valuesService,
CatalogFetchResults: make(map[string]CatalogFetchResult),
SchemaFetchResults: make(map[string]SchemaFetchResult),
}
return s, nil
}