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

feat: add common labels to etcd services #537

Merged
merged 1 commit into from
Mar 14, 2024
Merged
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
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
Loading