Skip to content

Commit fe9cd8a

Browse files
authored
cluster: migrate registry from host container to in-cluster deployment (knative#3856)
* cluster: migrate registry from host container to in-cluster deployment Migrates func cluster create to an in-cluster registry (Deployment + Service + Contour Ingress + local-registry-hosting), matching hack/cluster.sh (knative#3718). Host trust uses registry.localtest.me; containerd mirrors hostPort :5000. Also: - Typed k8s objects for registry manifests (sigs.k8s.io/yaml) - Wait for registry HTTP readiness on 127.0.0.1:5000/v2/ - Delete help + empty-list cleanup (fold #63 CLI path; no host-container teardown) - Promote sigs.k8s.io/yaml to a direct require Rebased onto current main (resolves merge conflict). Functions#43 / knative#3856 * cluster: fix go.mod tidy after rebase; drop host HTTP registry wait C1: restore main's dependency floor (knative#3978); only intentional go.mod delta is promoting sigs.k8s.io/yaml to a direct require (typed registry manifests). S1: remove waitForRegistryHTTP on 127.0.0.1:5000 — Kind does not map host port 5000 (hostPort is node-local for containerd). Rely on kubectl wait --for=condition=Available like hack/cluster.sh. Functions#43 / knative#3856
1 parent 7750348 commit fe9cd8a

5 files changed

Lines changed: 170 additions & 183 deletions

File tree

‎cmd/cluster.go‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,14 @@ SYNOPSIS
198198
[--skip-registry-config]
199199
200200
DESCRIPTION
201-
Deletes a local development cluster and its associated registry
202-
container. If no name is given, the default cluster "func" is deleted.
201+
Deletes a local development cluster. The in-cluster registry is removed
202+
with the Kind cluster; host registry trust is reverted only when this is
203+
the last func-managed cluster. If no name is given, the default cluster
204+
"func" is deleted.
205+
206+
When no func-managed clusters are tracked, delete still runs the cleanup
207+
path (no error) so host registry trust can be cleared. A name that does
208+
not match any tracked cluster is an error when others exist.
203209
204210
When multiple func-managed clusters exist, specify which one by name.
205211
Use '{{rootCmdUse}} cluster list' to see existing clusters.
@@ -252,7 +258,7 @@ func runClusterDelete(cmd *cobra.Command, args []string) error {
252258
// If clusters are tracked and a non-matching name was given, refuse with
253259
// a clear message — otherwise hand off to Delete, which handles both
254260
// "delete the matched cluster" and "nothing tracked" (idempotent cleanup
255-
// of shared resources Delete already owns when List() is empty).
261+
// of host registry trust when List() is empty).
256262
clusters := cluster.List()
257263
if len(clusters) > 0 {
258264
matched := false

‎go.mod‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ require (
7676
knative.dev/pkg v0.0.0-20260727151759-521cb33b33dd
7777
knative.dev/serving v0.50.0
7878
sigs.k8s.io/controller-runtime v0.23.3
79+
sigs.k8s.io/yaml v1.6.0
7980
)
8081

8182
require (
@@ -325,5 +326,4 @@ require (
325326
sigs.k8s.io/kustomize/kyaml v0.21.0 // indirect
326327
sigs.k8s.io/randfill v1.0.0 // indirect
327328
sigs.k8s.io/structured-merge-diff/v6 v6.3.2 // indirect
328-
sigs.k8s.io/yaml v1.6.0 // indirect
329329
)

‎pkg/cluster/delete.go‎

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ import (
88
"path/filepath"
99
)
1010

11-
// Delete removes a single func-managed dev cluster. The shared registry
12-
// container and the host's insecure-registries entry are removed only when
13-
// the *last* func-managed cluster is being torn down — other surviving
14-
// clusters keep using the shared registry.
11+
// Delete removes a func-managed dev cluster. The in-cluster registry is
12+
// destroyed automatically with the Kind cluster. Host-side trust config
13+
// (insecure-registries) is only reverted when this is the last func cluster,
14+
// since other surviving clusters share the same host entry.
1515
//
1616
// Delete is safe when nothing is tracked (empty List / no kubeconfig): it
17-
// still runs the empty-list shared-resource teardown and returns nil
18-
// (idempotent, rm -f style). kind-delete failures are only warned when a
19-
// kubeconfig was present — otherwise every empty-system delete would print
20-
// a scary "failed to delete cluster" for a cluster that never existed.
17+
// still runs empty-list host-trust teardown and returns nil (idempotent,
18+
// rm -f style). kind-delete failures are only warned when a kubeconfig was
19+
// present — otherwise every empty-system delete would print a scary
20+
// "failed to delete cluster" for a cluster that never existed.
2121
func Delete(ctx context.Context, cfg ClusterConfig, out io.Writer) error {
2222
// Set KUBECONFIG for child processes; restore the caller's value on return.
2323
defer setKubeconfig(cfg.Kubeconfig())()
@@ -40,16 +40,12 @@ func Delete(ctx context.Context, cfg ClusterConfig, out io.Writer) error {
4040
// below reflects the post-delete state.
4141
_ = os.RemoveAll(filepath.Dir(cfg.Kubeconfig()))
4242

43-
remaining := List()
44-
if len(remaining) == 0 {
45-
status(out, "Last func cluster removed; tearing down shared registry")
46-
teardownRegistry(ctx, cfg, out)
47-
if !cfg.SkipRegistryConfig {
48-
revertHostRegistry(out)
49-
}
50-
} else {
51-
fmt.Fprintf(out, "Registry left running; shared with %d other func-managed cluster(s): %v\n",
52-
len(remaining), remaining)
43+
if remaining := List(); len(remaining) > 0 {
44+
fmt.Fprintf(out, "Other func-managed cluster(s) still running: %v; leaving host registry config in place.\n",
45+
remaining)
46+
} else if !cfg.SkipRegistryConfig {
47+
status(out, "Last func cluster removed; reverting host registry trust")
48+
revertHostRegistry(out)
5349
}
5450

5551
fmt.Fprintf(out, "%s Downloaded container images are not automatically removed.\n", red("NOTE:"))

‎pkg/cluster/kubernetes.go‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const kindConfigTemplate = `kind: Cluster
1616
apiVersion: kind.x-k8s.io/v1alpha4
1717
nodes:
1818
- role: control-plane
19-
image: kindest/node:%[1]s
19+
image: kindest/node:%s
2020
extraPortMappings:
2121
- containerPort: 80
2222
hostPort: 80
@@ -29,14 +29,14 @@ nodes:
2929
listenAddress: "127.0.0.1"
3030
containerdConfigPatches:
3131
- |-
32-
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."localhost:%[2]d"]
33-
endpoint = ["http://%[3]s:%[4]d"]
34-
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."registry.default.svc.cluster.local:%[4]d"]
35-
endpoint = ["http://%[3]s:%[4]d"]
32+
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."registry.localtest.me"]
33+
endpoint = ["http://localhost:5000"]
34+
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."registry.default.svc.cluster.local:5000"]
35+
endpoint = ["http://localhost:5000"]
3636
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."ghcr.io"]
37-
endpoint = ["http://%[3]s:%[4]d"]
37+
endpoint = ["http://localhost:5000"]
3838
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."quay.io"]
39-
endpoint = ["http://%[3]s:%[4]d"]
39+
endpoint = ["http://localhost:5000"]
4040
`
4141

4242
const metalLBPoolTemplate = `apiVersion: metallb.io/v1beta1
@@ -59,8 +59,7 @@ func installKubernetes(ctx context.Context, cfg ClusterConfig, out io.Writer) er
5959
start := time.Now()
6060
status(out, "Allocating")
6161

62-
kindConfig := fmt.Sprintf(kindConfigTemplate,
63-
kindNodeVersion, registryHostPort, registryContainerName, registryContainerPort)
62+
kindConfig := fmt.Sprintf(kindConfigTemplate, kindNodeVersion)
6463

6564
err := run(ctx, out, kindConfig,
6665
cfg.kind(), "create", "cluster",

0 commit comments

Comments
 (0)