/
daemon_main.go
1665 lines (1352 loc) · 67.6 KB
/
daemon_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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2016-2019 Authors of Cilium
//
// 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 (
"context"
"errors"
"fmt"
"io/ioutil"
"net"
"os"
"os/exec"
"path"
"path/filepath"
"regexp"
"strings"
"time"
"github.com/cilium/cilium/api/v1/server"
"github.com/cilium/cilium/api/v1/server/restapi"
"github.com/cilium/cilium/common"
_ "github.com/cilium/cilium/pkg/alignchecker"
"github.com/cilium/cilium/pkg/bpf"
"github.com/cilium/cilium/pkg/cgroups"
"github.com/cilium/cilium/pkg/cleanup"
"github.com/cilium/cilium/pkg/components"
"github.com/cilium/cilium/pkg/controller"
"github.com/cilium/cilium/pkg/datapath/iptables"
linuxdatapath "github.com/cilium/cilium/pkg/datapath/linux"
"github.com/cilium/cilium/pkg/datapath/loader"
"github.com/cilium/cilium/pkg/datapath/maps"
"github.com/cilium/cilium/pkg/defaults"
"github.com/cilium/cilium/pkg/endpointmanager"
"github.com/cilium/cilium/pkg/envoy"
"github.com/cilium/cilium/pkg/flowdebug"
"github.com/cilium/cilium/pkg/identity"
"github.com/cilium/cilium/pkg/identity/cache"
"github.com/cilium/cilium/pkg/k8s"
"github.com/cilium/cilium/pkg/k8s/endpointsynchronizer"
"github.com/cilium/cilium/pkg/kvstore"
"github.com/cilium/cilium/pkg/labels"
"github.com/cilium/cilium/pkg/loadinfo"
"github.com/cilium/cilium/pkg/logging"
"github.com/cilium/cilium/pkg/logging/logfields"
ipcachemap "github.com/cilium/cilium/pkg/maps/ipcache"
"github.com/cilium/cilium/pkg/metrics"
monitorAPI "github.com/cilium/cilium/pkg/monitor/api"
"github.com/cilium/cilium/pkg/node"
"github.com/cilium/cilium/pkg/option"
"github.com/cilium/cilium/pkg/pidfile"
"github.com/cilium/cilium/pkg/policy"
"github.com/cilium/cilium/pkg/pprof"
"github.com/cilium/cilium/pkg/service"
"github.com/cilium/cilium/pkg/version"
"github.com/cilium/cilium/pkg/versioncheck"
"github.com/cilium/cilium/pkg/workloads"
"github.com/go-openapi/loads"
gops "github.com/google/gops/agent"
go_version "github.com/hashicorp/go-version"
"github.com/jessevdk/go-flags"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/vishvananda/netlink"
"golang.org/x/sys/unix"
"google.golang.org/grpc"
)
var (
minKernelVer = versioncheck.MustCompile(">= 4.8.0")
minClangVer = versioncheck.MustCompile(">= 3.8.0")
recKernelVer = versioncheck.MustCompile(">= 4.9.0")
recClangVer = versioncheck.MustCompile(">= 3.9.0")
// LLVM/clang version which supports `-mattr=dwarfris`
dwarfrisClangVer = versioncheck.MustCompile(">= 7.0.0")
canDisableDwarfRelocations bool
)
const (
// list of supported verbose debug groups
argDebugVerboseFlow = "flow"
argDebugVerboseKvstore = "kvstore"
argDebugVerboseEnvoy = "envoy"
apiTimeout = 60 * time.Second
daemonSubsys = "daemon"
// fatalSleep is the duration Cilium should sleep before existing in case
// of a log.Fatal is issued or a CLI flag is specified but does not exist.
fatalSleep = 2 * time.Second
)
var (
log = logging.DefaultLogger.WithField(logfields.LogSubsys, daemonSubsys)
bootstrapTimestamp = time.Now()
// RootCmd represents the base command when called without any subcommands
RootCmd = &cobra.Command{
Use: "cilium-agent",
Short: "Run the cilium agent",
Run: func(cmd *cobra.Command, args []string) {
bootstrapStats.earlyInit.Start()
initEnv(cmd)
bootstrapStats.earlyInit.End(true)
runDaemon()
},
}
bootstrapStats = bootstrapStatistics{}
)
func init() {
RootCmd.SetFlagErrorFunc(func(_ *cobra.Command, e error) error {
time.Sleep(fatalSleep)
return e
})
logrus.RegisterExitHandler(func() {
time.Sleep(fatalSleep)
},
)
}
func daemonMain() {
bootstrapStats.overall.Start()
// Open socket for using gops to get stacktraces of the agent.
if err := gops.Listen(gops.Options{}); err != nil {
errorString := fmt.Sprintf("unable to start gops: %s", err)
fmt.Println(errorString)
os.Exit(-1)
}
interruptCh := registerSigHandler()
if err := RootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(-1)
}
<-interruptCh
os.Exit(0)
}
func parseKernelVersion(ver string) (*go_version.Version, error) {
verStrs := strings.Split(ver, ".")
switch {
case len(verStrs) < 2:
return nil, fmt.Errorf("unable to get kernel version from %q", ver)
case len(verStrs) < 3:
verStrs = append(verStrs, "0")
}
// We are assuming the kernel version will be something as:
// 4.9.17-040917-generic
// If verStrs is []string{ "4", "9", "17-040917-generic" }
// then we need to retrieve patch number.
patch := regexp.MustCompilePOSIX(`^[0-9]+`).FindString(verStrs[2])
if patch == "" {
verStrs[2] = "0"
} else {
verStrs[2] = patch
}
return go_version.NewVersion(strings.Join(verStrs[:3], "."))
}
func getKernelVersion() (*go_version.Version, error) {
var unameBuf unix.Utsname
if err := unix.Uname(&unameBuf); err != nil {
log.WithError(err).Fatal("kernel version: NOT OK")
}
return parseKernelVersion(string(unameBuf.Release[:]))
}
func getClangVersion(filePath string) (*go_version.Version, error) {
verOut, err := exec.Command(filePath, "--version").CombinedOutput()
if err != nil {
log.WithError(err).Fatal("clang version: NOT OK")
}
res := regexp.MustCompile(`(clang version )([^ ]*)`).FindStringSubmatch(string(verOut))
if len(res) != 3 {
log.Fatalf("clang version: NOT OK: unable to get clang's version "+
"from: %q", string(verOut))
}
// at this point res is []string{"clang", "version", "maj.min.patch"}
verStrs := strings.Split(res[2], ".")
if len(verStrs) < 3 {
return nil, fmt.Errorf("unable to get clang version from %q", string(verOut))
}
v := strings.Join(verStrs[:3], ".")
// Handle Ubuntu versioning by removing the dash and everything after.
// F. ex. `4.0.0-1ubuntu1~16 -> 4.0.0` and `3.8.0-2ubuntu4 -> 3.8.0`.
v = strings.Split(v, "-")[0]
return go_version.NewVersion(v)
}
func checkBPFLogs(logType string, fatal bool) {
bpfLogFile := logType + ".log"
bpfLogPath := filepath.Join(option.Config.StateDir, bpfLogFile)
if _, err := os.Stat(bpfLogPath); os.IsNotExist(err) {
log.Infof("%s check: OK!", logType)
} else if err == nil {
bpfFeaturesLog, err := ioutil.ReadFile(bpfLogPath)
if err != nil {
log.WithError(err).WithField(logfields.Path, bpfLogPath).Fatalf("%s check: NOT OK. Unable to read", logType)
}
printer := log.Debugf
if fatal {
printer = log.Errorf
printer("%s check: NOT OK", logType)
} else {
printer("%s check: Some features may be limited:", logType)
}
lines := strings.Trim(string(bpfFeaturesLog), "\n")
for _, line := range strings.Split(lines, "\n") {
printer(line)
}
if fatal {
log.Fatalf("%s check failed.", logType)
}
} else {
log.WithError(err).WithField(logfields.Path, bpfLogPath).Fatalf("%s check: NOT OK. Unable to read", logType)
}
}
func checkMinRequirements() {
kernelVersion, err := getKernelVersion()
if err != nil {
log.WithError(err).Fatal("kernel version: NOT OK")
}
if !minKernelVer.Check(kernelVersion) {
log.Fatalf("kernel version: NOT OK: minimal supported kernel "+
"version is %s; kernel version that is running is: %s", minKernelVer, kernelVersion)
}
if option.Config.EnableIPv6 {
if _, err := os.Stat("/proc/net/if_inet6"); os.IsNotExist(err) {
log.Fatalf("kernel: ipv6 is enabled in agent but ipv6 is either disabled or not compiled in the kernel")
}
}
if filePath, err := exec.LookPath("clang"); err != nil {
log.WithError(err).Fatal("clang: NOT OK")
} else {
clangVersion, err := getClangVersion(filePath)
if err != nil {
log.WithError(err).Fatal("clang: NOT OK")
}
if !minClangVer.Check(clangVersion) {
log.Fatalf("clang version: NOT OK: minimal supported clang "+
"version is %s; clang version that is running is: %s", minClangVer, clangVersion)
}
//clang >= 3.9 / kernel < 4.9 - does not work
if recClangVer.Check(clangVersion) && !recKernelVer.Check(kernelVersion) {
log.Fatalf("clang (%s) and kernel (%s) version: NOT OK: please upgrade "+
"your kernel version to at least %s",
clangVersion, kernelVersion, recKernelVer)
}
canDisableDwarfRelocations = dwarfrisClangVer.Check(clangVersion)
log.Infof("clang (%s) and kernel (%s) versions: OK!", clangVersion, kernelVersion)
}
if filePath, err := exec.LookPath("llc"); err != nil {
log.WithError(err).Fatal("llc: NOT OK")
} else {
lccVersion, err := exec.Command(filePath, "--version").CombinedOutput()
if err == nil {
if strings.Contains(strings.ToLower(string(lccVersion)), "debug") {
log.Warn("llc version was compiled in debug mode, expect higher latency!")
}
}
// /usr/include/gnu/stubs-32.h is installed by 'glibc-devel.i686' in fedora
// /usr/include/sys/cdefs.h is installed by 'libc6-dev-i386' in ubuntu
// both files exist on both systems but cdefs.h already exists in fedora
// without 'glibc-devel.i686' so we check for 'stubs-32.h first.
if _, err := os.Stat("/usr/include/gnu/stubs-32.h"); os.IsNotExist(err) {
log.Fatal("linking environment: NOT OK, please make sure you have 'glibc-devel.i686' if you use fedora system or 'libc6-dev-i386' if you use ubuntu system")
}
if _, err := os.Stat("/usr/include/sys/cdefs.h"); os.IsNotExist(err) {
log.Fatal("linking environment: NOT OK, please make sure you have 'libc6-dev-i386' in your ubuntu system")
}
log.Info("linking environment: OK!")
}
globalsDir := option.Config.GetGlobalsDir()
if err := os.MkdirAll(globalsDir, defaults.StateDirRights); err != nil {
log.WithError(err).WithField(logfields.Path, globalsDir).Fatal("Could not create runtime directory")
}
if err := os.Chdir(option.Config.LibDir); err != nil {
log.WithError(err).WithField(logfields.Path, option.Config.LibDir).Fatal("Could not change to runtime directory")
}
probeScript := filepath.Join(option.Config.BpfDir, "run_probes.sh")
if err := exec.Command(probeScript, option.Config.BpfDir, option.Config.StateDir).Run(); err != nil {
log.WithError(err).Fatal("BPF Verifier: NOT OK. Unable to run checker for bpf_features")
}
featuresFilePath := filepath.Join(globalsDir, "bpf_features.h")
if _, err := os.Stat(featuresFilePath); os.IsNotExist(err) {
log.WithError(err).WithField(logfields.Path, globalsDir).Fatal("BPF Verifier: NOT OK. Unable to read bpf_features.h")
}
checkBPFLogs("bpf_requirements", true)
checkBPFLogs("bpf_features", false)
bpf.ReadFeatureProbes(featuresFilePath)
}
func skipInit(basePath string) bool {
switch basePath {
case components.CiliumAgentName, components.CiliumDaemonTestName:
return false
default:
return true
}
}
func init() {
if skipInit(path.Base(os.Args[0])) {
log.Debug("Skipping preparation of cilium-agent environment")
return
}
cobra.OnInitialize(initConfig)
// Reset the help function to also exit, as we block elsewhere in interrupts
// and would not exit when called with -h.
oldHelpFunc := RootCmd.HelpFunc()
RootCmd.SetHelpFunc(func(c *cobra.Command, a []string) {
oldHelpFunc(c, a)
os.Exit(0)
})
flags := RootCmd.Flags()
// Validators
option.Config.FixedIdentityMappingValidator = option.Validator(func(val string) (string, error) {
vals := strings.Split(val, "=")
if len(vals) != 2 {
return "", fmt.Errorf(`invalid fixed identity: expecting "<numeric-identity>=<identity-name>" got %q`, val)
}
ni, err := identity.ParseNumericIdentity(vals[0])
if err != nil {
return "", fmt.Errorf(`invalid numeric identity %q: %s`, val, err)
}
if !identity.IsUserReservedIdentity(ni) {
return "", fmt.Errorf(`invalid numeric identity %q: valid numeric identity is between %d and %d`,
val, identity.UserReservedNumericIdentity.Uint32(), identity.MinimalNumericIdentity.Uint32())
}
lblStr := vals[1]
lbl := labels.ParseLabel(lblStr)
if lbl.IsReservedSource() {
return "", fmt.Errorf(`invalid source %q for label: %s`, labels.LabelSourceReserved, lblStr)
}
return val, nil
})
// Env bindings
flags.String(option.AccessLog, "", "Path to access log of supported L7 requests observed")
option.BindEnv(option.AccessLog)
flags.StringSlice(option.AgentLabels, []string{}, "Additional labels to identify this agent")
option.BindEnv(option.AgentLabels)
flags.String(option.AllowLocalhost, option.AllowLocalhostAuto, "Policy when to allow local stack to reach local endpoints { auto | always | policy }")
option.BindEnv(option.AllowLocalhost)
flags.Bool(option.AnnotateK8sNode, defaults.AnnotateK8sNode, "Annotate Kubernetes node")
option.BindEnv(option.AnnotateK8sNode)
flags.Bool(option.BlacklistConflictingRoutes, defaults.BlacklistConflictingRoutes, "Don't blacklist IP allocations conflicting with local non-cilium routes")
option.BindEnv(option.BlacklistConflictingRoutes)
flags.Bool(option.AutoCreateCiliumNodeResource, defaults.AutoCreateCiliumNodeResource, "Automatically create CiliumNode resource for own node on startup")
option.BindEnv(option.AutoCreateCiliumNodeResource)
flags.String(option.BPFRoot, "", "Path to BPF filesystem")
option.BindEnv(option.BPFRoot)
flags.String(option.CGroupRoot, "", "Path to Cgroup2 filesystem")
option.BindEnv(option.CGroupRoot)
flags.Bool(option.BPFCompileDebugName, false, "Enable debugging of the BPF compilation process")
option.BindEnv(option.BPFCompileDebugName)
flags.Bool(option.SockopsEnableName, defaults.SockopsEnable, "Enable sockops when kernel supported")
option.BindEnv(option.SockopsEnableName)
flags.Int(option.ClusterIDName, 0, "Unique identifier of the cluster")
option.BindEnv(option.ClusterIDName)
flags.String(option.ClusterName, defaults.ClusterName, "Name of the cluster")
option.BindEnv(option.ClusterName)
flags.String(option.ClusterMeshConfigName, "", "Path to the ClusterMesh configuration directory")
option.BindEnv(option.ClusterMeshConfigName)
flags.String(option.ConfigFile, "", `Configuration file (default "$HOME/ciliumd.yaml")`)
option.BindEnv(option.ConfigFile)
flags.String(option.ConfigDir, "", `Configuration directory that contains a file for each option`)
option.BindEnv(option.ConfigDir)
flags.Uint(option.ConntrackGarbageCollectorIntervalDeprecated, 0, "Garbage collection interval for the connection tracking table (in seconds)")
flags.MarkDeprecated(option.ConntrackGarbageCollectorIntervalDeprecated, fmt.Sprintf("please use --%s", option.ConntrackGCInterval))
option.BindEnv(option.ConntrackGarbageCollectorIntervalDeprecated)
flags.Duration(option.ConntrackGCInterval, time.Duration(0), "Overwrite the connection-tracking garbage collection interval")
option.BindEnv(option.ConntrackGCInterval)
flags.StringSlice(option.ContainerRuntime, option.ContainerRuntimeAuto, `Sets the container runtime(s) used by Cilium { containerd | crio | docker | none | auto } ( "auto" uses the container runtime found in the order: "docker", "containerd", "crio" )`)
option.BindEnv(option.ContainerRuntime)
flags.Var(option.NewNamedMapOptions(option.ContainerRuntimeEndpoint, &option.Config.ContainerRuntimeEndpoint, nil),
option.ContainerRuntimeEndpoint, `Container runtime(s) endpoint(s). (default: `+workloads.GetDefaultEPOptsStringWithPrefix("--container-runtime-endpoint=")+`)`)
option.BindEnv(option.ContainerRuntimeEndpoint)
flags.BoolP(option.DebugArg, "D", false, "Enable debugging mode")
option.BindEnv(option.DebugArg)
flags.StringSlice(option.DebugVerbose, []string{}, "List of enabled verbose debug groups")
option.BindEnv(option.DebugVerbose)
flags.StringP(option.Device, "d", "undefined", "Device facing cluster/external network for direct L3 (non-overlay mode)")
option.BindEnv(option.Device)
flags.String(option.DatapathMode, defaults.DatapathMode, "Datapath mode name")
option.BindEnv(option.DatapathMode)
flags.StringP(option.IpvlanMasterDevice, "", "undefined", "Device facing external network acting as ipvlan master")
option.BindEnv(option.IpvlanMasterDevice)
flags.Bool(option.DisableConntrack, false, "Disable connection tracking")
option.BindEnv(option.DisableConntrack)
flags.Bool(option.LegacyDisableIPv4Name, false, "Disable IPv4 mode")
flags.MarkHidden(option.LegacyDisableIPv4Name)
option.BindEnv(option.LegacyDisableIPv4Name)
flags.Bool(option.EnableEndpointRoutes, defaults.EnableEndpointRoutes, "Use per endpoint routes instead of routing via cilium_host")
option.BindEnv(option.EnableEndpointRoutes)
flags.Bool(option.EnableHealthChecking, defaults.EnableHealthChecking, "Enable connectivity health checking")
option.BindEnv(option.EnableHealthChecking)
flags.Bool(option.EnableEndpointHealthChecking, defaults.EnableEndpointHealthChecking, "Enable connectivity health checking between virtual endpoints")
option.BindEnv(option.EnableEndpointHealthChecking)
flags.Bool(option.EnableIPv4Name, defaults.EnableIPv4, "Enable IPv4 support")
option.BindEnv(option.EnableIPv4Name)
flags.Bool(option.EnableIPv6Name, defaults.EnableIPv6, "Enable IPv6 support")
option.BindEnv(option.EnableIPv6Name)
flags.String(option.EncryptInterface, "", "Transparent encryption interface")
option.BindEnv(option.EncryptInterface)
flags.Bool(option.EncryptNode, defaults.EncryptNode, "Enables encrypting traffic from non-Cilium pods and host networking")
option.BindEnv(option.EncryptNode)
flags.StringSlice(option.IPv4PodSubnets, []string{}, "List of IPv4 pod subnets to preconfigure for encryption")
option.BindEnv(option.IPv4PodSubnets)
flags.StringSlice(option.IPv6PodSubnets, []string{}, "List of IPv6 pod subnets to preconfigure for encryption")
option.BindEnv(option.IPv6PodSubnets)
flags.String(option.EndpointInterfaceNamePrefix, defaults.EndpointInterfaceNamePrefix, "Prefix of interface name shared by all endpoints")
option.BindEnv(option.EndpointInterfaceNamePrefix)
flags.StringSlice(option.ExcludeLocalAddress, []string{}, "Exclude CIDR from being recognized as local address")
option.BindEnv(option.ExcludeLocalAddress)
flags.Bool(option.DisableCiliumEndpointCRDName, false, "Disable use of CiliumEndpoint CRD")
option.BindEnv(option.DisableCiliumEndpointCRDName)
flags.Bool(option.DisableK8sServices, false, "Disable east-west K8s load balancing by cilium")
option.BindEnv(option.DisableK8sServices)
flags.String(option.EgressMasqueradeInterfaces, "", "Limit egress masquerading to interface selector")
option.BindEnv(option.EgressMasqueradeInterfaces)
flags.Bool(option.EnableHostReachableServices, false, "Enable reachability of services for host applications (beta)")
option.BindEnv(option.EnableHostReachableServices)
flags.StringSlice(option.HostReachableServicesProtos, []string{option.HostServicesTCP, option.HostServicesUDP}, "Only enable reachability of services for host applications for specific protocols")
option.BindEnv(option.HostReachableServicesProtos)
flags.Bool(option.DeprecatedEnableLegacyServices, false, "Enable legacy (prior-v1.5) services")
flags.MarkDeprecated(option.DeprecatedEnableLegacyServices, "this option is deprecated as of v1.6")
option.BindEnv(option.DeprecatedEnableLegacyServices)
flags.StringP(option.Docker, "e", workloads.GetRuntimeDefaultOpt(workloads.Docker, "endpoint"), "Path to docker runtime socket (DEPRECATED: use container-runtime-endpoint instead)")
option.BindEnv(option.Docker)
flags.Bool(option.EnableAutoDirectRoutingName, defaults.EnableAutoDirectRouting, "Enable automatic L2 routing between nodes")
option.BindEnv(option.EnableAutoDirectRoutingName)
flags.Bool(option.EnableXTSocketFallbackName, defaults.EnableXTSocketFallback, "Enable fallback for missing xt_socket module")
option.BindEnv(option.EnableXTSocketFallbackName)
flags.String(option.EnablePolicy, option.DefaultEnforcement, "Enable policy enforcement")
option.BindEnv(option.EnablePolicy)
flags.Bool(option.EnableL7Proxy, defaults.EnableL7Proxy, "Enable L7 proxy for L7 policy enforcement")
option.BindEnv(option.EnableL7Proxy)
flags.Bool(option.EnableTracing, false, "Enable tracing while determining policy (debugging)")
option.BindEnv(option.EnableTracing)
flags.String(option.EnvoyLog, "", "Path to a separate Envoy log file, if any")
option.BindEnv(option.EnvoyLog)
flags.Bool(option.EnableIPSecName, defaults.EnableIPSec, "Enable IPSec support")
option.BindEnv(option.EnableIPSecName)
flags.String(option.IPSecKeyFileName, "", "Path to IPSec key file")
option.BindEnv(option.IPSecKeyFileName)
flags.Bool(option.ForceLocalPolicyEvalAtSource, defaults.ForceLocalPolicyEvalAtSource, "Force policy evaluation of all local communication at the source endpoint")
option.BindEnv(option.ForceLocalPolicyEvalAtSource)
flags.String(option.HTTP403Message, "", "Message returned in proxy L7 403 body")
flags.MarkHidden(option.HTTP403Message)
option.BindEnv(option.HTTP403Message)
flags.Uint(option.HTTPRequestTimeout, 60*60, "Time after which a forwarded HTTP request is considered failed unless completed (in seconds); Use 0 for unlimited")
option.BindEnv(option.HTTPRequestTimeout)
flags.Uint(option.HTTPIdleTimeout, 0, "Time after which a non-gRPC HTTP stream is considered failed unless traffic in the stream has been processed (in seconds); defaults to 0 (unlimited)")
option.BindEnv(option.HTTPIdleTimeout)
flags.Uint(option.HTTPMaxGRPCTimeout, 0, "Time after which a forwarded gRPC request is considered failed unless completed (in seconds). A \"grpc-timeout\" header may override this with a shorter value; defaults to 0 (unlimited)")
option.BindEnv(option.HTTPMaxGRPCTimeout)
flags.Uint(option.HTTPRetryCount, 3, "Number of retries performed after a forwarded request attempt fails")
option.BindEnv(option.HTTPRetryCount)
flags.Uint(option.HTTPRetryTimeout, 0, "Time after which a forwarded but uncompleted request is retried (connection failures are retried immediately); defaults to 0 (never)")
option.BindEnv(option.HTTPRetryTimeout)
flags.Uint(option.ProxyConnectTimeout, 1, "Time after which a TCP connect attempt is considered failed unless completed (in seconds)")
option.BindEnv(option.ProxyConnectTimeout)
flags.Bool(option.DisableEnvoyVersionCheck, false, "Do not perform Envoy binary version check on startup")
flags.MarkHidden(option.DisableEnvoyVersionCheck)
// Disable version check if Envoy build is disabled
option.BindEnvWithLegacyEnvFallback(option.DisableEnvoyVersionCheck, "CILIUM_DISABLE_ENVOY_BUILD")
flags.Var(option.NewNamedMapOptions(option.FixedIdentityMapping, &option.Config.FixedIdentityMapping, option.Config.FixedIdentityMappingValidator),
option.FixedIdentityMapping, "Key-value for the fixed identity mapping which allows to use reserved label for fixed identities")
option.BindEnv(option.FixedIdentityMapping)
flags.Duration(option.IdentityChangeGracePeriod, defaults.IdentityChangeGracePeriod, "Time to wait before using new identity on endpoint identity change")
option.BindEnv(option.IdentityChangeGracePeriod)
flags.String(option.IdentityAllocationMode, option.IdentityAllocationModeKVstore, "Method to use for identity allocation")
option.BindEnv(option.IdentityAllocationMode)
flags.String(option.IPAM, "", "Backend to use for IPAM")
option.BindEnv(option.IPAM)
flags.Int(option.IPv4ClusterCIDRMaskSize, 8, "Mask size for the cluster wide CIDR")
option.BindEnv(option.IPv4ClusterCIDRMaskSize)
flags.String(option.IPv4Range, AutoCIDR, "Per-node IPv4 endpoint prefix, e.g. 10.16.0.0/16")
option.BindEnv(option.IPv4Range)
flags.String(option.IPv6Range, AutoCIDR, "Per-node IPv6 endpoint prefix, must be /96, e.g. fd02:1:1::/96")
option.BindEnv(option.IPv6Range)
flags.String(option.IPv6ClusterAllocCIDRName, defaults.IPv6ClusterAllocCIDR, "IPv6 /64 CIDR used to allocate per node endpoint /96 CIDR")
option.BindEnv(option.IPv6ClusterAllocCIDRName)
flags.String(option.IPv4ServiceRange, AutoCIDR, "Kubernetes IPv4 services CIDR if not inside cluster prefix")
option.BindEnv(option.IPv4ServiceRange)
flags.String(option.IPv6ServiceRange, AutoCIDR, "Kubernetes IPv6 services CIDR if not inside cluster prefix")
option.BindEnv(option.IPv6ServiceRange)
flags.Bool(option.K8sEventHandover, defaults.K8sEventHandover, "Enable k8s event handover to kvstore for improved scalability")
option.BindEnv(option.K8sEventHandover)
flags.String(option.K8sAPIServer, "", "Kubernetes api address server (for https use --k8s-kubeconfig-path instead)")
option.BindEnv(option.K8sAPIServer)
flags.String(option.K8sKubeConfigPath, "", "Absolute path of the kubernetes kubeconfig file")
option.BindEnv(option.K8sKubeConfigPath)
flags.String(option.K8sNamespaceName, "", "Name of the Kubernetes namespace in which Cilium is deployed in")
flags.MarkHidden(option.K8sNamespaceName)
option.BindEnv(option.K8sNamespaceName)
flags.Bool(option.K8sRequireIPv4PodCIDRName, false, "Require IPv4 PodCIDR to be specified in node resource")
option.BindEnv(option.K8sRequireIPv4PodCIDRName)
flags.Bool(option.K8sRequireIPv6PodCIDRName, false, "Require IPv6 PodCIDR to be specified in node resource")
option.BindEnv(option.K8sRequireIPv6PodCIDRName)
flags.Uint(option.K8sServiceCacheSize, defaults.K8sServiceCacheSize, "Cilium service cache size for kubernetes")
option.BindEnv(option.K8sServiceCacheSize)
flags.MarkHidden(option.K8sServiceCacheSize)
flags.Bool(option.K8sForceJSONPatch, false, "When set uses JSON Patch to update CNP and CEP status in kube-apiserver")
option.BindEnv(option.K8sForceJSONPatch)
flags.MarkHidden(option.K8sForceJSONPatch)
flags.String(option.K8sWatcherEndpointSelector, defaults.K8sWatcherEndpointSelector, "K8s endpoint watcher will watch for these k8s endpoints")
option.BindEnv(option.K8sWatcherEndpointSelector)
flags.Bool(option.KeepConfig, false, "When restoring state, keeps containers' configuration in place")
option.BindEnv(option.KeepConfig)
flags.Bool(option.KeepBPFTemplates, false, "Do not restore BPF template files from binary")
option.BindEnv(option.KeepBPFTemplates)
flags.String(option.KVStore, "", "Key-value store type")
option.BindEnv(option.KVStore)
flags.Duration(option.KVstoreLeaseTTL, defaults.KVstoreLeaseTTL, "Time-to-live for the KVstore lease.")
flags.MarkHidden(option.KVstoreLeaseTTL)
option.BindEnv(option.KVstoreLeaseTTL)
flags.Duration(option.KVstorePeriodicSync, defaults.KVstorePeriodicSync, "Periodic KVstore synchronization interval")
option.BindEnv(option.KVstorePeriodicSync)
flags.Duration(option.KVstoreConnectivityTimeout, defaults.KVstoreConnectivityTimeout, "Time after which an incomplete kvstore operation is considered failed")
option.BindEnv(option.KVstoreConnectivityTimeout)
flags.Duration(option.IPAllocationTimeout, defaults.IPAllocationTimeout, "Time after which an incomplete CIDR allocation is considered failed")
option.BindEnv(option.IPAllocationTimeout)
flags.Var(option.NewNamedMapOptions(option.KVStoreOpt, &option.Config.KVStoreOpt, nil),
option.KVStoreOpt, "Key-value store options")
option.BindEnv(option.KVStoreOpt)
flags.Duration(option.K8sSyncTimeoutName, defaults.K8sSyncTimeout, "Timeout for synchronizing k8s resources before exiting")
flags.MarkHidden(option.K8sSyncTimeoutName)
option.BindEnv(option.K8sSyncTimeoutName)
flags.Uint(option.K8sWatcherQueueSize, 1024, "Queue size used to serialize each k8s event type")
option.BindEnv(option.K8sWatcherQueueSize)
flags.String(option.LabelPrefixFile, "", "Valid label prefixes file path")
option.BindEnv(option.LabelPrefixFile)
flags.StringSlice(option.Labels, []string{}, "List of label prefixes used to determine identity of an endpoint")
option.BindEnv(option.Labels)
flags.String(option.LB, "", "Enables load balancer mode where load balancer bpf program is attached to the given interface")
option.BindEnv(option.LB)
flags.Bool(option.EnableNodePort, false, "Enable NodePort type services by Cilium (beta)")
option.BindEnv(option.EnableNodePort)
flags.StringSlice(option.NodePortRange, []string{fmt.Sprintf("%d", option.NodePortMinDefault), fmt.Sprintf("%d", option.NodePortMaxDefault)}, fmt.Sprintf("Set the min/max NodePort port range"))
option.BindEnv(option.NodePortRange)
flags.String(option.LibDir, defaults.LibraryPath, "Directory path to store runtime build environment")
option.BindEnv(option.LibDir)
flags.StringSlice(option.LogDriver, []string{}, "Logging endpoints to use for example syslog")
option.BindEnv(option.LogDriver)
flags.Var(option.NewNamedMapOptions(option.LogOpt, &option.Config.LogOpt, nil),
option.LogOpt, "Log driver options for cilium")
option.BindEnv(option.LogOpt)
flags.Bool(option.LogSystemLoadConfigName, false, "Enable periodic logging of system load")
option.BindEnv(option.LogSystemLoadConfigName)
flags.String(option.LoopbackIPv4, defaults.LoopbackIPv4, "IPv4 address for service loopback SNAT")
option.BindEnv(option.LoopbackIPv4)
flags.String(option.NAT46Range, defaults.DefaultNAT46Prefix, "IPv6 prefix to map IPv4 addresses to")
option.BindEnv(option.NAT46Range)
flags.Bool(option.Masquerade, true, "Masquerade packets from endpoints leaving the host")
option.BindEnv(option.Masquerade)
flags.Bool(option.InstallIptRules, true, "Install base iptables rules for cilium to mainly interact with kube-proxy (and masquerading)")
option.BindEnv(option.InstallIptRules)
flags.Duration(option.IPTablesLockTimeout, 5*time.Second, "Time to pass to each iptables invocation to wait for xtables lock acquisition")
option.BindEnv(option.IPTablesLockTimeout)
flags.Int(option.MaxCtrlIntervalName, 0, "Maximum interval (in seconds) between controller runs. Zero is no limit.")
flags.MarkHidden(option.MaxCtrlIntervalName)
option.BindEnv(option.MaxCtrlIntervalName)
flags.StringSlice(option.Metrics, []string{}, "Metrics that should be enabled or disabled from the default metric list. (+metric_foo to enable metric_foo , -metric_bar to disable metric_bar)")
option.BindEnv(option.Metrics)
flags.String(option.MonitorAggregationName, "None",
"Level of monitor aggregation for traces from the datapath")
option.BindEnvWithLegacyEnvFallback(option.MonitorAggregationName, "CILIUM_MONITOR_AGGREGATION_LEVEL")
flags.Int(option.MonitorQueueSizeName, 0, "Size of the event queue when reading monitor events")
option.BindEnv(option.MonitorQueueSizeName)
flags.Int(option.MTUName, 0, "Overwrite auto-detected MTU of underlying network")
option.BindEnv(option.MTUName)
flags.Bool(option.PrependIptablesChainsName, true, "Prepend custom iptables chains instead of appending")
option.BindEnvWithLegacyEnvFallback(option.PrependIptablesChainsName, "CILIUM_PREPEND_IPTABLES_CHAIN")
flags.String(option.IPv6NodeAddr, "auto", "IPv6 address of node")
option.BindEnv(option.IPv6NodeAddr)
flags.String(option.IPv4NodeAddr, "auto", "IPv4 address of node")
option.BindEnv(option.IPv4NodeAddr)
flags.String(option.ReadCNIConfiguration, "", "Read to the CNI configuration at specified path to extract per node configuration")
option.BindEnv(option.ReadCNIConfiguration)
flags.Bool(option.Restore, true, "Restores state, if possible, from previous daemon")
option.BindEnv(option.Restore)
flags.Bool(option.SidecarHTTPProxy, false, "Disable host HTTP proxy, assuming proxies in sidecar containers")
flags.MarkHidden(option.SidecarHTTPProxy)
option.BindEnv(option.SidecarHTTPProxy)
flags.String(option.SidecarIstioProxyImage, k8s.DefaultSidecarIstioProxyImageRegexp,
"Regular expression matching compatible Istio sidecar istio-proxy container image names")
option.BindEnv(option.SidecarIstioProxyImage)
flags.Bool(option.SingleClusterRouteName, false,
"Use a single cluster route instead of per node routes")
option.BindEnv(option.SingleClusterRouteName)
flags.String(option.SocketPath, defaults.SockPath, "Sets daemon's socket path to listen for connections")
option.BindEnv(option.SocketPath)
flags.String(option.StateDir, defaults.RuntimePath, "Directory path to store runtime state")
option.BindEnv(option.StateDir)
flags.StringP(option.TunnelName, "t", "", fmt.Sprintf("Tunnel mode {%s} (default \"vxlan\" for the \"veth\" datapath mode)", option.GetTunnelModes()))
option.BindEnv(option.TunnelName)
flags.Int(option.TracePayloadlen, 128, "Length of payload to capture when tracing")
option.BindEnv(option.TracePayloadlen)
flags.Bool(option.Version, false, "Print version information")
option.BindEnv(option.Version)
flags.String(option.FlannelMasterDevice, "",
"Installs a BPF program to allow for policy enforcement in the given network interface. "+
"Allows to run Cilium on top of other CNI plugins that provide networking, "+
"e.g. flannel, where for flannel, this value should be set with 'cni0'. [EXPERIMENTAL]")
option.BindEnv(option.FlannelMasterDevice)
flags.Bool(option.FlannelUninstallOnExit, false, fmt.Sprintf("When used along the %s "+
"flag, it cleans up all BPF programs installed when Cilium agent is terminated.", option.FlannelMasterDevice))
option.BindEnv(option.FlannelUninstallOnExit)
flags.Bool(option.FlannelManageExistingContainers, false,
fmt.Sprintf("Installs a BPF program to allow for policy enforcement in already running containers managed by Flannel."+
" Require Cilium to be running in the hostPID."))
option.BindEnv(option.FlannelManageExistingContainers)
flags.Bool(option.PProf, false, "Enable serving the pprof debugging API")
option.BindEnv(option.PProf)
flags.String(option.PrefilterDevice, "undefined", "Device facing external network for XDP prefiltering")
option.BindEnv(option.PrefilterDevice)
flags.String(option.PrefilterMode, option.ModePreFilterNative, "Prefilter mode { "+option.ModePreFilterNative+" | "+option.ModePreFilterGeneric+" } (default: "+option.ModePreFilterNative+")")
option.BindEnv(option.PrefilterMode)
flags.Bool(option.PreAllocateMapsName, defaults.PreAllocateMaps, "Enable BPF map pre-allocation")
option.BindEnv(option.PreAllocateMapsName)
// We expect only one of the possible variables to be filled. The evaluation order is:
// --prometheus-serve-addr, CILIUM_PROMETHEUS_SERVE_ADDR, then PROMETHEUS_SERVE_ADDR
// The second environment variable (without the CILIUM_ prefix) is here to
// handle the case where someone uses a new image with an older spec, and the
// older spec used the older variable name.
flags.String(option.PrometheusServeAddr, "", "IP:Port on which to serve prometheus metrics (pass \":Port\" to bind on all interfaces, \"\" is off)")
option.BindEnvWithLegacyEnvFallback(option.PrometheusServeAddr, "PROMETHEUS_SERVE_ADDR")
flags.Int(option.CTMapEntriesGlobalTCPName, option.CTMapEntriesGlobalTCPDefault, "Maximum number of entries in TCP CT table")
option.BindEnvWithLegacyEnvFallback(option.CTMapEntriesGlobalTCPName, "CILIUM_GLOBAL_CT_MAX_TCP")
flags.Int(option.CTMapEntriesGlobalAnyName, option.CTMapEntriesGlobalAnyDefault, "Maximum number of entries in non-TCP CT table")
option.BindEnvWithLegacyEnvFallback(option.CTMapEntriesGlobalAnyName, "CILIUM_GLOBAL_CT_MAX_ANY")
flags.Duration(option.CTMapEntriesTimeoutTCPName, 21600*time.Second, "Timeout for established entries in TCP CT table")
option.BindEnv(option.CTMapEntriesTimeoutTCPName)
flags.Duration(option.CTMapEntriesTimeoutAnyName, 60*time.Second, "Timeout for entries in non-TCP CT table")
option.BindEnv(option.CTMapEntriesTimeoutAnyName)
flags.Duration(option.CTMapEntriesTimeoutSVCTCPName, 21600*time.Second, "Timeout for established service entries in TCP CT table")
option.BindEnv(option.CTMapEntriesTimeoutSVCTCPName)
flags.Duration(option.CTMapEntriesTimeoutSVCAnyName, 60*time.Second, "Timeout for service entries in non-TCP CT table")
option.BindEnv(option.CTMapEntriesTimeoutSVCAnyName)
flags.Duration(option.CTMapEntriesTimeoutSYNName, 60*time.Second, "Establishment timeout for entries in TCP CT table")
option.BindEnv(option.CTMapEntriesTimeoutSYNName)
flags.Duration(option.CTMapEntriesTimeoutFINName, 10*time.Second, "Teardown timeout for entries in TCP CT table")
option.BindEnv(option.CTMapEntriesTimeoutFINName)
flags.Int(option.NATMapEntriesGlobalName, option.NATMapEntriesGlobalDefault, "Maximum number of entries for the global BPF NAT table")
option.BindEnv(option.NATMapEntriesGlobalName)
flags.Int(option.PolicyMapEntriesName, defaults.PolicyMapEntries, "Maximum number of entries in endpoint policy map (per endpoint)")
option.BindEnv(option.PolicyMapEntriesName)
flags.String(option.CMDRef, "", "Path to cmdref output directory")
flags.MarkHidden(option.CMDRef)
option.BindEnv(option.CMDRef)
flags.Int(option.ToFQDNsMinTTL, 0, fmt.Sprintf("The minimum time, in seconds, to use DNS data for toFQDNs policies. (default %d when --tofqdns-enable-poller, %d otherwise)", defaults.ToFQDNsMinTTLPoller, defaults.ToFQDNsMinTTL))
option.BindEnv(option.ToFQDNsMinTTL)
flags.Int(option.ToFQDNsProxyPort, 0, "Global port on which the in-agent DNS proxy should listen. Default 0 is a OS-assigned port.")
option.BindEnv(option.ToFQDNsProxyPort)
flags.Bool(option.ToFQDNsEnablePoller, false, "Enable proactive polling of DNS names in toFQDNs.matchName rules.")
option.BindEnv(option.ToFQDNsEnablePoller)
flags.Bool(option.ToFQDNsEnablePollerEvents, true, "Emit DNS responses seen by the DNS poller as Monitor events, if the poller is enabled.")
option.BindEnv(option.ToFQDNsEnablePollerEvents)
flags.StringVar(&option.Config.FQDNRejectResponse, option.FQDNRejectResponseCode, option.FQDNProxyDenyWithRefused, fmt.Sprintf("DNS response code for rejecting DNS requests, available options are '%v'", option.FQDNRejectOptions))
option.BindEnv(option.FQDNRejectResponseCode)
flags.Int(option.ToFQDNsMaxIPsPerHost, defaults.ToFQDNsMaxIPsPerHost, "Maximum number of IPs to maintain per FQDN name for each endpoint")
option.BindEnv(option.ToFQDNsMaxIPsPerHost)
flags.DurationVar(&option.Config.FQDNProxyResponseMaxDelay, option.FQDNProxyResponseMaxDelay, 50*time.Millisecond, "The maximum time the DNS proxy holds an allowed DNS response before sending it along. Responses are sent as soon as the datapath is updated with the new IP information.")
option.BindEnv(option.FQDNProxyResponseMaxDelay)
flags.String(option.ToFQDNsPreCache, defaults.ToFQDNsPreCache, "DNS cache data at this path is preloaded on agent startup")
option.BindEnv(option.ToFQDNsPreCache)
flags.Int(option.PolicyQueueSize, defaults.PolicyQueueSize, "size of queues for policy-related events")
option.BindEnv(option.PolicyQueueSize)
flags.Int(option.EndpointQueueSize, defaults.EndpointQueueSize, "size of EventQueue per-endpoint")
option.BindEnv(option.EndpointQueueSize)
flags.Bool(option.SelectiveRegeneration, true, "only regenerate endpoints which need to be regenerated upon policy changes")
flags.MarkHidden(option.SelectiveRegeneration)
option.BindEnv(option.SelectiveRegeneration)
flags.Bool(option.SkipCRDCreation, false, "Skip Kubernetes Custom Resource Definitions creations")
option.BindEnv(option.SkipCRDCreation)
flags.String(option.WriteCNIConfigurationWhenReady, "", fmt.Sprintf("Write the CNI configuration as specified via --%s to path when agent is ready", option.ReadCNIConfiguration))
option.BindEnv(option.WriteCNIConfigurationWhenReady)
flags.Duration(option.PolicyTriggerInterval, defaults.PolicyTriggerInterval, "Time between triggers of policy updates (regenerations for all endpoints)")
flags.MarkHidden(option.PolicyTriggerInterval)
option.BindEnv(option.PolicyTriggerInterval)
flags.Bool(option.DisableCNPStatusUpdates, false, "Do not send CNP NodeStatus updates to the Kubernetes api-server (recommended to run with `cnp-node-status-gc=false` in cilium-operator)")
option.BindEnv(option.DisableCNPStatusUpdates)
viper.BindPFlags(flags)
}
// RestoreExecPermissions restores file permissions to 0740 of all files inside
// `searchDir` with the given regex `patterns`.
func RestoreExecPermissions(searchDir string, patterns ...string) error {
fileList := []string{}
err := filepath.Walk(searchDir, func(path string, f os.FileInfo, err error) error {
for _, pattern := range patterns {
if regexp.MustCompile(pattern).MatchString(f.Name()) {
fileList = append(fileList, path)
break
}
}
return nil
})
for _, fileToChange := range fileList {
// Changing files permissions to -rwx:r--:---, we are only
// adding executable permission to the owner and keeping the
// same permissions stored by go-bindata.
if err := os.Chmod(fileToChange, os.FileMode(0740)); err != nil {
return err
}
}
return err
}
// initConfig reads in config file and ENV variables if set.
func initConfig() {
if viper.GetBool("version") {
fmt.Printf("Cilium %s\n", version.Version)
os.Exit(0)
}
if option.Config.CMDRefDir != "" {
return
}
option.Config.ConfigFile = viper.GetString(option.ConfigFile) // enable ability to specify config file via flag
option.Config.ConfigDir = viper.GetString(option.ConfigDir)
viper.SetEnvPrefix("cilium")
if option.Config.ConfigDir != "" {
if _, err := os.Stat(option.Config.ConfigDir); os.IsNotExist(err) {
log.Fatalf("Non-existent configuration directory %s", option.Config.ConfigDir)
}
if m, err := option.ReadDirConfig(option.Config.ConfigDir); err != nil {
log.Fatalf("Unable to read configuration directory %s: %s", option.Config.ConfigDir, err)
} else {
// replace deprecated fields with new fields
option.ReplaceDeprecatedFields(m)
err := option.MergeConfig(m)
if err != nil {
log.Fatalf("Unable to merge configuration: %s", err)
}
}
}
if option.Config.ConfigFile != "" {
viper.SetConfigFile(option.Config.ConfigFile)
} else {
viper.SetConfigName("ciliumd") // name of config file (without extension)
viper.AddConfigPath("$HOME") // adding home directory as first search path
}
// If a config file is found, read it in.
if err := viper.ReadInConfig(); err == nil {
log.WithField(logfields.Path, viper.ConfigFileUsed()).
Info("Using config from file")
} else if option.Config.ConfigFile != "" {
log.WithField(logfields.Path, option.Config.ConfigFile).
Fatal("Error reading config file")
} else {
log.WithField(logfields.Reason, err).Info("Skipped reading configuration file")
}
}
func initEnv(cmd *cobra.Command) {
// Prepopulate option.Config with options from CLI.
option.Config.Populate()
// add hooks after setting up metrics in the option.Confog
logging.DefaultLogger.Hooks.Add(metrics.NewLoggingHook(components.CiliumAgentName))
// Logging should always be bootstrapped first. Do not add any code above this!
logging.SetupLogging(option.Config.LogDriver, option.Config.LogOpt, "cilium-agent", option.Config.Debug)
if option.Config.CMDRefDir != "" {
genMarkdown(cmd)
}
option.LogRegisteredOptions(log)
for _, grp := range option.Config.DebugVerbose {
switch grp {
case argDebugVerboseFlow:
log.Debugf("Enabling flow debug")
flowdebug.Enable()
case argDebugVerboseKvstore:
kvstore.EnableTracing()
case argDebugVerboseEnvoy:
log.Debugf("Enabling Envoy tracing")
envoy.EnableTracing()
default:
log.Warningf("Unknown verbose debug group: %s", grp)
}
}
common.RequireRootPrivilege("cilium-agent")
log.Info(" _ _ _")
log.Info(" ___|_| |_|_ _ _____")
log.Info("| _| | | | | | |")
log.Info("|___|_|_|_|___|_|_|_|")
log.Infof("Cilium %s", version.Version)
if option.Config.LogSystemLoadConfig {
loadinfo.StartBackgroundLogger()
}
if option.Config.DisableEnvoyVersionCheck {
log.Info("Envoy version check disabled")
} else {
envoyVersion := envoy.GetEnvoyVersion()
log.Infof("%s", envoyVersion)
envoyVersionArray := strings.Fields(envoyVersion)
if len(envoyVersionArray) < 3 {
log.Fatal("Truncated Envoy version string, cannot verify version match.")