Skip to content

Commit 201b614

Browse files
committed
Revert "enhancement: enforcing the internal registry port matching the external one (#1550)"
This reverts commit c569517.
1 parent 3b03590 commit 201b614

File tree

8 files changed

+8
-64
lines changed

8 files changed

+8
-64
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,13 @@ K3D_HELPER_VERSION ?=
6666
# Go options
6767
GO ?= go
6868
GOENVPATH := $(shell go env GOPATH)
69+
PKG := $(shell go work vendor)
6970
TAGS :=
7071
TESTS := ./...
7172
TESTFLAGS :=
7273
LDFLAGS := -w -s -X github.com/k3d-io/k3d/v5/version.Version=${GIT_TAG} -X github.com/k3d-io/k3d/v5/version.K3sVersion=${K3S_TAG}
7374
GCFLAGS :=
74-
GOFLAGS := -mod=vendor
75+
GOFLAGS := -mod=readonly
7576
BINDIR := $(CURDIR)/bin
7677
BINARIES := k3d
7778

cmd/cluster/clusterCreate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ func applyCLIOverrides(cfg conf.SimpleConfig) (conf.SimpleConfig, error) {
575575
}
576576
cfg.Registries.Create.Name = fvSplit[0]
577577
if len(fvSplit) > 1 {
578-
exposeAPI, err = cliutil.ParseRegistryPortExposureSpec(fvSplit[1])
578+
exposeAPI, err = cliutil.ParsePortExposureSpec(fvSplit[1], "1234") // internal port is unused after all
579579
if err != nil {
580580
return cfg, fmt.Errorf("failed to registry port spec: %w", err)
581581
}

cmd/registry/registryCreate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func parseCreateRegistryCmd(cmd *cobra.Command, args []string, flags *regCreateF
134134
}
135135

136136
// --port
137-
exposePort, err := cliutil.ParseRegistryPortExposureSpec(ppFlags.Port)
137+
exposePort, err := cliutil.ParsePortExposureSpec(ppFlags.Port, k3d.DefaultRegistryPort)
138138
if err != nil {
139139
l.Log().Errorln("Failed to parse registry port")
140140
l.Log().Fatalln(err)

cmd/util/ports.go

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,8 @@ import (
3636

3737
var apiPortRegexp = regexp.MustCompile(`^(?P<hostref>(?P<hostip>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})|(?P<hostname>\S+):)?(?P<port>(\d{1,5}|random))$`)
3838

39-
func ParsePortExposureSpec(exposedPortSpec, internalPort string) (*k3d.ExposureOpts, error) {
40-
return parsePortExposureSpec(exposedPortSpec, internalPort, false)
41-
}
42-
43-
func ParseRegistryPortExposureSpec(exposedPortSpec string) (*k3d.ExposureOpts, error) {
44-
return parsePortExposureSpec(exposedPortSpec, k3d.DefaultRegistryPort, true)
45-
}
46-
4739
// ParsePortExposureSpec parses/validates a string to create an exposePort struct from it
48-
func parsePortExposureSpec(exposedPortSpec, internalPort string, enforcePortMatch bool) (*k3d.ExposureOpts, error) {
40+
func ParsePortExposureSpec(exposedPortSpec, internalPort string) (*k3d.ExposureOpts, error) {
4941
match := apiPortRegexp.FindStringSubmatch(exposedPortSpec)
5042

5143
if len(match) == 0 {
@@ -91,7 +83,7 @@ func parsePortExposureSpec(exposedPortSpec, internalPort string, enforcePortMatc
9183
}
9284

9385
// port: get a free one if there's none defined or set to random
94-
if submatches["port"] == "random" {
86+
if submatches["port"] == "" || submatches["port"] == "random" {
9587
l.Log().Debugf("Port Exposure Mapping didn't specify hostPort, choosing one randomly...")
9688
freePort, err := GetFreePort()
9789
if err != nil || freePort == 0 {
@@ -104,10 +96,6 @@ func parsePortExposureSpec(exposedPortSpec, internalPort string, enforcePortMatc
10496
}
10597
}
10698

107-
if enforcePortMatch {
108-
internalPort = submatches["port"]
109-
}
110-
11199
realPortString += fmt.Sprintf("%s:%s/tcp", submatches["port"], internalPort)
112100

113101
portMapping, err := nat.ParsePortSpec(realPortString)

cmd/util/ports_test.go

Lines changed: 0 additions & 41 deletions
This file was deleted.

pkg/client/registry.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,6 @@ func RegistryCreate(ctx context.Context, runtime runtimes.Runtime, reg *k3d.Regi
7676
Env: []string{},
7777
}
7878

79-
if reg.ExposureOpts.Binding.HostPort != "" {
80-
registryNode.Env = append(registryNode.Env, fmt.Sprintf("REGISTRY_HTTP_ADDR=:%s", reg.ExposureOpts.Binding.HostPort))
81-
}
82-
8379
if reg.Options.Proxy.RemoteURL != "" {
8480
registryNode.Env = append(registryNode.Env, fmt.Sprintf("REGISTRY_PROXY_REMOTEURL=%s", reg.Options.Proxy.RemoteURL))
8581

pkg/config/transform.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ func TransformSimpleToClusterConfig(ctx context.Context, runtime runtimes.Runtim
320320
epSpecHost = simpleConfig.Registries.Create.Host
321321
}
322322

323-
regPort, err := cliutil.ParseRegistryPortExposureSpec(fmt.Sprintf("%s:%s", epSpecHost, epSpecPort))
323+
regPort, err := cliutil.ParsePortExposureSpec(fmt.Sprintf("%s:%s", epSpecHost, epSpecPort), k3d.DefaultRegistryPort)
324324
if err != nil {
325325
return nil, fmt.Errorf("failed to get port for registry: %w", err)
326326
}

tests/test_registry.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ kubectl get configmap -n kube-public local-registry-hosting -o go-template='{{in
5252

5353
# 3. load an image into the registry
5454
info "Pushing an image to the registry..."
55-
registryPort=$(docker inspect $registryname | jq '.[0].NetworkSettings.Ports | with_entries(select(.value | . != null)) | to_entries[0].value[0].HostPort' | sed -E 's/"//g')
55+
registryPort=$(docker inspect $registryname | jq '.[0].NetworkSettings.Ports["5000/tcp"][0].HostPort' | sed -E 's/"//g')
5656
docker pull alpine:latest > /dev/null
5757
docker tag alpine:latest "localhost:$registryPort/alpine:local" > /dev/null
5858
docker push "localhost:$registryPort/alpine:local" || failed "Failed to push image to managed registry"

0 commit comments

Comments
 (0)