Skip to content

Commit

Permalink
cmd/contour: optional CRDs (projectcontour#5080) (projectcontour#5080)
Browse files Browse the repository at this point in the history
Allow disabling certain informers for CRDs by passing a
command line flag to the serve command. This makes the
corresponding CRD effectively optional.

Fixes projectcontour#4684

Signed-off-by: Niklas Simons <niklas.simons@est.tech>
  • Loading branch information
nsimons authored and tsaarni committed Mar 7, 2023
1 parent 0344602 commit b8db1c2
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 3 deletions.
8 changes: 8 additions & 0 deletions changelogs/unreleased/5080-nsimons-minor.md
Original file line number Diff line number Diff line change
@@ -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`
15 changes: 12 additions & 3 deletions cmd/contour/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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("<ipaddr>").StringVar(&ctx.debugAddr)
serve.Flag("debug-http-port", "Port the debug http endpoint will bind to.").PlaceHolder("<port>").IntVar(&ctx.debugPort)
serve.Flag("disable-feature", "Do not start an informer for the specified resources.").PlaceHolder("<extensionservices>").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)
Expand Down Expand Up @@ -469,15 +470,23 @@ 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{},
"contourconfigurations": &contour_api_v1alpha1.ContourConfiguration{},
"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")
}
Expand Down
3 changes: 3 additions & 0 deletions cmd/contour/servecontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ type serveContext struct {

// Leader election configuration.
LeaderElection LeaderElection

// Features disabled by the user.
disabledFeatures []string
}

type ServerConfig struct {
Expand Down
1 change: 1 addition & 0 deletions site/content/docs/main/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<envoy\|json>` | Format for Envoy access logs |
| `--disable-leader-election` | Disable leader election mechanism |
| `--disable-feature=<extensionservices>` | 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. |
Expand Down
6 changes: 6 additions & 0 deletions site/content/docs/main/deploy-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit b8db1c2

Please sign in to comment.