Skip to content

Commit

Permalink
chore: retrocompatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
cyrinux committed Dec 6, 2024
1 parent 5a4b4f0 commit cf485c9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
20 changes: 18 additions & 2 deletions internal/controller/dragonfly_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion internal/resources/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit cf485c9

Please sign in to comment.