-
Notifications
You must be signed in to change notification settings - Fork 1
/
ack.go
96 lines (81 loc) · 2.61 KB
/
ack.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
package app
import (
"errors"
"fmt"
"github.com/beego/beego/v2/core/validation"
"github.com/cloud-barista/poc-cicd-ladybug/src/core/model"
"github.com/cloud-barista/poc-cicd-ladybug/src/utils/config"
"github.com/cloud-barista/poc-cicd-ladybug/src/utils/lang"
"github.com/labstack/echo/v4"
)
type Status struct {
Message string `json:"message"`
}
func SendMessage(c echo.Context, httpCode int, msg string) error {
return c.JSON(httpCode, Status{Message: msg})
}
func Send(c echo.Context, httpCode int, json interface{}) error {
return c.JSON(httpCode, json)
}
func Validate(c echo.Context, params []string) error {
valid := validation.Validation{}
for _, name := range params {
valid.Required(c.Param(name), name)
}
if valid.HasErrors() {
for _, err := range valid.Errors {
return errors.New(fmt.Sprintf("[%s]%s", err.Key, err.Error()))
}
}
return nil
}
func ClusterReqDef(clusterReq model.ClusterReq) {
clusterReq.Config.Kubernetes.NetworkCni = lang.NVL(clusterReq.Config.Kubernetes.NetworkCni, config.NETWORKCNI_KILO)
clusterReq.Config.Kubernetes.PodCidr = lang.NVL(clusterReq.Config.Kubernetes.PodCidr, config.POD_CIDR)
clusterReq.Config.Kubernetes.ServiceCidr = lang.NVL(clusterReq.Config.Kubernetes.ServiceCidr, config.SERVICE_CIDR)
clusterReq.Config.Kubernetes.ServiceDnsDomain = lang.NVL(clusterReq.Config.Kubernetes.ServiceDnsDomain, config.SERVICE_DOMAIN)
}
func ClusterReqValidate(req model.ClusterReq) error {
if len(req.ControlPlane) == 0 {
return errors.New("control plane node must be at least one")
}
if len(req.ControlPlane) > 1 {
return errors.New("only one control plane node is supported")
}
if len(req.Worker) == 0 {
return errors.New("worker node must be at least one")
}
if !(req.Config.Kubernetes.NetworkCni == config.NETWORKCNI_CANAL || req.Config.Kubernetes.NetworkCni == config.NETWORKCNI_KILO) {
return errors.New("network cni allows only kilo or canal")
}
if len(req.Name) == 0 {
return errors.New("cluster name is empty")
} else {
err := lang.CheckName(req.Name)
if err != nil {
return err
}
}
if len(req.Config.Kubernetes.PodCidr) > 0 {
err := lang.CheckIpCidr("podCidr", req.Config.Kubernetes.PodCidr)
if err != nil {
return err
}
}
if len(req.Config.Kubernetes.ServiceCidr) > 0 {
err := lang.CheckIpCidr("serviceCidr", req.Config.Kubernetes.ServiceCidr)
if err != nil {
return err
}
}
return nil
}
func NodeReqValidate(req model.NodeReq) error {
if len(req.ControlPlane) > 0 {
return errors.New("control plane node is not supported")
}
if len(req.Worker) == 0 {
return errors.New("worker node must be at least one")
}
return nil
}