Skip to content

Commit 67275e1

Browse files
author
OpenShift Bot
authored
Merge pull request #14094 from smarterclayton/elect
Merged by openshift-bot
2 parents 21254d2 + 17c4ce7 commit 67275e1

File tree

14 files changed

+319
-46
lines changed

14 files changed

+319
-46
lines changed

Diff for: contrib/completions/bash/openshift

+2
Original file line numberDiff line numberDiff line change
@@ -35301,6 +35301,8 @@ _openshift_start_master_controllers()
3530135301
local_nonpersistent_flags+=("--config=")
3530235302
flags+=("--listen=")
3530335303
local_nonpersistent_flags+=("--listen=")
35304+
flags+=("--lock-service-name=")
35305+
local_nonpersistent_flags+=("--lock-service-name=")
3530435306
flags+=("--azure-container-registry-config=")
3530535307
flags+=("--google-json-key=")
3530635308
flags+=("--log-flush-frequency=")

Diff for: contrib/completions/zsh/openshift

+2
Original file line numberDiff line numberDiff line change
@@ -35450,6 +35450,8 @@ _openshift_start_master_controllers()
3545035450
local_nonpersistent_flags+=("--config=")
3545135451
flags+=("--listen=")
3545235452
local_nonpersistent_flags+=("--listen=")
35453+
flags+=("--lock-service-name=")
35454+
local_nonpersistent_flags+=("--lock-service-name=")
3545335455
flags+=("--azure-container-registry-config=")
3545435456
flags+=("--google-json-key=")
3545535457
flags+=("--log-flush-frequency=")

Diff for: contrib/kubernetes/controllers.yaml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: controllers
5+
labels:
6+
master.openshift.io/controllers: 'true'
7+
spec:
8+
containers:
9+
- name: controller
10+
image: openshift/origin:latest
11+
args:
12+
- start
13+
- master
14+
- controllers
15+
- --listen=0.0.0.0:8444
16+
- --config=/etc/origin/master/master-config.yaml
17+
volumeMounts:
18+
- name: config
19+
mountPath: /etc/origin/master
20+
ports:
21+
- containerPort: 8444
22+
name: https
23+
volumes:
24+
- hostPath:
25+
path: /data/src/github.com/openshift/origin/openshift.local.test/master
26+
name: config

Diff for: pkg/cmd/server/api/serialization_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ func fuzzInternalObject(t *testing.T, forVersion schema.GroupVersion, item runti
4343
if len(obj.Controllers) == 0 {
4444
obj.Controllers = configapi.ControllersAll
4545
}
46+
if election := obj.ControllerConfig.Election; election != nil {
47+
if len(election.LockNamespace) == 0 {
48+
election.LockNamespace = "kube-system"
49+
}
50+
if len(election.LockResource.Group) == 0 && len(election.LockResource.Resource) == 0 {
51+
election.LockResource.Resource = "endpoints"
52+
}
53+
}
4654
if obj.ServingInfo.RequestTimeoutSeconds == 0 {
4755
obj.ServingInfo.RequestTimeoutSeconds = 60 * 60
4856
}

Diff for: pkg/cmd/server/api/types.go

+32-4
Original file line numberDiff line numberDiff line change
@@ -334,12 +334,14 @@ type MasterConfig struct {
334334
Controllers string
335335
// PauseControllers instructs the master to not automatically start controllers, but instead
336336
// to wait until a notification to the server is received before launching them.
337-
// TODO: will be disabled in function for 1.1.
337+
// Deprecated: Will be removed in 3.7.
338338
PauseControllers bool
339-
// ControllerLeaseTTL enables controller election, instructing the master to attempt to acquire
340-
// a lease before controllers start and renewing it within a number of seconds defined by this value.
341-
// Setting this value non-negative forces pauseControllers=true. This value defaults off (0, or
339+
// ControllerLeaseTTL enables controller election against etcd, instructing the master to attempt to
340+
// acquire a lease before controllers start and renewing it within a number of seconds defined by this
341+
// value. Setting this value non-negative forces pauseControllers=true. This value defaults off (0, or
342342
// omitted) and controller election can be disabled with -1.
343+
// Deprecated: use controllerConfig.lockServiceName to force leader election via config, and the
344+
// appropriate leader election flags in controllerArguments. Will be removed in 3.9.
343345
ControllerLeaseTTL int
344346
// TODO: the next field added to controllers must be added to a new controllers struct
345347

@@ -1395,11 +1397,37 @@ type AdmissionConfig struct {
13951397

13961398
// ControllerConfig holds configuration values for controllers
13971399
type ControllerConfig struct {
1400+
// Election defines the configuration for electing a controller instance to make changes to
1401+
// the cluster. If unspecified, the ControllerTTL value is checked to determine whether the
1402+
// legacy direct etcd election code will be used.
1403+
Election *ControllerElectionConfig
13981404
// ServiceServingCert holds configuration for service serving cert signer which creates cert/key pairs for
13991405
// pods fulfilling a service to serve with.
14001406
ServiceServingCert ServiceServingCert
14011407
}
14021408

1409+
// ControllerElectionConfig contains configuration values for deciding how a controller
1410+
// will be elected to act as leader.
1411+
type ControllerElectionConfig struct {
1412+
// LockName is the resource name used to act as the lock for determining which controller
1413+
// instance should lead.
1414+
LockName string
1415+
// LockNamespace is the resource namespace used to act as the lock for determining which
1416+
// controller instance should lead. It defaults to "kube-system"
1417+
LockNamespace string
1418+
// LockResource is the group and resource name to use to coordinate for the controller lock.
1419+
// If unset, defaults to "endpoints".
1420+
LockResource GroupResource
1421+
}
1422+
1423+
// GroupResource points to a resource by its name and API group.
1424+
type GroupResource struct {
1425+
// Group is the name of an API group
1426+
Group string
1427+
// Resource is the name of a resource.
1428+
Resource string
1429+
}
1430+
14031431
// ServiceServingCert holds configuration for service serving cert signer which creates cert/key pairs for
14041432
// pods fulfilling a service to serve with.
14051433
type ServiceServingCert struct {

Diff for: pkg/cmd/server/api/v1/conversions.go

+8
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ func addDefaultingFuncs(scheme *runtime.Scheme) error {
2020
if len(obj.Controllers) == 0 {
2121
obj.Controllers = ControllersAll
2222
}
23+
if election := obj.ControllerConfig.Election; election != nil {
24+
if len(election.LockNamespace) == 0 {
25+
election.LockNamespace = "kube-system"
26+
}
27+
if len(election.LockResource.Group) == 0 && len(election.LockResource.Resource) == 0 {
28+
election.LockResource.Resource = "endpoints"
29+
}
30+
}
2331
if obj.ServingInfo.RequestTimeoutSeconds == 0 {
2432
obj.ServingInfo.RequestTimeoutSeconds = 60 * 60
2533
}

Diff for: pkg/cmd/server/api/v1/swagger_doc.go

+24-2
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,25 @@ func (ClientConnectionOverrides) SwaggerDoc() map[string]string {
133133

134134
var map_ControllerConfig = map[string]string{
135135
"": "ControllerConfig holds configuration values for controllers",
136+
"election": "Election defines the configuration for electing a controller instance to make changes to the cluster. If unspecified, the ControllerTTL value is checked to determine whether the legacy direct etcd election code will be used.",
136137
"serviceServingCert": "ServiceServingCert holds configuration for service serving cert signer which creates cert/key pairs for pods fulfilling a service to serve with.",
137138
}
138139

139140
func (ControllerConfig) SwaggerDoc() map[string]string {
140141
return map_ControllerConfig
141142
}
142143

144+
var map_ControllerElectionConfig = map[string]string{
145+
"": "ControllerElectionConfig contains configuration values for deciding how a controller will be elected to act as leader.",
146+
"lockName": "LockName is the resource name used to act as the lock for determining which controller instance should lead.",
147+
"lockNamespace": "LockNamespace is the resource namespace used to act as the lock for determining which controller instance should lead. It defaults to \"kube-system\"",
148+
"lockResource": "LockResource is the group and resource name to use to coordinate for the controller lock. If unset, defaults to \"endpoints\".",
149+
}
150+
151+
func (ControllerElectionConfig) SwaggerDoc() map[string]string {
152+
return map_ControllerElectionConfig
153+
}
154+
143155
var map_DNSConfig = map[string]string{
144156
"": "DNSConfig holds the necessary configuration options for DNS",
145157
"bindAddress": "BindAddress is the ip:port to serve DNS on",
@@ -259,6 +271,16 @@ func (GrantConfig) SwaggerDoc() map[string]string {
259271
return map_GrantConfig
260272
}
261273

274+
var map_GroupResource = map[string]string{
275+
"": "GroupResource points to a resource by its name and API group.",
276+
"group": "Group is the name of an API group",
277+
"resource": "Resource is the name of a resource.",
278+
}
279+
280+
func (GroupResource) SwaggerDoc() map[string]string {
281+
return map_GroupResource
282+
}
283+
262284
var map_HTPasswdPasswordIdentityProvider = map[string]string{
263285
"": "HTPasswdPasswordIdentityProvider provides identities for users authenticating using htpasswd credentials",
264286
"file": "File is a reference to your htpasswd file",
@@ -463,8 +485,8 @@ var map_MasterConfig = map[string]string{
463485
"apiLevels": "APILevels is a list of API levels that should be enabled on startup: v1 as examples",
464486
"masterPublicURL": "MasterPublicURL is how clients can access the OpenShift API server",
465487
"controllers": "Controllers is a list of the controllers that should be started. If set to \"none\", no controllers will start automatically. The default value is \"*\" which will start all controllers. When using \"*\", you may exclude controllers by prepending a \"-\" in front of their name. No other values are recognized at this time.",
466-
"pauseControllers": "PauseControllers instructs the master to not automatically start controllers, but instead to wait until a notification to the server is received before launching them.",
467-
"controllerLeaseTTL": "ControllerLeaseTTL enables controller election, instructing the master to attempt to acquire a lease before controllers start and renewing it within a number of seconds defined by this value. Setting this value non-negative forces pauseControllers=true. This value defaults off (0, or omitted) and controller election can be disabled with -1.",
488+
"pauseControllers": "PauseControllers instructs the master to not automatically start controllers, but instead to wait until a notification to the server is received before launching them. This field is ignored if controllerConfig.lockServiceName is specified. Deprecated: Will be removed in 3.7.",
489+
"controllerLeaseTTL": "ControllerLeaseTTL enables controller election against etcd, instructing the master to attempt to acquire a lease before controllers start and renewing it within a number of seconds defined by this value. Setting this value non-negative forces pauseControllers=true. This value defaults off (0, or omitted) and controller election can be disabled with -1. This field is ignored if controllerConfig.lockServiceName is specified. Deprecated: use controllerConfig.lockServiceName to force leader election via config, and the\n appropriate leader election flags in controllerArguments. Will be removed in 3.9.",
468490
"admissionConfig": "AdmissionConfig contains admission control plugin configuration.",
469491
"controllerConfig": "ControllerConfig holds configuration values for controllers",
470492
"disabledFeatures": "DisabledFeatures is a list of features that should not be started. We omitempty here because its very unlikely that anyone will want to manually disable features and we don't want to encourage it.",

Diff for: pkg/cmd/server/api/v1/types.go

+36-5
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,17 @@ type MasterConfig struct {
197197
// values are recognized at this time.
198198
Controllers string `json:"controllers"`
199199
// PauseControllers instructs the master to not automatically start controllers, but instead
200-
// to wait until a notification to the server is received before launching them.
200+
// to wait until a notification to the server is received before launching them. This field is
201+
// ignored if controllerConfig.lockServiceName is specified.
202+
// Deprecated: Will be removed in 3.7.
201203
PauseControllers bool `json:"pauseControllers"`
202-
// ControllerLeaseTTL enables controller election, instructing the master to attempt to acquire
203-
// a lease before controllers start and renewing it within a number of seconds defined by this value.
204-
// Setting this value non-negative forces pauseControllers=true. This value defaults off (0, or
205-
// omitted) and controller election can be disabled with -1.
204+
// ControllerLeaseTTL enables controller election against etcd, instructing the master to attempt to
205+
// acquire a lease before controllers start and renewing it within a number of seconds defined by this
206+
// value. Setting this value non-negative forces pauseControllers=true. This value defaults off (0, or
207+
// omitted) and controller election can be disabled with -1. This field is ignored if
208+
// controllerConfig.lockServiceName is specified.
209+
// Deprecated: use controllerConfig.lockServiceName to force leader election via config, and the
210+
// appropriate leader election flags in controllerArguments. Will be removed in 3.9.
206211
ControllerLeaseTTL int `json:"controllerLeaseTTL"`
207212

208213
// AdmissionConfig contains admission control plugin configuration.
@@ -1329,11 +1334,37 @@ type AdmissionConfig struct {
13291334

13301335
// ControllerConfig holds configuration values for controllers
13311336
type ControllerConfig struct {
1337+
// Election defines the configuration for electing a controller instance to make changes to
1338+
// the cluster. If unspecified, the ControllerTTL value is checked to determine whether the
1339+
// legacy direct etcd election code will be used.
1340+
Election *ControllerElectionConfig `json:"election"`
13321341
// ServiceServingCert holds configuration for service serving cert signer which creates cert/key pairs for
13331342
// pods fulfilling a service to serve with.
13341343
ServiceServingCert ServiceServingCert `json:"serviceServingCert"`
13351344
}
13361345

1346+
// ControllerElectionConfig contains configuration values for deciding how a controller
1347+
// will be elected to act as leader.
1348+
type ControllerElectionConfig struct {
1349+
// LockName is the resource name used to act as the lock for determining which controller
1350+
// instance should lead.
1351+
LockName string `json:"lockName"`
1352+
// LockNamespace is the resource namespace used to act as the lock for determining which
1353+
// controller instance should lead. It defaults to "kube-system"
1354+
LockNamespace string `json:"lockNamespace"`
1355+
// LockResource is the group and resource name to use to coordinate for the controller lock.
1356+
// If unset, defaults to "endpoints".
1357+
LockResource GroupResource `json:"lockResource"`
1358+
}
1359+
1360+
// GroupResource points to a resource by its name and API group.
1361+
type GroupResource struct {
1362+
// Group is the name of an API group
1363+
Group string `json:"group"`
1364+
// Resource is the name of a resource.
1365+
Resource string `json:"resource"`
1366+
}
1367+
13371368
// ServiceServingCert holds configuration for service serving cert signer which creates cert/key pairs for
13381369
// pods fulfilling a service to serve with.
13391370
type ServiceServingCert struct {

Diff for: pkg/cmd/server/api/v1/types_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ auditConfig:
118118
authConfig:
119119
requestHeader: null
120120
controllerConfig:
121+
election: null
121122
serviceServingCert:
122123
signer: null
123124
controllerLeaseTTL: 0

Diff for: pkg/cmd/server/api/validation/master.go

+17
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,23 @@ func ValidateAuditConfig(config api.AuditConfig, fldPath *field.Path) Validation
249249
func ValidateControllerConfig(config api.ControllerConfig, fldPath *field.Path) ValidationResults {
250250
validationResults := ValidationResults{}
251251

252+
if election := config.Election; election != nil {
253+
if len(election.LockName) == 0 {
254+
validationResults.AddErrors(field.Invalid(fldPath.Child("election", "lockName"), election.LockName, "may not be empty"))
255+
}
256+
for _, msg := range kvalidation.ValidateServiceName(election.LockName, false) {
257+
validationResults.AddErrors(field.Invalid(fldPath.Child("election", "lockName"), election.LockName, msg))
258+
}
259+
if len(election.LockNamespace) == 0 {
260+
validationResults.AddErrors(field.Invalid(fldPath.Child("election", "lockNamespace"), election.LockNamespace, "may not be empty"))
261+
}
262+
for _, msg := range kvalidation.ValidateNamespaceName(election.LockNamespace, false) {
263+
validationResults.AddErrors(field.Invalid(fldPath.Child("election", "lockNamespace"), election.LockNamespace, msg))
264+
}
265+
if len(election.LockResource.Resource) == 0 {
266+
validationResults.AddErrors(field.Invalid(fldPath.Child("election", "lockResource", "resource"), election.LockResource.Resource, "may not be empty"))
267+
}
268+
}
252269
if config.ServiceServingCert.Signer != nil {
253270
validationResults.AddErrors(ValidateCertInfo(*config.ServiceServingCert.Signer, true, fldPath.Child("serviceServingCert.signer"))...)
254271
}

0 commit comments

Comments
 (0)