-
Notifications
You must be signed in to change notification settings - Fork 98
/
new.go
116 lines (104 loc) · 3.3 KB
/
new.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
// 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-2019 Datadog, Inc.
package testutils
import (
datadoghqv1alpha1 "github.com/DataDog/datadog-operator/api/v1alpha1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// NewDatadogAgentOptions used to provide creation options to the NewDatadogAgent function
type NewDatadogAgentOptions struct {
ExtraLabels map[string]string
ExtraAnnotations map[string]string
ClusterAgentEnabled bool
UseEDS bool
APIKey string
}
var (
pullPolicy = v1.PullIfNotPresent
)
// NewDatadogAgent returns new DatadogAgent instance with is config hash
func NewDatadogAgent(ns, name, image string, options *NewDatadogAgentOptions) *datadoghqv1alpha1.DatadogAgent {
ad := &datadoghqv1alpha1.DatadogAgent{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: ns,
},
}
ad.Spec = datadoghqv1alpha1.DatadogAgentSpec{
Credentials: datadoghqv1alpha1.AgentCredentials{
APIKey: "adflkajdflkjalkcmlkdjacsf",
AppKey: "sgfggtdhfghfghfghfgbdfdgs",
},
Agent: &datadoghqv1alpha1.DatadogAgentSpecAgentSpec{
Image: datadoghqv1alpha1.ImageConfig{},
Config: datadoghqv1alpha1.NodeAgentConfig{
Resources: &v1.ResourceRequirements{
Requests: v1.ResourceList{
v1.ResourceCPU: resource.MustParse("0"),
v1.ResourceMemory: resource.MustParse("0"),
},
},
CriSocket: &datadoghqv1alpha1.CRISocketConfig{
CriSocketPath: datadoghqv1alpha1.NewStringPointer("/var/run/containerd/containerd.sock"),
},
Env: []v1.EnvVar{
{
Name: "DD_KUBELET_TLS_VERIFY",
Value: "false",
},
},
LeaderElection: datadoghqv1alpha1.NewBoolPointer(true),
},
DeploymentStrategy: &datadoghqv1alpha1.DaemonSetDeploymentStrategy{},
Apm: datadoghqv1alpha1.APMSpec{},
Log: datadoghqv1alpha1.LogSpec{},
Process: datadoghqv1alpha1.ProcessSpec{},
},
}
ad = datadoghqv1alpha1.DefaultDatadogAgent(ad)
ad.Spec.Agent.Image = datadoghqv1alpha1.ImageConfig{
Name: image,
PullPolicy: &pullPolicy,
PullSecrets: &[]v1.LocalObjectReference{},
}
ad.Spec.Agent.Rbac.Create = datadoghqv1alpha1.NewBoolPointer(true)
if options != nil {
if options.APIKey != "" {
ad.Spec.Credentials.APIKey = options.APIKey
}
if options.UseEDS && ad.Spec.Agent != nil {
ad.Spec.Agent.UseExtendedDaemonset = &options.UseEDS
}
if options.ExtraLabels != nil {
if ad.Labels == nil {
ad.Labels = map[string]string{}
}
for key, val := range options.ExtraLabels {
ad.Labels[key] = val
}
}
if options.ExtraAnnotations != nil {
if ad.Annotations == nil {
ad.Annotations = map[string]string{}
}
for key, val := range options.ExtraAnnotations {
ad.Annotations[key] = val
}
}
if options.ClusterAgentEnabled {
ad.Spec.ClusterAgent = &datadoghqv1alpha1.DatadogAgentSpecClusterAgentSpec{
Config: datadoghqv1alpha1.ClusterAgentConfig{},
Image: datadoghqv1alpha1.ImageConfig{
Name: image,
PullPolicy: &pullPolicy,
PullSecrets: &[]v1.LocalObjectReference{},
},
}
}
}
return ad
}