Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Set nofile ulimit for loadbalancer container #7344

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/blang/semver v3.5.1+incompatible
github.com/docker/docker v20.10.17+incompatible
github.com/docker/go-connections v0.4.0
github.com/docker/go-units v0.4.0
github.com/flatcar/ignition v0.36.2
github.com/go-logr/logr v1.2.3
github.com/onsi/ginkgo/v2 v2.2.0
Expand Down Expand Up @@ -49,7 +50,6 @@ require (
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/distribution v2.8.1+incompatible // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/drone/envsubst/v2 v2.0.0-20210730161058-179042472c46 // indirect
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
Expand Down
1 change: 1 addition & 0 deletions test/infrastructure/container/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ func (d *dockerRuntime) RunContainer(ctx context.Context, runConfig *RunContaine
Tmpfs: runConfig.Tmpfs,
PortBindings: nat.PortMap{},
RestartPolicy: dockercontainer.RestartPolicy{Name: "unless-stopped"},
Resources: runConfig.Resources,
}
networkConfig := network.NetworkingConfig{}

Expand Down
4 changes: 4 additions & 0 deletions test/infrastructure/container/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"fmt"
"io"

dockercontainer "github.com/docker/docker/api/types/container"

clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
)

Expand Down Expand Up @@ -95,6 +97,8 @@ type RunContainerInput struct {
PortMappings []PortMapping
// IPFamily is the IP version to use.
IPFamily clusterv1.ClusterIPFamily
// Resource limits and settings for the container.
Resources dockercontainer.Resources
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could also be exposed at the DockerCluster level for resource limits on the load balancer, but I wanted some feedback before making this a user-facing change.

}

// ExecContainerInput contains values for running exec on a container.
Expand Down
20 changes: 18 additions & 2 deletions test/infrastructure/docker/internal/docker/kind_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"fmt"
"net"

dockercontainer "github.com/docker/docker/api/types/container"
"github.com/docker/go-units"
"github.com/pkg/errors"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/kind/pkg/apis/config/v1alpha4"
Expand Down Expand Up @@ -52,6 +54,7 @@ type nodeCreateOpts struct {
PortMappings []v1alpha4.PortMapping
Labels map[string]string
IPFamily clusterv1.ClusterIPFamily
Resources dockercontainer.Resources
}

// CreateControlPlaneNode will create a new control plane container.
Expand Down Expand Up @@ -116,20 +119,32 @@ func (m *Manager) CreateExternalLoadBalancerNode(ctx context.Context, name, imag
}
port = p
}

// load balancer port mapping
portMappings := []v1alpha4.PortMapping{{
ListenAddress: listenAddress,
HostPort: port,
ContainerPort: ControlPlanePort,
Protocol: v1alpha4.PortMappingProtocolTCP,
}}

// load balancer resource limits
resources := dockercontainer.Resources{
Ulimits: []*units.Ulimit{
{
Name: "nofile",
Soft: 65536,
Hard: 65536,
},
},
}

createOpts := &nodeCreateOpts{
Name: name,
Image: image,
ClusterName: clusterName,
Role: constants.ExternalLoadBalancerNodeRoleValue,
PortMappings: portMappings,
Resources: resources,
}
node, err := createNode(ctx, createOpts)
if err != nil {
Expand Down Expand Up @@ -168,7 +183,8 @@ func createNode(ctx context.Context, opts *nodeCreateOpts) (*types.Node, error)
"/tmp": "", // various things depend on working /tmp
"/run": "", // systemd wants a writable /run
},
IPFamily: opts.IPFamily,
Resources: opts.Resources,
IPFamily: opts.IPFamily,
}
log.V(6).Info("Container run options: %+v", runOptions)

Expand Down