forked from rancher/rancher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
service.go
44 lines (38 loc) · 995 Bytes
/
service.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
package service
import (
"strconv"
"github.com/rancher/norman/types"
"github.com/rancher/norman/types/convert"
v3 "github.com/rancher/types/client/project/v3"
"github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/util/intstr"
)
func New(store types.Store) types.Store {
return &Store{
store,
}
}
type Store struct {
types.Store
}
func (p *Store) Create(apiContext *types.APIContext, schema *types.Schema, data map[string]interface{}) (map[string]interface{}, error) {
formatData(data)
data, err := p.Store.Create(apiContext, schema, data)
return data, err
}
func formatData(data map[string]interface{}) {
var ports []interface{}
servicePort := v3.ServicePort{
Port: 42,
TargetPort: intstr.Parse(strconv.FormatInt(42, 10)),
Protocol: "TCP",
Name: "default",
}
m, err := convert.EncodeToMap(servicePort)
if err != nil {
logrus.Warnf("Failed to transform service port to map: %v", err)
return
}
ports = append(ports, m)
data["ports"] = ports
}