Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
6 changes: 4 additions & 2 deletions cmd/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,10 @@ SYNOPSIS
[--skip-registry-config]

DESCRIPTION
Deletes a local development cluster and its associated registry
container. If no name is given, the default cluster "func" is deleted.
Deletes a local development cluster. The in-cluster registry is removed
with the Kind cluster; host registry trust is reverted only when this is
the last func-managed cluster. If no name is given, the default cluster
"func" is deleted.

When multiple func-managed clusters exist, specify which one by name.
Use '{{rootCmdUse}} cluster list' to see existing clusters.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ require (
knative.dev/pkg v0.0.0-20260622140654-39ebae2ee2dc
knative.dev/serving v0.49.1-0.20260624144117-dbce551f802c
sigs.k8s.io/controller-runtime v0.23.3
sigs.k8s.io/yaml v1.6.0
)

require (
Expand Down Expand Up @@ -325,5 +326,4 @@ require (
sigs.k8s.io/kustomize/kyaml v0.21.0 // indirect
sigs.k8s.io/randfill v1.0.0 // indirect
sigs.k8s.io/structured-merge-diff/v6 v6.3.2 // indirect
sigs.k8s.io/yaml v1.6.0 // indirect
)
44 changes: 18 additions & 26 deletions pkg/cluster/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,29 @@ import (
"path/filepath"
)

// Delete removes a single func-managed dev cluster. The shared registry
// container and the host's insecure-registries entry are removed only when
// the *last* func-managed cluster is being torn down — other surviving
// clusters keep using the shared registry.
// Delete removes a func-managed dev cluster. The in-cluster registry is
// destroyed automatically with the Kind cluster. Host-side trust config
// (insecure-registries) is only reverted when this is the last func cluster,
// since other surviving clusters share the same host entry.
func Delete(ctx context.Context, cfg ClusterConfig, out io.Writer) error {
// Set KUBECONFIG for child processes; restore the caller's value on return.
defer setKubeconfig(cfg.Kubeconfig())()

status(out, "Deleting Cluster")

if err := run(ctx, out, "",
cfg.kind(), "delete", "cluster",
"--name="+cfg.Name,
"--kubeconfig="+cfg.Kubeconfig()); err != nil {
warnf(out, "failed to delete cluster %q: %v", cfg.Name, err)
if _, err := os.Stat(cfg.Kubeconfig()); err == nil {
Comment thread
lkingland marked this conversation as resolved.
status(out, "Deleting Cluster")
if err := run(ctx, out, "",
cfg.kind(), "delete", "cluster",
"--name="+cfg.Name,
"--kubeconfig="+cfg.Kubeconfig()); err != nil {
warnf(out, "failed to delete cluster %q: %v", cfg.Name, err)
}
_ = os.RemoveAll(filepath.Dir(cfg.Kubeconfig()))
}

// Remove this cluster's kubeconfig dir so the "last cluster?" check
// below reflects the post-delete state.
_ = os.RemoveAll(filepath.Dir(cfg.Kubeconfig()))

remaining := List()
if len(remaining) == 0 {
status(out, "Last func cluster removed; tearing down shared registry")
teardownRegistry(ctx, cfg, out)
if !cfg.SkipRegistryConfig {
revertHostRegistry(out)
}
} else {
fmt.Fprintf(out, "Registry left running; shared with %d other func-managed cluster(s): %v\n",
len(remaining), remaining)
if remaining := List(); len(remaining) > 0 {
fmt.Fprintf(out, "Other func-managed cluster(s) still running: %v; leaving host registry config in place.\n",
remaining)
} else if !cfg.SkipRegistryConfig {
revertHostRegistry(out)
}

fmt.Fprintf(out, "%s Downloaded container images are not automatically removed.\n", red("NOTE:"))
Expand Down
17 changes: 8 additions & 9 deletions pkg/cluster/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const kindConfigTemplate = `kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
image: kindest/node:%[1]s
image: kindest/node:%s
extraPortMappings:
- containerPort: 80
hostPort: 80
Expand All @@ -29,14 +29,14 @@ nodes:
listenAddress: "127.0.0.1"
containerdConfigPatches:
- |-
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."localhost:%[2]d"]
endpoint = ["http://%[3]s:%[4]d"]
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."registry.default.svc.cluster.local:%[4]d"]
endpoint = ["http://%[3]s:%[4]d"]
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."registry.localtest.me"]
endpoint = ["http://localhost:5000"]
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."registry.default.svc.cluster.local:5000"]
endpoint = ["http://localhost:5000"]
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."ghcr.io"]
endpoint = ["http://%[3]s:%[4]d"]
endpoint = ["http://localhost:5000"]
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."quay.io"]
endpoint = ["http://%[3]s:%[4]d"]
endpoint = ["http://localhost:5000"]
`

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

kindConfig := fmt.Sprintf(kindConfigTemplate,
kindNodeVersion, registryHostPort, registryContainerName, registryContainerPort)
kindConfig := fmt.Sprintf(kindConfigTemplate, kindNodeVersion)

err := run(ctx, out, kindConfig,
cfg.kind(), "create", "cluster",
Expand Down
Loading
Loading