forked from envoyproxy/xds-relay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
70 lines (63 loc) · 2.52 KB
/
main.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
package main
import (
"io/ioutil"
"log"
"github.com/envoyproxy/xds-relay/internal/app/server"
"github.com/envoyproxy/xds-relay/internal/pkg/util/yamlproto"
aggregationv1 "github.com/envoyproxy/xds-relay/pkg/api/aggregation/v1"
bootstrapv1 "github.com/envoyproxy/xds-relay/pkg/api/bootstrap/v1"
"github.com/spf13/cobra"
)
var (
bootstrapConfigFile string
aggregationRulesConfigFile string
logLevel string
mode string
bootstrapCmd = &cobra.Command{
Use: "xds-relay",
Run: func(cmd *cobra.Command, args []string) {
bootstrapConfigFileContent, err := ioutil.ReadFile(bootstrapConfigFile)
if err != nil {
log.Fatal("failed to read bootstrap config file: ", err)
}
var bootstrapConfig bootstrapv1.Bootstrap
err = yamlproto.FromYAMLToBootstrapConfiguration(string(bootstrapConfigFileContent), &bootstrapConfig)
if err != nil {
log.Fatal("failed to translate bootstrap config: ", err)
}
aggregationRulesFileContent, err := ioutil.ReadFile(aggregationRulesConfigFile)
if err != nil {
log.Fatal("failed to read aggregation rules file: ", err)
}
var aggregationRulesConfig aggregationv1.KeyerConfiguration
err = yamlproto.FromYAMLToKeyerConfiguration(string(aggregationRulesFileContent), &aggregationRulesConfig)
if err != nil {
log.Fatal("failed to translate aggregation rules: ", err)
}
switch mode {
case "serve", "validate":
server.Run(&bootstrapConfig, &aggregationRulesConfig, logLevel, mode)
default:
log.Fatal("unrecognized mode provided: ", mode)
}
},
}
)
func main() {
bootstrapCmd.Flags().StringVarP(&bootstrapConfigFile, "config-file", "c", "", "path to bootstrap configuration file")
bootstrapCmd.Flags().StringVarP(&aggregationRulesConfigFile,
"aggregation-rules", "a", "", "path to aggregation rules file")
bootstrapCmd.Flags().StringVarP(&logLevel, "log-level", "l", "", "the logging level")
bootstrapCmd.Flags().StringVarP(&mode, "mode", "m", "serve",
"operating mode. Set to 'serve' by default to validate user-entered configs and start the server. "+
"Set to 'validate' to only validate user-entered configs.")
if err := bootstrapCmd.MarkFlagRequired("config-file"); err != nil {
log.Fatal("Could not mark the config-file flag as required: ", err)
}
if err := bootstrapCmd.MarkFlagRequired("aggregation-rules"); err != nil {
log.Fatal("Could not mark the aggregation-rules flag as required: ", err)
}
if err := bootstrapCmd.Execute(); err != nil {
log.Fatal("Issue parsing command line: ", err)
}
}