diff --git a/changelogs/unreleased/4340-sunjayBhatia-deprecation.md b/changelogs/unreleased/4340-sunjayBhatia-deprecation.md new file mode 100644 index 00000000000..487cf357348 --- /dev/null +++ b/changelogs/unreleased/4340-sunjayBhatia-deprecation.md @@ -0,0 +1,4 @@ +## Remove leader election configuration from configuration file + +Leader election configuration via configuration file was deprecated in Contour v1.20.0. +Configuration of leader election lease details and resource must now be done via command line flag. diff --git a/cmd/contour/serve.go b/cmd/contour/serve.go index 00a58671118..e4456574486 100644 --- a/cmd/contour/serve.go +++ b/cmd/contour/serve.go @@ -120,12 +120,12 @@ func registerServe(app *kingpin.Application) (*kingpin.CmdClause, *serveContext) serve.Flag("incluster", "Use in cluster configuration.").BoolVar(&ctx.Config.InCluster) serve.Flag("kubeconfig", "Path to kubeconfig (if not in running inside a cluster).").PlaceHolder("/path/to/file").StringVar(&ctx.Config.Kubeconfig) - serve.Flag("disable-leader-election", "Disable leader election mechanism.").BoolVar(&ctx.DisableLeaderElection) - serve.Flag("leader-election-lease-duration", "The duration of the leadership lease.").Default("15s").DurationVar(&ctx.Config.LeaderElection.LeaseDuration) - serve.Flag("leader-election-renew-deadline", "The duration leader will retry refreshing leadership before giving up.").Default("10s").DurationVar(&ctx.Config.LeaderElection.RenewDeadline) - serve.Flag("leader-election-retry-period", "The interval which Contour will attempt to acquire leadership lease.").Default("2s").DurationVar(&ctx.Config.LeaderElection.RetryPeriod) - serve.Flag("leader-election-resource-name", "The name of the resource (Lease) leader election will lease.").Default("leader-elect").StringVar(&ctx.Config.LeaderElection.Name) - serve.Flag("leader-election-resource-namespace", "The namespace of the resource (Lease) leader election will lease.").Default(ctx.Config.LeaderElection.Namespace).StringVar(&ctx.Config.LeaderElection.Namespace) + serve.Flag("disable-leader-election", "Disable leader election mechanism.").BoolVar(&ctx.LeaderElection.Disable) + serve.Flag("leader-election-lease-duration", "The duration of the leadership lease.").Default("15s").DurationVar(&ctx.LeaderElection.LeaseDuration) + serve.Flag("leader-election-renew-deadline", "The duration leader will retry refreshing leadership before giving up.").Default("10s").DurationVar(&ctx.LeaderElection.RenewDeadline) + serve.Flag("leader-election-retry-period", "The interval which Contour will attempt to acquire leadership lease.").Default("2s").DurationVar(&ctx.LeaderElection.RetryPeriod) + serve.Flag("leader-election-resource-name", "The name of the resource (Lease) leader election will lease.").Default("leader-elect").StringVar(&ctx.LeaderElection.Name) + serve.Flag("leader-election-resource-namespace", "The namespace of the resource (Lease) leader election will lease.").Default(config.GetenvOr("CONTOUR_NAMESPACE", "projectcontour")).StringVar(&ctx.LeaderElection.Namespace) serve.Flag("xds-address", "xDS gRPC API address.").PlaceHolder("").StringVar(&ctx.xdsAddr) serve.Flag("xds-port", "xDS gRPC API port.").PlaceHolder("").IntVar(&ctx.xdsPort) @@ -200,17 +200,17 @@ func NewServer(log logrus.FieldLogger, ctx *serveContext) (*Server, error) { MetricsBindAddress: "0", HealthProbeBindAddress: "0", } - if ctx.DisableLeaderElection { + if ctx.LeaderElection.Disable { log.Info("Leader election disabled") options.LeaderElection = false } else { options.LeaderElection = true options.LeaderElectionResourceLock = "leases" - options.LeaderElectionNamespace = ctx.Config.LeaderElection.Namespace - options.LeaderElectionID = ctx.Config.LeaderElection.Name - options.LeaseDuration = &ctx.Config.LeaderElection.LeaseDuration - options.RenewDeadline = &ctx.Config.LeaderElection.RenewDeadline - options.RetryPeriod = &ctx.Config.LeaderElection.RetryPeriod + options.LeaderElectionNamespace = ctx.LeaderElection.Namespace + options.LeaderElectionID = ctx.LeaderElection.Name + options.LeaseDuration = &ctx.LeaderElection.LeaseDuration + options.RenewDeadline = &ctx.LeaderElection.RenewDeadline + options.RetryPeriod = &ctx.LeaderElection.RetryPeriod options.LeaderElectionReleaseOnCancel = true } mgr, err := manager.New(restConfig, options) diff --git a/cmd/contour/servecontext.go b/cmd/contour/servecontext.go index 465dd6a6c64..3a26c65103e 100644 --- a/cmd/contour/servecontext.go +++ b/cmd/contour/servecontext.go @@ -85,8 +85,8 @@ type serveContext struct { // PermitInsecureGRPC disables TLS on Contour's gRPC listener. PermitInsecureGRPC bool - // DisableLeaderElection can only be set by command line flag. - DisableLeaderElection bool + // Leader election configuration. + LeaderElection LeaderElection } type ServerConfig struct { @@ -96,27 +96,35 @@ type ServerConfig struct { caFile, contourCert, contourKey string } +type LeaderElection struct { + Disable bool + LeaseDuration time.Duration + RenewDeadline time.Duration + RetryPeriod time.Duration + Namespace string + Name string +} + // newServeContext returns a serveContext initialized to defaults. func newServeContext() *serveContext { // Set defaults for parameters which are then overridden via flags, ENV, or ConfigFile return &serveContext{ - Config: config.Defaults(), - statsAddr: "0.0.0.0", - statsPort: 8002, - debugAddr: "127.0.0.1", - debugPort: 6060, - healthAddr: "0.0.0.0", - healthPort: 8000, - metricsAddr: "0.0.0.0", - metricsPort: 8000, - httpAccessLog: xdscache_v3.DEFAULT_HTTP_ACCESS_LOG, - httpsAccessLog: xdscache_v3.DEFAULT_HTTPS_ACCESS_LOG, - httpAddr: "0.0.0.0", - httpsAddr: "0.0.0.0", - httpPort: 8080, - httpsPort: 8443, - PermitInsecureGRPC: false, - DisableLeaderElection: false, + Config: config.Defaults(), + statsAddr: "0.0.0.0", + statsPort: 8002, + debugAddr: "127.0.0.1", + debugPort: 6060, + healthAddr: "0.0.0.0", + healthPort: 8000, + metricsAddr: "0.0.0.0", + metricsPort: 8000, + httpAccessLog: xdscache_v3.DEFAULT_HTTP_ACCESS_LOG, + httpsAccessLog: xdscache_v3.DEFAULT_HTTPS_ACCESS_LOG, + httpAddr: "0.0.0.0", + httpsAddr: "0.0.0.0", + httpPort: 8080, + httpsPort: 8443, + PermitInsecureGRPC: false, ServerConfig: ServerConfig{ xdsAddr: "127.0.0.1", xdsPort: 8001, diff --git a/pkg/config/parameters.go b/pkg/config/parameters.go index bd2707b75c2..11ee92c9628 100644 --- a/pkg/config/parameters.go +++ b/pkg/config/parameters.go @@ -357,16 +357,6 @@ type GatewayParameters struct { ControllerName string `yaml:"controllerName,omitempty"` } -// LeaderElectionParameters holds the config bits for leader election -// inside the configuration file. -type LeaderElectionParameters struct { - LeaseDuration time.Duration `yaml:"lease-duration,omitempty"` - RenewDeadline time.Duration `yaml:"renew-deadline,omitempty"` - RetryPeriod time.Duration `yaml:"retry-period,omitempty"` - Namespace string `yaml:"configmap-namespace,omitempty"` - Name string `yaml:"configmap-name,omitempty"` -} - // TimeoutParameters holds various configurable proxy timeout values. type TimeoutParameters struct { // RequestTimeout sets the client request timeout globally for Contour. Note that @@ -609,11 +599,6 @@ type Parameters struct { // TODO(youngnick): put a link to the issue and CVE here. EnableExternalNameService bool `yaml:"enableExternalNameService,omitempty"` - // LeaderElection contains leader election parameters. - // Note: This method of configuring leader election is deprecated, - // please use command line flags instead. - LeaderElection LeaderElectionParameters `yaml:"leaderelection,omitempty"` - // Timeouts holds various configurable timeouts that can // be set in the config file. Timeouts TimeoutParameters `yaml:"timeouts,omitempty"` @@ -802,13 +787,6 @@ func Defaults() Parameters { TLS: TLSParameters{}, DisablePermitInsecure: false, DisableAllowChunkedLength: false, - LeaderElection: LeaderElectionParameters{ - LeaseDuration: time.Second * 15, - RenewDeadline: time.Second * 10, - RetryPeriod: time.Second * 2, - Name: "leader-elect", - Namespace: contourNamespace, - }, Timeouts: TimeoutParameters{ // This is chosen as a rough default to stop idle connections wasting resources, // without stopping slow connections from being terminated too quickly. diff --git a/pkg/config/parameters_test.go b/pkg/config/parameters_test.go index a650e36f0e4..45420cc7f7e 100644 --- a/pkg/config/parameters_test.go +++ b/pkg/config/parameters_test.go @@ -17,7 +17,6 @@ import ( "os" "strings" "testing" - "time" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -72,12 +71,6 @@ json-fields: - upstream_service_time - user_agent - x_forwarded_for -leaderelection: - lease-duration: 15s - renew-deadline: 10s - retry-period: 2s - configmap-namespace: projectcontour - configmap-name: leader-elect timeouts: connection-idle-timeout: 60s envoy-service-namespace: projectcontour @@ -462,12 +455,6 @@ func TestConfigFileDefaultOverrideImport(t *testing.T) { incluster: false disablePermitInsecure: false disableAllowChunkedLength: false -leaderelection: - configmap-name: leader-elect - configmap-namespace: projectcontour - lease-duration: 15s - renew-deadline: 10s - retry-period: 2s `, ) @@ -488,32 +475,6 @@ tls: - ECDHE-RSA-AES256-GCM-SHA384 `) - check(func(t *testing.T, conf *Parameters) { - assert.Equal(t, "foo", conf.LeaderElection.Name) - assert.Equal(t, "bar", conf.LeaderElection.Namespace) - }, ` -leaderelection: - configmap-name: foo - configmap-namespace: bar -`) - - check(func(t *testing.T, conf *Parameters) { - assert.Equal(t, conf.LeaderElection, - LeaderElectionParameters{ - Name: "foo", - Namespace: "bar", - LeaseDuration: 600 * time.Second, - RenewDeadline: 500 * time.Second, - RetryPeriod: 60 * time.Second, - }) - }, ` -leaderelection: - configmap-name: foo - configmap-namespace: bar - lease-duration: 600s - renew-deadline: 500s - retry-period: 60s -`) check(func(t *testing.T, conf *Parameters) { assert.ElementsMatch(t, []HTTPVersionType{HTTPVersion1, HTTPVersion2, HTTPVersion2, HTTPVersion1},