Skip to content

Commit fef2a88

Browse files
Merge pull request #913 from jhadvig/OCPBUGS-33715_2
OCPBUGS-33715: Cache organization ID when the ID changes
2 parents a780773 + 1e61a76 commit fef2a88

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

pkg/console/operator/sync_v400.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -478,10 +478,11 @@ func (co *consoleOperator) GetTelemetryConfiguration(ctx context.Context, operat
478478
if err != nil {
479479
return nil, err
480480
}
481-
482-
organizationID := telemetry.GetOrganizationID(telemetryConfig, co.trackables.organizationID, clusterID, accessToken)
483-
// cache ORGANIZATION_ID
484-
co.trackables.organizationID = organizationID
481+
organizationID, refreshCache := telemetry.GetOrganizationID(telemetryConfig, co.trackables.organizationID, clusterID, accessToken)
482+
// cache fetched ORGANIZATION_ID
483+
if refreshCache {
484+
co.trackables.organizationID = organizationID
485+
}
485486
telemetryConfig["ORGANIZATION_ID"] = organizationID
486487

487488
return telemetryConfig, nil

pkg/console/telemetry/telemetry.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,21 @@ func GetAccessToken(secretsLister v1.SecretLister) (string, error) {
8484
// 1. custom ORGANIZATION_ID is awailable as telemetry annotation on console-operator config or in telemetry-config configmap
8585
// 2. cached ORGANIZATION_ID is available on the operator controller instance
8686
// else fetch the ORGANIZATION_ID from OCM
87-
func GetOrganizationID(telemetryConfig map[string]string, cachedOrganizationID, clusterID, accessToken string) string {
88-
if customOrganizationID, isCustomOrgIDSet := telemetryConfig["ORGANIZATION_ID"]; isCustomOrgIDSet {
89-
return customOrganizationID
87+
func GetOrganizationID(telemetryConfig map[string]string, cachedOrganizationID, clusterID, accessToken string) (string, bool) {
88+
customOrganizationID, isCustomOrgIDSet := telemetryConfig["ORGANIZATION_ID"]
89+
if isCustomOrgIDSet {
90+
return customOrganizationID, false
9091
}
9192

9293
if cachedOrganizationID != "" {
93-
return cachedOrganizationID
94+
return cachedOrganizationID, false
9495
}
9596

9697
fetchedOrganizationID, err := FetchOrganizationID(clusterID, accessToken)
97-
klog.V(4).Infoln("Fetching ORGANIZATION_ID from OCM")
9898
if err != nil {
9999
klog.Errorf("telemetry config error: %s", err)
100100
}
101-
return fetchedOrganizationID
101+
return fetchedOrganizationID, true
102102
}
103103

104104
// Needed to create our own types for OCM Subscriptions since their types and client are useless

0 commit comments

Comments
 (0)