Skip to content

Commit

Permalink
Updated configmap mountpoints based on ETCD replicas.
Browse files Browse the repository at this point in the history
  • Loading branch information
abdasgupta committed Mar 24, 2022
1 parent 40405d2 commit 657935b
Show file tree
Hide file tree
Showing 23 changed files with 1,402 additions and 624 deletions.
8 changes: 5 additions & 3 deletions api/v1alpha1/etcd_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ type StoreSpec struct {

// TLSConfig hold the TLS configuration details.
type TLSConfig struct {
// +required
TLSCASecretRef corev1.SecretReference `json:"tlsCASecretRef"`
// +required
ServerTLSSecretRef corev1.SecretReference `json:"serverTLSSecretRef"`
// +required
ClientTLSSecretRef corev1.SecretReference `json:"clientTLSSecretRef"`
// +required
TLSCASecretRef corev1.SecretReference `json:"tlsCASecretRef"`
}

// CompressionSpec defines parameters related to compression of Snapshots(full as well as delta).
Expand Down Expand Up @@ -210,7 +210,9 @@ type EtcdConfig struct {
// +optional
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
// +optional
TLS *TLSConfig `json:"tls,omitempty"`
ClientUrlTLS *TLSConfig `json:"clientUrlTls,omitempty"`
// +optional
PeerUrlTLS *TLSConfig `json:"peerUrlTls,omitempty"`
// EtcdDefragTimeout defines the timeout duration for etcd defrag call
// +optional
EtcdDefragTimeout *metav1.Duration `json:"etcdDefragTimeout,omitempty"`
Expand Down
25 changes: 18 additions & 7 deletions api/v1alpha1/etcd_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,24 @@ func getEtcd(name, namespace string) *Etcd {
prefix := "etcd-test"
garbageCollectionPolicy := GarbageCollectionPolicy(GarbageCollectionPolicyExponential)

tlsConfig := &TLSConfig{
clientTlsConfig := &TLSConfig{
TLSCASecretRef: corev1.SecretReference{
Name: "client-url-ca-etcd",
},
ClientTLSSecretRef: corev1.SecretReference{
Name: "etcd-client-tls",
Name: "client-url-etcd-client-tls",
},
ServerTLSSecretRef: corev1.SecretReference{
Name: "etcd-server-tls",
Name: "client-url-etcd-server-tls",
},
}

peerTlsConfig := &TLSConfig{
TLSCASecretRef: corev1.SecretReference{
Name: "ca-etcd",
Name: "peer-url-ca-etcd",
},
ServerTLSSecretRef: corev1.SecretReference{
Name: "peer-url-etcd-server-tls",
},
}

Expand Down Expand Up @@ -144,6 +153,7 @@ func getEtcd(name, namespace string) *Etcd {
Backup: BackupSpec{
Image: &imageBR,
Port: &backupPort,
TLS: clientTlsConfig,
FullSnapshotSchedule: &snapshotSchedule,
GarbageCollectionPolicy: &garbageCollectionPolicy,
GarbageCollectionPeriod: &garbageCollectionPeriod,
Expand Down Expand Up @@ -184,9 +194,10 @@ func getEtcd(name, namespace string) *Etcd {
"memory": parseQuantity("1000Mi"),
},
},
ClientPort: &clientPort,
ServerPort: &serverPort,
TLS: tlsConfig,
ClientPort: &clientPort,
ServerPort: &serverPort,
ClientUrlTLS: clientTlsConfig,
PeerUrlTLS: peerTlsConfig,
},
},
}
Expand Down
11 changes: 8 additions & 3 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

84 changes: 0 additions & 84 deletions charts/etcd/templates/etcd-configmap.yaml

This file was deleted.

106 changes: 63 additions & 43 deletions charts/etcd/templates/etcd-statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ metadata:
{{ toYaml .Values.labels | indent 4 }}
{{- end }}
spec:
podManagementPolicy: Parallel
updateStrategy:
type: RollingUpdate
serviceName: {{ .Values.serviceName }}
Expand All @@ -27,7 +28,6 @@ spec:
template:
metadata:
annotations:
checksum/etcd-configmap: {{ include (print $.Template.BasePath "/etcd-configmap.yaml") . | sha256sum }}
{{- if .Values.annotations }}
{{ toYaml .Values.annotations | indent 8 }}
{{- end }}
Expand All @@ -53,12 +53,20 @@ spec:
command:
- /var/etcd/bin/bootstrap.sh
readinessProbe:
httpGet:
{{- if .Values.etcd.enableTLS }}
scheme: HTTPS
{{- end }}
path: /healthz
port: {{ .Values.backup.port }}
exec:
command:
- /usr/bin/curl
{{- if .Values.etcd.enableClientTLS }}
- --cert
- /var/etcd/ssl/client/client/tls.crt
- --key
- /var/etcd/ssl/client/client/tls.key
- --cacert
- /var/etcd/ssl/client/ca/ca.crt
- https://{{ .Values.name }}-local:{{- if eq .Values.replicas 1.0 }}{{ .Values.backup.port }}{{ else }}{{ .Values.etcd.clientPort }}{{ end }}/health{{- if eq .Values.replicas 1.0 }}z{{ end }}
{{ else }}
- http://{{ .Values.name }}-local:{{- if eq .Values.replicas 1.0 }}{{ .Values.backup.port }}{{ else }}{{ .Values.etcd.clientPort }}{{ end }}/health{{- if eq .Values.replicas 1.0 }}z{{ end }}
{{ end }}
initialDelaySeconds: 15
periodSeconds: 5
livenessProbe:
Expand All @@ -68,10 +76,10 @@ spec:
- -ec
- ETCDCTL_API=3
- etcdctl
{{- if .Values.etcd.enableTLS }}
- --cert=/var/etcd/ssl/client/tls.crt
- --key=/var/etcd/ssl/client/tls.key
- --cacert=/var/etcd/ssl/ca/ca.crt
{{- if .Values.etcd.enableClientTLS }}
- --cert=/var/etcd/ssl/client/client/tls.crt
- --key=/var/etcd/ssl/client/client/tls.key
- --cacert=/var/etcd/ssl/client/ca/ca.crt
- --endpoints=https://{{ .Values.name }}-local:{{ .Values.etcd.clientPort }}
{{ else }}
- --endpoints=http://{{ .Values.name }}-local:{{ .Values.etcd.clientPort }}
Expand All @@ -94,23 +102,27 @@ spec:
{{ toYaml .Values.etcd.resources | indent 10 }}
env:
- name: ENABLE_TLS
value: {{ .Values.etcd.enableTLS }}
value: {{ .Values.etcd.enableClientTLS }}
- name: BACKUP_ENDPOINT
value: "http{{ if .Values.etcd.enableTLS }}s{{ end }}://{{ .Values.name }}-local:{{ .Values.backup.port }}"
value: "http{{ if .Values.backup.enableTLS }}s{{ end }}://{{ .Values.name }}-local:{{ .Values.backup.port }}"
- name: FAIL_BELOW_REVISION_PARAMETER
value: "{{ if .Values.backup.failBelowRevision }}&failbelowrevision={{ int $.Values.backup.failBelowRevision }}{{ end }}"
volumeMounts:
- name: {{ .Values.volumeClaimTemplateName }}
mountPath: /var/etcd/data/
- name: etcd-config-file
mountPath: /var/etcd/config/
{{- if .Values.etcd.enableTLS }}
- name: ca-etcd
mountPath: /var/etcd/ssl/ca
- name: etcd-server-tls
mountPath: /var/etcd/ssl/server
- name: etcd-client-tls
mountPath: /var/etcd/ssl/client
{{- if .Values.etcd.enableClientTLS }}
- name: client-url-ca-etcd
mountPath: /var/etcd/ssl/client/ca
- name: client-url-etcd-server-tls
mountPath: /var/etcd/ssl/client/server
- name: client-url-etcd-client-tls
mountPath: /var/etcd/ssl/client/client
{{- end }}
{{- if .Values.etcd.enablePeerTLS }}
- name: peer-url-ca-etcd
mountPath: /var/etcd/ssl/peer/ca
- name: peer-url-etcd-server-tls
mountPath: /var/etcd/ssl/peer/server
{{- end }}
- name: backup-restore
command:
Expand Down Expand Up @@ -144,16 +156,16 @@ spec:
{{- if .Values.backup.enableProfiling }}
- --enable-profiling={{ .Values.backup.enableProfiling }}
{{- end }}
{{- if .Values.etcd.enableTLS }}
- --cert=/var/etcd/ssl/client/tls.crt
- --key=/var/etcd/ssl/client/tls.key
- --cacert=/var/etcd/ssl/ca/ca.crt
{{- if .Values.backup.enableTLS }}
- --cert=/var/etcd/ssl/client/client/tls.crt
- --key=/var/etcd/ssl/client/client/tls.key
- --cacert=/var/etcd/ssl/client/ca/ca.crt
- --insecure-transport=false
- --insecure-skip-tls-verify=false
- --endpoints=https://{{ .Values.name }}-local:{{ .Values.etcd.clientPort }}
# enable TLS on backup-restore server reusing etcd cert bundle
- --server-cert=/var/etcd/ssl/server/tls.crt
- --server-key=/var/etcd/ssl/server/tls.key
- --server-cert=/var/etcd/ssl/client/server/tls.crt
- --server-key=/var/etcd/ssl/client/server/tls.key
{{ else }}
- --insecure-transport=true
- --insecure-skip-tls-verify=true
Expand All @@ -177,7 +189,7 @@ spec:
{{- if .Values.backup.compression.enabled }}
- --compress-snapshots={{ .Values.backup.compression.enabled }}
{{- end }}
{{- if .Values.backup.compression.policy }}
{{- if .Values.backup.compression.policy }}
- --compression-policy={{ .Values.backup.compression.policy }}
{{- end }}
{{- end }}
Expand Down Expand Up @@ -315,13 +327,13 @@ spec:
mountPath: /var/etcd/data
- name: etcd-config-file
mountPath: /var/etcd/config/
{{- if .Values.etcd.enableTLS }}
- name: ca-etcd
mountPath: /var/etcd/ssl/ca
- name: etcd-server-tls
mountPath: /var/etcd/ssl/server
- name: etcd-client-tls
mountPath: /var/etcd/ssl/client
{{- if .Values.backup.enableTLS }}
- name: client-url-ca-etcd
mountPath: /var/etcd/ssl/client/ca
- name: client-url-etcd-server-tls
mountPath: /var/etcd/ssl/client/server
- name: client-url-etcd-client-tls
mountPath: /var/etcd/ssl/client/client
{{- end }}
{{- if eq .Values.store.storageProvider "GCS" }}
- name: etcd-backup
Expand Down Expand Up @@ -362,16 +374,24 @@ spec:
items:
- key: etcd.conf.yaml
path: etcd.conf.yaml
{{- if .Values.etcd.enableTLS }}
- name: etcd-server-tls
{{- if .Values.etcd.enableClientTLS }}
- name: client-url-ca-etcd
secret:
secretName: {{ .Values.clientUrlTlsCASecret }}
- name: client-url-etcd-server-tls
secret:
secretName: {{ .Values.tlsServerSecret }}
- name: etcd-client-tls
secretName: {{ .Values.clientUrlTlsServerSecret }}
- name: client-url-etcd-client-tls
secret:
secretName: {{ .Values.clientUrlTlsClientSecret }}
{{- end }}
{{- if .Values.etcd.enablePeerTLS }}
- name: peer-url-ca-etcd
secret:
secretName: {{ .Values.tlsClientSecret }}
- name: ca-etcd
secretName: {{ .Values.peerUrlTlsCASecret }}
- name: peer-url-etcd-server-tls
secret:
secretName: {{ .Values.tlsCASecret }}
secretName: {{ .Values.peerUrlTlsServerSecret }}
{{- end }}
{{- if eq .Values.store.storageProvider "GCS" }}
- name: etcd-backup
Expand Down
Loading

0 comments on commit 657935b

Please sign in to comment.