Skip to content

Commit

Permalink
Use oneAgent.hostGroup in ApplicationMonitoring mode (#2776)
Browse files Browse the repository at this point in the history
  • Loading branch information
aorcholski authored Feb 20, 2024
1 parent df8dfb0 commit 087cccf
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 10 deletions.
23 changes: 16 additions & 7 deletions pkg/api/v1beta1/dynakube/properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,13 +480,22 @@ func (dk *DynaKube) HostGroup() string {

func (dk *DynaKube) HostGroupAsParam() string {
var hostGroup string
if dk.CloudNativeFullstackMode() && dk.Spec.OneAgent.CloudNativeFullStack.Args != nil {
for _, arg := range dk.Spec.OneAgent.CloudNativeFullStack.Args {
key, value := splitArg(arg)
if key == "--set-host-group" {
hostGroup = value
break
}
var args []string

switch {
case dk.CloudNativeFullstackMode() && dk.Spec.OneAgent.CloudNativeFullStack.Args != nil:
args = dk.Spec.OneAgent.CloudNativeFullStack.Args
case dk.ClassicFullStackMode() && dk.Spec.OneAgent.ClassicFullStack.Args != nil:
args = dk.Spec.OneAgent.ClassicFullStack.Args
case dk.HostMonitoringMode() && dk.Spec.OneAgent.HostMonitoring.Args != nil:
args = dk.Spec.OneAgent.HostMonitoring.Args
}

for _, arg := range args {
key, value := splitArg(arg)
if key == "--set-host-group" {
hostGroup = value
break
}
}
return hostGroup
Expand Down
4 changes: 1 addition & 3 deletions pkg/controllers/dynakube/oneagent/daemonset/arguments.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ func (dsInfo *builderInfo) arguments() ([]string, error) {

dsInfo.appendHostInjectArgs(argMap)

if dsInfo.dynakube.CloudNativeFullstackMode() {
dsInfo.appendHostGroupArg(argMap)
}
dsInfo.appendHostGroupArg(argMap)

return argMap.AsKeyValueStrings(), nil
}
Expand Down
70 changes: 70 additions & 0 deletions pkg/controllers/dynakube/oneagent/daemonset/arguments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ const (
testClusterID = "test-cluster-id"
testURL = "https://testing.dev.dynatracelabs.com/api"
testName = "test-name"

testNewHostGroupName = "newhostgroup"
testOldHostGroupArgument = "--set-host-group=oldhostgroup"
testNewHostGroupArgument = "--set-host-group=newhostgroup"
)

func TestArguments(t *testing.T) {
Expand Down Expand Up @@ -231,4 +235,70 @@ func TestPodSpec_Arguments(t *testing.T) {
podSpecs := daemonset.Spec.Template.Spec
assert.Contains(t, podSpecs.Containers[0].Args, "--set-host-id-source=k8s-node-name")
})
t.Run(`has host-group for classicFullstack`, func(t *testing.T) {
classicInstance := &dynatracev1beta1.DynaKube{
Spec: dynatracev1beta1.DynaKubeSpec{
OneAgent: dynatracev1beta1.OneAgentSpec{
HostGroup: testNewHostGroupName,
ClassicFullStack: &dynatracev1beta1.HostInjectSpec{
Args: []string{testOldHostGroupArgument},
},
},
},
}

dsInfo := HostMonitoring{
builderInfo{
dynakube: classicInstance,
hostInjectSpec: classicInstance.Spec.OneAgent.ClassicFullStack,
},
}
arguments, err := dsInfo.arguments()
require.NoError(t, err)
assert.Contains(t, arguments, testNewHostGroupArgument)
})
t.Run(`has host-group for cloudNativeFullstack`, func(t *testing.T) {
cloudNativeInstance := &dynatracev1beta1.DynaKube{
Spec: dynatracev1beta1.DynaKubeSpec{
OneAgent: dynatracev1beta1.OneAgentSpec{
HostGroup: testNewHostGroupName,
CloudNativeFullStack: &dynatracev1beta1.CloudNativeFullStackSpec{
HostInjectSpec: dynatracev1beta1.HostInjectSpec{Args: []string{testOldHostGroupArgument}},
},
},
},
}

dsInfo := HostMonitoring{
builderInfo{
dynakube: cloudNativeInstance,
hostInjectSpec: &cloudNativeInstance.Spec.OneAgent.CloudNativeFullStack.HostInjectSpec,
},
}
arguments, err := dsInfo.arguments()
require.NoError(t, err)
assert.Contains(t, arguments, testNewHostGroupArgument)
})
t.Run(`has host-group for HostMonitoring`, func(t *testing.T) {
hostMonitoringInstance := &dynatracev1beta1.DynaKube{
Spec: dynatracev1beta1.DynaKubeSpec{
OneAgent: dynatracev1beta1.OneAgentSpec{
HostGroup: testNewHostGroupName,
HostMonitoring: &dynatracev1beta1.HostInjectSpec{
Args: []string{testOldHostGroupArgument},
},
},
},
}

dsInfo := HostMonitoring{
builderInfo{
dynakube: hostMonitoringInstance,
hostInjectSpec: hostMonitoringInstance.Spec.OneAgent.HostMonitoring,
},
}
arguments, err := dsInfo.arguments()
require.NoError(t, err)
assert.Contains(t, arguments, testNewHostGroupArgument)
})
}
7 changes: 7 additions & 0 deletions pkg/injection/startup/dtclient_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func (builder *dtclientBuilder) setOptions() {
builder.addCertCheck()
builder.addProxy()
builder.addNetworkZone()
builder.addHostGroup()
builder.addTrustedCerts()
}

Expand All @@ -59,6 +60,12 @@ func (builder *dtclientBuilder) addNetworkZone() {
}
}

func (builder *dtclientBuilder) addHostGroup() {
if builder.config.HostGroup != "" {
builder.options = append(builder.options, dtclient.HostGroup(builder.config.HostGroup))
}
}

func (builder *dtclientBuilder) addTrustedCerts() {
if builder.config.TrustedCAs != "" {
log.Info("using TrustedCAs, check the secret for more details")
Expand Down
5 changes: 5 additions & 0 deletions pkg/injection/startup/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ func (runner *Runner) getProcessModuleConfig() (*dtclient.ProcessModuleConfig, e
if runner.config.OneAgentNoProxy != "" {
processModuleConfig = processModuleConfig.AddNoProxy(runner.config.OneAgentNoProxy)
}

if runner.config.HostGroup != "" {
processModuleConfig.AddHostGroup(runner.config.HostGroup)
}

return processModuleConfig, nil
}

Expand Down
32 changes: 32 additions & 0 deletions pkg/webhook/validation/dynakube/oneagent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,38 @@ func TestOneAgentHostGroup(t *testing.T) {
1,
createDynakubeWithHostGroup([]string{"--set-host-group=arg"}, "field"),
&defaultCSIDaemonSet)

assertAllowedResponseWithWarnings(t,
1,
&dynatracev1beta1.DynaKube{
ObjectMeta: defaultDynakubeObjectMeta,
Spec: dynatracev1beta1.DynaKubeSpec{
APIURL: testApiUrl,
OneAgent: dynatracev1beta1.OneAgentSpec{
ClassicFullStack: &dynatracev1beta1.HostInjectSpec{
Args: []string{"--set-host-group=arg"},
},
HostGroup: "",
},
},
},
&defaultCSIDaemonSet)

assertAllowedResponseWithWarnings(t,
1,
&dynatracev1beta1.DynaKube{
ObjectMeta: defaultDynakubeObjectMeta,
Spec: dynatracev1beta1.DynaKubeSpec{
APIURL: testApiUrl,
OneAgent: dynatracev1beta1.OneAgentSpec{
HostMonitoring: &dynatracev1beta1.HostInjectSpec{
Args: []string{"--set-host-group=arg"},
},
HostGroup: "",
},
},
},
&defaultCSIDaemonSet)
})
}

Expand Down

0 comments on commit 087cccf

Please sign in to comment.