Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PROCS-3915] Add agent version check to Orchestrator Explorer feature to determine if process agent is required #1125

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I understand V1 is being deprecated. however this was done to maintain current behavior.


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
Loading