Skip to content

Commit

Permalink
Modified configmap name to be pefixed with etcd.Name for consistency …
Browse files Browse the repository at this point in the history
…with other resources like leases, roles, etc.
  • Loading branch information
anveshreddy18 committed Feb 27, 2024
1 parent af42936 commit f247507
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 15 deletions.
2 changes: 1 addition & 1 deletion api/v1alpha1/types_etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/types_etcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down Expand Up @@ -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:
```
Expand Down
2 changes: 1 addition & 1 deletion docs/proposals/03-scaling-up-an-etcd-cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 14 additions & 0 deletions pkg/component/etcd/configmap/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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"`
Expand Down
9 changes: 6 additions & 3 deletions pkg/component/etcd/configmap/configmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -76,6 +77,7 @@ var _ = Describe("Configmap", func() {
quota = resource.MustParse("8Gi")
clientPort = 2222
serverPort = 3333
snapshotCount = 75000
autoCompactionMode = "periodic"
autoCompactionRetention = "30m"

Expand Down Expand Up @@ -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,
Expand All @@ -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,
},
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/component/etcd/statefulset/statefulset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/etcd_backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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())
Expand Down
6 changes: 3 additions & 3 deletions test/integration/controllers/etcd/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion test/utils/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down

0 comments on commit f247507

Please sign in to comment.