Skip to content

Commit 2f67cc7

Browse files
authored
cluster: Contour when --serving=false; drop dead delete --container-engine (knative#3985)
Post-knative#3856 follow-up (review S1/S2 landed after the squash merge): S1: Remove --container-engine from cluster delete — nothing read it after host registry teardown went away. S2: Extract installContour; when --serving=false install Contour before the registry so registry.localtest.me Ingress is not inert. Default --serving=true unchanged (hack/cluster.sh always has Contour via networking). Help text documents Contour on minimal create. Functions follow-up to #43 / knative#3856
1 parent 2871d3b commit 2f67cc7

3 files changed

Lines changed: 63 additions & 41 deletions

File tree

‎cmd/cluster.go‎

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ EXAMPLES
5454
o Create a default development cluster
5555
$ {{rootCmdUse}} cluster create
5656
57-
o Create a minimal cluster (just Kubernetes + registry)
57+
o Create a minimal cluster (Kubernetes + Contour + registry; no Serving/Eventing)
5858
$ {{rootCmdUse}} cluster create --serving=false --eventing=false
5959
6060
o List existing clusters
@@ -99,14 +99,17 @@ DESCRIPTION
9999
export KUBECONFIG=~/.config/func/clusters/func.local/kubeconfig.yaml
100100
101101
Installed components are controlled by the --serving, --eventing,
102-
--tekton, and --keda flags. Required binaries are downloaded into the
103-
func config directory on first use unless --skip-binaries is set.
102+
--tekton, and --keda flags. --serving and --eventing default to true
103+
(hack/cluster.sh always installs Serving). Contour is always present for
104+
the registry host Ingress: with Serving (default path) or standalone when
105+
--serving=false. Required binaries are downloaded into the func config
106+
directory on first use unless --skip-binaries is set.
104107
105108
EXAMPLES
106-
o Create a default development cluster
109+
o Create a default development cluster (Serving + Eventing + registry)
107110
$ {{rootCmdUse}} cluster create
108111
109-
o Create a minimal cluster (just Kubernetes + registry)
112+
o Create a minimal cluster (Kubernetes + Contour + registry; no Serving/Eventing)
110113
$ {{rootCmdUse}} cluster create --serving=false --eventing=false
111114
112115
o Create a cluster with a custom name and domain
@@ -180,7 +183,6 @@ func newClusterCreateConfig() cluster.ClusterConfig {
180183
ContainerEngineOverride: viper.GetString("container-engine"),
181184
KubectlOverride: os.Getenv("FUNC_TEST_KUBECTL"), // override binary path
182185
KindOverride: os.Getenv("FUNC_TEST_KIND"), // override binary path
183-
ActOverride: os.Getenv("FUNC_TEST_ACT"), // override binary path
184186
GitHubActions: os.Getenv("GITHUB_ACTIONS") == "true", // detect CI environments
185187
}
186188
}
@@ -195,8 +197,7 @@ NAME
195197
{{rootCmdUse}} cluster delete - Delete a local development cluster
196198
197199
SYNOPSIS
198-
{{rootCmdUse}} cluster delete [name] [--container-engine]
199-
[--skip-registry-config]
200+
{{rootCmdUse}} cluster delete [name] [--skip-registry-config]
200201
201202
DESCRIPTION
202203
Deletes a local development cluster. The in-cluster registry is removed
@@ -225,14 +226,12 @@ EXAMPLES
225226
226227
`,
227228

228-
PreRunE: bindEnv("container-engine", "skip-registry-config"),
229+
PreRunE: bindEnv("skip-registry-config"),
229230
RunE: func(cmd *cobra.Command, args []string) error {
230231
return runClusterDelete(cmd, args)
231232
},
232233
}
233234

234-
cmd.Flags().String("container-engine", "",
235-
"Container engine: docker or podman; auto-detected if unset, preferring docker when both are installed ($FUNC_CONTAINER_ENGINE)")
236235
cmd.Flags().Bool("skip-registry-config", false,
237236
"Skip host registry configuration revert ($FUNC_SKIP_REGISTRY_CONFIG)")
238237

@@ -241,13 +240,11 @@ EXAMPLES
241240

242241
func newClusterDeleteConfig() cluster.ClusterConfig {
243242
return cluster.ClusterConfig{
244-
Name: "func",
245-
ContainerEngineOverride: viper.GetString("container-engine"),
246-
SkipRegistryConfig: viper.GetBool("skip-registry-config"),
247-
KubectlOverride: os.Getenv("FUNC_TEST_KUBECTL"),
248-
KindOverride: os.Getenv("FUNC_TEST_KIND"),
249-
ActOverride: os.Getenv("FUNC_TEST_ACT"),
250-
GitHubActions: os.Getenv("GITHUB_ACTIONS") == "true",
243+
Name: "func",
244+
SkipRegistryConfig: viper.GetBool("skip-registry-config"),
245+
KubectlOverride: os.Getenv("FUNC_TEST_KUBECTL"),
246+
KindOverride: os.Getenv("FUNC_TEST_KIND"),
247+
GitHubActions: os.Getenv("GITHUB_ACTIONS") == "true",
251248
}
252249
}
253250

‎pkg/cluster/create.go‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ func allocateCluster(ctx context.Context, cfg ClusterConfig, out io.Writer) (err
7575
}
7676

7777
// Phase 2: Parallel component installation
78+
// Mirrors hack/cluster.sh: (serving && dns && networking) || registry || …
79+
// in parallel. Shell always installs Serving; Go allows --serving=false
80+
// (e.g. future KEDA-only). Registry Ingress needs Contour (contour-external)
81+
// for host access to registry.localtest.me — when Serving is off we still
82+
// install Contour on the reg path so the Ingress is not inert.
7883
status(out, "Beginning Cluster Configuration")
7984
fmt.Fprintln(out, "Tasks will be executed in parallel. Logs will be prefixed:")
8085
if cfg.Serving {
@@ -95,6 +100,7 @@ func allocateCluster(ctx context.Context, cfg ClusterConfig, out io.Writer) (err
95100
g, gctx := errgroup.WithContext(ctx)
96101

97102
// svr: serving -> dns -> networking (sequential within goroutine)
103+
// networking = Contour + net-contour + Serving config (hack/cluster.sh networking)
98104
if cfg.Serving {
99105
g.Go(func() error {
100106
w := newPrefixedWriter(out, "svr ")
@@ -121,10 +127,16 @@ func allocateCluster(ctx context.Context, cfg ClusterConfig, out io.Writer) (err
121127
})
122128
}
123129

124-
// reg: registry (always)
130+
// reg: registry (always). Shell always has Contour via the svr job;
131+
// with --serving=false install Contour first so registry Ingress works.
125132
g.Go(func() error {
126133
w := newPrefixedWriter(out, "reg ")
127134
defer w.Flush()
135+
if !cfg.Serving {
136+
if err := installContour(gctx, cfg, w); err != nil {
137+
return fmt.Errorf("contour (registry host ingress): %w", err)
138+
}
139+
}
128140
return installRegistry(gctx, cfg, w)
129141
})
130142

‎pkg/cluster/serving.go‎

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ func configureDNS(ctx context.Context, cfg ClusterConfig, out io.Writer) error {
7474
return fmt.Errorf("unable to set Knative domain after 10 attempts: %w", lastErr)
7575
}
7676

77-
// installNetworking installs Contour ingress controller and configures Knative
78-
// to use it. The Contour YAML is modified in Go (replacing yq) to add IPv6
79-
// dual-stack support args.
80-
func installNetworking(ctx context.Context, cfg ClusterConfig, out io.Writer) error {
81-
start := time.Now()
77+
// installContour installs the Contour ingress controller (contour-external)
78+
// used by standard Kubernetes Ingress objects (registry.localtest.me, broker
79+
// host, etc.). Mirrors the Contour half of hack/cluster.sh networking().
80+
// Does not install knative net-contour or patch Serving — that is installNetworking.
81+
func installContour(ctx context.Context, cfg ClusterConfig, out io.Writer) error {
8282
status(out, "Installing Ingress Controller (Contour)")
8383
fmt.Fprintf(out, "Version: %s\n", contourVersion)
8484

@@ -106,13 +106,42 @@ func installNetworking(ctx context.Context, cfg ClusterConfig, out io.Writer) er
106106
return fmt.Errorf("waiting for contour pods: %w", err)
107107
}
108108

109+
fmt.Fprintln(out, "Patching contour to prefer dual-stack")
110+
err = run(ctx, out, "",
111+
cfg.kubectl(), "patch", "-n", "contour-external", "svc/envoy",
112+
"--type", "merge",
113+
"--patch", `{"spec":{"ipFamilyPolicy":"PreferDualStack"}}`)
114+
if err != nil {
115+
return fmt.Errorf("patching contour dual-stack: %w", err)
116+
}
117+
118+
err = run(ctx, out, "",
119+
cfg.kubectl(), "wait", "pod", "--for=condition=Ready", "-l", "!job-name",
120+
"-n", "contour-external", "--timeout=10m")
121+
if err != nil {
122+
return fmt.Errorf("waiting for contour: %w", err)
123+
}
124+
return nil
125+
}
126+
127+
// installNetworking installs Contour and configures Knative Serving to use it.
128+
// Mirrors hack/cluster.sh networking() (Contour + net-contour + Serving patches).
129+
// Callers that need Contour without Serving (e.g. --serving=false + registry
130+
// host Ingress) should use installContour only.
131+
func installNetworking(ctx context.Context, cfg ClusterConfig, out io.Writer) error {
132+
start := time.Now()
133+
134+
if err := installContour(ctx, cfg, out); err != nil {
135+
return err
136+
}
137+
109138
fmt.Fprintln(out, "Installing the Knative Contour controller.")
110139
netContourURL := fmt.Sprintf("https://github.com/knative/net-contour/releases/download/knative-%s/net-contour.yaml", contourVersion)
111140
if err := run(ctx, out, "", cfg.kubectl(), "apply", "-f", netContourURL); err != nil {
112141
return fmt.Errorf("applying net-contour: %w", err)
113142
}
114143

115-
err = run(ctx, out, "",
144+
err := run(ctx, out, "",
116145
cfg.kubectl(), "wait", "pod",
117146
"--for=condition=Ready", "-l", "!job-name",
118147
"-n", "knative-serving", "--timeout=10m")
@@ -138,22 +167,6 @@ func installNetworking(ctx context.Context, cfg ClusterConfig, out io.Writer) er
138167
return fmt.Errorf("patching domain-template: %w", err)
139168
}
140169

141-
fmt.Fprintln(out, "Patching contour to prefer dual-stack")
142-
err = run(ctx, out, "",
143-
cfg.kubectl(), "patch", "-n", "contour-external", "svc/envoy",
144-
"--type", "merge",
145-
"--patch", `{"spec":{"ipFamilyPolicy":"PreferDualStack"}}`)
146-
if err != nil {
147-
return fmt.Errorf("patching contour dual-stack: %w", err)
148-
}
149-
150-
err = run(ctx, out, "",
151-
cfg.kubectl(), "wait", "pod", "--for=condition=Ready", "-l", "!job-name",
152-
"-n", "contour-external", "--timeout=10m")
153-
if err != nil {
154-
return fmt.Errorf("waiting for contour: %w", err)
155-
}
156-
157170
err = run(ctx, out, "",
158171
cfg.kubectl(), "wait", "pod", "--for=condition=Ready", "-l", "!job-name",
159172
"-n", "knative-serving", "--timeout=10m")

0 commit comments

Comments
 (0)