Skip to content

Commit

Permalink
Check Scrubbing for default only if OrchestratorExplorer is enabled (#…
Browse files Browse the repository at this point in the history
…308)

`IsDefaultedOrchestratorExplorer` would return `false` for the following
config, since `Scrubbing` would be `nil`:

```
orchestratorExplorer:
  enabled: false
```

Unfortunately, this caused the CR to never be reconciled, since the
defaulting does not add `Scrubbing` if the orchestrator explorer is
disabled.

To work around this, now we only check that `Scrubbing` is defaulted
when the orchestrator explorer is enabled.
  • Loading branch information
juliogreff committed Jun 1, 2021
1 parent 8b4b796 commit 98b09f5
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 6 deletions.
14 changes: 8 additions & 6 deletions api/v1alpha1/datadogagent_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,16 +194,18 @@ func IsDefaultedOrchestratorExplorer(orc *OrchestratorExplorerConfig) bool {
return false
}

if orc.Scrubbing == nil {
if orc.Enabled == nil {
return false
}

if orc.Scrubbing.Containers == nil {
return false
}
if BoolValue(orc.Enabled) {
if orc.Scrubbing == nil {
return false
}

if orc.Enabled == nil {
return false
if orc.Scrubbing.Containers == nil {
return false
}
}

return true
Expand Down
53 changes: 53 additions & 0 deletions api/v1alpha1/datadogagent_default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"testing"

"github.com/google/go-cmp/cmp"
"sigs.k8s.io/yaml"
)

func TestDefaultConfigDogstatsd(t *testing.T) {
Expand Down Expand Up @@ -142,3 +143,55 @@ func TestDefaultFeatures(t *testing.T) {
})
}
}

func TestIsDefaultedOrchestratorExplorer(t *testing.T) {
tests := []struct {
name string
orc *OrchestratorExplorerConfig
want bool
}{
{
name: "empty",
orc: &OrchestratorExplorerConfig{},
want: false,
},
{
name: "enabled orchestrator explorer, no scrubbing",
orc: &OrchestratorExplorerConfig{
Enabled: NewBoolPointer(true),
},
want: false,
},
{
name: "disabled orchestrator",
orc: &OrchestratorExplorerConfig{
Enabled: NewBoolPointer(false),
},
want: true,
},
{
name: "enabled orchestrator, filled scrubbing",
orc: &OrchestratorExplorerConfig{
Enabled: NewBoolPointer(true),
Scrubbing: &Scrubbing{
Containers: NewBoolPointer(true),
},
},
want: true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := IsDefaultedOrchestratorExplorer(tt.orc)
if got != tt.want {
yaml, err := yaml.Marshal(tt.orc)
if err != nil {
t.Fatalf("cannot marshal yaml: %s", err)
}

t.Errorf("got %t, want %t from OrchestratorExplorerConfig:\n%s", got, tt.want, yaml)
}
})
}
}

0 comments on commit 98b09f5

Please sign in to comment.