Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 1f94d7e

Browse files
committed
etcd: expose more configs for the etcd pods.
1 parent 8347d27 commit 1f94d7e

File tree

3 files changed

+115
-10
lines changed

3 files changed

+115
-10
lines changed

pkg/apis/etcd/v1beta2/cluster.go

+36
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,39 @@ func (c *EtcdCluster) AsOwner() metav1.OwnerReference {
6464
}
6565
}
6666

67+
type ProbeConfig struct {
68+
InitialDelaySeconds int `json:"initialDelaySeconds,omitempty"`
69+
TimeoutSeconds int `json:"timeoutSeconds,omitempty"`
70+
PeriodSeconds int `json:"periodSeconds,omitempty"`
71+
FailureThreshold int `json:"failureThreshold,omitempty"`
72+
}
73+
74+
type EtcdConfig struct {
75+
// Heartbeat timeout setting for etcd pod
76+
HeartbeatTimeout int `json:"heartbeatTimeout,omitempty"`
77+
78+
// Election timeout setting for etcd pod
79+
ElectionTimeout int `json:"electionTimeout,omitempty"`
80+
81+
// Snapshot count setting for etcd pod
82+
SnapshotCount int `json:"snapshotCount,omitempty"`
83+
84+
// AutoCompactionMode, https://github.com/etcd-io/etcd/blob/master/Documentation/op-guide/maintenance.md
85+
AutoCompactionMode string `json:"autoCompactionMode,omitempty"`
86+
87+
// AutoCompactionRetention, https://github.com/etcd-io/etcd/blob/master/Documentation/op-guide/maintenance.md
88+
AutoCompactionRetention string `json:"autoCompactionRetention,omitempty"`
89+
90+
// ExperimentalPeerSkipClientSANVerification indicates whether the peer client san verification will be skipped.
91+
ExperimentalPeerSkipClientSANVerification bool `json:"experimentalPeerSkipClientSANVerification,omitempty"`
92+
93+
// ReadinessProbeConfig is for the container's readiness probe.
94+
ReadinessProbeConfig ProbeConfig `json:"readinessProbe,omitempty"`
95+
96+
// LivenessProbeConfig is for the container's readiness probe.
97+
LivenessProbeConfig ProbeConfig `json:"livenessProbe,omitempty"`
98+
}
99+
67100
type ClusterSpec struct {
68101
// Size is the expected size of the etcd cluster.
69102
// The etcd-operator will eventually make the size of the running
@@ -92,6 +125,9 @@ type ClusterSpec struct {
92125
// Paused is to pause the control of the operator for the etcd cluster.
93126
Paused bool `json:"paused,omitempty"`
94127

128+
// EtcdConfig contains the more configs for the etcd pods.
129+
EtcdConfig `json:",inline"`
130+
95131
// Pod defines the policy to create pod for the etcd pod.
96132
//
97133
// Updating Pod does not take effect on any existing etcd pods.

pkg/util/k8sutil/k8sutil.go

+79-6
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,30 @@ func newEtcdPod(m *etcdutil.Member, initialCluster []string, clusterName, state,
302302
"--listen-peer-urls=%s --listen-client-urls=%s --advertise-client-urls=%s "+
303303
"--initial-cluster=%s --initial-cluster-state=%s",
304304
dataDir, m.Name, m.PeerURL(), m.ListenPeerURL(), m.ListenClientURL(), m.ClientURL(), strings.Join(initialCluster, ","), state)
305+
if cs.HeartbeatTimeout > 0 {
306+
commands += fmt.Sprintf(" --heartbeat-interval=%d", cs.HeartbeatTimeout)
307+
}
308+
309+
if cs.ElectionTimeout > 0 {
310+
commands += fmt.Sprintf(" --election-timeout=%d", cs.ElectionTimeout)
311+
}
312+
313+
if cs.SnapshotCount > 0 {
314+
commands += fmt.Sprintf(" --snapshot-count=%d", cs.SnapshotCount)
315+
}
316+
317+
if cs.AutoCompactionMode != "" {
318+
commands += fmt.Sprintf(" --auto-compaction-mode=%s", cs.AutoCompactionMode)
319+
}
320+
321+
if cs.AutoCompactionRetention != "" {
322+
commands += fmt.Sprintf(" --auto-compaction-retention=%s", cs.AutoCompactionRetention)
323+
}
324+
325+
if cs.ExperimentalPeerSkipClientSANVerification {
326+
commands += fmt.Sprintf(" --experimental-peer-skip-client-san-verification")
327+
}
328+
305329
if m.SecurePeer {
306330
commands += fmt.Sprintf(" --peer-client-cert-auth=true --peer-trusted-ca-file=%[1]s/peer-ca.crt --peer-cert-file=%[1]s/peer.crt --peer-key-file=%[1]s/peer.key", peerTLSDir)
307331
}
@@ -318,12 +342,7 @@ func newEtcdPod(m *etcdutil.Member, initialCluster []string, clusterName, state,
318342
"etcd_cluster": clusterName,
319343
}
320344

321-
livenessProbe := newEtcdProbe(cs.TLS.IsSecureClient())
322-
readinessProbe := newEtcdProbe(cs.TLS.IsSecureClient())
323-
readinessProbe.InitialDelaySeconds = 1
324-
readinessProbe.TimeoutSeconds = 5
325-
readinessProbe.PeriodSeconds = 5
326-
readinessProbe.FailureThreshold = 3
345+
livenessProbe, readinessProbe := provisionProbeConfigs(cs)
327346

328347
container := containerWithProbes(
329348
etcdContainer(strings.Split(commands, " "), cs.Repository, cs.Version),
@@ -406,6 +425,60 @@ func newEtcdPod(m *etcdutil.Member, initialCluster []string, clusterName, state,
406425
return pod
407426
}
408427

428+
func provisionProbeConfigs(cs api.ClusterSpec) (livenessProbe *v1.Probe, readinessProbe *v1.Probe) {
429+
livenessProbe = newEtcdProbe(cs.TLS.IsSecureClient())
430+
431+
if cs.LivenessProbeConfig.InitialDelaySeconds != 0 {
432+
livenessProbe.InitialDelaySeconds = cs.LivenessProbeConfig.InitialDelaySeconds
433+
} else {
434+
livenessProbe.InitialDelaySeconds = 10
435+
}
436+
437+
if cs.LivenessProbeConfig.TimeoutSeconds != 0 {
438+
livenessProbe.TimeoutSeconds = cs.LivenessProbeConfig.TimeoutSeconds
439+
} else {
440+
livenessProbe.TimeoutSeconds = 10
441+
}
442+
443+
if cs.LivenessProbeConfig.PeriodSeconds != 0 {
444+
livenessProbe.PeriodSeconds = cs.LivenessProbeConfig.PeriodSeconds
445+
} else {
446+
livenessProbe.PeriodSeconds = 60
447+
}
448+
449+
if cs.LivenessProbeConfig.FailureThreshold != 0 {
450+
livenessProbe.FailureThreshold = cs.LivenessProbeConfig.FailureThreshold
451+
} else {
452+
livenessProbe.FailureThreshold = 3
453+
}
454+
455+
readinessProbe = newEtcdProbe(cs.TLS.IsSecureClient())
456+
457+
if cs.ReadinessProbeConfig.InitialDelaySeconds != 0 {
458+
livenessProbe.InitialDelaySeconds = cs.LivenessProbeConfig.InitialDelaySeconds
459+
} else {
460+
livenessProbe.InitialDelaySeconds = 1
461+
}
462+
463+
if cs.ReadinessProbeConfig.TimeoutSeconds != 0 {
464+
livenessProbe.TimeoutSeconds = cs.LivenessProbeConfig.TimeoutSeconds
465+
} else {
466+
livenessProbe.TimeoutSeconds = 5
467+
}
468+
469+
if cs.ReadinessProbeConfig.PeriodSeconds != 0 {
470+
livenessProbe.PeriodSeconds = cs.LivenessProbeConfig.PeriodSeconds
471+
} else {
472+
livenessProbe.PeriodSeconds = 5
473+
}
474+
475+
if cs.ReadinessProbeConfig.FailureThreshold != 0 {
476+
livenessProbe.FailureThreshold = cs.LivenessProbeConfig.FailureThreshold
477+
} else {
478+
livenessProbe.FailureThreshold = 3
479+
}
480+
}
481+
409482
func podSecurityContext(podPolicy *api.PodPolicy) *v1.PodSecurityContext {
410483
if podPolicy == nil {
411484
return nil

pkg/util/k8sutil/pod_util.go

-4
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,6 @@ func newEtcdProbe(isSecure bool) *v1.Probe {
8181
Command: []string{"/bin/sh", "-ec", cmd},
8282
},
8383
},
84-
InitialDelaySeconds: 10,
85-
TimeoutSeconds: 10,
86-
PeriodSeconds: 60,
87-
FailureThreshold: 3,
8884
}
8985
}
9086

0 commit comments

Comments
 (0)