Skip to content

Commit

Permalink
Merge pull request #537 from subnix/fix/etcd-setvices-labels
Browse files Browse the repository at this point in the history
feat: add common labels to etcd services
  • Loading branch information
frouioui authored Mar 14, 2024
2 parents 45cf717 + 618b0d7 commit adbd328
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions pkg/controller/etcdlockserver/reconcile_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
},
})
Expand All @@ -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)
},
})
Expand Down

0 comments on commit adbd328

Please sign in to comment.