Skip to content

Commit

Permalink
feat(injector): allow configuring injector version
Browse files Browse the repository at this point in the history
This commit allows users to optionally pin the injector version to a
specifc image tag.
  • Loading branch information
betterengineering committed Jan 9, 2025
1 parent 827d9c2 commit 06090e9
Show file tree
Hide file tree
Showing 11 changed files with 163 additions and 9 deletions.
12 changes: 12 additions & 0 deletions api/datadoghq/v2alpha1/datadogagent_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ type SingleStepInstrumentation struct {
// (Requires Agent 7.52.0+ and Cluster Agent 7.52.0+)
// +optional
LanguageDetection *LanguageDetectionConfig `json:"languageDetection,omitempty"`

// Injector configures the APM Injector.
// +optional
Injector *InjectorConfig `json:"injector,omitempty"`
}

// LanguageDetectionConfig contains the config for Language Detection.
Expand All @@ -175,6 +179,14 @@ type LanguageDetectionConfig struct {
Enabled *bool `json:"enabled,omitempty"`
}

// InjectorConfig contains the configuration for the APM Injector.
type InjectorConfig struct {
// Set the image version to use for the APM Injector.
// (Requires Cluster Agent 7.57.0+)
// +optional
ImageTag string `json:"imageTag,omitempty"`
}

// ASMFeatureConfig contains Application Security Management (ASM) configuration.
// Note that this will only affect pods where the Datadog client libraries are installed or APM Single Step Instrumentation is enabled.
type ASMFeatureConfig struct {
Expand Down
20 changes: 20 additions & 0 deletions api/datadoghq/v2alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions config/crd/bases/v1/datadoghq.com_datadogagents.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,15 @@ spec:
type: string
type: array
x-kubernetes-list-type: set
injector:
description: Injector configures the APM Injector.
properties:
imageTag:
description: |-
Set the image version to use for the APM Injector.
(Requires Cluster Agent 7.57.0+)
type: string
type: object
languageDetection:
description: |-
LanguageDetection detects languages and adds them as annotations on Deployments, but does not use these languages for injecting libraries to workload pods.
Expand Down Expand Up @@ -7391,6 +7400,15 @@ spec:
type: string
type: array
x-kubernetes-list-type: set
injector:
description: Injector configures the APM Injector.
properties:
imageTag:
description: |-
Set the image version to use for the APM Injector.
(Requires Cluster Agent 7.57.0+)
type: string
type: object
languageDetection:
description: |-
LanguageDetection detects languages and adds them as annotations on Deployments, but does not use these languages for injecting libraries to workload pods.
Expand Down
22 changes: 22 additions & 0 deletions config/crd/bases/v1/datadoghq.com_datadogagents_v2alpha1.json
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,17 @@
"type": "array",
"x-kubernetes-list-type": "set"
},
"injector": {
"additionalProperties": false,
"description": "Injector configures the APM Injector.",
"properties": {
"imageTag": {
"description": "Set the image version to use for the APM Injector.\n(Requires Cluster Agent 7.57.0+)",
"type": "string"
}
},
"type": "object"
},
"languageDetection": {
"additionalProperties": false,
"description": "LanguageDetection detects languages and adds them as annotations on Deployments, but does not use these languages for injecting libraries to workload pods.\n(Requires Agent 7.52.0+ and Cluster Agent 7.52.0+)",
Expand Down Expand Up @@ -7336,6 +7347,17 @@
"type": "array",
"x-kubernetes-list-type": "set"
},
"injector": {
"additionalProperties": false,
"description": "Injector configures the APM Injector.",
"properties": {
"imageTag": {
"description": "Set the image version to use for the APM Injector.\n(Requires Cluster Agent 7.57.0+)",
"type": "string"
}
},
"type": "object"
},
"languageDetection": {
"additionalProperties": false,
"description": "LanguageDetection detects languages and adds them as annotations on Deployments, but does not use these languages for injecting libraries to workload pods.\n(Requires Agent 7.52.0+ and Cluster Agent 7.52.0+)",
Expand Down
1 change: 1 addition & 0 deletions docs/configuration.v2alpha1.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ spec:
| features.apm.instrumentation.disabledNamespaces | DisabledNamespaces disables injecting the Datadog APM libraries into pods in specific namespaces. |
| features.apm.instrumentation.enabled | Enables injecting the Datadog APM libraries into all pods in the cluster. Default: false |
| features.apm.instrumentation.enabledNamespaces | EnabledNamespaces enables injecting the Datadog APM libraries into pods in specific namespaces. |
| features.apm.instrumentation.injector.imageTag | Set the image version to use for the APM Injector. (Requires Cluster Agent 7.57.0+) |
| features.apm.instrumentation.languageDetection.enabled | Enables Language Detection to automatically detect languages of user workloads (beta). Requires SingleStepInstrumentation.Enabled to be true. Default: true |
| features.apm.instrumentation.libVersions | LibVersions configures injection of specific tracing library versions with Single Step Instrumentation. <Library>: <Version> ex: "java": "v1.18.0" |
| features.apm.unixDomainSocketConfig.enabled | Enables Unix Domain Socket. Default: true |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,10 @@ func defaultFeaturesConfig(ddaSpec *v2alpha1.DatadogAgentSpec) {
ddaSpec.Features.APM.SingleStepInstrumentation.LanguageDetection = &v2alpha1.LanguageDetectionConfig{}
}

if ddaSpec.Features.APM.SingleStepInstrumentation.Injector == nil {
ddaSpec.Features.APM.SingleStepInstrumentation.Injector = &v2alpha1.InjectorConfig{}
}

apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.APM.SingleStepInstrumentation.Enabled, defaultAPMSingleStepInstrEnabled)
apiutils.DefaultBooleanIfUnset(&ddaSpec.Features.APM.SingleStepInstrumentation.LanguageDetection.Enabled, defaultLanguageDetectionEnabled)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ func Test_defaultFeatures(t *testing.T) {
SingleStepInstrumentation: &v2alpha1.SingleStepInstrumentation{
Enabled: apiutils.NewBoolPointer(defaultAPMSingleStepInstrEnabled),
LanguageDetection: &v2alpha1.LanguageDetectionConfig{Enabled: apiutils.NewBoolPointer(defaultLanguageDetectionEnabled)},
Injector: &v2alpha1.InjectorConfig{},
},
},
OtelCollector: &v2alpha1.OtelCollectorFeatureConfig{
Expand Down Expand Up @@ -562,6 +563,7 @@ func Test_defaultFeatures(t *testing.T) {
SingleStepInstrumentation: &v2alpha1.SingleStepInstrumentation{
Enabled: apiutils.NewBoolPointer(defaultAPMSingleStepInstrEnabled),
LanguageDetection: &v2alpha1.LanguageDetectionConfig{Enabled: apiutils.NewBoolPointer(defaultLanguageDetectionEnabled)},
Injector: &v2alpha1.InjectorConfig{},
},
},
OtelCollector: &v2alpha1.OtelCollectorFeatureConfig{
Expand Down Expand Up @@ -709,6 +711,7 @@ func Test_defaultFeatures(t *testing.T) {
SingleStepInstrumentation: &v2alpha1.SingleStepInstrumentation{
Enabled: apiutils.NewBoolPointer(defaultAPMSingleStepInstrEnabled),
LanguageDetection: &v2alpha1.LanguageDetectionConfig{Enabled: apiutils.NewBoolPointer(defaultLanguageDetectionEnabled)},
Injector: &v2alpha1.InjectorConfig{},
},
},
OtelCollector: &v2alpha1.OtelCollectorFeatureConfig{
Expand Down Expand Up @@ -851,6 +854,7 @@ func Test_defaultFeatures(t *testing.T) {
SingleStepInstrumentation: &v2alpha1.SingleStepInstrumentation{
Enabled: apiutils.NewBoolPointer(defaultAPMSingleStepInstrEnabled),
LanguageDetection: &v2alpha1.LanguageDetectionConfig{Enabled: apiutils.NewBoolPointer(defaultLanguageDetectionEnabled)},
Injector: &v2alpha1.InjectorConfig{},
},
},
OtelCollector: &v2alpha1.OtelCollectorFeatureConfig{
Expand Down Expand Up @@ -993,6 +997,7 @@ func Test_defaultFeatures(t *testing.T) {
SingleStepInstrumentation: &v2alpha1.SingleStepInstrumentation{
Enabled: apiutils.NewBoolPointer(defaultAPMSingleStepInstrEnabled),
LanguageDetection: &v2alpha1.LanguageDetectionConfig{Enabled: apiutils.NewBoolPointer(defaultLanguageDetectionEnabled)},
Injector: &v2alpha1.InjectorConfig{},
},
},
OtelCollector: &v2alpha1.OtelCollectorFeatureConfig{
Expand Down Expand Up @@ -1144,6 +1149,7 @@ func Test_defaultFeatures(t *testing.T) {
SingleStepInstrumentation: &v2alpha1.SingleStepInstrumentation{
Enabled: apiutils.NewBoolPointer(defaultAPMSingleStepInstrEnabled),
LanguageDetection: &v2alpha1.LanguageDetectionConfig{Enabled: apiutils.NewBoolPointer(defaultLanguageDetectionEnabled)},
Injector: &v2alpha1.InjectorConfig{},
},
},
OtelCollector: &v2alpha1.OtelCollectorFeatureConfig{
Expand Down Expand Up @@ -1286,6 +1292,7 @@ func Test_defaultFeatures(t *testing.T) {
SingleStepInstrumentation: &v2alpha1.SingleStepInstrumentation{
Enabled: apiutils.NewBoolPointer(defaultAPMSingleStepInstrEnabled),
LanguageDetection: &v2alpha1.LanguageDetectionConfig{Enabled: apiutils.NewBoolPointer(defaultLanguageDetectionEnabled)},
Injector: &v2alpha1.InjectorConfig{},
},
},
OtelCollector: &v2alpha1.OtelCollectorFeatureConfig{
Expand Down Expand Up @@ -1431,6 +1438,7 @@ func Test_defaultFeatures(t *testing.T) {
SingleStepInstrumentation: &v2alpha1.SingleStepInstrumentation{
Enabled: apiutils.NewBoolPointer(defaultAPMSingleStepInstrEnabled),
LanguageDetection: &v2alpha1.LanguageDetectionConfig{Enabled: apiutils.NewBoolPointer(defaultLanguageDetectionEnabled)},
Injector: &v2alpha1.InjectorConfig{},
},
},
OtelCollector: &v2alpha1.OtelCollectorFeatureConfig{
Expand Down Expand Up @@ -1571,6 +1579,7 @@ func Test_defaultFeatures(t *testing.T) {
SingleStepInstrumentation: &v2alpha1.SingleStepInstrumentation{
Enabled: apiutils.NewBoolPointer(defaultAPMSingleStepInstrEnabled),
LanguageDetection: &v2alpha1.LanguageDetectionConfig{Enabled: apiutils.NewBoolPointer(defaultLanguageDetectionEnabled)},
Injector: &v2alpha1.InjectorConfig{},
},
},
OtelCollector: &v2alpha1.OtelCollectorFeatureConfig{
Expand Down Expand Up @@ -1730,6 +1739,7 @@ func Test_defaultFeatures(t *testing.T) {
SingleStepInstrumentation: &v2alpha1.SingleStepInstrumentation{
Enabled: apiutils.NewBoolPointer(defaultAPMSingleStepInstrEnabled),
LanguageDetection: &v2alpha1.LanguageDetectionConfig{Enabled: apiutils.NewBoolPointer(defaultLanguageDetectionEnabled)},
Injector: &v2alpha1.InjectorConfig{},
},
},
OtelCollector: &v2alpha1.OtelCollectorFeatureConfig{
Expand Down Expand Up @@ -1873,6 +1883,7 @@ func Test_defaultFeatures(t *testing.T) {
SingleStepInstrumentation: &v2alpha1.SingleStepInstrumentation{
Enabled: apiutils.NewBoolPointer(defaultAPMSingleStepInstrEnabled),
LanguageDetection: &v2alpha1.LanguageDetectionConfig{Enabled: apiutils.NewBoolPointer(defaultLanguageDetectionEnabled)},
Injector: &v2alpha1.InjectorConfig{},
},
},
OtelCollector: &v2alpha1.OtelCollectorFeatureConfig{
Expand Down Expand Up @@ -2037,6 +2048,7 @@ func Test_defaultFeatures(t *testing.T) {
SingleStepInstrumentation: &v2alpha1.SingleStepInstrumentation{
Enabled: apiutils.NewBoolPointer(defaultAPMSingleStepInstrEnabled),
LanguageDetection: &v2alpha1.LanguageDetectionConfig{Enabled: apiutils.NewBoolPointer(defaultLanguageDetectionEnabled)},
Injector: &v2alpha1.InjectorConfig{},
},
},
OtelCollector: &v2alpha1.OtelCollectorFeatureConfig{
Expand Down Expand Up @@ -2182,6 +2194,7 @@ func Test_defaultFeatures(t *testing.T) {
SingleStepInstrumentation: &v2alpha1.SingleStepInstrumentation{
Enabled: apiutils.NewBoolPointer(defaultAPMSingleStepInstrEnabled),
LanguageDetection: &v2alpha1.LanguageDetectionConfig{Enabled: apiutils.NewBoolPointer(defaultLanguageDetectionEnabled)},
Injector: &v2alpha1.InjectorConfig{},
},
},
OtelCollector: &v2alpha1.OtelCollectorFeatureConfig{
Expand Down
1 change: 1 addition & 0 deletions internal/controller/datadogagent/feature/apm/envvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const (
DDAPMReceiverPort = "DD_APM_RECEIVER_PORT"
DDAPMReceiverSocket = "DD_APM_RECEIVER_SOCKET"
DDAPMInstrumentationEnabled = "DD_APM_INSTRUMENTATION_ENABLED"
DDAPMInstrumentationInjectorImageTag = "DD_APM_INSTRUMENTATION_INJECTOR_IMAGE_TAG"
DDAPMInstrumentationEnabledNamespaces = "DD_APM_INSTRUMENTATION_ENABLED_NAMESPACES"
DDAPMInstrumentationDisabledNamespaces = "DD_APM_INSTRUMENTATION_DISABLED_NAMESPACES"
DDAPMInstrumentationLibVersions = "DD_APM_INSTRUMENTATION_LIB_VERSIONS"
Expand Down
20 changes: 20 additions & 0 deletions internal/controller/datadogagent/feature/apm/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,17 @@ type instrumentationConfig struct {
disabledNamespaces []string
libVersions map[string]string
languageDetection *languageDetection
injector *injector
}

type languageDetection struct {
enabled bool
}

type injector struct {
imageTag string
}

// ID returns the ID of the Feature
func (f *apmFeature) ID() feature.IDType {
return feature.APMIDType
Expand Down Expand Up @@ -146,6 +151,7 @@ func (f *apmFeature) Configure(dda *v2alpha1.DatadogAgent) (reqComp feature.Requ
f.singleStepInstrumentation.enabledNamespaces = apm.SingleStepInstrumentation.EnabledNamespaces
f.singleStepInstrumentation.libVersions = apm.SingleStepInstrumentation.LibVersions
f.singleStepInstrumentation.languageDetection = &languageDetection{enabled: apiutils.BoolValue(dda.Spec.Features.APM.SingleStepInstrumentation.LanguageDetection.Enabled)}
f.singleStepInstrumentation.injector = &injector{imageTag: apm.SingleStepInstrumentation.Injector.ImageTag}
reqComp.ClusterAgent = feature.RequiredComponent{
IsRequired: apiutils.NewBoolPointer(true),
Containers: []apicommon.AgentContainerName{
Expand All @@ -163,6 +169,13 @@ func (f *apmFeature) Configure(dda *v2alpha1.DatadogAgent) (reqComp feature.Requ
return reqComp
}

func (f *apmFeature) shouldSetCustomInjectorImage() bool {
return f.singleStepInstrumentation != nil &&
f.singleStepInstrumentation.enabled &&
f.singleStepInstrumentation.injector != nil &&
f.singleStepInstrumentation.injector.imageTag != ""
}

func (f *apmFeature) shouldEnableLanguageDetection() bool {
return f.singleStepInstrumentation != nil &&
f.singleStepInstrumentation.enabled &&
Expand Down Expand Up @@ -272,6 +285,13 @@ func (f *apmFeature) ManageClusterAgent(managers feature.PodTemplateManagers) er
Value: apiutils.BoolToString(&f.singleStepInstrumentation.enabled),
})

if f.shouldSetCustomInjectorImage() {
managers.EnvVar().AddEnvVarToContainer(apicommon.ClusterAgentContainerName, &corev1.EnvVar{
Name: DDAPMInstrumentationInjectorImageTag,
Value: f.singleStepInstrumentation.injector.imageTag,
})
}

if f.shouldEnableLanguageDetection() {
managers.EnvVar().AddEnvVarToContainer(apicommon.ClusterAgentContainerName, &corev1.EnvVar{
Name: DDLanguageDetectionEnabled,
Expand Down
Loading

0 comments on commit 06090e9

Please sign in to comment.