@@ -16,11 +16,14 @@ package tasks
1616
1717import (
1818 "context"
19+ "fmt"
1920 "net/url"
2021
22+ "github.com/pkg/errors"
23+ v1 "k8s.io/api/core/v1"
24+
2125 "github.com/openshift/cluster-monitoring-operator/pkg/client"
2226 "github.com/openshift/cluster-monitoring-operator/pkg/manifests"
23- "github.com/pkg/errors"
2427)
2528
2629type ConfigSharingTask struct {
@@ -71,7 +74,49 @@ func (t *ConfigSharingTask) Run(ctx context.Context) error {
7174 return errors .Wrap (err , "failed to retrieve Thanos Querier host" )
7275 }
7376
74- cm := t .factory .SharingConfig (promURL , amURL , thanosURL )
77+ var (
78+ svc * v1.Service
79+ webPort , tenancyPort int
80+ )
81+ if t .config .UserWorkloadConfiguration .Alertmanager .Enabled {
82+ // User-defined alerts are routed to the UWM Alertmanager.
83+ svc , err = t .factory .AlertmanagerUserWorkloadService ()
84+ if err != nil {
85+ return errors .Wrap (err , "initializing Alertmanager User Workload Service failed" )
86+ }
87+ } else {
88+ // User-defined alerts are routed to the platform Alertmanager.
89+ svc , err = t .factory .AlertmanagerService ()
90+ if err != nil {
91+ return errors .Wrap (err , "initializing Alertmanager Service failed" )
92+ }
93+ }
94+
95+ for _ , port := range svc .Spec .Ports {
96+ switch port .Name {
97+ case "web" :
98+ webPort = int (port .Port )
99+ case "tenancy" :
100+ tenancyPort = int (port .Port )
101+ }
102+ }
103+
104+ if webPort == 0 {
105+ return errors .New ("failed to find Alertmanager web port" )
106+ }
107+
108+ if tenancyPort == 0 {
109+ return errors .New ("failed to find Alertmanager tenancy port" )
110+ }
111+
112+ cm := t .factory .SharingConfig (
113+ promURL ,
114+ amURL ,
115+ thanosURL ,
116+ fmt .Sprintf ("%s.%s.svc:%d" , svc .Name , svc .Namespace , webPort ),
117+ fmt .Sprintf ("%s.%s.svc:%d" , svc .Name , svc .Namespace , tenancyPort ),
118+ )
119+
75120 err = t .client .CreateOrUpdateConfigMap (ctx , cm )
76121 if err != nil {
77122 return errors .Wrapf (err , "reconciling %s/%s Config ConfigMap failed" , cm .Namespace , cm .Name )
0 commit comments