Skip to content
27 changes: 27 additions & 0 deletions pkg/apis/psmdb/v1/psmdb_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,33 @@ type ReplsetSpec struct {
PrimaryPreferTagSelector PrimaryPreferTagSelectorSpec `json:"primaryPreferTagSelector,omitempty"`
}

func (r *ReplsetSpec) GetHorizons(withPorts bool) map[string]string {
horizons := make(map[string]string)
for podName, m := range r.Horizons {
overrides, ok := r.ReplsetOverrides[podName]
hasOverrides := ok && len(overrides.Horizons) > 0

for h, domain := range m {
if hasOverrides {
d, ok := overrides.Horizons[h]
if ok {
domain = d
}
}

idx := strings.IndexRune(domain, ':')
if withPorts && idx == -1 {
domain = fmt.Sprintf("%s:%d", domain, r.GetPort())
}
if !withPorts && idx != -1 {
domain = domain[:idx]
}
horizons[h] = domain
}
}
Copy link

Copilot AI Dec 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The GetHorizons method only iterates over base Horizons (line 769) and applies overrides to them. This means if a pod has horizons defined exclusively in ReplsetOverrides but not in the base Horizons map, those override-only horizons will be ignored. Consider also iterating over ReplsetOverrides to ensure all horizon configurations are included, even if they don't have a corresponding entry in the base Horizons map.

Suggested change
}
}
for podName, overrides := range r.ReplsetOverrides {
if len(overrides.Horizons) == 0 {
continue
}
// Skip pods that already have horizons from the base spec.
if _, exists := horizons[podName]; exists {
continue
}
horizons[podName] = make(map[string]string, len(overrides.Horizons))
for h, domain := range overrides.Horizons {
if withPorts {
if !strings.Contains(domain, ":") {
domain = fmt.Sprintf("%s:%d", domain, r.GetPort())
}
}
horizons[podName][h] = domain
}
}

Copilot uses AI. Check for mistakes.
return horizons
}

func (r *ReplsetSpec) PodName(cr *PerconaServerMongoDB, idx int) string {
return fmt.Sprintf("%s-%s-%d", cr.Name, r.Name, idx)
}
Expand Down
18 changes: 2 additions & 16 deletions pkg/controller/perconaservermongodb/mgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,23 +273,9 @@ func (r *ReconcilePerconaServerMongoDB) getConfigMemberForPod(ctx context.Contex
member.Priority = *overrides.Priority
}

horizons := make(map[string]string)
for h, domain := range rs.Horizons[pod.Name] {
d := domain
if !strings.Contains(d, ":") {
d = fmt.Sprintf("%s:%d", d, rs.GetPort())
}
horizons[h] = d
}
for h, domain := range overrides.Horizons {
d := domain
if !strings.Contains(d, ":") {
d = fmt.Sprintf("%s:%d", d, rs.GetPort())
}
horizons[h] = d
}
horizons := rs.GetHorizons(true)
if len(horizons) > 0 {
member.Horizons = horizons
member.Horizons = rs.GetHorizons(true)
}

tags := util.MapMerge(mongo.ReplsetTags{
Expand Down
11 changes: 7 additions & 4 deletions pkg/psmdb/tls/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,14 @@ func GetCertificateSans(cr *api.PerconaServerMongoDB) []string {
cr.Name + "-" + replset.Name + "." + cr.Namespace + "." + cr.Spec.MultiCluster.DNSSuffix,
"*." + cr.Name + "-" + replset.Name + "." + cr.Namespace + "." + cr.Spec.MultiCluster.DNSSuffix,
}...)
}
if cr.CompareVersion("1.13.0") >= 0 {
sans = append(sans, "*."+cr.Namespace+"."+cr.Spec.MultiCluster.DNSSuffix)
}

if cr.CompareVersion("1.22.0") >= 0 && len(replset.Horizons) > 0 {
for _, domain := range replset.GetHorizons(false) {
sans = append(sans, domain)
}
}
}
sans = append(sans, "*."+cr.Namespace+"."+cr.Spec.MultiCluster.DNSSuffix)
sans = append(sans, getShardingSans(cr)...)

return sans
Expand Down
Loading