forked from projectcalico/felix
/
felix.go
96 lines (79 loc) · 2.92 KB
/
felix.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
// Copyright (c) 2017-2018 Tigera, Inc. All rights reserved.
//
// 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 infrastructure
import (
"fmt"
log "github.com/sirupsen/logrus"
"github.com/projectcalico/felix/fv/containers"
"github.com/projectcalico/felix/fv/utils"
)
type Felix struct {
*containers.Container
// ExpectedIPIPTunnelAddr contains the IP that the infrastructure expects to
// get assigned to the IPIP tunnel. Filled in by AddNode().
ExpectedIPIPTunnelAddr string
}
func (f *Felix) GetFelixPID() int {
return f.GetSinglePID("calico-felix")
}
func (f *Felix) GetFelixPIDs() []int {
return f.GetPIDs("calico-felix")
}
func RunFelix(infra DatastoreInfra, options TopologyOptions) *Felix {
log.Info("Starting felix")
ipv6Enabled := fmt.Sprint(options.EnableIPv6)
args := infra.GetDockerArgs()
args = append(args,
"--privileged",
"-e", "FELIX_LOGSEVERITYSCREEN="+options.FelixLogSeverity,
"-e", "FELIX_PROMETHEUSMETRICSENABLED=true",
"-e", "FELIX_USAGEREPORTINGENABLED=false",
"-e", "FELIX_IPV6SUPPORT="+ipv6Enabled,
"-v", "/lib/modules:/lib/modules",
)
for k, v := range options.ExtraEnvVars {
args = append(args, "-e", fmt.Sprintf("%s=%s", k, v))
}
for k, v := range options.ExtraVolumes {
args = append(args, "-v", fmt.Sprintf("%s:%s", k, v))
}
args = append(args,
utils.Config.FelixImage,
)
c := containers.Run("felix",
containers.RunOpts{AutoRemove: true},
args...,
)
if options.EnableIPv6 {
c.Exec("sysctl", "-w", "net.ipv6.conf.all.disable_ipv6=0")
c.Exec("sysctl", "-w", "net.ipv6.conf.default.disable_ipv6=0")
c.Exec("sysctl", "-w", "net.ipv6.conf.lo.disable_ipv6=0")
c.Exec("sysctl", "-w", "net.ipv6.conf.all.forwarding=1")
} else {
c.Exec("sysctl", "-w", "net.ipv6.conf.all.disable_ipv6=1")
c.Exec("sysctl", "-w", "net.ipv6.conf.default.disable_ipv6=1")
c.Exec("sysctl", "-w", "net.ipv6.conf.lo.disable_ipv6=1")
c.Exec("sysctl", "-w", "net.ipv6.conf.all.forwarding=0")
}
// Configure our model host to drop forwarded traffic by default. Modern
// Kubernetes/Docker hosts now have this setting, and the consequence is that
// whenever Calico policy intends to allow a packet, it must explicitly ACCEPT
// that packet, not just allow it to pass through cali-FORWARD and assume it will
// be accepted by the rest of the chain. Establishing that setting in this FV
// allows us to test that.
c.Exec("iptables", "-P", "FORWARD", "DROP")
return &Felix{
Container: c,
}
}