From 618b0d7e6e7b25bac695194c9bddf84ba9b96590 Mon Sep 17 00:00:00 2001 From: subnix Date: Wed, 6 Mar 2024 11:27:55 +0400 Subject: [PATCH] feat: add common labels to etcd services Signed-off-by: subnix --- .../etcdlockserver/reconcile_services.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/pkg/controller/etcdlockserver/reconcile_services.go b/pkg/controller/etcdlockserver/reconcile_services.go index de2e934b..165ab8f5 100644 --- a/pkg/controller/etcdlockserver/reconcile_services.go +++ b/pkg/controller/etcdlockserver/reconcile_services.go @@ -38,6 +38,16 @@ func (r *ReconcileEtcdLockserver) reconcileServices(ctx context.Context, ls *pla labels := map[string]string{ etcd.LockserverLabel: lockserverName, } + // Backward-compatible labels change + // We shouldn't pass the extended labels to the reconciler directly, because it compares the labels, + // but we can use the extended labels in the reconciler.Strategy for creation/update. + extendedLabels := map[string]string{ + etcd.LockserverLabel: lockserverName, + planetscalev2.ComponentLabel: planetscalev2.EtcdComponentName, + } + if _, hasClusterLabel := ls.Labels[planetscalev2.ClusterLabel]; hasClusterLabel { + extendedLabels[planetscalev2.ClusterLabel] = ls.Labels[planetscalev2.ClusterLabel] + } // Reconcile the client Service. if *ls.Spec.CreateClientService { @@ -49,13 +59,13 @@ func (r *ReconcileEtcdLockserver) reconcileServices(ctx context.Context, ls *pla Kind: &corev1.Service{}, New: func(key client.ObjectKey) runtime.Object { - svc := etcd.NewClientService(key, labels) + svc := etcd.NewClientService(key, extendedLabels) update.ServiceOverrides(svc, ls.Spec.ClientService) return svc }, UpdateInPlace: func(key client.ObjectKey, obj runtime.Object) { svc := obj.(*corev1.Service) - etcd.UpdateClientService(svc, labels) + etcd.UpdateClientService(svc, extendedLabels) update.InPlaceServiceOverrides(svc, ls.Spec.ClientService) }, }) @@ -74,13 +84,13 @@ func (r *ReconcileEtcdLockserver) reconcileServices(ctx context.Context, ls *pla Kind: &corev1.Service{}, New: func(key client.ObjectKey) runtime.Object { - svc := etcd.NewPeerService(key, labels) + svc := etcd.NewPeerService(key, extendedLabels) update.ServiceOverrides(svc, ls.Spec.PeerService) return svc }, UpdateInPlace: func(key client.ObjectKey, obj runtime.Object) { svc := obj.(*corev1.Service) - etcd.UpdatePeerService(svc, labels) + etcd.UpdatePeerService(svc, extendedLabels) update.InPlaceServiceOverrides(svc, ls.Spec.PeerService) }, })