From cf485c98e7e61b6cd164751dc5c864e1cb70a6e2 Mon Sep 17 00:00:00 2001 From: Cyril Levis Date: Fri, 6 Dec 2024 09:43:14 +0100 Subject: [PATCH] chore: retrocompatibility --- internal/controller/dragonfly_instance.go | 20 ++++++++++++++++++-- internal/resources/const.go | 3 ++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/internal/controller/dragonfly_instance.go b/internal/controller/dragonfly_instance.go index b56986f..2142425 100644 --- a/internal/controller/dragonfly_instance.go +++ b/internal/controller/dragonfly_instance.go @@ -235,8 +235,12 @@ func (dfi *DragonflyInstance) checkReplicaRole(ctx context.Context, pod *corev1. } } - if masterIp != redisMasterIp && masterIp != pod.Labels[resources.MasterIp] { - return false, nil + // for compatibily, to be remove in futur version + // check if the masterIp matches either the label (for compatibility) or the annotation + if masterIp != redisMasterIp { + if masterIp != pod.Labels[resources.MasterIpLabel] && masterIp != pod.Annotations[resources.MasterIp] { + return false, nil + } } return true, nil @@ -354,6 +358,12 @@ func (dfi *DragonflyInstance) replicaOf(ctx context.Context, pod *corev1.Pod, ma pod.Annotations = make(map[string]string) } pod.Annotations[resources.MasterIp] = masterIp + + // for compatibily, to be remove in futur version + if !strings.Contains(masterIp, ":") { + pod.Labels[resources.MasterIpLabel] = masterIp + } + if err := dfi.client.Update(ctx, pod); err != nil { return fmt.Errorf("could not update replica annotation: %w", err) } @@ -383,10 +393,16 @@ func (dfi *DragonflyInstance) replicaOfNoOne(ctx context.Context, pod *corev1.Po dfi.log.Info("Marking pod role as master", "pod", pod.Name, "masterIp", masterIp) pod.Labels[resources.Role] = resources.Master + // for compatibily, to be remove in futur version + if !strings.Contains(masterIp, ":") { + pod.Labels[resources.MasterIpLabel] = masterIp + } + if pod.Annotations == nil { pod.Annotations = make(map[string]string) } pod.Annotations[resources.MasterIp] = masterIp + if err := dfi.client.Update(ctx, pod); err != nil { return err } diff --git a/internal/resources/const.go b/internal/resources/const.go index e4c8ca6..79b5c11 100644 --- a/internal/resources/const.go +++ b/internal/resources/const.go @@ -56,7 +56,8 @@ const ( // KubernetesPartOfLabel is the name of a higher level application this one is part of KubernetesPartOfLabelKey = "app.kubernetes.io/part-of" - MasterIp string = "operator.dragonflydb.io/masterIP" + MasterIpLabel string = "master-ip" + MasterIp string = "operator.dragonflydb.io/masterIP" Role string = "role"