@@ -135,6 +135,32 @@ func (r *Reconciler) ReconcileSystemSecrets() error {
135
135
if err := r .ReconcileObject (r .SecretEndpoints , r .SetDesiredSecretEndpoints ); err != nil {
136
136
return err
137
137
}
138
+
139
+ if err := r .ReconcileObject (r .SecretMetricsAuth , r .SetDesiredMetricsAuth ); err != nil {
140
+ return err
141
+ }
142
+
143
+ return nil
144
+ }
145
+
146
+ // SetDesiredMetricsAuth updates the ServiceAccount as desired for reconciling
147
+ func (r * Reconciler ) SetDesiredMetricsAuth () error {
148
+
149
+ // Load string data from data
150
+ util .SecretResetStringDataFromData (r .SecretMetricsAuth )
151
+ // SecretMetricsAuth exists means the system already created and we can skip
152
+ if r .SecretMetricsAuth .StringData ["metrics_token" ] != "" {
153
+ return nil
154
+ }
155
+ res , err := r .NBClient .CreateAuthAPI (nb.CreateAuthParams {
156
+ System : r .Request .Name ,
157
+ Role : "metrics-auth" ,
158
+ Email : options .OperatorAccountEmail ,
159
+ })
160
+ if err != nil {
161
+ return fmt .Errorf ("cannot create an auth token for metrics, error: %v" , err )
162
+ }
163
+ r .SecretMetricsAuth .StringData ["metrics_token" ] = res .Token
138
164
return nil
139
165
}
140
166
@@ -619,11 +645,11 @@ func (r *Reconciler) setDesiredEndpointMounts(podSpec *corev1.PodSpec, container
619
645
//this is a way to let containers explicitly know
620
646
//that an nsr should be mounted on them
621
647
envVar := corev1.EnvVar {
622
- Name : "NSFS_NSR_" + nsStore .Name ,
648
+ Name : "NSFS_NSR_" + nsStore .Name ,
623
649
Value : "mounted" ,
624
650
}
625
651
626
- util .MergeEnvArrays (& container .Env , & []corev1.EnvVar {envVar });
652
+ util .MergeEnvArrays (& container .Env , & []corev1.EnvVar {envVar })
627
653
}
628
654
}
629
655
@@ -1583,15 +1609,42 @@ func (r *Reconciler) ReconcileServiceMonitors() error {
1583
1609
1584
1610
r .ApplyMonitoringLabels (r .ServiceMonitorMgmt )
1585
1611
1586
- if err := r .ReconcileObjectOptional (r .ServiceMonitorMgmt , nil ); err != nil {
1612
+ if err := r .ReconcileObjectOptional (r .ServiceMonitorMgmt , r . setDesiredServiceMonitorMgmt ); err != nil {
1587
1613
return err
1588
1614
}
1589
- if err := r .ReconcileObjectOptional (r .ServiceMonitorS3 , nil ); err != nil {
1615
+ if err := r .ReconcileObjectOptional (r .ServiceMonitorS3 , r . setDesiredServiceMonitorS3 ); err != nil {
1590
1616
return err
1591
1617
}
1592
1618
return nil
1593
1619
}
1594
1620
1621
+ // setDesiredServiceMonitorMgmt set authorization to managemnt ServiceMonitor
1622
+ func (r * Reconciler ) setDesiredServiceMonitorMgmt () error {
1623
+ r .setServiceMonitorAuthorization (r .ServiceMonitorMgmt .Spec .Endpoints )
1624
+ return nil
1625
+ }
1626
+
1627
+ // setDesiredServiceMonitorS3 set authorization to s3 ServiceMonitor
1628
+ func (r * Reconciler ) setDesiredServiceMonitorS3 () error {
1629
+ r .setServiceMonitorAuthorization (r .ServiceMonitorS3 .Spec .Endpoints )
1630
+ return nil
1631
+ }
1632
+
1633
+ // setServiceMonitorAuthorization set authorization to both managemnt and s3 ServiceMonitor
1634
+ func (r * Reconciler ) setServiceMonitorAuthorization (endpoints []monitoringv1.Endpoint ) {
1635
+ for i := range endpoints {
1636
+ endpoints [i ].Authorization = & monitoringv1.SafeAuthorization {
1637
+ Type : "Bearer" ,
1638
+ Credentials : & corev1.SecretKeySelector {
1639
+ LocalObjectReference : corev1.LocalObjectReference {
1640
+ Name : r .SecretMetricsAuth .Name ,
1641
+ },
1642
+ Key : "metrics_token" ,
1643
+ },
1644
+ }
1645
+ }
1646
+ }
1647
+
1595
1648
// ReconcileReadSystem calls read_system on noobaa server and stores the result
1596
1649
func (r * Reconciler ) ReconcileReadSystem () error {
1597
1650
// Skip if joining another NooBaa
0 commit comments