Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/config: Remove leader election configuration #4340

Merged
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
4 changes: 4 additions & 0 deletions changelogs/unreleased/4340-sunjayBhatia-deprecation.md
Original file line number Diff line number Diff line change
@@ -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.
24 changes: 12 additions & 12 deletions cmd/contour/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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("<ipaddr>").StringVar(&ctx.xdsAddr)
serve.Flag("xds-port", "xDS gRPC API port.").PlaceHolder("<port>").IntVar(&ctx.xdsPort)
Expand Down Expand Up @@ -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)
Expand Down
46 changes: 27 additions & 19 deletions cmd/contour/servecontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down
22 changes: 0 additions & 22 deletions pkg/config/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"`
Expand Down Expand Up @@ -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.
Expand Down
39 changes: 0 additions & 39 deletions pkg/config/parameters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"os"
"strings"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
`,
)

Expand All @@ -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},
Expand Down