-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathconfig.go
70 lines (61 loc) · 3.77 KB
/
config.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
/*
Copyright (c) 2021-2024 Nordix Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import (
"errors"
"fmt"
"net/url"
"strconv"
"strings"
"time"
)
// Config for the proxy
type Config struct {
Name string `default:"load-balancer" desc:"Name of the pod"`
ServiceName string `default:"load-balancer" desc:"Name of providing service" split_words:"true"`
ConnectTo url.URL `default:"unix:///var/lib/networkservicemesh/nsm.io.sock" desc:"url to connect to NSM" split_words:"true"`
DialTimeout time.Duration `default:"5s" desc:"timeout to dial NSMgr" split_words:"true"`
RequestTimeout time.Duration `default:"15s" desc:"timeout to request NSE" split_words:"true"`
MaxTokenLifetime time.Duration `default:"24h" desc:"maximum lifetime of tokens" split_words:"true"`
NSPService string `default:"nsp-service:7778" desc:"IP (or domain) and port of the NSP Service" split_words:"true"`
ConduitName string `default:"load-balancer" desc:"Name of the conduit" split_words:"true"`
TrenchName string `default:"default" desc:"Trench the pod is running on" split_words:"true"`
LogLevel string `default:"DEBUG" desc:"Log level" split_words:"true"`
Nfqueue string `default:"0:3" desc:"netfilter queue(s) to be used by nfqlb" split_words:"true"`
NfqueueFanout bool `default:"false" desc:"enable fanout nfqueue option" split_words:"true"`
IdentifierOffsetStart int `default:"5000" desc:"Each Stream will get a unique identifier range starting from that value" split_words:"true"`
GRPCKeepaliveTime time.Duration `default:"30s" desc:"gRPC keepalive timeout" envconfig:"grpc_keepalive_time"`
GRPCProbeRPCTimeout time.Duration `default:"1s" desc:"RPC timeout of internal gRPC health probe" envconfig:"grpc_probe_rpc_timeout"`
GRPCMaxBackoff time.Duration `default:"5s" desc:"Upper bound on gRPC connection backoff delay" envconfig:"grpc_max_backoff"`
MetricsEnabled bool `default:"false" desc:"Enable the metrics collection" split_words:"true"`
MetricsPort int `default:"2223" desc:"Specify the port used to expose the metrics" split_words:"true"`
Socket url.URL `default:"unix:///var/lib/meridio/lb.sock" desc:"Server socket to host Stream Availability Service" split_words:"true"`
Namespace string `default:"default" desc:"Namespace the pod is running on" split_words:"true"`
TargetDisconnectMonitoring bool `default:"true" desc:"Enable listening to Target disconnect events to clean-up linux neighbor cache" split_words:"true"`
}
// IsValid checks if the configuration is valid
func (c *Config) IsValid() error {
if c.ConnectTo.String() == "" {
return errors.New("no NSMGr ConnectTO URL are specified")
}
nfq := strings.Split(c.Nfqueue, ":")
if _, err := strconv.ParseUint(nfq[0], 10, 16); err != nil {
return fmt.Errorf("wrong Nfqueue format; %v (%v)", nfq[0], err)
}
if len(nfq) >= 2 {
if _, err := strconv.ParseUint(nfq[1], 10, 16); err != nil {
return fmt.Errorf("wrong Nfqueue format; %v (%v)", nfq[1], err)
}
}
return nil
}