Skip to content

Commit

Permalink
[PROCS-3915] Add agent version check to Orchestrator Explorer feature…
Browse files Browse the repository at this point in the history
… to determine if process agent is required (#1125)

* Add agent version check to orchestrator explorer

* Add unit tests for agent version checks

* Add unit tests for agent version checks

* fix v1 tests

* Fix generated files

* Update agent check logic

* min version var
  • Loading branch information
daniel-taf authored Mar 26, 2024
1 parent 98276c5 commit 7db14b9
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
23 changes: 21 additions & 2 deletions controllers/datadogagent/feature/orchestratorexplorer/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ import (
apiutils "github.com/DataDog/datadog-operator/apis/utils"
"github.com/DataDog/datadog-operator/pkg/controller/utils/comparison"
"github.com/DataDog/datadog-operator/pkg/kubernetes"
"github.com/DataDog/datadog-operator/pkg/utils"
"github.com/go-logr/logr"

apicommon "github.com/DataDog/datadog-operator/apis/datadoghq/common"
apicommonv1 "github.com/DataDog/datadog-operator/apis/datadoghq/common/v1"
common "github.com/DataDog/datadog-operator/controllers/datadogagent/common"
"github.com/DataDog/datadog-operator/controllers/datadogagent/component"
"github.com/DataDog/datadog-operator/controllers/datadogagent/feature"
"github.com/DataDog/datadog-operator/controllers/datadogagent/object"
"github.com/DataDog/datadog-operator/controllers/datadogagent/object/volume"
Expand Down Expand Up @@ -60,8 +62,12 @@ type orchestratorExplorerFeature struct {
logger logr.Logger
customConfigAnnotationKey string
customConfigAnnotationValue string

processAgentRequired bool
}

const NoProcessAgentMinVersion = "7.51.0"

// ID returns the ID of the Feature
func (f *orchestratorExplorerFeature) ID() feature.IDType {
return feature.OrchestratorExplorerIDType
Expand All @@ -74,9 +80,19 @@ func (f *orchestratorExplorerFeature) Configure(dda *v2alpha1.DatadogAgent) (req

if orchestratorExplorer != nil && apiutils.BoolValue(orchestratorExplorer.Enabled) {
reqComp.ClusterAgent.IsRequired = apiutils.NewBoolPointer(true)
reqContainers := []apicommonv1.AgentContainerName{apicommonv1.CoreAgentContainerName}

// Process Agent is not required as of agent version 7.51.0
if nodeAgent, ok := dda.Spec.Override[v2alpha1.NodeAgentComponentName]; ok {
if nodeAgent.Image != nil && !utils.IsAboveMinVersion(component.GetAgentVersionFromImage(*nodeAgent.Image), NoProcessAgentMinVersion) {
f.processAgentRequired = true
reqContainers = append(reqContainers, apicommonv1.ProcessAgentContainerName)
}
}

reqComp.Agent = feature.RequiredComponent{
IsRequired: apiutils.NewBoolPointer(true),
Containers: []apicommonv1.AgentContainerName{apicommonv1.CoreAgentContainerName, apicommonv1.ProcessAgentContainerName},
Containers: reqContainers,
}

if orchestratorExplorer.Conf != nil {
Expand Down Expand Up @@ -116,6 +132,7 @@ func (f *orchestratorExplorerFeature) Configure(dda *v2alpha1.DatadogAgent) (req
func (f *orchestratorExplorerFeature) ConfigureV1(dda *v1alpha1.DatadogAgent) (reqComp feature.RequiredComponents) {
f.owner = dda
orchestratorExplorer := dda.Spec.Features.OrchestratorExplorer
f.processAgentRequired = true

if orchestratorExplorer != nil && apiutils.BoolValue(orchestratorExplorer.Enabled) {
reqComp.ClusterAgent.IsRequired = apiutils.NewBoolPointer(true)
Expand Down Expand Up @@ -231,7 +248,9 @@ func (f *orchestratorExplorerFeature) ManageSingleContainerNodeAgent(managers fe
// It should do nothing if the feature doesn't need to configure it.
func (f *orchestratorExplorerFeature) ManageNodeAgent(managers feature.PodTemplateManagers, provider string) error {
for _, env := range f.getEnvVars() {
managers.EnvVar().AddEnvVarToContainer(apicommonv1.ProcessAgentContainerName, env)
if f.processAgentRequired {
managers.EnvVar().AddEnvVarToContainer(apicommonv1.ProcessAgentContainerName, env)
}
managers.EnvVar().AddEnvVarToContainer(apicommonv1.CoreAgentContainerName, env)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

apicommon "github.com/DataDog/datadog-operator/apis/datadoghq/common"
apicommonv1 "github.com/DataDog/datadog-operator/apis/datadoghq/common/v1"
"github.com/DataDog/datadog-operator/apis/datadoghq/v2alpha1"
v2alpha1test "github.com/DataDog/datadog-operator/apis/datadoghq/v2alpha1/test"

apiutils "github.com/DataDog/datadog-operator/apis/utils"
Expand Down Expand Up @@ -67,10 +68,11 @@ func Test_orchestratorExplorerFeature_Configure(t *testing.T) {
WithOrchestratorExplorerExtraTags([]string{"a:z", "b:y", "c:x"}).
WithOrchestratorExplorerDDUrl("https://foo.bar").
WithOrchestratorExplorerCustomConfigData(customConfDataV2).
WithComponentOverride(v2alpha1.NodeAgentComponentName, v2alpha1.DatadogAgentComponentOverride{Image: &apicommonv1.AgentImageConfig{Tag: "7.51.0"}}).
Build(),
WantConfigure: true,
ClusterAgent: orchestratorExplorerClusterAgentWantFuncV2(),
Agent: test.NewDefaultComponentTest().WithWantFunc(orchestratorExplorerNodeAgentWantFunc),
Agent: test.NewDefaultComponentTest().WithWantFunc(orchestratorExplorerNodeAgentNoProcessAgentWantFunc),
},
{
Name: "v2alpha1 orchestrator explorer enabled and runs on cluster checks runner",
Expand All @@ -82,12 +84,27 @@ func Test_orchestratorExplorerFeature_Configure(t *testing.T) {
WithOrchestratorExplorerCustomConfigData(customConfDataV2).
WithClusterChecksEnabled(true).
WithClusterChecksUseCLCEnabled(true).
WithComponentOverride(v2alpha1.NodeAgentComponentName, v2alpha1.DatadogAgentComponentOverride{Image: &apicommonv1.AgentImageConfig{Tag: "7.51.0"}}).
Build(),
WantConfigure: true,
ClusterAgent: orchestratorExplorerClusterAgentWantFuncV2(),
Agent: test.NewDefaultComponentTest().WithWantFunc(orchestratorExplorerNodeAgentWantFunc),
Agent: test.NewDefaultComponentTest().WithWantFunc(orchestratorExplorerNodeAgentNoProcessAgentWantFunc),
ClusterChecksRunner: test.NewDefaultComponentTest().WithWantFunc(orchestratorExplorerClusterChecksRunnerWantFunc),
},
{
Name: "v2alpha1 orchestrator explorer enabled on version requiring process agent",
DDAv2: v2alpha1test.NewDatadogAgentBuilder().
WithOrchestratorExplorerEnabled(true).
WithOrchestratorExplorerScrubContainers(true).
WithOrchestratorExplorerExtraTags([]string{"a:z", "b:y", "c:x"}).
WithOrchestratorExplorerDDUrl("https://foo.bar").
WithOrchestratorExplorerCustomConfigData(customConfDataV2).
WithComponentOverride(v2alpha1.NodeAgentComponentName, v2alpha1.DatadogAgentComponentOverride{Image: &apicommonv1.AgentImageConfig{Tag: "7.50.0"}}).
Build(),
WantConfigure: true,
ClusterAgent: orchestratorExplorerClusterAgentWantFuncV2(),
Agent: test.NewDefaultComponentTest().WithWantFunc(orchestratorExplorerNodeAgentWantFunc),
},
}

tests.Run(t, buildOrchestratorExplorerFeature)
Expand All @@ -97,6 +114,16 @@ func orchestratorExplorerNodeAgentWantFunc(t testing.TB, mgrInterface feature.Po
mgr := mgrInterface.(*fake.PodTemplateManagers)
agentEnvVars := mgr.EnvVarMgr.EnvVarsByC[apicommonv1.ProcessAgentContainerName]
assert.True(t, apiutils.IsEqualStruct(agentEnvVars, expectedOrchestratorEnvsV2), "Process agent envvars \ndiff = %s", cmp.Diff(agentEnvVars, expectedOrchestratorEnvsV2))
agentEnvVars = mgr.EnvVarMgr.EnvVarsByC[apicommonv1.CoreAgentContainerName]
assert.True(t, apiutils.IsEqualStruct(agentEnvVars, expectedOrchestratorEnvsV2), "Core agent envvars \ndiff = %s", cmp.Diff(agentEnvVars, expectedOrchestratorEnvsV2))
}

func orchestratorExplorerNodeAgentNoProcessAgentWantFunc(t testing.TB, mgrInterface feature.PodTemplateManagers) {
mgr := mgrInterface.(*fake.PodTemplateManagers)
agentEnvVars := mgr.EnvVarMgr.EnvVarsByC[apicommonv1.ProcessAgentContainerName]
assert.True(t, apiutils.IsEqualStruct(agentEnvVars, nil), "Process agent envvars \ndiff = %s", cmp.Diff(agentEnvVars, expectedOrchestratorEnvsV2))
agentEnvVars = mgr.EnvVarMgr.EnvVarsByC[apicommonv1.CoreAgentContainerName]
assert.True(t, apiutils.IsEqualStruct(agentEnvVars, expectedOrchestratorEnvsV2), "Core agent envvars \ndiff = %s", cmp.Diff(agentEnvVars, expectedOrchestratorEnvsV2))
}

func orchestratorExplorerClusterChecksRunnerWantFunc(t testing.TB, mgrInterface feature.PodTemplateManagers) {
Expand Down

0 comments on commit 7db14b9

Please sign in to comment.