-
Notifications
You must be signed in to change notification settings - Fork 2
/
models.go
133 lines (108 loc) · 4.5 KB
/
models.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package apis
import (
"fmt"
"k8s.io/client-go/pkg/api/v1"
appsv1beta1 "k8s.io/client-go/pkg/apis/apps/v1beta1"
"k8s.io/client-go/pkg/apis/extensions/v1beta1"
"github.com/aws/aws-sdk-go/service/ecs"
)
type ClusterNode struct {
Id int `form:"id" json:"id" binding:"required"`
InstanceType string `form:"instanceType" json:"instanceType" binding:"required"`
Labels map[string]string `form:"labels" json:"labels" binding:"required"`
}
// ClusterDefinition storing the information of a cluster
type ClusterDefinition struct {
Nodes []ClusterNode `form:"nodes" json:"nodes" binding:"required"`
}
type GCPDefinition struct {
ClusterVersion string `form:"clusterVersion" json:"clusterVersion"`
}
type NodeMapping struct {
Id int `json:"id"`
Task string `json:"task"`
}
// Service return a string with suffix "-service"
func (mapping NodeMapping) Service() string {
return mapping.Task + "-service"
}
// ImageIdAttribute return imageId for putAttribute function
func (mapping NodeMapping) ImageIdAttribute() string {
return fmt.Sprintf("imageId-%d", mapping.Id)
}
// ECSDeployment storing the information of a ECS deployment
type ECSDeployment struct {
TaskDefinitions []ecs.RegisterTaskDefinitionInput `form:"taskDefinitions" json:"taskDefinitions" binding:"required"`
}
type KubernetesTask struct {
DaemonSet *v1beta1.DaemonSet `form:"daemonset" json:"daemonset,omitempty"`
StatefulSet *appsv1beta1.StatefulSet `form:"statefulset" json:"statefulset,omitempty"`
Deployment *v1beta1.Deployment `form:"deployment" json:"deployment,omitempty"`
Family string `form:"family" json:"family" binding:"required"`
// Type of each port opened by a container: 0 - private, 1 - public
PortTypes []int `form:"portTypes" json:"portTypes"`
}
func (task *KubernetesTask) GetPorts() []v1.ContainerPort {
ports := []v1.ContainerPort{}
var containers []v1.Container
if task.DaemonSet != nil {
containers = task.DaemonSet.Spec.Template.Spec.Containers
} else if task.StatefulSet != nil {
containers = task.StatefulSet.Spec.Template.Spec.Containers
} else if task.Deployment != nil {
containers = task.Deployment.Spec.Template.Spec.Containers
}
if containers != nil {
for _, container := range containers {
for _, port := range container.Ports {
ports = append(ports, port)
}
}
}
return ports
}
// KubernetesDeployment storing the information of a Kubernetes deployment
type KubernetesDeployment struct {
Kubernetes []KubernetesTask `form:"taskDefinitions" json:"taskDefinitions" binding:"required"`
Secrets []v1.Secret `form:"secrets" json:"secrets"`
SkipDeleteOnFailure bool `form:"skipdDeleteOnFailure" json:"skipDeleteOnFailure"`
GCPDefinition *GCPDefinition `form:"gcpDefinition" json:"gcpDefinition"`
}
type NodeMappings []NodeMapping
func (d NodeMappings) Len() int { return len(d) }
func (d NodeMappings) Less(i, j int) bool {
return d[i].Id < d[j].Id
}
func (d NodeMappings) Swap(i, j int) { d[i], d[j] = d[j], d[i] }
type VPCPeering struct {
TargetOwnerId string `json:"targetOwnerId"`
TargetVpcId string `json:"targetVpcId"`
}
type Deployment struct {
UserId string `form:"userId" json:"userId"`
Name string `form:"name" json:"name" binding:"required"`
Region string `form:"region" json:"region" binding:"required"`
ClusterType string `form:"clusterType" json:"clusterType"`
Files []struct {
FileId string `json:"fileId"`
FileUrl string `json:"fileUrl"`
Path string `json:"path"`
} `form:"files" json:"files"`
AllowedPorts []int `form:"allowedPorts" json:"allowedPorts"`
ClusterDefinition ClusterDefinition `form:"clusterDefinition" json:"clusterDefinition" binding:"required"`
NodeMapping NodeMappings `form:"nodeMapping" json:"nodeMapping" binding:"required"`
IamRole `form:"iamRole" json:"iamRole" binding:"required"`
*ECSDeployment `form:"ecs" json:"ecs,omitempty"`
*KubernetesDeployment `form:"kubernetes" json:"kubernetes,omitempty"`
*VPCPeering `json:"vpcPeering,omitempty"`
ShutDownTime string `form:"shutDownTime" json:"shutDownTime,omitempty"`
}
// IamRole store the information of iam role
type IamRole struct {
PolicyDocument string `form:"policyDocument" json:"policyDocument"`
}
// ServiceAddress object that stores the information of service container
type ServiceAddress struct {
Host string `bson:"host,omitempty" json:"host,omitempty"`
Port int32 `bson:"port,omitempty" json:"port,omitempty"`
}