Skip to content

Commit

Permalink
feat(agent): add sysctls option to builder (#966)
Browse files Browse the repository at this point in the history
  • Loading branch information
nandor-magyar authored May 8, 2024
1 parent a71886e commit 764b23f
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 12 deletions.
2 changes: 2 additions & 0 deletions golang/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ GOSEC=v2.19.0
GOLANGCI=v1.57.2
GOFUMPT=v0.6.0
YAMLFMT=v0.11.0
FIELDALIGN=v0.20.0

# support for: linux darwin windows
GOOS?=linux
Expand Down Expand Up @@ -121,6 +122,7 @@ install-go-tools:
go install github.com/securego/gosec/v2/cmd/gosec@${GOSEC}
go install mvdan.cc/gofumpt@${GOFUMPT}
go install github.com/google/yamlfmt/cmd/yamlfmt@${YAMLFMT}
go install go install golang.org/x/tools/go/analysis/passes/fieldalignment/cmd/fieldalignment@${FIELDALIGN}

.PHONY: compile-agents
compile-agents: compile-crane compile-dagent
Expand Down
20 changes: 15 additions & 5 deletions golang/pkg/builder/container/container_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type Builder interface {
WithPullDisplayFunc(imageHelper.PullDisplayFn) Builder
WithExtraHosts(hosts []string) Builder
WithWorkingDirectory(workingDirectory string) Builder
WithSysctls(sysctls map[string]string) Builder
WithPreCreateHooks(hooks ...LifecycleFunc) Builder
WithPostCreateHooks(hooks ...LifecycleFunc) Builder
WithPreStartHooks(hooks ...LifecycleFunc) Builder
Expand All @@ -66,32 +67,33 @@ type DockerContainerBuilder struct {
logger dogger.LogWriter
client client.APIClient
ctx context.Context
logConfig *container.LogConfig
user *int64
networkMap map[string]string
labels map[string]string
pullDisplayFn imageHelper.PullDisplayFn
containerID *string
user *int64
logConfig *container.LogConfig
sysctls map[string]string
workingDirectory string
containerName string
imageWithTag string
registryAuth string
networkMode string
restartPolicy container.RestartPolicyMode
networks []string
hooksPostStart []LifecycleFunc
hooksPreStart []LifecycleFunc
portList []PortBinding
hooksPreCreate []LifecycleFunc
entrypoint []string
cmd []string
shell []string
hooksPostCreate []LifecycleFunc
mountList []mount.Mount
portRanges []PortRangeBinding
portList []PortBinding
hooksPreStart []LifecycleFunc
envList []string
networkAliases []string
extraHosts []string
networks []string
imagePriority imageHelper.PullPriority
tty bool
withoutConflict bool
Expand Down Expand Up @@ -281,6 +283,13 @@ func (dc *DockerContainerBuilder) WithWorkingDirectory(workingDirectory string)
return dc
}

// Sets the the sysctl/kernel parameters for containers runtime,
// key is the name of the setting value is the actual value eg. { "net.core.somaxconn": "1024" }
func (dc *DockerContainerBuilder) WithSysctls(sysctls map[string]string) Builder {
dc.sysctls = sysctls
return dc
}

// Sets an array of hooks which runs before the container is created. ContainerID is nil in these hooks.
func (dc *DockerContainerBuilder) WithPreCreateHooks(hooks ...LifecycleFunc) Builder {
dc.hooksPreCreate = hooks
Expand Down Expand Up @@ -313,6 +322,7 @@ func builderToDockerConfig(dc *DockerContainerBuilder) (hostConfig *container.Ho
PortBindings: portListNat,
AutoRemove: dc.remove,
ExtraHosts: dc.extraHosts,
Sysctls: dc.sysctls,
}

containerConfig = &container.Config{
Expand Down
1 change: 0 additions & 1 deletion web/crux-ui/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: '3.3'
services:
crux-ui:
container_name: crux-ui
Expand Down
4 changes: 2 additions & 2 deletions web/crux-ui/e2e/utils/global.teardown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ export const fetchCruxFromBrowser = async (cookie: string, cruxUrl: string, url:
let body: any = null
try {
body = await res.json()
} catch {
console.error('[ERROR]: Crux fetch failed to parse error body of url', url)
} catch (e: any) {
console.error('[ERROR]: Crux fetch failed to parse error body of url', `${cruxUrl}${url}`, e)
}

if (body && isDyoError(body)) {
Expand Down
3 changes: 1 addition & 2 deletions web/crux-ui/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ const resultOrder = process.env.DNS_DEFAULT_RESULT_ORDER

if (resultOrder) {
dns.setDefaultResultOrder(resultOrder === 'ipv4first' ? 'ipv4first' : 'verbatim')
} else if (process.env.NODE_ENV !== 'production') {
dns.setDefaultResultOrder('ipv4first')
}

const nextTranslate = require('next-translate-plugin')

module.exports = {
Expand Down
4 changes: 2 additions & 2 deletions web/crux-ui/src/server/crux-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export const fetchCrux = async (
let body: any = null
try {
body = await res.json()
} catch {
console.error('[ERROR]: Crux fetch failed to parse error body of url', url)
} catch (e: any) {
console.error('[ERROR]: Crux fetch failed to parse error body of url', `${cruxUrl}${url}`, e)
}

const apiError = fromApiError(res.status, body ?? {})
Expand Down

0 comments on commit 764b23f

Please sign in to comment.