Skip to content

Commit

Permalink
[create-vm-agent-config-adxt-84] docker: Added PoC for custom config
Browse files Browse the repository at this point in the history
  • Loading branch information
CelianR committed Jan 17, 2025
1 parent 164b58b commit 736bcae
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 10 deletions.
9 changes: 9 additions & 0 deletions components/datadog/dockeragentparams/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ type Params struct {
PulumiDependsOn []pulumi.ResourceOption
// FIPS is true if FIPS image is needed.
FIPS bool
// Will be merged with the default agent configuration
AgentConfig string
}

type Option = func(*Params) error
Expand Down Expand Up @@ -244,3 +246,10 @@ func WithExtraComposeInlineManifest(cpms ...docker.ComposeInlineManifest) func(*
return nil
}
}

func WithAgentConfig(config string) func(*Params) error {
return func(p *Params) error {
p.AgentConfig = config
return nil
}
}
64 changes: 62 additions & 2 deletions components/docker/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (d *Manager) ComposeFileUp(composeFilePath string, opts ...pulumi.ResourceO
)
}

func (d *Manager) ComposeStrUp(name string, composeManifests []ComposeInlineManifest, envVars pulumi.StringMap, opts ...pulumi.ResourceOption) (command.Command, error) {
func (d *Manager) ComposeStrUp(name string, composeManifests []ComposeInlineManifest, envVars pulumi.StringMap, opts ...pulumi.ResourceOption) (pulumi.Resource, error) {
opts = utils.MergeOptions(d.opts, opts...)

homeCmd, composePath, err := d.Host.OS.FileManager().HomeDirectory(name+"-compose-tmp", opts...)
Expand Down Expand Up @@ -128,7 +128,7 @@ func (d *Manager) ComposeStrUp(name string, composeManifests []ComposeInlineMani
envVars["CONTENT_HASH"] = contentHash

composeFileArgs := "-f " + strings.Join(remoteComposePaths, " -f ")
return d.Host.OS.Runner().Command(
cmd, err := d.Host.OS.Runner().Command(
d.namer.ResourceName("compose-run", name),
&command.Args{
Create: pulumi.Sprintf("docker-compose %s up --detach --wait --timeout %d", composeFileArgs, defaultTimeout),
Expand All @@ -137,6 +137,66 @@ func (d *Manager) ComposeStrUp(name string, composeManifests []ComposeInlineMani
},
utils.MergeOptions(d.opts, utils.PulumiDependsOn(runCommandDeps...), pulumi.DeleteBeforeReplace(true))...,
)
if err != nil {
return nil, err
}

// Merge configurations if needed
// TODO: If ... return cmd, nil

// TODO: Check errors
// 1. Read default agent configuration
// TODO: Restore config on delete ?
cmd2, err := d.Host.OS.Runner().Command(
d.namer.ResourceName("read-container-agent-config", name),
&command.Args{
Create: pulumi.Sprintf("docker-compose %s exec -T %s /bin/cat /etc/datadog-agent/datadog.yaml", composeFileArgs, name),
},
utils.MergeOptions(d.opts, utils.PulumiDependsOn(cmd))...,
)

if err != nil {
return nil, err
}

// 2. Merge default and custom configurations
// TODO: True merge not concat + with custom configuration
mergedConfig := cmd2.StdoutOutput().ApplyT(func(output string) string {
return output + "\n" + "hello: world"
}).(pulumi.StringOutput)

// 3. Write merged configuration
// 3.a. Copy to host config
// TODO: True tmp
cmd3, err := d.Host.OS.FileManager().CopyInlineFile(mergedConfig, "/tmp/datadog.yaml", opts...)

if err != nil {
return nil, err
}

// 3.b. Copy to container config
// docker-compose -f agent-compose-tmp/docker-compose-agent.yml cp /tmp/datadog.yaml agent:/tmp/datadog.yaml
cmd4, err := d.Host.OS.Runner().Command(
d.namer.ResourceName("write-container-agent-config", name),
&command.Args{
Create: pulumi.Sprintf("docker-compose %s cp /tmp/datadog.yaml %s:/etc/datadog-agent/datadog.yaml", composeFileArgs, name),
},
utils.MergeOptions(d.opts, utils.PulumiDependsOn(cmd3))...,
)

if err != nil {
return nil, err
}

return cmd4, err

// return d.Host.OS.Runner().Command(
// d.namer.ResourceName("cc-test", name),
// &command.Args{
// Create: pulumi.Sprintf("docker-compose %s exec -T %s /bin/bash -c 'echo \"hello: world\" >> /etc/datadog-agent/datadog.yaml'", composeFileArgs, name),
// },
// utils.MergeOptions(d.opts, utils.PulumiDependsOn(a))...,
// )
}

func (d *Manager) install() (command.Command, error) {
Expand Down
15 changes: 7 additions & 8 deletions scenarios/aws/ec2/vm_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,13 @@ func VMRunWithDocker(ctx *pulumi.Context) error {
agentOptions = append(agentOptions, dockeragentparams.WithFakeintake(fakeintake))
}

// TODO A: Update docker params
// if env.AgentConfigPath() != "" {
// configContent, err := env.CustomAgentConfig()
// if err != nil {
// return err
// }
// agentOptions = append(agentOptions, dockeragentparams.WithAgentConfig(configContent))
// }
if env.AgentConfigPath() != "" {
configContent, err := env.CustomAgentConfig()
if err != nil {
return err
}
agentOptions = append(agentOptions, dockeragentparams.WithAgentConfig(configContent))
}

if env.TestingWorkloadDeploy() {
agentOptions = append(agentOptions, dockeragentparams.WithExtraComposeManifest(dogstatsd.DockerComposeManifest.Name, dogstatsd.DockerComposeManifest.Content))
Expand Down

0 comments on commit 736bcae

Please sign in to comment.