@@ -12,6 +12,7 @@ import (
12
12
"k8s.io/apimachinery/pkg/api/errors"
13
13
appsv1listers "k8s.io/client-go/listers/apps/v1"
14
14
v1 "k8s.io/client-go/listers/core/v1"
15
+ "k8s.io/klog/v2"
15
16
16
17
"github.com/openshift/console-operator/pkg/api"
17
18
deploymentsub "github.com/openshift/console-operator/pkg/console/subresource/deployment"
@@ -79,6 +80,27 @@ func GetAccessToken(secretsLister v1.SecretLister) (string, error) {
79
80
return authsBytes .Auth , nil
80
81
}
81
82
83
+ // check if:
84
+ // 1. custom ORGANIZATION_ID is awailable as telemetry annotation on console-operator config or in telemetry-config configmap
85
+ // 2. cached ORGANIZATION_ID is available on the operator controller instance
86
+ // 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
90
+ }
91
+
92
+ if cachedOrganizationID != "" {
93
+ return cachedOrganizationID
94
+ }
95
+
96
+ fetchedOrganizationID , err := FetchOrganizationID (clusterID , accessToken )
97
+ klog .V (4 ).Infoln ("Fetching ORGANIZATION_ID from OCM" )
98
+ if err != nil {
99
+ klog .Errorf ("telemetry config error: %s" , err )
100
+ }
101
+ return fetchedOrganizationID
102
+ }
103
+
82
104
// Needed to create our own types for OCM Subscriptions since their types and client are useless
83
105
// https://github.com/openshift-online/ocm-sdk-go/blob/main/accountsmgmt/v1/subscription_client.go - everything private
84
106
// https://github.com/openshift-online/ocm-sdk-go/blob/main/accountsmgmt/v1/subscriptions_client.go#L38-L41 - useless client
@@ -89,8 +111,8 @@ type Organization struct {
89
111
OrganizationID string `json:"organization_id"`
90
112
}
91
113
92
- // GetOrganizationID fetches the organization ID using the cluster ID and access token
93
- func GetOrganizationID (clusterID , accessToken string ) (string , error ) {
114
+ // FetchOrganizationID fetches the organization ID using the cluster ID and access token
115
+ func FetchOrganizationID (clusterID , accessToken string ) (string , error ) {
94
116
u , err := buildURL (clusterID )
95
117
if err != nil {
96
118
return "" , err // more contextual error handling can be added here if needed
0 commit comments