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

Make auto-compaction-mode and auto-compaction-retention configurable #157

Merged
merged 1 commit into from
Apr 22, 2021
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
22 changes: 22 additions & 0 deletions api/v1alpha1/etcd_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ const (
DefaultCompression CompressionPolicy = GzipCompression
// DefaultCompressionEnabled is constant to define whether to compress the snapshots or not.
DefaultCompressionEnabled = false

// Periodic is a constant to set auto-compaction-mode 'periodic' for duration based retention.
Periodic CompactionMode = "periodic"
// Revision is a constant to set auto-compaction-mode 'revision' for revision number based retention.
Revision CompactionMode = "revision"
)

// MetricsLevel defines the level 'basic' or 'extensive'.
Expand All @@ -59,6 +64,11 @@ type StorageProvider string
// +kubebuilder:validation:Enum=gzip;lzw;zlib
type CompressionPolicy string

// CompactionMode defines the auto-compaction-mode: 'periodic' or 'revision'.
// 'periodic' for duration based retention and 'revision' for revision number based retention.
// +kubebuilder:validation:Enum=periodic;revision
type CompactionMode string

// StoreSpec defines parameters related to ObjectStore persisting backups
type StoreSpec struct {
// +optional
Expand Down Expand Up @@ -154,6 +164,16 @@ type EtcdConfig struct {
TLS *TLSConfig `json:"tls,omitempty"`
}

// SharedConfig defines parameters shared and used by Etcd as well as backup-restore sidecar.
type SharedConfig struct {
// AutoCompactionMode defines the auto-compaction-mode:'periodic' mode or 'revision' mode for etcd and embedded-Etcd of backup-restore sidecar.
// +optional
AutoCompactionMode *CompactionMode `json:"autoCompactionMode,omitempty"`
//AutoCompactionRetention defines the auto-compaction-retention length for etcd as well as for embedded-Etcd of backup-restore sidecar.
// +optional
AutoCompactionRetention *string `json:"autoCompactionRetention,omitempty"`
}

// EtcdSpec defines the desired state of Etcd
type EtcdSpec struct {
// selector is a label query over pods that should match the replica count.
Expand All @@ -168,6 +188,8 @@ type EtcdSpec struct {
Etcd EtcdConfig `json:"etcd"`
// +required
Backup BackupSpec `json:"backup"`
// +optional
Common SharedConfig `json:"sharedConfig,omitempty"`
// +required
Replicas int `json:"replicas"`
// PriorityClassName is the name of a priority class that shall be used for the etcd pods.
Expand Down
14 changes: 11 additions & 3 deletions charts/etcd/templates/etcd-bootstrap-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,17 @@ data:
# Initial cluster state ('new' or 'existing').
initial-cluster-state: {{ .Values.etcd.initialClusterState }}

# keep one day of history
auto-compaction-mode: periodic
auto-compaction-retention: "24"
{{- if .Values.sharedConfig }}
# auto-compaction-mode ("periodic" or "revision").
{{- if .Values.sharedConfig.autoCompactionMode }}
auto-compaction-mode: {{ .Values.sharedConfig.autoCompactionMode }}
{{- end }}

# auto-compaction-retention defines Auto compaction retention length for etcd.
{{- if .Values.sharedConfig.autoCompactionRetention }}
auto-compaction-retention: {{ .Values.sharedConfig.autoCompactionRetention }}
{{- end }}
{{- end }}

{{- if .Values.etcd.enableTLS }}
client-transport-security:
Expand Down
8 changes: 8 additions & 0 deletions charts/etcd/templates/etcd-statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@ spec:
{{- if .Values.backup.compression.policy }}
- --compression-policy={{ .Values.backup.compression.policy }}
{{- end }}
{{- end }}
{{- if .Values.sharedConfig }}
{{- if .Values.sharedConfig.autoCompactionMode }}
- --auto-compaction-mode={{ .Values.sharedConfig.autoCompactionMode }}
{{- end }}
{{- if .Values.sharedConfig.autoCompactionRetention }}
- --auto-compaction-retention={{ .Values.sharedConfig.autoCompactionRetention }}
{{- end }}
{{- end }}
- --snapstore-temp-directory={{ .Values.backup.snapstoreTempDir }}
image: {{ .Values.backup.image }}
Expand Down
8 changes: 8 additions & 0 deletions charts/etcd/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ backup:
# enabled: true
# policy: "gzip"

# sharedConfig defines parameters shared and used by Etcd as well as backup-restore sidecar.
sharedConfig:
# autoCompaction defines the specification to be used by Etcd as well as by embedded-Etcd of backup-restore sidecar during restoration.
# auto-compaction mode: 'periodic' mode or 'revision' mode for etcd as well as for embedded-Etcd of backup-restore sidecar.
# auto-compaction retention length for etcd as well as for embedded-Etcd of backup-restore sidecar.
autoCompactionMode: periodic
autoCompactionRetention: "30m"

volumeClaimTemplateName: test
storageClass: ""
storageCapacity: 16Gi
Expand Down
13 changes: 13 additions & 0 deletions config/crd/bases/druid.gardener.cloud_etcds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,19 @@ spec:
description: matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels map is equivalent to an element of matchExpressions, whose key field is "key", the operator is "In", and the values array contains only "value". The requirements are ANDed.
type: object
type: object
sharedConfig:
description: SharedConfig defines parameters shared and used by Etcd as well as backup-restore sidecar.
properties:
autoCompactionMode:
description: AutoCompactionMode defines the auto-compaction-mode:'periodic' mode or 'revision' mode for etcd and embedded-Etcd of backup-restore sidecar.
enum:
- periodic
- revision
type: string
autoCompactionRetention:
description: AutoCompactionRetention defines the auto-compaction-retention length for etcd as well as for embedded-Etcd of backup-restore sidecar.
type: string
type: object
storageCapacity:
anyOf:
- type: integer
Expand Down
7 changes: 6 additions & 1 deletion config/samples/druid_v1alpha1_etcd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ spec:
clientPort: 2379
serverPort: 2380
backup:
image: eu.gcr.io/gardener-project/gardener/etcdbrctl:v0.12.0-dev-e6df91b7463cf784f651bd6cc6ac7fc4d2e5a70b
image: eu.gcr.io/gardener-project/gardener/etcdbrctl:v0.12.0-dev-34f854c06838d14d6e7b08099d6cfa6fca2ad50d
port: 8080
fullSnapshotSchedule: "0 */24 * * *"
resources:
Expand All @@ -57,6 +57,11 @@ spec:
compression:
enabled: false
policy: "gzip"

sharedConfig:
autoCompactionMode: periodic
autoCompactionRetention: "30m"

replicas: 1
# priorityClassName: foo
storageClass: gardener.cloud-fast
Expand Down
30 changes: 29 additions & 1 deletion controllers/etcd_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ const (
DefaultInterval = 5 * time.Second
// EtcdReady implies that etcd is ready
EtcdReady = true
// DefaultAutoCompactionRetention defines the default auto-compaction-retention length for etcd.
DefaultAutoCompactionRetention = "30m"
)

var (
Expand Down Expand Up @@ -220,7 +222,7 @@ func (r *EtcdReconciler) reconcile(ctx context.Context, etcd *druidv1alpha1.Etcd
logger.Infof("Adding finalizer (%s) to etcd %s", FinalizerName, etcd.GetName())
finalizers.Insert(FinalizerName)
etcd.Finalizers = finalizers.UnsortedList()
if err := r.Update(ctx, etcd); err != nil {
if err := r.updateWithLock(ctx, etcd); err != nil {
if err := r.updateEtcdErrorStatus(ctx, etcd, nil, err); err != nil {
return ctrl.Result{
Requeue: true,
Expand Down Expand Up @@ -271,6 +273,15 @@ func (r *EtcdReconciler) reconcile(ctx context.Context, etcd *druidv1alpha1.Etcd
}, nil
}

// updateWithLock is wrapper function which helps in synchronization between controller threads(etcd-druid controller and custodian controller).
func (r *EtcdReconciler) updateWithLock(ctx context.Context, etcd *druidv1alpha1.Etcd) error {
m := getMutex()
m.Lock()
defer m.Unlock()

return r.Update(ctx, etcd)
}

func (r *EtcdReconciler) delete(ctx context.Context, etcd *druidv1alpha1.Etcd) (ctrl.Result, error) {
logger.Infof("Deletion timestamp set for etcd: %s", etcd.GetName())

Expand Down Expand Up @@ -955,6 +966,19 @@ func (r *EtcdReconciler) getMapFromEtcd(etcd *druidv1alpha1.Etcd) (map[string]in
volumeClaimTemplateName = *etcd.Spec.VolumeClaimTemplate
}

sharedConfigValues := map[string]interface{}{
"autoCompactionMode": druidv1alpha1.Periodic,
"autoCompactionRetention": DefaultAutoCompactionRetention,
}

if etcd.Spec.Common.AutoCompactionMode != nil {
sharedConfigValues["autoCompactionMode"] = etcd.Spec.Common.AutoCompactionMode
}

if etcd.Spec.Common.AutoCompactionRetention != nil {
sharedConfigValues["autoCompactionRetention"] = etcd.Spec.Common.AutoCompactionRetention
}

values := map[string]interface{}{
"name": etcd.Name,
"uid": etcd.UID,
Expand All @@ -963,6 +987,7 @@ func (r *EtcdReconciler) getMapFromEtcd(etcd *druidv1alpha1.Etcd) (map[string]in
"annotations": etcd.Spec.Annotations,
"etcd": etcdValues,
"backup": backupValues,
"sharedConfig": sharedConfigValues,
"replicas": etcd.Spec.Replicas,
"statefulsetReplicas": statefulsetReplicas,
"serviceName": fmt.Sprintf("%s-client", etcd.Name),
Expand Down Expand Up @@ -1218,6 +1243,9 @@ func (r *EtcdReconciler) removeOperationAnnotation(ctx context.Context, etcd *dr
}

func (r *EtcdReconciler) updateEtcdStatusAsNotReady(ctx context.Context, etcd *druidv1alpha1.Etcd) (*druidv1alpha1.Etcd, error) {
m := getMutex()
m.Lock()
defer m.Unlock()
etcdCopy := etcd.DeepCopy()
etcdCopy.Status.Ready = nil
etcdCopy.Status.ReadyReplicas = 0
Expand Down
19 changes: 15 additions & 4 deletions controllers/etcd_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ var (
storageClass = "gardener.fast"
priorityClassName = "class_priority"
deltaSnapShotMemLimit = resource.MustParse("100Mi")
autoCompactionMode = druidv1alpha1.Periodic
autoCompactionRetention = "2m"
quota = resource.MustParse("8Gi")
provider = druidv1alpha1.StorageProvider("Local")
prefix = "/tmp"
Expand Down Expand Up @@ -666,8 +668,8 @@ func validateEtcdWithDefaults(s *appsv1.StatefulSet, cm *corev1.ConfigMap, svc *
"advertise-client-urls": Equal(fmt.Sprintf("http://0.0.0.0:%d", clientPort)),
"initial-cluster-token": Equal("initial"),
"initial-cluster-state": Equal("new"),
"auto-compaction-mode": Equal("periodic"),
"auto-compaction-retention": Equal("24"),
"auto-compaction-mode": Equal(string(druidv1alpha1.Periodic)),
"auto-compaction-retention": Equal(DefaultAutoCompactionRetention),
}))

Expect(*svc).To(MatchFields(IgnoreExtras, Fields{
Expand Down Expand Up @@ -866,6 +868,8 @@ func validateEtcdWithDefaults(s *appsv1.StatefulSet, cm *corev1.ConfigMap, svc *
fmt.Sprintf("--endpoints=http://%s-local:%d", instance.Name, clientPort): Equal(fmt.Sprintf("--endpoints=http://%s-local:%d", instance.Name, clientPort)),
fmt.Sprintf("--embedded-etcd-quota-bytes=%d", int64(quota.Value())): Equal(fmt.Sprintf("--embedded-etcd-quota-bytes=%d", int64(quota.Value()))),
fmt.Sprintf("--max-backups=%d", maxBackups): Equal(fmt.Sprintf("--max-backups=%d", maxBackups)),
fmt.Sprintf("--auto-compaction-mode=%s", druidv1alpha1.Periodic): Equal(fmt.Sprintf("--auto-compaction-mode=%s", druidv1alpha1.Periodic)),
fmt.Sprintf("--auto-compaction-retention=%s", DefaultAutoCompactionRetention): Equal(fmt.Sprintf("--auto-compaction-retention=%s", DefaultAutoCompactionRetention)),
}),
"Ports": ConsistOf([]corev1.ContainerPort{
corev1.ContainerPort{
Expand Down Expand Up @@ -1016,8 +1020,8 @@ func validateEtcd(s *appsv1.StatefulSet, cm *corev1.ConfigMap, svc *corev1.Servi
"advertise-client-urls": Equal(fmt.Sprintf("https://0.0.0.0:%d", *instance.Spec.Etcd.ClientPort)),
"initial-cluster-token": Equal("initial"),
"initial-cluster-state": Equal("new"),
"auto-compaction-mode": Equal("periodic"),
"auto-compaction-retention": Equal("24"),
"auto-compaction-mode": Equal(string(*instance.Spec.Common.AutoCompactionMode)),
"auto-compaction-retention": Equal(*instance.Spec.Common.AutoCompactionRetention),

"client-transport-security": MatchKeys(IgnoreExtras, Keys{
"cert-file": Equal("/var/etcd/ssl/server/tls.crt"),
Expand Down Expand Up @@ -1252,6 +1256,8 @@ func validateEtcd(s *appsv1.StatefulSet, cm *corev1.ConfigMap, svc *corev1.Servi
fmt.Sprintf("--embedded-etcd-quota-bytes=%d", int64(instance.Spec.Etcd.Quota.Value())): Equal(fmt.Sprintf("--embedded-etcd-quota-bytes=%d", int64(instance.Spec.Etcd.Quota.Value()))),
fmt.Sprintf("%s=%s", "--delta-snapshot-period", instance.Spec.Backup.DeltaSnapshotPeriod.Duration.String()): Equal(fmt.Sprintf("%s=%s", "--delta-snapshot-period", instance.Spec.Backup.DeltaSnapshotPeriod.Duration.String())),
fmt.Sprintf("%s=%s", "--garbage-collection-period", instance.Spec.Backup.GarbageCollectionPeriod.Duration.String()): Equal(fmt.Sprintf("%s=%s", "--garbage-collection-period", instance.Spec.Backup.GarbageCollectionPeriod.Duration.String())),
fmt.Sprintf("%s=%s", "--auto-compaction-mode", *instance.Spec.Common.AutoCompactionMode): Equal(fmt.Sprintf("%s=%s", "--auto-compaction-mode", autoCompactionMode)),
fmt.Sprintf("%s=%s", "--auto-compaction-retention", *instance.Spec.Common.AutoCompactionRetention): Equal(fmt.Sprintf("%s=%s", "--auto-compaction-retention", autoCompactionRetention)),
}),
"Ports": ConsistOf([]corev1.ContainerPort{
corev1.ContainerPort{
Expand Down Expand Up @@ -1994,6 +2000,7 @@ func getEtcdWithDefault(name, namespace string) *druidv1alpha1.Etcd {
Replicas: 1,
Backup: druidv1alpha1.BackupSpec{},
Etcd: druidv1alpha1.EtcdConfig{},
Common: druidv1alpha1.SharedConfig{},
},
}
return instance
Expand Down Expand Up @@ -2073,6 +2080,10 @@ func getEtcd(name, namespace string, tlsEnabled bool) *druidv1alpha1.Etcd {
ClientPort: &clientPort,
ServerPort: &serverPort,
},
Common: druidv1alpha1.SharedConfig{
AutoCompactionMode: &autoCompactionMode,
AutoCompactionRetention: &autoCompactionRetention,
},
},
}

Expand Down