-
Notifications
You must be signed in to change notification settings - Fork 40
/
vector_container_config_provider.go
78 lines (67 loc) · 2 KB
/
vector_container_config_provider.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package vector
import (
"fmt"
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/docker_manager"
"github.com/kurtosis-tech/stacktrace"
)
const (
shBinaryFilepath = "/bin/sh"
printfCmdName = "printf"
shCmdFlag = "-c"
)
type vectorContainerConfigProvider struct {
config *VectorConfig
}
func newVectorContainerConfigProvider(config *VectorConfig) *vectorContainerConfigProvider {
return &vectorContainerConfigProvider{config: config}
}
func (vector *vectorContainerConfigProvider) GetContainerArgs(
containerName string,
containerLabels map[string]string,
networkId string,
logsStorageVolumeName string,
) (*docker_manager.CreateAndStartContainerArgs, error) {
volumeMounts := map[string]string{
logsStorageVolumeName: logsStorageDirpath,
}
logsAggregatorConfigContentStr, err := vector.config.getConfigFileContent()
if err != nil {
return nil, stacktrace.Propagate(err, "An error occurred getting the Loki server's configuration content")
}
// Create cmd to
// 1. create config file in appropriate location in logs aggregator container
// 2. start the logs aggregator with the config file
overrideCmd := []string{
shCmdFlag,
fmt.Sprintf(
"%v '%v' > %v && %v %v=%v",
printfCmdName,
logsAggregatorConfigContentStr,
configFilepath,
binaryFilepath,
configFileFlag,
configFilepath,
),
}
// The logs aggregator should ALWAYS be running to ensure that no logs are lost for services in enclaves
// Thus, instruct docker to restart the container if it exits with non-zero status code for whatever reason
restartPolicy := docker_manager.RestartPolicy(docker_manager.RestartAlways)
createAndStartArgs := docker_manager.NewCreateAndStartContainerArgsBuilder(
containerImage,
containerName,
networkId,
).WithLabels(
containerLabels,
).WithVolumeMounts(
volumeMounts,
).WithEntrypointArgs(
[]string{
shBinaryFilepath,
},
).WithCmdArgs(
overrideCmd,
).WithRestartPolicy(
restartPolicy,
).Build()
return createAndStartArgs, nil
}