-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DatadogAgent][Flare] Additional environment variables and RBAC to pe…
…rmit user manifests retrieval (#1477) * Inject DCA, node Agent and DDA names in DCA * Add DCA RBAC to query dd CR * Add utils test * Change datadog_agent_cr_name to datadogagent_cr_name
- Loading branch information
Showing
6 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
internal/controller/datadogagent/feature/enabledefault/const.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// 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-present Datadog, Inc. | ||
|
||
package enabledefault | ||
|
||
const ( | ||
DDAgentDaemonSet = "AGENT_DAEMONSET" | ||
DDClusterAgentDeployment = "CLUSTER_AGENT_DEPLOYMENT" | ||
DDDatadogAgentCustomResource = "DATADOGAGENT_CR_NAME" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
internal/controller/datadogagent/feature/enabledefault/utils.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// 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-present Datadog, Inc. | ||
|
||
package enabledefault | ||
|
||
import ( | ||
"github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1" | ||
componentagent "github.com/DataDog/datadog-operator/internal/controller/datadogagent/component/agent" | ||
componentdca "github.com/DataDog/datadog-operator/internal/controller/datadogagent/component/clusteragent" | ||
) | ||
|
||
// getDaemonSetNameFromDatadogAgent returns the expected node Agent DS/EDS name based on | ||
// the DDA name and nodeAgent name override | ||
func getDaemonSetNameFromDatadogAgent(dda *v2alpha1.DatadogAgent) string { | ||
dsName := componentagent.GetAgentName(dda) | ||
if componentOverride, ok := dda.Spec.Override[v2alpha1.NodeAgentComponentName]; ok { | ||
if componentOverride.Name != nil && *componentOverride.Name != "" { | ||
dsName = *componentOverride.Name | ||
} | ||
} | ||
return dsName | ||
} | ||
|
||
// getDeploymentNameFromDatadogAgent returns the expected Cluster Agent Deployment name based on | ||
// the DDA name and clusterAgent name override | ||
func getDeploymentNameFromDatadogAgent(dda *v2alpha1.DatadogAgent) string { | ||
deployName := componentdca.GetClusterAgentName(dda) | ||
if componentOverride, ok := dda.Spec.Override[v2alpha1.ClusterAgentComponentName]; ok { | ||
if componentOverride.Name != nil && *componentOverride.Name != "" { | ||
deployName = *componentOverride.Name | ||
} | ||
} | ||
return deployName | ||
} |
84 changes: 84 additions & 0 deletions
84
internal/controller/datadogagent/feature/enabledefault/utils_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// 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-present Datadog, Inc. | ||
|
||
package enabledefault | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1" | ||
v2alpha1test "github.com/DataDog/datadog-operator/api/datadoghq/v2alpha1/test" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_getDaemonSetNameFromDatadogAgent(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
ddaName string | ||
overrideAgentName string | ||
expectedName string | ||
}{ | ||
{ | ||
name: "No override", | ||
ddaName: "foo", | ||
overrideAgentName: "", | ||
expectedName: "foo-agent", | ||
}, | ||
{ | ||
name: "With override", | ||
ddaName: "bar", | ||
overrideAgentName: "node", | ||
expectedName: "node", | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
dda := v2alpha1test.NewDatadogAgentBuilder(). | ||
WithName(tt.ddaName). | ||
WithComponentOverride(v2alpha1.NodeAgentComponentName, v2alpha1.DatadogAgentComponentOverride{ | ||
Name: &tt.overrideAgentName, | ||
}). | ||
Build() | ||
dsName := getDaemonSetNameFromDatadogAgent(dda) | ||
assert.Equal(t, tt.expectedName, dsName) | ||
}) | ||
} | ||
} | ||
|
||
func Test_getDeploymentNameFromDatadogAgent(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
ddaName string | ||
overrideClusterAgentName string | ||
expectedName string | ||
}{ | ||
{ | ||
name: "No override", | ||
ddaName: "foo", | ||
overrideClusterAgentName: "", | ||
expectedName: "foo-cluster-agent", | ||
}, | ||
{ | ||
name: "With override", | ||
ddaName: "bar", | ||
overrideClusterAgentName: "dca", | ||
expectedName: "dca", | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
dda := v2alpha1test.NewDatadogAgentBuilder(). | ||
WithName(tt.ddaName). | ||
WithComponentOverride(v2alpha1.ClusterAgentComponentName, v2alpha1.DatadogAgentComponentOverride{ | ||
Name: &tt.overrideClusterAgentName, | ||
}). | ||
Build() | ||
deployName := getDeploymentNameFromDatadogAgent(dda) | ||
assert.Equal(t, tt.expectedName, deployName) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters