• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

noironetworks / aci-containers / 7615

pending completion
7615

push

travis-pro

GitHub
Merge pull request #1125 from noironetworks/travis-backport-kmr2

Travis backport kmr2

12040 of 21626 relevant lines covered (55.67%)

0.62 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

74.51
/pkg/controller/config.go
1
// Copyright 2017 Cisco Systems, Inc.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15
package controller
16

17
import (
18
        "flag"
19

20
        "github.com/noironetworks/aci-containers/pkg/ipam"
21
)
22

23
const (
24
        lbTypeAci = "aci-nlb"
25
)
26

27
type OpflexGroup struct {
28
        PolicySpace string `json:"policy-space,omitempty"`
29
        Name        string `json:"name,omitempty"`
30
}
31

32
type delayService struct {
33
        Delay     int    `json:"delay,omitempty"`
34
        Name      string `json:"name,omitempty"`
35
        Namespace string `json:"namespace,omitempty"`
36
}
37

38
type serviceGraphEpAddDelay struct {
39
        Delay    int            `json:"delay,omitempty"`
40
        Services []delayService `json:"services,omitempty"`
41
}
42

43
// Configuration for the controller
44
type ControllerConfig struct {
45
        // Log level
46
        LogLevel string `json:"log-level,omitempty"`
47

48
        // Absolute path to a kubeconfig file
49
        KubeConfig string `json:"kubeconfig,omitempty"`
50

51
        // TCP port to run status server on (or 0 to disable)
52
        StatusPort int `json:"status-port,omitempty"`
53

54
        // Default endpoint group annotation value
55
        DefaultEg OpflexGroup `json:"default-endpoint-group,omitempty"`
56

57
        // Default security group annotation value
58
        DefaultSg []OpflexGroup `json:"default-security-group,omitempty"`
59

60
        // Override default endpoint group assignments for a namespace
61
        // map ns name -> group
62
        NamespaceDefaultEg map[string]OpflexGroup `json:"namespace-default-endpoint-group,omitempty"`
63

64
        // Override default security group assignments for namespaces
65
        // map ns name -> slice of groups
66
        NamespaceDefaultSg map[string][]OpflexGroup `json:"namespace-default-security-group,omitempty"`
67

68
        // The hostnames or IPs for connecting to apic
69
        ApicHosts []string `json:"apic-hosts,omitempty"`
70

71
        // The username for connecting to APIC
72
        ApicUsername string `json:"apic-username,omitempty"`
73

74
        // The password for connecting to APIC
75
        ApicPassword string `json:"apic-password,omitempty"`
76

77
        // The number of seconds that APIC should wait before timing
78
        // out a subscription on a websocket connection. If not
79
        // explicitly set, then a default of 1800 seconds will
80
        // be sent in websocket subscriptions. If it is set to 0,
81
        // then a timeout will not be sent in websocket
82
        // subscriptions, and APIC will use it's default timeout
83
        // of 80 seconds. If set to a non-zero value, then the
84
        // timeout value will be provided when we subscribe to
85
        // a URL on APIC. NOTE: the subscription timeout is not
86
        // supported by APIC versions before 3.2(3), so this
87
        // value must not be set when used with APIC versions
88
        // older than that release.
89
        // Also, note that this is a string.
90
        ApicRefreshTimer string `json:"apic-refreshtime,omitempty"`
91

92
        // Delay in milliseconds after each subscription query
93
        // Will be defaulted to 100ms.
94
        ApicSubscriptionDelay int `json:"apic-subscription-delay,omitempty"`
95

96
        // How early (seconds) the subscriptions to be refreshed than
97
        // actual subscription refresh-timeout. Will be defaulted to 150Seconds.
98
        ApicRefreshTickerAdjust string `json:"apic-refreshticker-adjust,omitempty"`
99

100
        // A path for a PEM-encoded private key for client certificate
101
        // authentication for APIC API
102
        ApicPrivateKeyPath string `json:"apic-private-key-path,omitempty"`
103

104
        // A path for a PEM-encoded public certificate for APIC server to
105
        // enable secure TLS server verifification
106
        ApicCertPath string `json:"apic-cert-path,omitempty"`
107

108
        // The type of the ACI VMM domain: either "kubernetes",
109
        // "openshift"
110
        AciVmmDomainType string `json:"aci-vmm-type,omitempty"`
111

112
        // The name of the ACI VMM domain
113
        AciVmmDomain string `json:"aci-vmm-domain,omitempty"`
114

115
        // The name of the ACI VMM domain controller instance
116
        AciVmmController string `json:"aci-vmm-controller,omitempty"`
117

118
        // Name prefix to use when creating policy to avoid namespace
119
        // collisions
120
        AciPrefix string `json:"aci-prefix,omitempty"`
121

122
        // Tenant to use when creating policy objects in APIC
123
        AciPolicyTenant string `json:"aci-policy-tenant,omitempty"`
124

125
        // Load Balancer Type
126
        LBType string `json:"lb-type,omitempty"`
127

128
        // Physical domain used for service device clusters
129
        AciServicePhysDom string `json:"aci-service-phys-dom,omitempty"`
130

131
        // Encap used for service device clusters
132
        AciServiceEncap string `json:"aci-service-encap,omitempty"`
133

134
        // Time in seconds between service node ICMP probes for more
135
        // quickly removing failed nodes from service pools
136
        // 0 (default) means don't monitor
137
        AciServiceMonitorInterval int `json:"aci-service-monitor-interval,omitempty"`
138

139
        // Whether to enable PBR tracking for non-SNAT services
140
        // when AciServiceMonitorInterval is set to non-zero, PBR tracking
141
        // is enabled for snat
142
        AciPbrTrackingNonSnat bool `json:"aci-pbr-tracking-non-snat,omitempty"`
143

144
        // The tenants related to AciVrf where BDs/EPGs/Subnets could exist.
145
        // Usually AciVrfTenant and AciPolicyTenant
146
        AciVrfRelatedTenants []string `json:"aci-vrf-related-tenants,omitempty"`
147

148
        // ACI Pod-BD for this kubernetes instance
149
        AciPodBdDn string `json:"aci-podbd-dn,omitempty"`
150

151
        // ACI Node-BD for this kubernetes instance
152
        AciNodeBdDn string `json:"aci-nodebd-dn,omitempty"`
153

154
        // ACI VRF for this kubernetes instance
155
        AciVrf string `json:"aci-vrf,omitempty"`
156

157
        // ACI VRF for this kubernetes instance
158
        AciVrfDn string `json:"aci-vrf-dn,omitempty"`
159

160
        // Tenant containing the ACI VRF for this kubernetes instance
161
        AciVrfTenant string `json:"aci-vrf-tenant,omitempty"`
162

163
        // L3 out to use for services, service device clusters need to be
164
        // created in this tenant
165
        AciL3Out string `json:"aci-l3out,omitempty"`
166

167
        // L3 external networks (within the l3out) that will be able to
168
        // access the service IPs
169
        AciExtNetworks []string `json:"aci-ext-networks,omitempty"`
170

171
        // IP addresses used for pod network
172
        PodIpPool []ipam.IpRange `json:"pod-ip-pool,omitempty"`
173

174
        // The number of IP addresses to allocate when a pod starts to run low
175
        PodIpPoolChunkSize int `json:"pod-subnet-chunk-size,omitempty"`
176

177
        // Pod subnet CIDRs in the form <gateway-address>/<prefix-length> that
178
        // cover all pod-ip-pools
179
        PodSubnets []string `json:"pod-subnets,omitempty"`
180

181
        // Whether to allocate service IPs or to assume they will be
182
        // allocated by another controller
183
        AllocateServiceIps *bool `json:"allocate-service-ips,omitempty"`
184

185
        // IP addresses used for externally exposed load balanced services
186
        ServiceIpPool []ipam.IpRange `json:"service-ip-pool,omitempty"`
187

188
        // IP addresses that can be requested as static service IPs in
189
        // service spec
190
        StaticServiceIpPool []ipam.IpRange `json:"static-service-ip-pool,omitempty"`
191

192
        // IP addresses to use for node service endpoints
193
        NodeServiceIpPool []ipam.IpRange `json:"node-service-ip-pool,omitempty"`
194

195
        // a list of subnet/gateway CIDR addresses that cover the
196
        // addresses in the node service IP pool
197
        NodeServiceSubnets []string `json:"node-service-subnets,omitempty"`
198

199
        // default port range to use for SNAT svc graph filter
200
        SnatDefaultPortRangeStart int `json:"snat-default-port-range-start,omitempty"`
201
        SnatDefaultPortRangeEnd   int `json:"snat-default-port-range-end,omitempty"`
202

203
        // Contract scope used for SNAT svc graph
204
        SnatSvcContractScope string `json:"snat-contract-scope,omitempty"`
205

206
        // Maximum number of nodes permitted in a svc graph
207
        MaxSvcGraphNodes int `json:"max-nodes-svc-graph,omitempty"`
208

209
        // Disable routine to sync snatglobalinfo with nodeinfo
210
        // periodically
211
        DisablePeriodicSnatGlobalInfoSync bool `json:"disable-periodic-snat-global-info-sync,omitempty"`
212

213
        // True when we dont want to wait for service ep to be ready
214
        // before adding it to service graph
215
        // Default is false
216
        NoWaitForServiceEpReadiness bool `json:"no-wait-for-service-ep-readiness,omitempty"`
217

218
        ServiceGraphEndpointAddDelay serviceGraphEpAddDelay `json:"service-graph-endpoint-add-delay,omitempty"`
219
        // True when to add extern_dynamic and extern_static subnets to rdconfig
220
        // Default is false
221
        AddExternalSubnetsToRdconfig bool `json:"add-external-subnets-to-rdconfig,omitempty"`
222

223
        ExternStatic []string `json:"extern-static,omitempty"`
224

225
        ExternDynamic []string `json:"extern-dynamic,omitempty"`
226

227
        // Default is false
228
        HppOptimization bool `json:"hpp-optimization,omitempty"`
229

230
        // Default is false
231
        AciMultipod bool `json:"aci-multipod,omitempty"`
232

233
        // Install Istio ControlPlane components
234
        InstallIstio bool `json:"install-istio,omitempty"`
235

236
        // Maximum CSR tunnels
237
        MaxCSRTunnels   int `json:"max-csr-tunnels,omitempty"`
238
        CSRTunnelIDBase int `json:"csr-tunnel-id-base,omitempty"`
239
        // enable EndpointSlice
240
        EnabledEndpointSlice bool `json:"enable_endpointslice,omitempty"`
241

242
        // Cluster Flavour
243
        Flavor string `json:"flavor,omitempty"`
244

245
        // Enable creation of VmmInjectedLabel, default is false
246
        EnableVmmInjectedLabels bool `json:"enable-vmm-injected-labels,omitempty"`
247

248
        // Timeout to delete old opflex devices
249
        OpflexDeviceDeleteTimeout float64 `json:"opflex-device-delete-timeout,omitempty"`
250

251
        // Configure sleep time for global SNAT sync
252
        SleepTimeSnatGlobalInfoSync int `json:"sleep-time-snat-global-info-sync,omitempty"`
253
}
254

255
type netIps struct {
256
        V4 *ipam.IpAlloc
257
        V6 *ipam.IpAlloc
258
}
259

260
func newNetIps() *netIps {
1✔
261
        return &netIps{
1✔
262
                V4: ipam.New(),
1✔
263
                V6: ipam.New(),
1✔
264
        }
1✔
265
}
1✔
266

267
func NewConfig() *ControllerConfig {
1✔
268
        t := true
1✔
269
        return &ControllerConfig{
1✔
270
                DefaultSg:          make([]OpflexGroup, 0),
1✔
271
                NamespaceDefaultEg: make(map[string]OpflexGroup),
1✔
272
                NamespaceDefaultSg: make(map[string][]OpflexGroup),
1✔
273
                AciVmmDomainType:   "Kubernetes",
1✔
274
                AciPolicyTenant:    "kubernetes",
1✔
275
                AciPrefix:          "kube",
1✔
276
                AllocateServiceIps: &t,
1✔
277
                LBType:             lbTypeAci,
1✔
278
        }
1✔
279
}
1✔
280

281
func InitFlags(config *ControllerConfig) {
×
282
        flag.StringVar(&config.LogLevel, "log-level", "info", "Log level")
×
283

×
284
        flag.StringVar(&config.KubeConfig, "kube-config", "", "Absolute path to a kubeconfig file")
×
285

×
286
        flag.IntVar(&config.StatusPort, "status-port", 8091, " TCP port to run status server on (or 0 to disable)")
×
287
        flag.StringVar(&config.LBType, "loadbalancer", lbTypeAci, "Loadbalancer")
×
288
        flag.IntVar(&config.MaxCSRTunnels, "max-csr-tunnels", 16, "Number of CSR tunnels")
×
289
        flag.IntVar(&config.CSRTunnelIDBase, "csr-tunnel-id-base", 4001, "CSR starting tunnel ID")
×
290
        flag.BoolVar(&config.EnableVmmInjectedLabels, "enable-vmm-injected-labels", false, "Enable creation of VmmInjectedLabel")
×
291
}
×
292

293
func (cont *AciController) loadIpRanges(v4 *ipam.IpAlloc, v6 *ipam.IpAlloc,
294
        ipranges []ipam.IpRange) {
1✔
295

1✔
296
        for _, r := range ipranges {
2✔
297
                if r.Start.To4() != nil && r.End.To4() != nil {
2✔
298
                        v4.AddRange(r.Start, r.End)
1✔
299
                } else if r.Start.To16() != nil && r.End.To16() != nil {
3✔
300
                        v6.AddRange(r.Start, r.End)
1✔
301
                } else {
1✔
302
                        cont.log.Warn("Range invalid: ", r)
×
303
                }
×
304
        }
305
}
306

307
func (cont *AciController) initIpam() {
1✔
308
        cont.loadIpRanges(cont.configuredPodNetworkIps.V4, cont.configuredPodNetworkIps.V6,
1✔
309
                cont.config.PodIpPool)
1✔
310
        cont.podNetworkIps.V4.AddAll(cont.configuredPodNetworkIps.V4)
1✔
311
        cont.podNetworkIps.V6.AddAll(cont.configuredPodNetworkIps.V6)
1✔
312
        cont.serviceIps.LoadRanges(cont.config.ServiceIpPool)
1✔
313
        cont.loadIpRanges(cont.staticServiceIps.V4, cont.staticServiceIps.V6,
1✔
314
                cont.config.StaticServiceIpPool)
1✔
315
        cont.loadIpRanges(cont.nodeServiceIps.V4, cont.nodeServiceIps.V6,
1✔
316
                cont.config.NodeServiceIpPool)
1✔
317
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc