-
Notifications
You must be signed in to change notification settings - Fork 2
/
factory.go
78 lines (70 loc) · 2.46 KB
/
factory.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
package clustermanagers
import (
"errors"
"fmt"
"strings"
"github.com/hyperpilotio/deployer/apis"
"github.com/hyperpilotio/deployer/clustermanagers/awsecs"
"github.com/hyperpilotio/deployer/clustermanagers/awsk8s"
"github.com/hyperpilotio/deployer/clustermanagers/gcpgke"
"github.com/hyperpilotio/deployer/clusters"
"github.com/hyperpilotio/deployer/job"
"github.com/hyperpilotio/go-utils/log"
"github.com/pborman/uuid"
"github.com/spf13/viper"
)
// Cluster manager specific Deployer, able to deployer containers and services
type Deployer interface {
CreateDeployment(uploadedFiles map[string]string) (interface{}, error)
UpdateDeployment(updateDeployment *apis.Deployment) error
DeployExtensions(extensions *apis.Deployment, mergedDeployment *apis.Deployment) error
DeleteDeployment() error
ReloadClusterState(storeInfo interface{}) error
GetStoreInfo() interface{}
NewStoreInfo() interface{}
// TODO(tnachen): Eventually we should support multiple clouds, then we need to abstract AWSCluster
GetCluster() clusters.Cluster
GetLog() *log.FileLog
GetScheduler() *job.Scheduler
SetScheduler(sheduler *job.Scheduler)
GetServiceUrl(serviceName string) (string, error)
GetServiceAddress(serviceName string) (*apis.ServiceAddress, error)
GetServiceMappings() (map[string]interface{}, error)
GetKubeConfigPath() (string, error)
}
func NewDeployer(
config *viper.Viper,
userProfile clusters.UserProfile,
deployType string,
deployment *apis.Deployment,
createName bool) (Deployer, error) {
if createName {
deployment.Name = CreateUniqueDeploymentName(deployment.Name)
}
if config.GetBool("inCluster") {
switch deployType {
case "K8S":
return awsk8s.NewInClusterDeployer(config, deployment)
default:
return nil, errors.New("Unsupported in cluster deploy type: " + deployType)
}
}
if config.GetBool("hyperpilot-shared-gcp.use") {
return gcpgke.NewSharedDeployer(config, deployment)
}
cluster := clusters.NewCluster(config, deployType, userProfile, deployment)
switch deployType {
case "ECS":
return awsecs.NewDeployer(config, cluster, deployment)
case "K8S":
return awsk8s.NewDeployer(config, cluster, deployment)
case "GCP":
return gcpgke.NewDeployer(config, cluster, deployment)
default:
return nil, errors.New("Unsupported deploy type: " + deployType)
}
}
func CreateUniqueDeploymentName(familyName string) string {
randomId := strings.ToUpper(strings.Split(uuid.NewUUID().String(), "-")[0])
return fmt.Sprintf("%s-%s", familyName, randomId)
}