Skip to content

Commit

Permalink
[Enhancement] Improved Podman compatibility (#868)
Browse files Browse the repository at this point in the history
- fix: Remove call to ContainerExecStart when execing
- feat: Allow creating the registry on user-defined networks
  • Loading branch information
serverwentdown authored Dec 4, 2021
1 parent ca47fac commit 858c314
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 16 deletions.
9 changes: 6 additions & 3 deletions cmd/registry/registryCreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ type regCreatePreProcessedFlags struct {
}

type regCreateFlags struct {
Image string
NoHelp bool
Image string
Network string
NoHelp bool
}

var helptext string = `# You can now use the registry like this (example):
Expand Down Expand Up @@ -103,6 +104,8 @@ func NewCmdRegistryCreate() *cobra.Command {

cmd.Flags().StringVarP(&ppFlags.Port, "port", "p", "random", "Select which port the registry should be listening on on your machine (localhost) (Format: `[HOST:]HOSTPORT`)\n - Example: `k3d registry create --port 0.0.0.0:5111`")

cmd.Flags().StringVar(&flags.Network, "default-network", k3d.DefaultRuntimeNetwork, "Specify the network connected to the registry")

cmd.Flags().BoolVar(&flags.NoHelp, "no-help", false, "Disable the help text (How-To use the registry)")

// done
Expand Down Expand Up @@ -135,5 +138,5 @@ func parseCreateRegistryCmd(cmd *cobra.Command, args []string, flags *regCreateF
registryName = fmt.Sprintf("%s-%s", k3d.DefaultObjectNamePrefix, args[0])
}

return &k3d.Registry{Host: registryName, Image: flags.Image, ExposureOpts: *exposePort}, clusters
return &k3d.Registry{Host: registryName, Image: flags.Image, ExposureOpts: *exposePort, Network: flags.Network}, clusters
}
2 changes: 1 addition & 1 deletion pkg/client/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ func ClusterDelete(ctx context.Context, runtime k3drt.Runtime, cluster *k3d.Clus
if net == cluster.Network.Name {
continue
}
if net == "bridge" || net == "host" {
if net == k3d.DefaultRuntimeNetwork || net == "host" {
continue
}
l.Log().Tracef("net: %s", net)
Expand Down
6 changes: 5 additions & 1 deletion pkg/client/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,15 @@ func RegistryCreate(ctx context.Context, runtime runtimes.Runtime, reg *k3d.Regi
// l.Log().Fatalln(err)
// }

if len(reg.Network) == 0 {
reg.Network = k3d.DefaultRuntimeNetwork
}

registryNode := &k3d.Node{
Name: reg.Host,
Image: reg.Image,
Role: k3d.RegistryRole,
Networks: []string{"bridge"}, // Default network: TODO: change to const from types
Networks: []string{reg.Network},
Restart: true,
}

Expand Down
7 changes: 2 additions & 5 deletions pkg/runtimes/docker/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,16 +403,13 @@ func executeInNode(ctx context.Context, node *k3d.Node, cmd []string, stdin io.R
}

execConnection, err := docker.ContainerExecAttach(ctx, exec.ID, types.ExecStartCheck{
Tty: true,
// Don't use tty true when piping stdin.
Tty: !attachStdin,
})
if err != nil {
return nil, fmt.Errorf("docker failed to attach to exec process in node '%s': %w", node.Name, err)
}

if err := docker.ContainerExecStart(ctx, exec.ID, types.ExecStartCheck{Tty: true}); err != nil {
return nil, fmt.Errorf("docker failed to start exec process in node '%s': %w", node.Name, err)
}

// If we need to write to stdin pipe, start a new goroutine that writes the stream to stdin
if stdin != nil {
go func() {
Expand Down
3 changes: 3 additions & 0 deletions pkg/types/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,6 @@ func GetDefaultObjectName(name string) string {
// container is in a crash loop.
// This makes sense e.g. when a new server is waiting to join an existing cluster and has to wait for other learners to finish.
const DefaultNodeWaitForLogMessageCrashLoopBackOffLimit = 10

// DefaultNetwork defines the default (Docker) runtime network
const DefaultRuntimeNetwork = "bridge"
13 changes: 7 additions & 6 deletions pkg/types/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ const (

// Registry describes a k3d-managed registry
type Registry struct {
ClusterRef string // filled automatically -> if created with a cluster
Protocol string `yaml:"protocol,omitempty" json:"protocol,omitempty"` // default: http
Host string `yaml:"host" json:"host"`
Image string `yaml:"image,omitempty" json:"image,omitempty"`
ExposureOpts ExposureOpts `yaml:"expose" json:"expose"`
Options struct {
ClusterRef string // filled automatically -> if created with a cluster
Protocol string `yaml:"protocol,omitempty" json:"protocol,omitempty"` // default: http
Host string `yaml:"host" json:"host"`
Image string `yaml:"image,omitempty" json:"image,omitempty"`
Network string `yaml:"Network,omitempty" json:"Network,omitempty"`
ExposureOpts ExposureOpts `yaml:"expose" json:"expose"`
Options struct {
ConfigFile string `yaml:"configFile,omitempty" json:"configFile,omitempty"`
Proxy struct {
RemoteURL string `yaml:"remoteURL" json:"remoteURL"`
Expand Down

0 comments on commit 858c314

Please sign in to comment.