-
Notifications
You must be signed in to change notification settings - Fork 0
/
spickspan.go
69 lines (59 loc) · 1.97 KB
/
spickspan.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
package spickspan
import (
"github.com/essentier/spickspan/config"
"github.com/essentier/spickspan/model"
"github.com/essentier/spickspan/probe"
"github.com/essentier/spickspan/provider/kube"
"github.com/essentier/spickspan/provider/local"
"github.com/essentier/spickspan/provider/nomock"
"github.com/go-errors/errors"
)
func GetHttpService(provider model.Provider, serviceName string, readinessPath string) (model.Service, error) {
service, err := provider.GetService(serviceName)
if err != nil {
return service, err
}
serviceReady := probe.ProbeHttpService(service, readinessPath)
if serviceReady {
return service, nil
} else {
defer provider.Release(service)
return service, errors.Errorf("Service is not ready yet. The service is %v", service)
}
}
func GetDefaultServiceProvider() (model.Provider, error) {
config, err := config.GetConfig()
if err != nil {
return nil, err
}
registry, err := GetDefaultKubeRegistry(config)
if err != nil {
return nil, err
}
return registry.ResolveProvider()
}
func GetMongoDBService(provider model.Provider, serviceName string) (model.Service, error) {
mgoService, err := provider.GetService(serviceName)
if err != nil {
return mgoService, err
}
serviceReady := probe.ProbeMgoService(mgoService)
if serviceReady {
return mgoService, nil
} else {
defer provider.Release(mgoService)
return mgoService, errors.Errorf("Service is not ready yet. The service is %v", mgoService)
}
}
func GetNomockProvider(config config.Model) (model.Provider, error) {
provider := nomock.CreateProvider(config)
err := provider.Init()
return provider, err
}
func GetDefaultKubeRegistry(config config.Model) (*model.ProviderRegistry, error) {
registry := &model.ProviderRegistry{}
registry.RegisterProvider(nomock.CreateProvider(config))
registry.RegisterProvider(kube.CreateProvider(config))
registry.RegisterProvider(local.CreateProvider(config))
return registry, nil
}