[FEATURE] host pid mode support for k3s-server and k3s-agent (#929)

pull/938/head
Hiroto Funakoshi 3 years ago committed by GitHub
parent a74f8ea18c
commit c16bf6f3d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      cmd/cluster/clusterCreate.go
  2. 20
      pkg/config/transform.go
  3. 1
      pkg/config/v1alpha3/types.go
  4. 4
      pkg/runtimes/docker/translate.go
  5. 1
      pkg/types/types.go

@ -327,6 +327,9 @@ func NewCmdClusterCreate() *cobra.Command {
cmd.Flags().String("agents-memory", "", "Memory limit imposed on the agents nodes [From docker]")
_ = cfgViper.BindPFlag("options.runtime.agentsmemory", cmd.Flags().Lookup("agents-memory"))
cmd.Flags().Bool("host-pid-mode", false, "Enable host pid mode of server(s) and agent(s)")
_ = cfgViper.BindPFlag("options.runtime.hostpidmode", cmd.Flags().Lookup("host-pid-mode"))
/* Image Importing */
cmd.Flags().Bool("no-image-volume", false, "Disable the creation of a volume for importing images")
_ = cfgViper.BindPFlag("options.k3d.disableimagevolume", cmd.Flags().Lookup("no-image-volume"))

@ -136,11 +136,12 @@ func TransformSimpleToClusterConfig(ctx context.Context, runtime runtimes.Runtim
for i := 0; i < simpleConfig.Servers; i++ {
serverNode := k3d.Node{
Name: client.GenerateNodeName(newCluster.Name, k3d.ServerRole, i),
Role: k3d.ServerRole,
Image: simpleConfig.Image,
ServerOpts: k3d.ServerOpts{},
Memory: simpleConfig.Options.Runtime.ServersMemory,
Name: client.GenerateNodeName(newCluster.Name, k3d.ServerRole, i),
Role: k3d.ServerRole,
Image: simpleConfig.Image,
ServerOpts: k3d.ServerOpts{},
Memory: simpleConfig.Options.Runtime.ServersMemory,
HostPidMode: simpleConfig.Options.Runtime.HostPidMode,
}
// first server node will be init node if we have more than one server specified but no external datastore
@ -158,10 +159,11 @@ func TransformSimpleToClusterConfig(ctx context.Context, runtime runtimes.Runtim
for i := 0; i < simpleConfig.Agents; i++ {
agentNode := k3d.Node{
Name: client.GenerateNodeName(newCluster.Name, k3d.AgentRole, i),
Role: k3d.AgentRole,
Image: simpleConfig.Image,
Memory: simpleConfig.Options.Runtime.AgentsMemory,
Name: client.GenerateNodeName(newCluster.Name, k3d.AgentRole, i),
Role: k3d.AgentRole,
Image: simpleConfig.Image,
Memory: simpleConfig.Options.Runtime.AgentsMemory,
HostPidMode: simpleConfig.Options.Runtime.HostPidMode,
}
newCluster.Nodes = append(newCluster.Nodes, &agentNode)
}

@ -104,6 +104,7 @@ type SimpleConfigOptionsRuntime struct {
GPURequest string `mapstructure:"gpuRequest" yaml:"gpuRequest,omitempty" json:"gpuRequest,omitempty"`
ServersMemory string `mapstructure:"serversMemory" yaml:"serversMemory,omitempty" json:"serversMemory,omitempty"`
AgentsMemory string `mapstructure:"agentsMemory" yaml:"agentsMemory,omitempty" json:"agentsMemory,omitempty"`
HostPidMode bool `mapstructure:"hostPidMode" yaml:"hostPidMode,omitempty" json:"hostPidMode,omitempty"`
Labels []LabelWithNodeFilters `mapstructure:"labels" yaml:"labels,omitempty" json:"labels,omitempty"`
}

@ -120,6 +120,10 @@ func TranslateNodeToContainer(node *k3d.Node) (*NodeInDocker, error) {
// TODO: can we replace this by a reduced set of capabilities?
hostConfig.Privileged = true
if node.HostPidMode {
hostConfig.PidMode = "host"
}
/* Volumes */
hostConfig.Binds = node.Volumes
// containerConfig.Volumes = map[string]struct{}{} // TODO: do we need this? We only used binds before

@ -284,6 +284,7 @@ type Node struct {
Ports nat.PortMap `yaml:"portMappings" json:"portMappings,omitempty"`
Restart bool `yaml:"restart" json:"restart,omitempty"`
Created string `yaml:"created" json:"created,omitempty"`
HostPidMode bool `yaml:"hostPidMode" json:"hostPidMode,omitempty"`
RuntimeLabels map[string]string `yaml:"runtimeLabels" json:"runtimeLabels,omitempty"`
K3sNodeLabels map[string]string `yaml:"k3sNodeLabels" json:"k3sNodeLabels,omitempty"`
Networks []string // filled automatically

Loading…
Cancel
Save