From f2475079fbf198ed9256a172d61e8990d2143186 Mon Sep 17 00:00:00 2001 From: Anvesh Reddy Pinnapureddy Date: Tue, 27 Feb 2024 13:16:58 +0530 Subject: [PATCH] Modified configmap name to be pefixed with etcd.Name for consistency with other resources like leases, roles, etc. --- api/v1alpha1/types_etcd.go | 2 +- api/v1alpha1/types_etcd_test.go | 2 +- ...y-from-permanent-quorum-loss-in-etcd-cluster.md | 4 ++-- docs/proposals/03-scaling-up-an-etcd-cluster.md | 2 +- pkg/component/etcd/configmap/configmap.go | 14 ++++++++++++++ pkg/component/etcd/configmap/configmap_test.go | 9 ++++++--- pkg/component/etcd/statefulset/statefulset_test.go | 2 +- test/e2e/etcd_backup_test.go | 4 ++-- .../controllers/etcd/reconciler_test.go | 6 +++--- test/utils/configmap.go | 2 +- 10 files changed, 32 insertions(+), 15 deletions(-) diff --git a/api/v1alpha1/types_etcd.go b/api/v1alpha1/types_etcd.go index 49513cfbc..c61af99ed 100644 --- a/api/v1alpha1/types_etcd.go +++ b/api/v1alpha1/types_etcd.go @@ -446,7 +446,7 @@ func (e *Etcd) GetServiceAccountName() string { // GetConfigmapName returns the name of the configmap for the Etcd. func (e *Etcd) GetConfigmapName() string { - return fmt.Sprintf("etcd-bootstrap-%s", string(e.UID[:6])) + return fmt.Sprintf("%s-bootstrap-%s", e.Name, (e.UID[:6])) } // GetCompactionJobName returns the compaction job name for the Etcd. diff --git a/api/v1alpha1/types_etcd_test.go b/api/v1alpha1/types_etcd_test.go index a46e57b19..c8c99209e 100644 --- a/api/v1alpha1/types_etcd_test.go +++ b/api/v1alpha1/types_etcd_test.go @@ -89,7 +89,7 @@ var _ = Describe("Etcd", func() { Context("GetConfigmapName", func() { It("should return the correct configmap name", func() { - Expect(created.GetConfigmapName()).To(Equal("etcd-bootstrap-123456")) + Expect(created.GetConfigmapName()).To(Equal(created.Name + "-bootstrap-123456")) }) }) diff --git a/docs/operations/recovery-from-permanent-quorum-loss-in-etcd-cluster.md b/docs/operations/recovery-from-permanent-quorum-loss-in-etcd-cluster.md index f20f0dfe5..98c69c727 100644 --- a/docs/operations/recovery-from-permanent-quorum-loss-in-etcd-cluster.md +++ b/docs/operations/recovery-from-permanent-quorum-loss-in-etcd-cluster.md @@ -28,7 +28,7 @@ There are two [Etcd clusters](https://github.com/gardener/etcd-druid/tree/master Volumes: etcd-config-file: Type: ConfigMap (a volume populated by a ConfigMap) - Name: etcd-bootstrap-4785b0 + Name: etcd-main-bootstrap-4785b0 Optional: false ``` @@ -63,7 +63,7 @@ There are two [Etcd clusters](https://github.com/gardener/etcd-druid/tree/master Delete all `etcd-main` member leases. - 6. Edit the `etcd-main` cluster's configmap (ex: `etcd-bootstrap-4785b0`) as follows: + 6. Edit the `etcd-main` cluster's configmap (ex: `etcd-main-bootstrap-4785b0`) as follows: Find the `initial-cluster` field in the configmap. It will look like the following: ``` diff --git a/docs/proposals/03-scaling-up-an-etcd-cluster.md b/docs/proposals/03-scaling-up-an-etcd-cluster.md index 3f678c47a..2b8633943 100644 --- a/docs/proposals/03-scaling-up-an-etcd-cluster.md +++ b/docs/proposals/03-scaling-up-an-etcd-cluster.md @@ -24,7 +24,7 @@ Now, it is detected whether peer URL was TLS enabled or not for single node etcd - If peer URL was not TLS enabled then etcd-druid has to intervene and make sure peer URL should be TLS enabled first for the single node before marking the cluster for scale-up. ## Action taken by etcd-druid to enable the peerURL TLS -1. Etcd-druid will update the `etcd-bootstrap` config-map with new config like initial-cluster,initial-advertise-peer-urls etc. Backup-restore will detect this change and update the member lease annotation to `member.etcd.gardener.cloud/tls-enabled: "true"`. +1. Etcd-druid will update the `{etcd.Name}-bootstrap` config-map with new config like initial-cluster,initial-advertise-peer-urls etc. Backup-restore will detect this change and update the member lease annotation to `member.etcd.gardener.cloud/tls-enabled: "true"`. 2. In case the peer URL TLS has been changed to `enabled`: Etcd-druid will add tasks to the deployment flow. - To ensure that the TLS enablement of peer URL is properly reflected in etcd, the existing etcd StatefulSet pods should be restarted twice. - The first restart pushes a new configuration which contains Peer URL TLS configuration. Backup-restore will update the member peer url. This will result in the change of the peer url in the etcd's database, but it may not reflect in the already running etcd container. Ideally a restart of an etcd container would have been sufficient but currently k8s doesn't expose an API to force restart a single container within a pod. Therefore, we need to restart the StatefulSet pod(s) once again. When the pod(s) is restarted the second time it will now start etcd with the correct peer url which will be TLS enabled. diff --git a/pkg/component/etcd/configmap/configmap.go b/pkg/component/etcd/configmap/configmap.go index 4545747cd..ad9bc913c 100644 --- a/pkg/component/etcd/configmap/configmap.go +++ b/pkg/component/etcd/configmap/configmap.go @@ -48,6 +48,11 @@ func New(c client.Client, namespace string, values *Values) gardenercomponent.De } func (c *component) Deploy(ctx context.Context) error { + // Fetch and delete the old configmap if it exists + oldConfigMap := c.getOldConfigmap() + if err := c.deleteConfigmap(ctx, oldConfigMap); err != nil { + return err + } cm := c.emptyConfigmap() return c.syncConfigmap(ctx, cm) } @@ -148,6 +153,15 @@ func (c *component) emptyConfigmap() *corev1.ConfigMap { } } +func (c *component) getOldConfigmap() *corev1.ConfigMap { + return &corev1.ConfigMap{ + ObjectMeta: metav1.ObjectMeta{ + Name: fmt.Sprintf("etcd-bootstrap-%s", string(c.values.EtcdUID[:6])), + Namespace: c.namespace, + }, + } +} + type etcdConfig struct { Name string `yaml:"name"` DataDir string `yaml:"data-dir"` diff --git a/pkg/component/etcd/configmap/configmap_test.go b/pkg/component/etcd/configmap/configmap_test.go index 88d819eec..e0f9a2a9c 100644 --- a/pkg/component/etcd/configmap/configmap_test.go +++ b/pkg/component/etcd/configmap/configmap_test.go @@ -54,6 +54,7 @@ var _ = Describe("Configmap", func() { metricsLevel druidv1alpha1.MetricsLevel quota resource.Quantity clientPort, serverPort int32 + snapshotCount int autoCompactionMode druidv1alpha1.CompactionMode autoCompactionRetention string labels map[string]string @@ -76,6 +77,7 @@ var _ = Describe("Configmap", func() { quota = resource.MustParse("8Gi") clientPort = 2222 serverPort = 3333 + snapshotCount = 75000 autoCompactionMode = "periodic" autoCompactionRetention = "30m" @@ -122,8 +124,9 @@ var _ = Describe("Configmap", func() { Name: "peer-url-etcd-server-tls", }, }, - ClientPort: &clientPort, - ServerPort: &serverPort, + ClientPort: &clientPort, + ServerPort: &serverPort, + SnapshotCount: &snapshotCount, }, Common: druidv1alpha1.SharedConfig{ AutoCompactionMode: &autoCompactionMode, @@ -136,7 +139,7 @@ var _ = Describe("Configmap", func() { cm = &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ - Name: fmt.Sprintf("etcd-bootstrap-%s", string(values.EtcdUID[:6])), + Name: fmt.Sprintf("%s-bootstrap-%s", etcd.Name, string(values.EtcdUID[:6])), Namespace: namespace, }, } diff --git a/pkg/component/etcd/statefulset/statefulset_test.go b/pkg/component/etcd/statefulset/statefulset_test.go index 3976db4a3..548c0fe0c 100644 --- a/pkg/component/etcd/statefulset/statefulset_test.go +++ b/pkg/component/etcd/statefulset/statefulset_test.go @@ -766,7 +766,7 @@ func checkStatefulset(sts *appsv1.StatefulSet, values Values) { "VolumeSource": MatchFields(IgnoreExtras, Fields{ "ConfigMap": PointTo(MatchFields(IgnoreExtras, Fields{ "LocalObjectReference": MatchFields(IgnoreExtras, Fields{ - "Name": Equal(fmt.Sprintf("etcd-bootstrap-%s", string(values.OwnerReference.UID[:6]))), + "Name": Equal(values.ConfigMapName), }), "DefaultMode": PointTo(Equal(int32(0644))), "Items": MatchAllElements(keyIterator, Elements{ diff --git a/test/e2e/etcd_backup_test.go b/test/e2e/etcd_backup_test.go index 0de133eb0..153f7c716 100644 --- a/test/e2e/etcd_backup_test.go +++ b/test/e2e/etcd_backup_test.go @@ -260,7 +260,7 @@ func checkEtcdReady(ctx context.Context, cl client.Client, logger logr.Logger, e logger.Info("Checking configmap") cm := &corev1.ConfigMap{} - ExpectWithOffset(2, cl.Get(ctx, client.ObjectKey{Name: "etcd-bootstrap-" + string(etcd.UID[:6]), Namespace: etcd.Namespace}, cm)).To(Succeed()) + ExpectWithOffset(2, cl.Get(ctx, client.ObjectKey{Name: etcd.Name + "-bootstrap-" + string(etcd.UID[:6]), Namespace: etcd.Namespace}, cm)).To(Succeed()) logger.Info("Checking client service") svc := &corev1.Service{} @@ -293,7 +293,7 @@ func deleteAndCheckEtcd(ctx context.Context, cl client.Client, logger logr.Logge ExpectWithOffset(1, cl.Get( ctx, - client.ObjectKey{Name: "etcd-bootstrap-" + string(etcd.UID[:6]), Namespace: etcd.Namespace}, + client.ObjectKey{Name: etcd.Name + "-bootstrap-" + string(etcd.UID[:6]), Namespace: etcd.Namespace}, &corev1.ConfigMap{}, ), ).Should(matchers.BeNotFoundError()) diff --git a/test/integration/controllers/etcd/reconciler_test.go b/test/integration/controllers/etcd/reconciler_test.go index dfec87c81..370f240b6 100644 --- a/test/integration/controllers/etcd/reconciler_test.go +++ b/test/integration/controllers/etcd/reconciler_test.go @@ -782,7 +782,7 @@ func validateDefaultValuesForEtcd(instance *druidv1alpha1.Etcd, s *appsv1.Statef "VolumeSource": MatchFields(IgnoreExtras, Fields{ "ConfigMap": PointTo(MatchFields(IgnoreExtras, Fields{ "LocalObjectReference": MatchFields(IgnoreExtras, Fields{ - "Name": Equal(fmt.Sprintf("etcd-bootstrap-%s", string(instance.UID[:6]))), + "Name": Equal(fmt.Sprintf("%s-bootstrap-%s", instance.Name, string(instance.UID[:6]))), }), "DefaultMode": PointTo(Equal(int32(0644))), "Items": MatchAllElements(testutils.KeyIterator, Elements{ @@ -847,7 +847,7 @@ func validateEtcd(instance *druidv1alpha1.Etcd, s *appsv1.StatefulSet, cm *corev Expect(*cm).To(MatchFields(IgnoreExtras, Fields{ "ObjectMeta": MatchFields(IgnoreExtras, Fields{ - "Name": Equal(fmt.Sprintf("etcd-bootstrap-%s", string(instance.UID[:6]))), + "Name": Equal(fmt.Sprintf("%s-bootstrap-%s", instance.Name, string(instance.UID[:6]))), "Namespace": Equal(instance.Namespace), "Labels": MatchAllKeys(Keys{ "name": Equal("etcd"), @@ -1190,7 +1190,7 @@ func validateEtcd(instance *druidv1alpha1.Etcd, s *appsv1.StatefulSet, cm *corev "VolumeSource": MatchFields(IgnoreExtras, Fields{ "ConfigMap": PointTo(MatchFields(IgnoreExtras, Fields{ "LocalObjectReference": MatchFields(IgnoreExtras, Fields{ - "Name": Equal(fmt.Sprintf("etcd-bootstrap-%s", string(instance.UID[:6]))), + "Name": Equal(fmt.Sprintf("%s-bootstrap-%s", instance.Name, string(instance.UID[:6]))), }), "DefaultMode": PointTo(Equal(int32(0644))), "Items": MatchAllElements(testutils.KeyIterator, Elements{ diff --git a/test/utils/configmap.go b/test/utils/configmap.go index 1cee03204..1d7250e3c 100644 --- a/test/utils/configmap.go +++ b/test/utils/configmap.go @@ -30,7 +30,7 @@ func ConfigMapIsCorrectlyReconciled(c client.Client, timeout time.Duration, inst ctx, cancel := context.WithTimeout(context.Background(), timeout) defer cancel() req := types.NamespacedName{ - Name: fmt.Sprintf("etcd-bootstrap-%s", string(instance.UID[:6])), + Name: fmt.Sprintf("%s-bootstrap-%s", instance.Name, string(instance.UID[:6])), Namespace: instance.Namespace, }