-
Notifications
You must be signed in to change notification settings - Fork 99
/
datadogagent_default.go
1194 lines (983 loc) · 43.3 KB
/
datadogagent_default.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
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.
package v1alpha1
import (
"path"
"strings"
"time"
"github.com/DataDog/datadog-operator/pkg/utils"
edsdatadoghqv1alpha1 "github.com/DataDog/extendeddaemonset/api/v1alpha1"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
)
// default values
const (
defaultLogLevel string = "INFO"
defaultAgentImageTag string = "7.28.0"
defaultClusterAgentImageTag string = "1.12.0"
defaultAgentImageName string = "agent"
defaultClusterAgentImageName string = "cluster-agent"
defaultCollectEvents bool = false
defaultLeaderElection bool = false
defaultDockerSocketPath string = "/var/run/docker.sock"
defaultDogstatsdOriginDetection bool = false
defaultUseDogStatsDSocketVolume bool = false
defaultHostDogstatsdSocketName string = "statsd.sock"
defaultHostDogstatsdSocketPath string = "/var/run/datadog"
defaultApmEnabled bool = false
defaultApmHostPort int32 = 8126
defaultSystemProbeEnabled bool = false
defaultSystemProbeOOMKillEnabled bool = false
defaultSystemProbeTCPQueueLengthEnabled bool = false
defaultSystemProbeConntrackEnabled bool = false
defaultSystemProbeCollectDNSStats bool = false
defaultSystemProbeBPFDebugEnabled bool = false
defaultSystemProbeSecCompRootPath string = "/var/lib/kubelet/seccomp"
defaultAppArmorProfileName string = "unconfined"
DefaultSeccompProfileName string = "localhost/system-probe"
defaultSecurityRuntimeEnabled bool = false
defaultSecurityComplianceEnabled bool = false
defaultSecuritySyscallMonitorEnabled bool = false
defaultHostApmSocketName string = "apm.sock"
defaultHostApmSocketPath string = "/var/run/datadog"
defaultLogEnabled bool = false
defaultLogsConfigContainerCollectAll bool = false
defaultLogsContainerCollectUsingFiles bool = true
defaultContainerLogsPath string = "/var/lib/docker/containers"
defaultPodLogsPath string = "/var/log/pods"
defaultContainerSymlinksPath string = "/var/log/containers"
defaultLogsTempStoragePath string = "/var/lib/datadog-agent/logs"
defaultLogsOpenFilesLimit int32 = 100
defaultProcessEnabled bool = false
// `false` defaults to live container, agent activated but no process collection
defaultProcessCollectionEnabled bool = false
defaultOrchestratorExplorerEnabled bool = true
defaultOrchestratorExplorerContainerScrubbingEnabled bool = true
defaultMetricsProviderPort int32 = 8443
defaultClusterChecksEnabled bool = false
DefaultKubeStateMetricsCoreConf string = "kube-state-metrics-core-config"
defaultKubeStateMetricsCoreEnabled bool = false
defaultPrometheusScrapeEnabled bool = false
defaultPrometheusScrapeServiceEndpoints bool = false
defaultRollingUpdateMaxUnavailable = "10%"
defaultUpdateStrategy = appsv1.RollingUpdateDaemonSetStrategyType
defaultRollingUpdateMaxPodSchedulerFailure = "10%"
defaultRollingUpdateMaxParallelPodCreation int32 = 250
defaultRollingUpdateSlowStartIntervalDuration = 1 * time.Minute
defaultRollingUpdateSlowStartAdditiveIncrease = "5"
defaultReconcileFrequency = 10 * time.Second
defaultRbacCreate = true
defaultMutateUnlabelled = false
DefaultAdmissionServiceName = "datadog-admission-controller"
defaultAdmissionControllerEnabled = false
// Liveness probe default config
defaultLivenessProbeInitialDelaySeconds int32 = 15
defaultLivenessProbePeriodSeconds int32 = 15
defaultLivenessProbeTimeoutSeconds int32 = 5
defaultLivenessProbeSuccessThreshold int32 = 1
defaultLivenessProbeFailureThreshold int32 = 6
defaultAgentHealthPort int32 = 5555
defaultLivenessProbeHTTPPath = "/live"
// Readiness probe default config
defaultReadinessProbeInitialDelaySeconds int32 = 15
defaultReadinessProbePeriodSeconds int32 = 15
defaultReadinessProbeTimeoutSeconds int32 = 5
defaultReadinessProbeSuccessThreshold int32 = 1
defaultReadinessProbeFailureThreshold int32 = 6
defaultReadinessProbeHTTPPath = "/ready"
)
var defaultImagePullPolicy = corev1.PullIfNotPresent
// DefaultDatadogAgent defaults the DatadogAgent
func DefaultDatadogAgent(dda *DatadogAgent) *DatadogAgentStatus {
// instOverrideStatus contains all the defaults from the runtime.
// It is published in the status of the DatadogAgent
dso := &DatadogAgentStatus{
DefaultOverride: &DatadogAgentSpec{},
}
// Cluster Agent
dso.DefaultOverride.ClusterAgent = *DefaultDatadogAgentSpecClusterAgent(&dda.Spec.ClusterAgent)
// Agent
dso.DefaultOverride.Agent = *DefaultDatadogAgentSpecAgent(&dda.Spec.Agent)
// CLC
dso.DefaultOverride.ClusterChecksRunner = *DefaultDatadogAgentSpecClusterChecksRunner(&dda.Spec.ClusterChecksRunner)
// Features
dso.DefaultOverride.Features = *DefaultFeatures(dda)
// Creds
if dda.Spec.Credentials == nil {
dda.Spec.Credentials = &AgentCredentials{}
}
if dda.Spec.Credentials.UseSecretBackend == nil {
dda.Spec.Credentials.UseSecretBackend = NewBoolPointer(false)
dso.DefaultOverride.Credentials = &AgentCredentials{
UseSecretBackend: dda.Spec.Credentials.UseSecretBackend,
}
}
// Override spec given featureset
FeatureOverride(&dda.Spec, dso.DefaultOverride)
return dso
}
// FeatureOverride defaults the feature section of the DatadogAgent
// TODO surface in the status when Overrides are not possible. Security agent requires the system probe
func FeatureOverride(dda *DatadogAgentSpec, dso *DatadogAgentSpec) {
if dda.Features.NetworkMonitoring != nil && BoolValue(dda.Features.NetworkMonitoring.Enabled) {
// If the Network monitoring Feature is enable, enable the System Probe.
if !BoolValue(dda.Agent.Enabled) || dda.Agent.SystemProbe != nil {
dda.Agent.SystemProbe.Enabled = NewBoolPointer(true)
dso.Agent.SystemProbe = DefaultDatadogAgentSpecAgentSystemProbe(&dda.Agent)
dso.Agent.SystemProbe.Enabled = dda.Agent.SystemProbe.Enabled
}
}
if dda.Features.OrchestratorExplorer != nil && BoolValue(dda.Features.OrchestratorExplorer.Enabled) {
if !BoolValue(dda.Agent.Enabled) || dda.Agent.Process != nil {
dda.Agent.Process.Enabled = NewBoolPointer(true)
dso.Agent.Process = DefaultDatadogAgentSpecAgentProcess(&dda.Agent)
dso.Agent.Process.Enabled = dda.Agent.Process.Enabled
}
}
}
// DefaultDatadogAgentSpecAgent used to default an DatadogAgentSpecAgentSpec
// return the defaulted DatadogAgentSpecAgentSpec
func DefaultDatadogAgentSpecAgent(agent *DatadogAgentSpecAgentSpec) *DatadogAgentSpecAgentSpec {
// If the Agent is not specified in the spec, disable it.
if IsEqualStruct(*agent, DatadogAgentSpecAgentSpec{}) {
agent.Enabled = NewBoolPointer(false)
return agent
}
if agent.Enabled == nil {
agent.Enabled = NewBoolPointer(true)
}
agentOverride := &DatadogAgentSpecAgentSpec{Enabled: agent.Enabled}
if agent.UseExtendedDaemonset == nil {
agent.UseExtendedDaemonset = NewBoolPointer(false)
agentOverride.UseExtendedDaemonset = agent.UseExtendedDaemonset
}
if img := DefaultDatadogAgentSpecAgentImage(agent, defaultAgentImageName, defaultAgentImageTag); !IsEqualStruct(*img, ImageConfig{}) {
agentOverride.Image = img
}
if cfg := DefaultDatadogAgentSpecAgentConfig(agent); !IsEqualStruct(*cfg, NodeAgentConfig{}) {
agentOverride.Config = cfg
}
if rbac := DefaultDatadogAgentSpecRbacConfig(agent); !IsEqualStruct(*rbac, RbacConfig{}) {
agentOverride.Rbac = rbac
}
deployStrat := DefaultDatadogAgentSpecDatadogAgentStrategy(agent)
if !IsEqualStruct(*deployStrat, DaemonSetDeploymentStrategy{}) {
agentOverride.DeploymentStrategy = deployStrat
}
if apm := DefaultDatadogAgentSpecAgentApm(agent); !IsEqualStruct(*apm, APMSpec{}) {
agentOverride.Apm = apm
}
if sysProb := DefaultDatadogAgentSpecAgentSystemProbe(agent); !IsEqualStruct(*sysProb, SystemProbeSpec{}) {
agentOverride.SystemProbe = sysProb
}
if sec := DefaultDatadogAgentSpecAgentSecurity(agent); !IsEqualStruct(*sec, SecuritySpec{}) {
agentOverride.Security = sec
}
if proc := DefaultDatadogAgentSpecAgentProcess(agent); !IsEqualStruct(*proc, ProcessSpec{}) {
agentOverride.Process = proc
}
if net := DefaultAgentNetworkPolicy(agent); !IsEqualStruct(*net, NetworkPolicySpec{}) {
agentOverride.NetworkPolicy = net
}
return agentOverride
}
// DefaultDatadogAgentSpecAgentImage used to default a ImageConfig for the Agent, Cluster Agent and the Cluster Check Runner.
// Returns the defaulted ImageConfig.
func DefaultDatadogAgentSpecAgentImage(agent *DatadogAgentSpecAgentSpec, name, tag string) *ImageConfig {
imgOverride := &ImageConfig{}
if agent.Image == nil {
agent.Image = &ImageConfig{}
}
if agent.Image.Name == "" {
agent.Image.Name = name
imgOverride.Name = agent.Image.Name
}
if agent.Image.Tag == "" {
agent.Image.Tag = tag
imgOverride.Tag = agent.Image.Tag
}
if agent.Image.PullPolicy == nil {
agent.Image.PullPolicy = &defaultImagePullPolicy
imgOverride.PullPolicy = agent.Image.PullPolicy
}
if agent.Image.PullSecrets == nil {
agent.Image.PullSecrets = &[]corev1.LocalObjectReference{}
}
return imgOverride
}
// GetDefaultLivenessProbe creates a all defaulted LivenessProbe
func GetDefaultLivenessProbe() *corev1.Probe {
livenessProbe := &corev1.Probe{
InitialDelaySeconds: defaultLivenessProbeInitialDelaySeconds,
PeriodSeconds: defaultLivenessProbePeriodSeconds,
TimeoutSeconds: defaultLivenessProbeTimeoutSeconds,
SuccessThreshold: defaultLivenessProbeSuccessThreshold,
FailureThreshold: defaultLivenessProbeFailureThreshold,
}
livenessProbe.HTTPGet = &corev1.HTTPGetAction{
Path: defaultLivenessProbeHTTPPath,
Port: intstr.IntOrString{
IntVal: defaultAgentHealthPort,
},
}
return livenessProbe
}
// GetDefaultReadinessProbe creates a all defaulted ReadynessProbe
func GetDefaultReadinessProbe() *corev1.Probe {
readinessProbe := &corev1.Probe{
InitialDelaySeconds: defaultReadinessProbeInitialDelaySeconds,
PeriodSeconds: defaultReadinessProbePeriodSeconds,
TimeoutSeconds: defaultReadinessProbeTimeoutSeconds,
SuccessThreshold: defaultReadinessProbeSuccessThreshold,
FailureThreshold: defaultReadinessProbeFailureThreshold,
}
readinessProbe.HTTPGet = &corev1.HTTPGetAction{
Path: defaultReadinessProbeHTTPPath,
Port: intstr.IntOrString{
IntVal: defaultAgentHealthPort,
},
}
return readinessProbe
}
// DefaultDatadogAgentSpecAgentConfig used to default a NodeAgentConfig
// return the defaulted NodeAgentConfig
func DefaultDatadogAgentSpecAgentConfig(agent *DatadogAgentSpecAgentSpec) *NodeAgentConfig {
configOverride := &NodeAgentConfig{}
if agent.Config == nil {
agent.Config = &NodeAgentConfig{}
}
if agent.Config.LogLevel == nil {
agent.Config.LogLevel = NewStringPointer(defaultLogLevel)
configOverride.LogLevel = agent.Config.LogLevel
}
if agent.Config.CollectEvents == nil {
agent.Config.CollectEvents = NewBoolPointer(defaultCollectEvents)
configOverride.CollectEvents = agent.Config.CollectEvents
}
if agent.Config.LeaderElection == nil {
agent.Config.LeaderElection = NewBoolPointer(defaultLeaderElection)
configOverride.LeaderElection = agent.Config.LeaderElection
}
// Don't default Docker/CRI paths with Agent >= 7.27.0
// Let Env AD do the work for us
// Image is defaulted prior to this function.
agentTag := strings.TrimSuffix(utils.GetTagFromImageName(agent.Image.Name), "-jmx")
// Check against image tag + "-0"; otherwise prelease versions are not compared.
// (See https://github.com/Masterminds/semver#working-with-prerelease-versions)
if !(agentTag == "latest" || utils.IsAboveMinVersion(agentTag, "7.27.0-0") || utils.IsAboveMinVersion(agentTag, "6.27.0-0")) {
if socketOverride := DefaultContainerSocket(agent.Config); !IsEqualStruct(socketOverride, CRISocketConfig{}) {
configOverride.CriSocket = socketOverride
}
}
if dsdOverride := DefaultConfigDogstatsd(agent.Config); !IsEqualStruct(dsdOverride, DogstatsdConfig{}) {
configOverride.Dogstatsd = dsdOverride
}
if agent.Config.Resources == nil {
agent.Config.Resources = &corev1.ResourceRequirements{}
}
if agent.Config.PodLabelsAsTags == nil {
agent.Config.PodLabelsAsTags = map[string]string{}
}
if agent.Config.PodAnnotationsAsTags == nil {
agent.Config.PodAnnotationsAsTags = map[string]string{}
}
if agent.Config.Tags == nil {
agent.Config.Tags = []string{}
}
if agent.Config.LivenessProbe == nil {
// TODO make liveness probe's fields more configurable
agent.Config.LivenessProbe = GetDefaultLivenessProbe()
configOverride.LivenessProbe = agent.Config.LivenessProbe
}
if agent.Config.ReadinessProbe == nil {
// TODO make readiness probe's fields more configurable
agent.Config.ReadinessProbe = GetDefaultReadinessProbe()
configOverride.ReadinessProbe = agent.Config.ReadinessProbe
}
if agent.Config.HealthPort == nil {
agent.Config.HealthPort = NewInt32Pointer(defaultAgentHealthPort)
configOverride.HealthPort = agent.Config.HealthPort
}
return configOverride
}
// DefaultContainerSocket defaults the socket configuration for the Datadog Agent
func DefaultContainerSocket(config *NodeAgentConfig) *CRISocketConfig {
if config.CriSocket == nil {
config.CriSocket = &CRISocketConfig{
DockerSocketPath: NewStringPointer(defaultDockerSocketPath),
}
return config.CriSocket
}
socketOverride := &CRISocketConfig{}
if config.CriSocket.DockerSocketPath == nil {
config.CriSocket.DockerSocketPath = NewStringPointer(defaultDockerSocketPath)
socketOverride.DockerSocketPath = config.CriSocket.DockerSocketPath
}
return socketOverride
}
// DefaultConfigDogstatsd used to default Dogstatsd config in NodeAgentConfig
func DefaultConfigDogstatsd(config *NodeAgentConfig) *DogstatsdConfig {
dsdOverride := &DogstatsdConfig{}
if config.Dogstatsd == nil {
config.Dogstatsd = &DogstatsdConfig{}
}
if config.Dogstatsd.DogstatsdOriginDetection == nil {
config.Dogstatsd.DogstatsdOriginDetection = NewBoolPointer(defaultDogstatsdOriginDetection)
dsdOverride.DogstatsdOriginDetection = config.Dogstatsd.DogstatsdOriginDetection
}
if uds := DefaultConfigDogstatsdUDS(config.Dogstatsd); !IsEqualStruct(uds, DSDUnixDomainSocketSpec{}) {
dsdOverride.UnixDomainSocket = uds
}
return dsdOverride
}
// DefaultConfigDogstatsdUDS used to default DSDUnixDomainSocketSpec
// return the defaulted DSDUnixDomainSocketSpec
func DefaultConfigDogstatsdUDS(dsd *DogstatsdConfig) *DSDUnixDomainSocketSpec {
if dsd.UnixDomainSocket == nil {
dsd.UnixDomainSocket = &DSDUnixDomainSocketSpec{}
}
udsOverride := &DSDUnixDomainSocketSpec{}
if dsd.UnixDomainSocket.Enabled == nil {
dsd.UnixDomainSocket.Enabled = NewBoolPointer(defaultUseDogStatsDSocketVolume)
udsOverride.Enabled = dsd.UnixDomainSocket.Enabled
}
if dsd.UnixDomainSocket.HostFilepath == nil {
socketPath := path.Join(defaultHostDogstatsdSocketPath, defaultHostDogstatsdSocketName)
dsd.UnixDomainSocket.HostFilepath = &socketPath
udsOverride.HostFilepath = dsd.UnixDomainSocket.HostFilepath
}
return udsOverride
}
// DefaultRbacConfig defaults the RBAC section of the DatadogAgent
func DefaultRbacConfig(rbac *RbacConfig) *RbacConfig {
rbacOverride := &RbacConfig{}
if rbac == nil {
rbac = &RbacConfig{}
}
if rbac.Create == nil {
rbac.Create = NewBoolPointer(defaultRbacCreate)
rbacOverride.Create = rbac.Create
}
return rbacOverride
}
// DefaultDatadogClusterCheckRunnerSpecRbacConfig used to default a RbacConfig of the Cluster Check Runner
func DefaultDatadogClusterCheckRunnerSpecRbacConfig(clc *DatadogAgentSpecClusterChecksRunnerSpec) *RbacConfig {
if clc.Rbac == nil {
// prevent passing an empty reference
clc.Rbac = &RbacConfig{}
}
return DefaultRbacConfig(clc.Rbac)
}
// DefaultDatadogClusterAgentSpecRbacConfig used to default a RbacConfig of the Cluster Agent
func DefaultDatadogClusterAgentSpecRbacConfig(dca *DatadogAgentSpecClusterAgentSpec) *RbacConfig {
if dca.Rbac == nil {
// prevent passing an empty reference
dca.Rbac = &RbacConfig{}
}
return DefaultRbacConfig(dca.Rbac)
}
// DefaultDatadogAgentSpecRbacConfig used to default a RbacConfig
// return the defaulted RbacConfig
func DefaultDatadogAgentSpecRbacConfig(agent *DatadogAgentSpecAgentSpec) *RbacConfig {
if agent.Rbac == nil {
// prevent passing an empty reference
agent.Rbac = &RbacConfig{}
}
return DefaultRbacConfig(agent.Rbac)
}
// DefaultDatadogAgentSpecDatadogAgentStrategy used to default a DaemonSetDeploymentStrategy
// return the defaulted DaemonSetDeploymentStrategy
func DefaultDatadogAgentSpecDatadogAgentStrategy(agent *DatadogAgentSpecAgentSpec) *DaemonSetDeploymentStrategy {
strategyOverride := &DaemonSetDeploymentStrategy{}
if agent.DeploymentStrategy == nil {
agent.DeploymentStrategy = &DaemonSetDeploymentStrategy{}
}
if agent.DeploymentStrategy.UpdateStrategyType == nil {
updateStrategy := defaultUpdateStrategy
agent.DeploymentStrategy.UpdateStrategyType = &updateStrategy
strategyOverride.UpdateStrategyType = agent.DeploymentStrategy.UpdateStrategyType
}
if agent.DeploymentStrategy.RollingUpdate.MaxUnavailable == nil {
agent.DeploymentStrategy.RollingUpdate.MaxUnavailable = &intstr.IntOrString{
Type: intstr.String,
StrVal: defaultRollingUpdateMaxUnavailable,
}
strategyOverride.RollingUpdate.MaxUnavailable = agent.DeploymentStrategy.RollingUpdate.MaxUnavailable
}
if agent.DeploymentStrategy.RollingUpdate.MaxPodSchedulerFailure == nil {
agent.DeploymentStrategy.RollingUpdate.MaxPodSchedulerFailure = &intstr.IntOrString{
Type: intstr.String,
StrVal: defaultRollingUpdateMaxPodSchedulerFailure,
}
strategyOverride.RollingUpdate.MaxPodSchedulerFailure = agent.DeploymentStrategy.RollingUpdate.MaxPodSchedulerFailure
}
if agent.DeploymentStrategy.RollingUpdate.MaxParallelPodCreation == nil {
agent.DeploymentStrategy.RollingUpdate.MaxParallelPodCreation = NewInt32Pointer(defaultRollingUpdateMaxParallelPodCreation)
strategyOverride.RollingUpdate.MaxParallelPodCreation = agent.DeploymentStrategy.RollingUpdate.MaxParallelPodCreation
}
if agent.DeploymentStrategy.RollingUpdate.SlowStartIntervalDuration == nil {
agent.DeploymentStrategy.RollingUpdate.SlowStartIntervalDuration = &metav1.Duration{
Duration: defaultRollingUpdateSlowStartIntervalDuration,
}
strategyOverride.RollingUpdate.SlowStartIntervalDuration = agent.DeploymentStrategy.RollingUpdate.SlowStartIntervalDuration
}
if agent.DeploymentStrategy.RollingUpdate.SlowStartAdditiveIncrease == nil {
agent.DeploymentStrategy.RollingUpdate.SlowStartAdditiveIncrease = &intstr.IntOrString{
Type: intstr.String,
StrVal: defaultRollingUpdateSlowStartAdditiveIncrease,
}
strategyOverride.RollingUpdate.SlowStartAdditiveIncrease = agent.DeploymentStrategy.RollingUpdate.SlowStartAdditiveIncrease
}
if agent.DeploymentStrategy.Canary == nil {
agent.DeploymentStrategy.Canary = edsdatadoghqv1alpha1.DefaultExtendedDaemonSetSpecStrategyCanary(&edsdatadoghqv1alpha1.ExtendedDaemonSetSpecStrategyCanary{})
strategyOverride.Canary = agent.DeploymentStrategy.Canary
}
if agent.DeploymentStrategy.ReconcileFrequency == nil {
agent.DeploymentStrategy.ReconcileFrequency = &metav1.Duration{
Duration: defaultReconcileFrequency,
}
strategyOverride.ReconcileFrequency = agent.DeploymentStrategy.ReconcileFrequency
}
return strategyOverride
}
// DefaultDatadogAgentSpecAgentApm used to default an APMSpec
// return the defaulted APMSpec
func DefaultDatadogAgentSpecAgentApm(agent *DatadogAgentSpecAgentSpec) *APMSpec {
if agent.Apm == nil {
agent.Apm = &APMSpec{Enabled: NewBoolPointer(defaultApmEnabled)}
return agent.Apm
}
apmOverride := &APMSpec{}
if agent.Apm.Enabled == nil {
agent.Apm.Enabled = NewBoolPointer(defaultApmEnabled)
apmOverride.Enabled = agent.Apm.Enabled
}
if !BoolValue(agent.Apm.Enabled) {
return apmOverride
}
if agent.Apm.HostPort == nil {
agent.Apm.HostPort = NewInt32Pointer(defaultApmHostPort)
apmOverride.HostPort = agent.Apm.HostPort
}
if agent.Apm.LivenessProbe == nil {
agent.Apm.LivenessProbe = getDefaultAPMAgentLivenessProbe()
apmOverride.LivenessProbe = agent.Apm.LivenessProbe
}
if udsOverride := DefaultDatadogAgentSpecAgentApmUDS(agent.Apm); !IsEqualStruct(udsOverride, APMUnixDomainSocketSpec{}) {
apmOverride.UnixDomainSocket = udsOverride
}
return apmOverride
}
func getDefaultAPMAgentLivenessProbe() *corev1.Probe {
livenessProbe := &corev1.Probe{
InitialDelaySeconds: defaultLivenessProbeInitialDelaySeconds,
PeriodSeconds: defaultLivenessProbePeriodSeconds,
TimeoutSeconds: defaultLivenessProbeTimeoutSeconds,
}
livenessProbe.TCPSocket = &corev1.TCPSocketAction{
Port: intstr.IntOrString{
IntVal: defaultApmHostPort,
},
}
return livenessProbe
}
// DefaultDatadogAgentSpecAgentApmUDS used to default APMUnixDomainSocketSpec
// rreturn the defaulted APMUnixDomainSocketSpec
func DefaultDatadogAgentSpecAgentApmUDS(apm *APMSpec) *APMUnixDomainSocketSpec {
if apm.UnixDomainSocket == nil {
apm.UnixDomainSocket = &APMUnixDomainSocketSpec{Enabled: NewBoolPointer(false)}
return apm.UnixDomainSocket
}
udsOverride := &APMUnixDomainSocketSpec{}
if apm.UnixDomainSocket.Enabled == nil {
apm.UnixDomainSocket.Enabled = NewBoolPointer(false)
udsOverride.Enabled = apm.UnixDomainSocket.Enabled
}
if !BoolValue(apm.UnixDomainSocket.Enabled) {
return udsOverride
}
if apm.UnixDomainSocket.HostFilepath == nil {
socketPath := path.Join(defaultHostApmSocketPath, defaultHostApmSocketName)
apm.UnixDomainSocket.HostFilepath = &socketPath
udsOverride.HostFilepath = apm.UnixDomainSocket.HostFilepath
}
return udsOverride
}
// DefaultDatadogAgentSpecAgentSystemProbe defaults the System Probe
// This method can be re-run as part of the FeatureOverride
func DefaultDatadogAgentSpecAgentSystemProbe(agent *DatadogAgentSpecAgentSpec) *SystemProbeSpec {
if agent.SystemProbe == nil {
agent.SystemProbe = &SystemProbeSpec{Enabled: NewBoolPointer(defaultSystemProbeEnabled)}
return agent.SystemProbe
}
sysOverride := &SystemProbeSpec{}
if agent.SystemProbe.Enabled == nil {
agent.SystemProbe.Enabled = NewBoolPointer(defaultSystemProbeEnabled)
sysOverride.Enabled = agent.SystemProbe.Enabled
}
if !BoolValue(agent.SystemProbe.Enabled) {
return sysOverride
}
if agent.SystemProbe.EnableOOMKill == nil {
agent.SystemProbe.EnableOOMKill = NewBoolPointer(defaultSystemProbeOOMKillEnabled)
sysOverride.EnableOOMKill = agent.SystemProbe.EnableOOMKill
}
if agent.SystemProbe.EnableTCPQueueLength == nil {
agent.SystemProbe.EnableTCPQueueLength = NewBoolPointer(defaultSystemProbeTCPQueueLengthEnabled)
sysOverride.EnableTCPQueueLength = agent.SystemProbe.EnableTCPQueueLength
}
if agent.SystemProbe.BPFDebugEnabled == nil {
agent.SystemProbe.BPFDebugEnabled = NewBoolPointer(defaultSystemProbeBPFDebugEnabled)
sysOverride.BPFDebugEnabled = agent.SystemProbe.BPFDebugEnabled
}
if agent.SystemProbe.CollectDNSStats == nil {
agent.SystemProbe.CollectDNSStats = NewBoolPointer(defaultSystemProbeCollectDNSStats)
sysOverride.CollectDNSStats = agent.SystemProbe.CollectDNSStats
}
if agent.SystemProbe.ConntrackEnabled == nil {
agent.SystemProbe.ConntrackEnabled = NewBoolPointer(defaultSystemProbeConntrackEnabled)
sysOverride.ConntrackEnabled = agent.SystemProbe.ConntrackEnabled
}
if agent.SystemProbe.SecCompRootPath == "" {
agent.SystemProbe.SecCompRootPath = defaultSystemProbeSecCompRootPath
sysOverride.SecCompRootPath = agent.SystemProbe.SecCompRootPath
}
if agent.SystemProbe.AppArmorProfileName == "" {
agent.SystemProbe.AppArmorProfileName = defaultAppArmorProfileName
sysOverride.AppArmorProfileName = agent.SystemProbe.AppArmorProfileName
}
if agent.SystemProbe.SecCompProfileName == "" {
agent.SystemProbe.SecCompProfileName = DefaultSeccompProfileName
sysOverride.SecCompProfileName = agent.SystemProbe.SecCompProfileName
}
return sysOverride
}
// DefaultDatadogAgentSpecAgentSecurity defaults the Security Agent in the DatadogAgentSpec
func DefaultDatadogAgentSpecAgentSecurity(agent *DatadogAgentSpecAgentSpec) *SecuritySpec {
secOverride := &SecuritySpec{}
if agent.Security == nil {
agent.Security = &SecuritySpec{}
}
if agent.Security.Compliance.Enabled == nil {
agent.Security.Compliance.Enabled = NewBoolPointer(defaultSecurityComplianceEnabled)
secOverride.Compliance.Enabled = agent.Security.Compliance.Enabled
}
if agent.Security.Runtime.Enabled == nil {
agent.Security.Runtime.Enabled = NewBoolPointer(defaultSecurityRuntimeEnabled)
secOverride.Runtime.Enabled = agent.Security.Runtime.Enabled
}
if agent.Security.Runtime.SyscallMonitor == nil {
agent.Security.Runtime.SyscallMonitor = &SyscallMonitorSpec{}
secOverride.Runtime.SyscallMonitor = agent.Security.Runtime.SyscallMonitor
}
if agent.Security.Runtime.SyscallMonitor.Enabled == nil {
agent.Security.Runtime.SyscallMonitor.Enabled = NewBoolPointer(defaultSecuritySyscallMonitorEnabled)
secOverride.Runtime.SyscallMonitor.Enabled = agent.Security.Runtime.SyscallMonitor.Enabled
}
return secOverride
}
// DefaultDatadogFeatureLogCollection used to default an LogCollectionConfig
// return the defaulted LogCollectionConfig
func DefaultDatadogFeatureLogCollection(ft *DatadogFeatures) *LogCollectionConfig {
if ft.LogCollection == nil {
ft.LogCollection = &LogCollectionConfig{Enabled: NewBoolPointer(defaultLogEnabled)}
return ft.LogCollection
}
if ft.LogCollection.Enabled == nil {
ft.LogCollection.Enabled = NewBoolPointer(defaultLogEnabled)
}
logOverride := &LogCollectionConfig{Enabled: ft.LogCollection.Enabled}
if !BoolValue(ft.LogCollection.Enabled) {
return logOverride
}
if ft.LogCollection.LogsConfigContainerCollectAll == nil {
ft.LogCollection.LogsConfigContainerCollectAll = NewBoolPointer(defaultLogsConfigContainerCollectAll)
logOverride.LogsConfigContainerCollectAll = ft.LogCollection.LogsConfigContainerCollectAll
}
if ft.LogCollection.ContainerCollectUsingFiles == nil {
ft.LogCollection.ContainerCollectUsingFiles = NewBoolPointer(defaultLogsContainerCollectUsingFiles)
logOverride.ContainerCollectUsingFiles = ft.LogCollection.ContainerCollectUsingFiles
}
if ft.LogCollection.ContainerLogsPath == nil {
ft.LogCollection.ContainerLogsPath = NewStringPointer(defaultContainerLogsPath)
logOverride.ContainerLogsPath = ft.LogCollection.ContainerLogsPath
}
if ft.LogCollection.PodLogsPath == nil {
ft.LogCollection.PodLogsPath = NewStringPointer(defaultPodLogsPath)
logOverride.PodLogsPath = ft.LogCollection.PodLogsPath
}
if ft.LogCollection.ContainerSymlinksPath == nil {
ft.LogCollection.ContainerSymlinksPath = NewStringPointer(defaultContainerSymlinksPath)
logOverride.ContainerSymlinksPath = ft.LogCollection.ContainerSymlinksPath
}
if ft.LogCollection.TempStoragePath == nil {
ft.LogCollection.TempStoragePath = NewStringPointer(defaultLogsTempStoragePath)
logOverride.TempStoragePath = ft.LogCollection.TempStoragePath
}
if ft.LogCollection.OpenFilesLimit == nil {
ft.LogCollection.OpenFilesLimit = NewInt32Pointer(defaultLogsOpenFilesLimit)
logOverride.OpenFilesLimit = ft.LogCollection.OpenFilesLimit
}
return logOverride
}
// DefaultDatadogAgentSpecAgentProcess used to default an ProcessSpec
// return the defaulted ProcessSpec
func DefaultDatadogAgentSpecAgentProcess(agent *DatadogAgentSpecAgentSpec) *ProcessSpec {
if agent.Process == nil {
agent.Process = &ProcessSpec{Enabled: NewBoolPointer(defaultProcessEnabled)}
return agent.Process
}
processOverride := &ProcessSpec{}
if agent.Process.Enabled == nil {
agent.Process.Enabled = NewBoolPointer(defaultProcessEnabled)
processOverride.Enabled = agent.Process.Enabled
}
if !BoolValue(agent.Process.Enabled) {
return processOverride
}
if agent.Process.ProcessCollectionEnabled == nil {
agent.Process.ProcessCollectionEnabled = NewBoolPointer(defaultProcessCollectionEnabled)
processOverride.ProcessCollectionEnabled = agent.Process.ProcessCollectionEnabled
}
return processOverride
}
func clusterChecksRunnerEnabled(dda *DatadogAgent) bool {
if dda.Spec.ClusterChecksRunner.Enabled != nil {
return *dda.Spec.ClusterChecksRunner.Enabled
}
return false
}
// DefaultFeatures used to initialized the Features' default values if necessary
func DefaultFeatures(dda *DatadogAgent) *DatadogFeatures {
ft := &dda.Spec.Features
featureOverride := &DatadogFeatures{}
if orch := DefaultDatadogFeatureOrchestratorExplorer(ft); !IsEqualStruct(*orch, OrchestratorExplorerConfig{}) {
featureOverride.OrchestratorExplorer = orch
}
if ksm := DefaultDatadogFeatureKubeStateMetricsCore(ft, clusterChecksRunnerEnabled(dda)); !IsEqualStruct(*ksm, KubeStateMetricsCore{}) {
featureOverride.KubeStateMetricsCore = ksm
}
if promScrape := DefaultDatadogFeaturePrometheusScrape(ft); !IsEqualStruct(*promScrape, PrometheusScrapeConfig{}) {
featureOverride.PrometheusScrape = promScrape
}
if logColl := DefaultDatadogFeatureLogCollection(ft); !IsEqualStruct(*logColl, LogCollectionConfig{}) {
featureOverride.LogCollection = logColl
}
if net := DefaultDatadogFeatureNetworkMonitoring(ft); !IsEqualStruct(*net, NetworkMonitoringConfig{}) {
featureOverride.NetworkMonitoring = net
}
return featureOverride
}
// DefaultDatadogFeatureOrchestratorExplorer used to default an OrchestratorExplorerConfig
// return the defaulted OrchestratorExplorerConfig
func DefaultDatadogFeatureOrchestratorExplorer(ft *DatadogFeatures) *OrchestratorExplorerConfig {
if ft.OrchestratorExplorer == nil {
ft.OrchestratorExplorer = &OrchestratorExplorerConfig{Enabled: NewBoolPointer(false)}
return ft.OrchestratorExplorer
}
if ft.OrchestratorExplorer.Enabled == nil {
ft.OrchestratorExplorer.Enabled = NewBoolPointer(defaultOrchestratorExplorerEnabled)
}
explorerConfigOverride := &OrchestratorExplorerConfig{Enabled: ft.OrchestratorExplorer.Enabled}
if !BoolValue(ft.OrchestratorExplorer.Enabled) {
return explorerConfigOverride
}
if ft.OrchestratorExplorer.Scrubbing == nil || ft.OrchestratorExplorer.Scrubbing.Containers == nil {
ft.OrchestratorExplorer.Scrubbing = &Scrubbing{Containers: NewBoolPointer(defaultOrchestratorExplorerContainerScrubbingEnabled)}
explorerConfigOverride.Scrubbing = ft.OrchestratorExplorer.Scrubbing
}
return explorerConfigOverride
}
// DefaultDatadogFeatureKubeStateMetricsCore used to default the Kubernetes State Metrics core check
// Disabled by default with no overridden configuration.
func DefaultDatadogFeatureKubeStateMetricsCore(ft *DatadogFeatures, withClusterChecksRunner bool) *KubeStateMetricsCore {
if ft.KubeStateMetricsCore == nil {
ft.KubeStateMetricsCore = &KubeStateMetricsCore{
Enabled: NewBoolPointer(defaultKubeStateMetricsCoreEnabled),
ClusterCheck: NewBoolPointer(withClusterChecksRunner),
}
return ft.KubeStateMetricsCore
}
if ft.KubeStateMetricsCore.Enabled == nil {
ft.KubeStateMetricsCore.Enabled = NewBoolPointer(defaultKubeStateMetricsCoreEnabled)
}
if ft.KubeStateMetricsCore.ClusterCheck == nil {
ft.KubeStateMetricsCore.ClusterCheck = NewBoolPointer(withClusterChecksRunner)
}
ksmCoreOverride := &KubeStateMetricsCore{Enabled: ft.KubeStateMetricsCore.Enabled, ClusterCheck: ft.KubeStateMetricsCore.ClusterCheck}
return ksmCoreOverride
}
// DefaultDatadogFeaturePrometheusScrape used to default the Prometheus Scrape config
func DefaultDatadogFeaturePrometheusScrape(ft *DatadogFeatures) *PrometheusScrapeConfig {
if ft.PrometheusScrape == nil {
ft.PrometheusScrape = &PrometheusScrapeConfig{Enabled: NewBoolPointer(defaultPrometheusScrapeEnabled)}
return ft.PrometheusScrape
}
if ft.PrometheusScrape.Enabled == nil {
ft.PrometheusScrape.Enabled = NewBoolPointer(defaultPrometheusScrapeEnabled)
}
promOverride := &PrometheusScrapeConfig{Enabled: ft.PrometheusScrape.Enabled}
if !BoolValue(ft.PrometheusScrape.Enabled) {
return promOverride
}
if ft.PrometheusScrape.ServiceEndpoints == nil {
ft.PrometheusScrape.ServiceEndpoints = NewBoolPointer(defaultPrometheusScrapeServiceEndpoints)
promOverride.ServiceEndpoints = ft.PrometheusScrape.ServiceEndpoints
}
return promOverride
}
// DefaultDatadogFeatureNetworkMonitoring used to default the NetworkMonitoring config
func DefaultDatadogFeatureNetworkMonitoring(ft *DatadogFeatures) *NetworkMonitoringConfig {
if ft.NetworkMonitoring == nil {
ft.NetworkMonitoring = &NetworkMonitoringConfig{Enabled: NewBoolPointer(false)}
return ft.NetworkMonitoring
}
if ft.NetworkMonitoring.Enabled == nil {
ft.NetworkMonitoring.Enabled = NewBoolPointer(false)
}
netOverride := &NetworkMonitoringConfig{Enabled: ft.NetworkMonitoring.Enabled}
return netOverride
}
// DefaultDatadogAgentSpecClusterAgent used to default an DatadogAgentSpecClusterAgentSpec
// Mutate the internal DatadogAgentSpecClusterAgent throughout the method
// return the defaulted DatadogAgentSpecClusterAgentSpec to update the status
func DefaultDatadogAgentSpecClusterAgent(clusterAgent *DatadogAgentSpecClusterAgentSpec) *DatadogAgentSpecClusterAgentSpec {
if IsEqualStruct(*clusterAgent, DatadogAgentSpecClusterAgentSpec{}) {
clusterAgent.Enabled = NewBoolPointer(false)
return clusterAgent
}
if clusterAgent.Enabled == nil {
// Cluster Agent is enabled by default unless undeclared then it is set to false.
clusterAgent.Enabled = NewBoolPointer(true)
}
clusterAgentOverride := &DatadogAgentSpecClusterAgentSpec{Enabled: clusterAgent.Enabled}
if clusterAgent.Image == nil {
clusterAgent.Image = &ImageConfig{}
}
if img := DefaultDatadogClusterAgentImage(clusterAgent, defaultClusterAgentImageName, defaultClusterAgentImageTag); !IsEqualStruct(*img, ImageConfig{}) {
clusterAgentOverride.Image = img
}
if cfg := DefaultDatadogAgentSpecClusterAgentConfig(clusterAgent); !IsEqualStruct(cfg, ClusterAgentConfig{}) {
clusterAgentOverride.Config = cfg
}
if rbac := DefaultDatadogClusterAgentSpecRbacConfig(clusterAgent); !IsEqualStruct(rbac, RbacConfig{}) {
clusterAgentOverride.Rbac = rbac
}
if net := DefaultClusterAgentNetworkPolicy(clusterAgent); !IsEqualStruct(net, NetworkPolicySpec{}) {
clusterAgentOverride.NetworkPolicy = net
}
return clusterAgentOverride
}
// DefaultDatadogAgentSpecClusterAgentConfig used to default an ClusterAgentConfig
// return the defaulted ClusterAgentConfig
func DefaultDatadogAgentSpecClusterAgentConfig(dca *DatadogAgentSpecClusterAgentSpec) *ClusterAgentConfig {
configOverride := &ClusterAgentConfig{}
if dca.Config == nil {
dca.Config = &ClusterAgentConfig{}
}
if dca.Config.LogLevel == nil {
dca.Config.LogLevel = NewStringPointer(defaultLogLevel)
configOverride.LogLevel = dca.Config.LogLevel
}
if extMetricsOverride := DefaultExternalMetrics(dca.Config); !IsEqualStruct(extMetricsOverride, ExternalMetricsConfig{}) {
configOverride.ExternalMetrics = extMetricsOverride
}
if dca.Config.ClusterChecksEnabled == nil {
dca.Config.ClusterChecksEnabled = NewBoolPointer(defaultClusterChecksEnabled)
configOverride.ClusterChecksEnabled = dca.Config.ClusterChecksEnabled
}
if dca.Config.CollectEvents == nil {
dca.Config.CollectEvents = NewBoolPointer(defaultCollectEvents)
configOverride.CollectEvents = dca.Config.CollectEvents
}
if admCtrlOverride := DefaultAdmissionController(dca.Config); !IsEqualStruct(admCtrlOverride, AdmissionControllerConfig{}) {
configOverride.AdmissionController = admCtrlOverride
}
if dca.Config.Resources == nil {
dca.Config.Resources = &corev1.ResourceRequirements{}
}
if dca.Config.HealthPort == nil {
dca.Config.HealthPort = NewInt32Pointer(defaultAgentHealthPort)
configOverride.HealthPort = dca.Config.HealthPort
}
return configOverride
}
// DefaultExternalMetrics defaults the External Metrics Server's config in the Cluster Agent's config
func DefaultExternalMetrics(conf *ClusterAgentConfig) *ExternalMetricsConfig {
if conf.ExternalMetrics == nil {
conf.ExternalMetrics = &ExternalMetricsConfig{Enabled: NewBoolPointer(false)}
return conf.ExternalMetrics
}
extMetricsOverride := &ExternalMetricsConfig{}
if conf.ExternalMetrics.Enabled == nil {
conf.ExternalMetrics.Enabled = NewBoolPointer(true)
extMetricsOverride.Enabled = conf.ExternalMetrics.Enabled
}
if conf.ExternalMetrics.Port == nil && BoolValue(conf.ExternalMetrics.Enabled) {
conf.ExternalMetrics.Port = NewInt32Pointer(defaultMetricsProviderPort)
extMetricsOverride.Port = conf.ExternalMetrics.Port
}
return extMetricsOverride
}