-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathpod.go
85 lines (74 loc) · 4.31 KB
/
pod.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
package entity
import (
"time"
"gopkg.in/mgo.v2/bson"
)
const (
// PodCollectionName is a const string
PodCollectionName string = "pods"
// PodHostNetwork is the network type for the Pod
// host means the pod use the hostNetwork (share the network with the host machine)
PodHostNetwork = "host"
// PodClusterNetwork is cluster which means use the cluster Network, maybe the flannel network
PodClusterNetwork = "cluster"
// PodCustomNetwork is custom which means the custom netwokr we created before, it support the OVS and DPDK network for additional network interface card
PodCustomNetwork = "custom"
)
// Container is the structure for init Container info
type Container struct {
Name string `bson:"name" json:"name" validate:"required,k8sname"`
Image string `bson:"image" json:"image" validate:"required"`
Command []string `bson:"command" json:"command" validate:"required,dive,required"`
ResourceRequestCPU int `bson:"resourceRequestCPU" json:"resourceRequestCPU" validate:"-"`
ResourceRequestMemory int `bson:"resourceRequestMemory" json:"resourceRequestMemory" validate:"-"`
}
// PodRouteGw is the structure for add IP routing table with gateway
type PodRouteGw struct {
DstCIDR string `bson:"dstCIDR" json:"dstCIDR" validate:"required,cidrv4"`
Gateway string `bson:"gateway" json:"gateway" validate:"required,ipv4"`
}
// PodRouteIntf is the structure for add IP routing table via interface
type PodRouteIntf struct {
DstCIDR string `bson:"dstCIDR" json:"dstCIDR" validate:"required,cidrv4"`
}
// PodNetwork is the structure for pod network info
type PodNetwork struct {
Name string `bson:"name" json:"name" validate:"required"`
IfName string `bson:"ifName" json:"ifName" validate:"required"`
// can not validate nil
VlanTag *int32 `bson:"vlanTag" json:"vlanTag" validate:"-"`
IPAddress string `bson:"ipAddress" json:"ipAddress" validate:"required,ipv4"`
Netmask string `bson:"netmask" json:"netmask" validate:"required,ipv4"`
RoutesGw []PodRouteGw `bson:"routesGw,omitempty" json:"routesGw" validate:"required,dive,required"`
RoutesIntf []PodRouteIntf `bson:"routesIntf,omitempty" json:"routesIntf" validate:"required,dive,required"`
// It's from the entity.Network entity
BridgeName string `bson:"bridgeName" json:"bridgeName" validate:"-"`
}
// PodVolume is the structure for pod volume info
type PodVolume struct {
Name string `bson:"name" json:"name" validate:"required"`
MountPath string `bson:"mountPath" json:"mountPath" validate:"required"`
}
// Pod is the structure for pod info
type Pod struct {
ID bson.ObjectId `bson:"_id,omitempty" json:"id" validate:"-"`
OwnerID bson.ObjectId `bson:"ownerID,omitempty" json:"ownerID" validate:"-"`
Name string `bson:"name" json:"name" validate:"required,k8sname"`
Namespace string `bson:"namespace" json:"namespace" validate:"required"`
Labels map[string]string `bson:"labels,omitempty" json:"labels" validate:"required,dive,keys,printascii,endkeys,required,printascii"`
EnvVars map[string]string `bson:"envVars,omitempty" json:"envVars" validate:"required,dive,keys,printascii,endkeys,required,printascii"`
Containers []Container `bson:"containers" json:"containers" validate:"required,dive,required"`
Volumes []PodVolume `bson:"volumes,omitempty" json:"volumes" validate:"required,dive,required"`
Networks []PodNetwork `bson:"networks,omitempty" json:"networks" validate:"required,dive,required"`
RestartPolicy string `bson:"restartPolicy" json:"restartPolicy" validate:"required,eq=Always|eq=OnFailure|eq=Never"`
Capability bool `bson:"capability" json:"capability" validate:"-"`
NetworkType string `bson:"networkType" json:"networkType" validate:"required,eq=host|eq=cluster|eq=custom"`
NodeAffinity []string `bson:"nodeAffinity" json:"nodeAffinity" validate:"required"`
HostNetwork bool `bson:"hostNetwork" json:"hostNetwork" validate:"-"`
CreatedBy User `json:"createdBy" validate:"-"`
CreatedAt *time.Time `bson:"createdAt,omitempty" json:"createdAt,omitempty" validate:"-"`
}
// GetCollection - get model mongo collection name.
func (m Pod) GetCollection() string {
return PodCollectionName
}