diff --git a/changelogs/unreleased/5080-nsimons-minor.md b/changelogs/unreleased/5080-nsimons-minor.md new file mode 100644 index 00000000000..6269c62f98d --- /dev/null +++ b/changelogs/unreleased/5080-nsimons-minor.md @@ -0,0 +1,8 @@ +## Allow Disabling Features + +The `contour serve` command takes a new optional flag, `--disable-feature`, that allows disabling +certain features. + +Currently this flag can be used to disable the informer for ExtensionService resources, +effectively making the ExtensionService CRD optional in the cluster. +To do this, use the flag as follows: `--disable-feature=extensionservices` diff --git a/cmd/contour/serve.go b/cmd/contour/serve.go index cae078fb96c..52f8c9451a2 100644 --- a/cmd/contour/serve.go +++ b/cmd/contour/serve.go @@ -126,6 +126,7 @@ func registerServe(app *kingpin.Application) (*kingpin.CmdClause, *serveContext) serve.Flag("debug", "Enable debug logging.").Short('d').BoolVar(&ctx.Config.Debug) serve.Flag("debug-http-address", "Address the debug http endpoint will bind to.").PlaceHolder("").StringVar(&ctx.debugAddr) serve.Flag("debug-http-port", "Port the debug http endpoint will bind to.").PlaceHolder("").IntVar(&ctx.debugPort) + serve.Flag("disable-feature", "Do not start an informer for the specified resources.").PlaceHolder("").EnumsVar(&ctx.disabledFeatures, "extensionservices") serve.Flag("disable-leader-election", "Disable leader election mechanism.").BoolVar(&ctx.LeaderElection.Disable) serve.Flag("envoy-http-access-log", "Envoy HTTP access log.").PlaceHolder("/path/to/file").StringVar(&ctx.httpAccessLog) @@ -469,14 +470,22 @@ func (s *Server) doServe() error { Counter: contourMetrics.EventHandlerOperations, } - // Inform on default resources. - for name, r := range map[string]client.Object{ + // Start to build informers. + informerResources := map[string]client.Object{ "httpproxies": &contour_api_v1.HTTPProxy{}, "tlscertificatedelegations": &contour_api_v1.TLSCertificateDelegation{}, "extensionservices": &contour_api_v1alpha1.ExtensionService{}, "services": &corev1.Service{}, "ingresses": &networking_v1.Ingress{}, - } { + } + + // Some of the resources are optional and can be disabled, do not create informers for those. + for _, feat := range s.ctx.disabledFeatures { + delete(informerResources, feat) + } + + // Inform on the remaining resources. + for name, r := range informerResources { if err := informOnResource(r, eventHandler, s.mgr.GetCache()); err != nil { s.log.WithError(err).WithField("resource", name).Fatal("failed to create informer") } diff --git a/cmd/contour/servecontext.go b/cmd/contour/servecontext.go index dab3bcd267e..d563f7df2ec 100644 --- a/cmd/contour/servecontext.go +++ b/cmd/contour/servecontext.go @@ -87,6 +87,9 @@ type serveContext struct { // Leader election configuration. LeaderElection LeaderElection + + // Features disabled by the user. + disabledFeatures []string } type ServerConfig struct { diff --git a/site/content/docs/main/configuration.md b/site/content/docs/main/configuration.md index 9fd9c77ff3d..d52bc9b0bef 100644 --- a/site/content/docs/main/configuration.md +++ b/site/content/docs/main/configuration.md @@ -50,6 +50,7 @@ Many of these flags are mirrored in the [Contour Configuration File](#configurat | `--use-proxy-protocol` | Use PROXY protocol for all listeners | | `--accesslog-format=` | Format for Envoy access logs | | `--disable-leader-election` | Disable leader election mechanism | +| `--disable-feature=` | Do not start an informer for the specified resources. | | `--leader-election-lease-duration` | The duration of the leadership lease. | | `--leader-election-renew-deadline` | The duration leader will retry refreshing leadership before giving up. | | `--leader-election-retry-period` | The interval which Contour will attempt to acquire leadership lease. | diff --git a/site/content/docs/main/deploy-options.md b/site/content/docs/main/deploy-options.md index a8753dbab7a..241a909e81d 100644 --- a/site/content/docs/main/deploy-options.md +++ b/site/content/docs/main/deploy-options.md @@ -201,6 +201,12 @@ Next, pass `--envoy-service-http-port=80 --envoy-service-https-port=443` to the This is best paired with a DaemonSet (perhaps paired with Node affinity) to ensure that a single instance of Contour runs on each Node. See the [AWS NLB tutorial][10] as an example. +## Disabling Features + +You can run Contour with certain features disabled by passing `--disable-feature` flag to the Contour `serve` command. +Currently this flag can be used to disable the informer for ExtensionService resources, effectively making the ExtensionService CRD optional in the cluster. +To do this, use the flag as follows: `--disable-feature=extensionservices` + ## Upgrading Contour/Envoy At times, it's needed to upgrade Contour, the version of Envoy, or both.