Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-4.14] OCPBUGS-28382: Use cached clients to avoid client side throttling #666

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 12 additions & 7 deletions pkg/operator/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ func Add(mgr, rootCredentialManager manager.Manager, kubeConfig string) error {
logger := log.WithField("controller", controllerName)

mc := &Calculator{
Client: utils.LiveClient(mgr),
Interval: 2 * time.Minute,
log: logger,
Client: mgr.GetClient(),
rootClient: rootCredentialManager.GetClient(),
Interval: 2 * time.Minute,
log: logger,
}
err := mgr.Add(mc)
if err != nil {
Expand All @@ -90,10 +91,14 @@ func Add(mgr, rootCredentialManager manager.Manager, kubeConfig string) error {
// a standard controller watching Kube resources, it runs periodically and then goes to sleep.
//
// This should be used for metrics which do not fit well into controller reconcile loops,
// things that are calculated globally rather than metrics releated to specific reconciliations.
// things that are calculated globally rather than metrics related to specific reconciliations.
type Calculator struct {
// controller-runtime client used for querying anything except the root credential
Client client.Client

// controller-runtime client used for querying the root credential only
rootClient client.Client

// Interval is the length of time we sleep between metrics calculations.
Interval time.Duration

Expand Down Expand Up @@ -178,10 +183,10 @@ func (mc *Calculator) getCloudSecret() (*corev1.Secret, error) {
case configv1.KubevirtPlatformType:
secretKey.Name = constants.KubevirtCloudCredSecretName
default:
mc.log.WithField("cloud", platformType).Info("unsupported cloud for determing CCO mode")
mc.log.WithField("cloud", platformType).Info("unsupported cloud for determining CCO mode")
return nil, nil
}
err = mc.Client.Get(context.TODO(), secretKey, secret)
err = mc.rootClient.Get(context.TODO(), secretKey, secret)
return secret, err
}

Expand Down Expand Up @@ -227,7 +232,7 @@ func newAccumulator(client client.Client, logger log.FieldLogger) *credRequestAc
}

// make entries with '0' so we make sure to send updated metrics for any
// condititons that may have cleared
// conditions that may have cleared
for _, c := range credreqv1.FailureConditionTypes {
acc.crConditions[c] = 0
}
Expand Down
12 changes: 7 additions & 5 deletions pkg/operator/metrics/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ var (
)

func TestSecretGetter(t *testing.T) {
configv1.AddToScheme(scheme.Scheme)
err := configv1.Install(scheme.Scheme)
assert.NoError(t, err, "error installing configv1 types to scheme")

logger := log.WithField("controller", "metricscontrollertest")

Expand Down Expand Up @@ -112,11 +113,12 @@ func TestSecretGetter(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {

fakeClient := fake.NewClientBuilder().WithRuntimeObjects(test.clusterInfra, test.cloudCredsSecret).Build()
fakeClient := fake.NewClientBuilder().WithRuntimeObjects(test.clusterInfra).Build()
fakeRootClient := fake.NewClientBuilder().WithRuntimeObjects(test.cloudCredsSecret).Build()
calc := &Calculator{
Client: fakeClient,
log: logger,
Client: fakeClient,
rootClient: fakeRootClient,
log: logger,
}

secret, err := calc.getCloudSecret()
Expand Down