@@ -81,14 +81,16 @@ func GetAccessToken(secretsLister v1.SecretLister) (string, error) {
81
81
}
82
82
83
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
84
+ // 1. custom ORGANIZATION_ID and ACCOUNT_MAIL is awailable as telemetry annotation on console-operator config or in telemetry-config configmap
85
+ // 2. cached ORGANIZATION_ID and ACCOUNT_MAIL is available on the operator controller instance
86
+ // else fetch the ORGANIZATION_ID and ACCOUNT_MAIL from OCM
87
87
func GetOrganizationMeta (telemetryConfig map [string ]string , cachedOrganizationID , cachedAccountEmail , clusterID , accessToken string ) (string , string , bool ) {
88
88
customOrganizationID , isCustomOrgIDSet := telemetryConfig ["ORGANIZATION_ID" ]
89
- if isCustomOrgIDSet {
90
- klog .V (4 ).Infoln ("telemetry config: using custom organization ID" )
91
- return customOrganizationID , "" , false
89
+ customAccountMail , isCustomAccountMailSet := telemetryConfig ["ACCOUNT_MAIL" ]
90
+
91
+ if isCustomOrgIDSet && isCustomAccountMailSet {
92
+ klog .V (4 ).Infoln ("telemetry config: using custom data" )
93
+ return customOrganizationID , customAccountMail , false
92
94
}
93
95
94
96
if cachedOrganizationID != "" && cachedAccountEmail != "" {
@@ -99,7 +101,15 @@ func GetOrganizationMeta(telemetryConfig map[string]string, cachedOrganizationID
99
101
fetchedOCMRespose , err := FetchSubscription (clusterID , accessToken )
100
102
if err != nil {
101
103
klog .Errorf ("telemetry config error: %s" , err )
104
+ return "" , "" , false // Ensure safe return in case of error
105
+ }
106
+
107
+ // Check if the fetched response is nil before accessing fields
108
+ if fetchedOCMRespose == nil {
109
+ klog .Errorf ("telemetry config error: FetchSubscription returned nil response" )
110
+ return "" , "" , false
102
111
}
112
+
103
113
return fetchedOCMRespose .Organization .ExternalId , fetchedOCMRespose .Creator .Email , true
104
114
}
105
115
@@ -160,8 +170,6 @@ func FetchSubscription(clusterID, accessToken string) (*Subscription, error) {
160
170
if err = json .Unmarshal (body , & ocmResponse ); err != nil {
161
171
return nil , fmt .Errorf ("error decoding JSON: %v" , err )
162
172
}
163
- klog .Infof ("---> data: %#v\n " , string (body ))
164
- klog .Infof ("---> ocmResponse: %#v\n " , ocmResponse )
165
173
166
174
if len (ocmResponse .Items ) == 0 {
167
175
return nil , fmt .Errorf ("empty OCM response" )
0 commit comments