@@ -39,19 +39,16 @@ import (
39
39
"k8s.io/client-go/tools/cache"
40
40
"k8s.io/client-go/transport"
41
41
"k8s.io/client-go/util/workqueue"
42
- "k8s.io/component-base/metrics/legacyregistry"
43
42
"k8s.io/klog/v2"
44
43
apiregistrationv1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1"
45
44
apiregistrationv1apihelper "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1/helper"
46
45
apiregistrationclient "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/typed/apiregistration/v1"
47
46
informers "k8s.io/kube-aggregator/pkg/client/informers/externalversions/apiregistration/v1"
48
47
listers "k8s.io/kube-aggregator/pkg/client/listers/apiregistration/v1"
49
48
"k8s.io/kube-aggregator/pkg/controllers"
49
+ availabilitymetrics "k8s.io/kube-aggregator/pkg/controllers/status/metrics"
50
50
)
51
51
52
- // making sure we only register metrics once into legacy registry
53
- var registerIntoLegacyRegistryOnce sync.Once
54
-
55
52
type certKeyFunc func () ([]byte , []byte )
56
53
57
54
// ServiceResolver knows how to convert a service reference into an actual location.
@@ -88,7 +85,7 @@ type AvailableConditionController struct {
88
85
cacheLock sync.RWMutex
89
86
90
87
// metrics registered into legacy registry
91
- metrics * availabilityMetrics
88
+ metrics * availabilitymetrics. Metrics
92
89
}
93
90
94
91
// NewAvailableConditionController returns a new AvailableConditionController.
@@ -100,6 +97,7 @@ func NewAvailableConditionController(
100
97
proxyTransportDial * transport.DialHolder ,
101
98
proxyCurrentCertKeyContent certKeyFunc ,
102
99
serviceResolver ServiceResolver ,
100
+ metrics * availabilitymetrics.Metrics ,
103
101
) (* AvailableConditionController , error ) {
104
102
c := & AvailableConditionController {
105
103
apiServiceClient : apiServiceClient ,
@@ -116,7 +114,7 @@ func NewAvailableConditionController(
116
114
),
117
115
proxyTransportDial : proxyTransportDial ,
118
116
proxyCurrentCertKeyContent : proxyCurrentCertKeyContent ,
119
- metrics : newAvailabilityMetrics () ,
117
+ metrics : metrics ,
120
118
}
121
119
122
120
// resync on this one because it is low cardinality and rechecking the actual discovery
@@ -148,15 +146,6 @@ func NewAvailableConditionController(
148
146
149
147
c .syncFn = c .sync
150
148
151
- // TODO: decouple from legacyregistry
152
- var err error
153
- registerIntoLegacyRegistryOnce .Do (func () {
154
- err = c .metrics .Register (legacyregistry .Register , legacyregistry .CustomRegister )
155
- })
156
- if err != nil {
157
- return nil , err
158
- }
159
-
160
149
return c , nil
161
150
}
162
151
@@ -385,7 +374,7 @@ func (c *AvailableConditionController) sync(key string) error {
385
374
// apiservices. Doing that means we don't want to quickly issue no-op updates.
386
375
func (c * AvailableConditionController ) updateAPIServiceStatus (originalAPIService , newAPIService * apiregistrationv1.APIService ) (* apiregistrationv1.APIService , error ) {
387
376
// update this metric on every sync operation to reflect the actual state
388
- c .setUnavailableGauge (newAPIService )
377
+ c .metrics . SetUnavailableGauge (newAPIService )
389
378
390
379
if equality .Semantic .DeepEqual (originalAPIService .Status , newAPIService .Status ) {
391
380
return newAPIService , nil
@@ -412,7 +401,7 @@ func (c *AvailableConditionController) updateAPIServiceStatus(originalAPIService
412
401
return nil , err
413
402
}
414
403
415
- c .setUnavailableCounter (originalAPIService , newAPIService )
404
+ c .metrics . SetUnavailableCounter (originalAPIService , newAPIService )
416
405
return newAPIService , nil
417
406
}
418
407
@@ -599,28 +588,3 @@ func (c *AvailableConditionController) deleteEndpoints(obj interface{}) {
599
588
c .queue .Add (apiService )
600
589
}
601
590
}
602
-
603
- // setUnavailableGauge set the metrics so that it reflect the current state base on availability of the given service
604
- func (c * AvailableConditionController ) setUnavailableGauge (newAPIService * apiregistrationv1.APIService ) {
605
- if apiregistrationv1apihelper .IsAPIServiceConditionTrue (newAPIService , apiregistrationv1 .Available ) {
606
- c .metrics .SetAPIServiceAvailable (newAPIService .Name )
607
- return
608
- }
609
-
610
- c .metrics .SetAPIServiceUnavailable (newAPIService .Name )
611
- }
612
-
613
- // setUnavailableCounter increases the metrics only if the given service is unavailable and its APIServiceCondition has changed
614
- func (c * AvailableConditionController ) setUnavailableCounter (originalAPIService , newAPIService * apiregistrationv1.APIService ) {
615
- wasAvailable := apiregistrationv1apihelper .IsAPIServiceConditionTrue (originalAPIService , apiregistrationv1 .Available )
616
- isAvailable := apiregistrationv1apihelper .IsAPIServiceConditionTrue (newAPIService , apiregistrationv1 .Available )
617
- statusChanged := isAvailable != wasAvailable
618
-
619
- if statusChanged && ! isAvailable {
620
- reason := "UnknownReason"
621
- if newCondition := apiregistrationv1apihelper .GetAPIServiceConditionByType (newAPIService , apiregistrationv1 .Available ); newCondition != nil {
622
- reason = newCondition .Reason
623
- }
624
- c .metrics .UnavailableCounter (newAPIService .Name , reason ).Inc ()
625
- }
626
- }
0 commit comments