-
Notifications
You must be signed in to change notification settings - Fork 2
/
output.go
80 lines (70 loc) · 2.26 KB
/
output.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
package translation
import (
"fmt"
kubev1 "github.com/eolinker/apinto-ingress-controller/pkg/kube/apinto/configs/apinto/v1"
apintov1 "github.com/eolinker/apinto-ingress-controller/pkg/types/apinto/v1"
)
func KubeOutputToApinto(ao *kubev1.ApintoOutput) *apintov1.Output {
kOutput := ao.Spec
apintoOutput := &apintov1.Output{
Metadata: apintov1.Metadata{
Name: kOutput.Name,
Profession: "output",
Driver: kOutput.Driver,
ID: fmt.Sprintf("%s@output", kOutput.Name),
},
}
switch kOutput.Driver {
case "file":
fileConf := kOutput.FileOutput.Config
cfg := make(apintov1.Config)
cfg["file"] = fileConf.File
cfg["dir"] = fileConf.Dir
cfg["period"] = fileConf.Period
cfg["expire"] = fileConf.Expire
cfg["type"] = fileConf.Type
cfg["formatter"] = map[string][]string(fileConf.Formatter)
apintoOutput.Config = cfg
case "nsqd":
nsqConf := kOutput.Nsqd.Config
cfg := make(apintov1.Config)
cfg["topic"] = nsqConf.Topic
cfg["address"] = nsqConf.Address
cfg["nsq_conf"] = nsqConf.ClientConf
cfg["type"] = nsqConf.Type
cfg["formatter"] = map[string][]string(nsqConf.Formatter)
apintoOutput.Config = cfg
case "http_output":
httpConf := kOutput.HttpOutput.Config
cfg := make(apintov1.Config)
cfg["method"] = httpConf.Method
cfg["url"] = httpConf.Url
cfg["headers"] = httpConf.Headers
cfg["type"] = httpConf.Type
cfg["formatter"] = map[string][]string(httpConf.Formatter)
apintoOutput.Config = cfg
case "syslog_output":
sysConf := kOutput.SysOutput.Config
cfg := make(apintov1.Config)
cfg["network"] = sysConf.Network
cfg["address"] = sysConf.Address
cfg["level"] = sysConf.Level
cfg["type"] = sysConf.Type
cfg["formatter"] = map[string][]string(sysConf.Formatter)
apintoOutput.Config = cfg
case "kafka_output":
kafkaConf := kOutput.KafkaOutput.Config
cfg := make(apintov1.Config)
cfg["topic"] = kafkaConf.Topic
cfg["address"] = kafkaConf.Address
cfg["timeout"] = kafkaConf.Timeout
cfg["version"] = kafkaConf.Version
cfg["partition_type"] = kafkaConf.PartitionType
cfg["partition"] = kafkaConf.Partition
cfg["partition_key"] = kafkaConf.PartitionKey
cfg["type"] = kafkaConf.Type
cfg["formatter"] = map[string][]string(kafkaConf.Formatter)
apintoOutput.Config = cfg
}
return apintoOutput
}