Skip to content

Commit 5b9b7b1

Browse files
committed
Added PodDNSConfig
Signed-off-by: Yuri Sa <[email protected]>
2 parents 96564b6 + c9ec877 commit 5b9b7b1

File tree

21 files changed

+1085
-367
lines changed

21 files changed

+1085
-367
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
2+
change_type: breaking
3+
4+
# The name of the component, or a single word describing the area of concern, (e.g. operator, target allocator, github action)
5+
component: operator
6+
7+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
8+
note: change dotnet instrumentation feature gate into command line flag --enable-dotnet-instrumentation
9+
10+
# One or more tracking issues related to the change
11+
issues: [2582, 2671]
12+
13+
# (Optional) One or more lines of additional information to render under the primary note.
14+
# These lines will be padded with 2 spaces and then inserted directly into the document.
15+
# Use pipe (|) for multiline entries.
16+
subtext:

apis/v1alpha1/convert.go

+335-136
Large diffs are not rendered by default.

apis/v1alpha1/convert_test.go

+251-46
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,20 @@ import (
1919
"time"
2020

2121
"github.com/stretchr/testify/assert"
22+
"github.com/stretchr/testify/require"
2223
"gopkg.in/yaml.v3"
24+
appsv1 "k8s.io/api/apps/v1"
25+
autoscalingv2 "k8s.io/api/autoscaling/v2"
2326
v1 "k8s.io/api/core/v1"
27+
networkingv1 "k8s.io/api/networking/v1"
2428
"k8s.io/apimachinery/pkg/api/resource"
2529
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2630
"k8s.io/apimachinery/pkg/util/intstr"
2731

2832
"github.com/open-telemetry/opentelemetry-operator/apis/v1beta1"
2933
)
3034

31-
func Test_V1Alpha1to2(t *testing.T) {
32-
t.Run("valid config", func(t *testing.T) {
33-
config := `---
35+
const collectorCfg = `---
3436
receivers:
3537
otlp:
3638
protocols:
@@ -48,9 +50,12 @@ service:
4850
processors: [resourcedetection]
4951
exporters: [otlp]
5052
`
53+
54+
func Test_tov1beta1_config(t *testing.T) {
55+
t.Run("valid config", func(t *testing.T) {
5156
cfgV1 := OpenTelemetryCollector{
5257
Spec: OpenTelemetryCollectorSpec{
53-
Config: config,
58+
Config: collectorCfg,
5459
Args: map[string]string{
5560
"test": "something",
5661
},
@@ -64,7 +69,7 @@ service:
6469

6570
yamlCfg, err := yaml.Marshal(&cfgV2.Spec.Config)
6671
assert.Nil(t, err)
67-
assert.YAMLEq(t, config, string(yamlCfg))
72+
assert.YAMLEq(t, collectorCfg, string(yamlCfg))
6873
})
6974
t.Run("invalid config", func(t *testing.T) {
7075
config := `!!!`
@@ -79,13 +84,252 @@ service:
7984
})
8085
}
8186

82-
func Test_TargetAllocator(t *testing.T) {
87+
func Test_tov1alpha1_config(t *testing.T) {
88+
cfg := v1beta1.Config{}
89+
err := yaml.Unmarshal([]byte(collectorCfg), &cfg)
90+
require.NoError(t, err)
91+
92+
beta1Col := v1beta1.OpenTelemetryCollector{
93+
Spec: v1beta1.OpenTelemetryCollectorSpec{
94+
Config: cfg,
95+
},
96+
}
97+
alpha1Col, err := tov1alpha1(beta1Col)
98+
require.NoError(t, err)
99+
assert.YAMLEq(t, collectorCfg, alpha1Col.Spec.Config)
100+
}
101+
102+
func Test_tov1beta1AndBack(t *testing.T) {
103+
one := int32(1)
104+
two := int64(2)
105+
intstrAAA := intstr.FromString("aaa")
106+
boolTrue := true
107+
ingressClass := "someClass"
108+
colalpha1 := &OpenTelemetryCollector{
109+
ObjectMeta: metav1.ObjectMeta{
110+
Name: "otel",
111+
Namespace: "observability",
112+
Labels: map[string]string{"foo": "bar"},
113+
Annotations: map[string]string{"bax": "foo"},
114+
},
115+
Spec: OpenTelemetryCollectorSpec{
116+
ManagementState: ManagementStateManaged,
117+
Resources: v1.ResourceRequirements{
118+
Limits: v1.ResourceList{
119+
v1.ResourceCPU: resource.MustParse("500m"),
120+
v1.ResourceMemory: resource.MustParse("128Mi"),
121+
},
122+
Requests: v1.ResourceList{
123+
v1.ResourceCPU: resource.MustParse("500m"),
124+
v1.ResourceMemory: resource.MustParse("128Mi"),
125+
},
126+
},
127+
NodeSelector: map[string]string{"aaa": "ccc"},
128+
Args: map[string]string{"foo": "bar"},
129+
Replicas: &one,
130+
Autoscaler: &AutoscalerSpec{
131+
MinReplicas: &one,
132+
MaxReplicas: &one,
133+
Behavior: &autoscalingv2.HorizontalPodAutoscalerBehavior{
134+
ScaleUp: &autoscalingv2.HPAScalingRules{
135+
Policies: []autoscalingv2.HPAScalingPolicy{
136+
{
137+
Type: "aaa",
138+
Value: 2,
139+
PeriodSeconds: 4,
140+
},
141+
},
142+
},
143+
},
144+
Metrics: []MetricSpec{
145+
{
146+
Type: autoscalingv2.ContainerResourceMetricSourceType,
147+
Pods: &autoscalingv2.PodsMetricSource{
148+
Metric: autoscalingv2.MetricIdentifier{
149+
Name: "rrrrt",
150+
},
151+
},
152+
},
153+
},
154+
TargetCPUUtilization: &one,
155+
TargetMemoryUtilization: &one,
156+
},
157+
PodDisruptionBudget: &PodDisruptionBudgetSpec{
158+
MinAvailable: &intstrAAA,
159+
MaxUnavailable: &intstrAAA,
160+
},
161+
SecurityContext: &v1.SecurityContext{
162+
RunAsUser: &two,
163+
},
164+
PodSecurityContext: &v1.PodSecurityContext{
165+
RunAsNonRoot: &boolTrue,
166+
},
167+
PodAnnotations: map[string]string{"foo": "bar"},
168+
TargetAllocator: createTA(),
169+
Mode: ModeDeployment,
170+
ServiceAccount: "foo",
171+
Image: "baz/bar:1.0",
172+
UpgradeStrategy: UpgradeStrategyAutomatic,
173+
ImagePullPolicy: v1.PullAlways,
174+
Config: collectorCfg,
175+
VolumeMounts: []v1.VolumeMount{
176+
{
177+
Name: "aaa",
178+
},
179+
},
180+
Ports: []v1.ServicePort{
181+
{
182+
Name: "otlp",
183+
},
184+
},
185+
Env: []v1.EnvVar{
186+
{
187+
Name: "foo",
188+
Value: "bar",
189+
ValueFrom: &v1.EnvVarSource{
190+
ResourceFieldRef: &v1.ResourceFieldSelector{
191+
ContainerName: "bbb",
192+
Resource: "aaa",
193+
Divisor: resource.Quantity{},
194+
},
195+
},
196+
},
197+
},
198+
EnvFrom: []v1.EnvFromSource{
199+
{
200+
Prefix: "aa",
201+
ConfigMapRef: &v1.ConfigMapEnvSource{
202+
LocalObjectReference: v1.LocalObjectReference{
203+
Name: "bbb",
204+
},
205+
},
206+
},
207+
},
208+
VolumeClaimTemplates: []v1.PersistentVolumeClaim{
209+
{
210+
TypeMeta: metav1.TypeMeta{},
211+
ObjectMeta: metav1.ObjectMeta{},
212+
Spec: v1.PersistentVolumeClaimSpec{
213+
VolumeName: "aaaa",
214+
},
215+
},
216+
},
217+
Tolerations: []v1.Toleration{
218+
{
219+
Key: "11",
220+
Operator: "33",
221+
Value: "44",
222+
Effect: "55",
223+
},
224+
},
225+
Volumes: []v1.Volume{
226+
{
227+
Name: "cfg",
228+
VolumeSource: v1.VolumeSource{},
229+
},
230+
},
231+
Ingress: Ingress{
232+
Type: IngressTypeRoute,
233+
RuleType: IngressRuleTypePath,
234+
Hostname: "foo.com",
235+
Annotations: map[string]string{"aa": "bb"},
236+
TLS: []networkingv1.IngressTLS{
237+
{
238+
Hosts: []string{"foo"},
239+
SecretName: "bar",
240+
},
241+
},
242+
IngressClassName: &ingressClass,
243+
Route: OpenShiftRoute{
244+
Termination: TLSRouteTerminationTypeEdge,
245+
},
246+
},
247+
HostNetwork: true,
248+
ShareProcessNamespace: true,
249+
PriorityClassName: "foobar",
250+
Affinity: &v1.Affinity{
251+
NodeAffinity: &v1.NodeAffinity{
252+
PreferredDuringSchedulingIgnoredDuringExecution: []v1.PreferredSchedulingTerm{{
253+
Weight: 444,
254+
}},
255+
},
256+
},
257+
Lifecycle: &v1.Lifecycle{
258+
PostStart: &v1.LifecycleHandler{
259+
Exec: &v1.ExecAction{
260+
Command: []string{"/bin"},
261+
},
262+
},
263+
},
264+
TerminationGracePeriodSeconds: &two,
265+
LivenessProbe: &Probe{
266+
PeriodSeconds: &one,
267+
},
268+
InitContainers: []v1.Container{
269+
{
270+
Name: "init",
271+
},
272+
},
273+
AdditionalContainers: []v1.Container{
274+
{
275+
Name: "some",
276+
},
277+
},
278+
Observability: ObservabilitySpec{
279+
Metrics: MetricsConfigSpec{
280+
EnableMetrics: true,
281+
DisablePrometheusAnnotations: true,
282+
},
283+
},
284+
TopologySpreadConstraints: []v1.TopologySpreadConstraint{
285+
{
286+
TopologyKey: "key",
287+
},
288+
},
289+
ConfigMaps: []ConfigMapsSpec{
290+
{
291+
Name: "aaa",
292+
MountPath: "bbb",
293+
},
294+
},
295+
UpdateStrategy: appsv1.DaemonSetUpdateStrategy{
296+
Type: appsv1.RollingUpdateDaemonSetStrategyType,
297+
},
298+
DeploymentUpdateStrategy: appsv1.DeploymentStrategy{
299+
Type: appsv1.RecreateDeploymentStrategyType,
300+
},
301+
},
302+
Status: OpenTelemetryCollectorStatus{
303+
Scale: ScaleSubresourceStatus{
304+
Selector: "bar",
305+
Replicas: 1,
306+
StatusReplicas: "foo",
307+
},
308+
Version: "1.0",
309+
Image: "foo/bar:1.0",
310+
},
311+
}
312+
313+
colbeta1, err := Tov1beta1(*colalpha1)
314+
require.NoError(t, err)
315+
colalpha1Converted, err := tov1alpha1(colbeta1)
316+
require.NoError(t, err)
317+
318+
assert.YAMLEq(t, colalpha1.Spec.Config, colalpha1Converted.Spec.Config)
319+
320+
// empty the config to enable assertion on the entire objects
321+
colalpha1.Spec.Config = ""
322+
colalpha1Converted.Spec.Config = ""
323+
assert.Equal(t, colalpha1, colalpha1Converted)
324+
}
325+
326+
func createTA() OpenTelemetryTargetAllocator {
83327
replicas := int32(2)
84328
runAsNonRoot := true
85329
privileged := true
86330
runAsUser := int64(1337)
87331
runasGroup := int64(1338)
88-
input := OpenTelemetryTargetAllocator{
332+
return OpenTelemetryTargetAllocator{
89333
Replicas: &replicas,
90334
NodeSelector: map[string]string{"key": "value"},
91335
Resources: v1.ResourceRequirements{
@@ -176,43 +420,4 @@ func Test_TargetAllocator(t *testing.T) {
176420
},
177421
},
178422
}
179-
180-
expected := v1beta1.TargetAllocatorEmbedded{
181-
Replicas: input.Replicas,
182-
NodeSelector: input.NodeSelector,
183-
Resources: input.Resources,
184-
AllocationStrategy: v1beta1.TargetAllocatorAllocationStrategyConsistentHashing,
185-
FilterStrategy: v1beta1.TargetAllocatorFilterStrategyRelabelConfig,
186-
ServiceAccount: input.ServiceAccount,
187-
Image: input.Image,
188-
Enabled: input.Enabled,
189-
Affinity: input.Affinity,
190-
PrometheusCR: v1beta1.TargetAllocatorPrometheusCR{
191-
Enabled: input.PrometheusCR.Enabled,
192-
ScrapeInterval: input.PrometheusCR.ScrapeInterval,
193-
PodMonitorSelector: &metav1.LabelSelector{
194-
MatchLabels: input.PrometheusCR.PodMonitorSelector,
195-
},
196-
ServiceMonitorSelector: &metav1.LabelSelector{
197-
MatchLabels: input.PrometheusCR.ServiceMonitorSelector,
198-
},
199-
},
200-
SecurityContext: input.SecurityContext,
201-
PodSecurityContext: input.PodSecurityContext,
202-
TopologySpreadConstraints: input.TopologySpreadConstraints,
203-
Tolerations: input.Tolerations,
204-
Env: input.Env,
205-
Observability: v1beta1.ObservabilitySpec{
206-
Metrics: v1beta1.MetricsConfigSpec{
207-
EnableMetrics: input.Observability.Metrics.EnableMetrics,
208-
DisablePrometheusAnnotations: input.Observability.Metrics.DisablePrometheusAnnotations,
209-
},
210-
},
211-
PodDisruptionBudget: &v1beta1.PodDisruptionBudgetSpec{
212-
MinAvailable: input.PodDisruptionBudget.MinAvailable,
213-
MaxUnavailable: input.PodDisruptionBudget.MaxUnavailable,
214-
},
215-
}
216-
217-
assert.Equal(t, expected, TargetAllocatorEmbedded(input))
218423
}

internal/config/main.go

+8
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ type Config struct {
4545
createRBACPermissions bool
4646
enableMultiInstrumentation bool
4747
enableApacheHttpdInstrumentation bool
48+
enableDotNetInstrumentation bool
4849
autoInstrumentationDotNetImage string
4950
autoInstrumentationGoImage string
5051
autoInstrumentationApacheHttpdImage string
@@ -79,6 +80,7 @@ func New(opts ...Option) Config {
7980
createRBACPermissions: o.createRBACPermissions,
8081
enableMultiInstrumentation: o.enableMultiInstrumentation,
8182
enableApacheHttpdInstrumentation: o.enableApacheHttpdInstrumentation,
83+
enableDotNetInstrumentation: o.enableDotNetInstrumentation,
8284
targetAllocatorImage: o.targetAllocatorImage,
8385
operatorOpAMPBridgeImage: o.operatorOpAMPBridgeImage,
8486
targetAllocatorConfigMapEntry: o.targetAllocatorConfigMapEntry,
@@ -118,10 +120,16 @@ func (c *Config) EnableMultiInstrumentation() bool {
118120
return c.enableMultiInstrumentation
119121
}
120122

123+
// EnableApacheHttpdAutoInstrumentation is true when the operator supports ApacheHttpd auto instrumentation.
121124
func (c *Config) EnableApacheHttpdAutoInstrumentation() bool {
122125
return c.enableApacheHttpdInstrumentation
123126
}
124127

128+
// EnableDotNetAutoInstrumentation is true when the operator supports dotnet auto instrumentation.
129+
func (c *Config) EnableDotNetAutoInstrumentation() bool {
130+
return c.enableDotNetInstrumentation
131+
}
132+
125133
// CollectorConfigMapEntry represents the configuration file name for the collector. Immutable.
126134
func (c *Config) CollectorConfigMapEntry() string {
127135
return c.collectorConfigMapEntry

0 commit comments

Comments
 (0)