diff --git a/cmd/registry/registryCreate.go b/cmd/registry/registryCreate.go index 3eaa42852..0309a6665 100644 --- a/cmd/registry/registryCreate.go +++ b/cmd/registry/registryCreate.go @@ -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): @@ -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 @@ -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 } diff --git a/pkg/client/cluster.go b/pkg/client/cluster.go index 5b5a99cf8..47b32a35d 100644 --- a/pkg/client/cluster.go +++ b/pkg/client/cluster.go @@ -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) diff --git a/pkg/client/registry.go b/pkg/client/registry.go index 7432c4c4a..6b52aa08d 100644 --- a/pkg/client/registry.go +++ b/pkg/client/registry.go @@ -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, } diff --git a/pkg/runtimes/docker/node.go b/pkg/runtimes/docker/node.go index f9399d489..b0e1f4d8b 100644 --- a/pkg/runtimes/docker/node.go +++ b/pkg/runtimes/docker/node.go @@ -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() { diff --git a/pkg/types/defaults.go b/pkg/types/defaults.go index 4acd19ab1..018a79ca4 100644 --- a/pkg/types/defaults.go +++ b/pkg/types/defaults.go @@ -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" diff --git a/pkg/types/registry.go b/pkg/types/registry.go index 07102a6ab..aae83f9b3 100644 --- a/pkg/types/registry.go +++ b/pkg/types/registry.go @@ -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"`