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

[Enhancement] Improved Podman compatibility #868

Merged
merged 6 commits into from
Dec 4, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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
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.Network, "Specify the network connected to the registry")
iwilltry42 marked this conversation as resolved.
Show resolved Hide resolved

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