@@ -17,7 +17,6 @@ import (
17
17
"k8s.io/apimachinery/pkg/util/wait"
18
18
"k8s.io/client-go/discovery"
19
19
20
- olmv1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1"
21
20
olmv1alpha1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
22
21
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
23
22
olmversion "github.com/operator-framework/operator-lifecycle-manager/pkg/version"
@@ -26,9 +25,10 @@ import (
26
25
const (
27
26
clusterOperatorOLM = "operator-lifecycle-manager"
28
27
clusterOperatorCatalogSource = "operator-lifecycle-manager-catalog"
28
+ openshiftNamespace = "openshift-operator-lifecycle-manager"
29
29
)
30
30
31
- func MonitorClusterStatus (name , namespace string , syncCh <- chan error , stopCh <- chan struct {}, opClient operatorclient.ClientInterface , configClient configv1client.ConfigV1Interface , crClient versioned.Interface ) {
31
+ func MonitorClusterStatus (name string , syncCh <- chan error , stopCh <- chan struct {}, opClient operatorclient.ClientInterface , configClient configv1client.ConfigV1Interface , crClient versioned.Interface ) {
32
32
var (
33
33
syncs int
34
34
successfulSyncs int
@@ -114,11 +114,14 @@ func MonitorClusterStatus(name, namespace string, syncCh <-chan error, stopCh <-
114
114
},
115
115
},
116
116
})
117
- created .Status .RelatedObjects = relatedObjects (name , namespace , opClient , crClient )
118
117
if createErr != nil {
119
118
log .Errorf ("Failed to create cluster operator: %v\n " , createErr )
120
119
return
121
120
}
121
+ created .Status .RelatedObjects , err = relatedObjects (name , opClient , crClient )
122
+ if err != nil {
123
+ log .Errorf ("Failed to get related objects: %v" , err )
124
+ }
122
125
existing = created
123
126
err = nil
124
127
}
@@ -247,38 +250,55 @@ func findOperatorStatusCondition(conditions []configv1.ClusterOperatorStatusCond
247
250
248
251
// relatedObjects returns RelatedObjects in the ClusterOperator.Status.
249
252
// RelatedObjects are consumed by https://github.com/openshift/must-gather
250
- func relatedObjects (name , namespace string , opClient operatorclient.ClientInterface , crClient versioned.Interface ) []configv1.ObjectReference {
253
+ func relatedObjects (name string , opClient operatorclient.ClientInterface , crClient versioned.Interface ) ( []configv1.ObjectReference , error ) {
251
254
var objectReferences []configv1.ObjectReference
255
+ log .Infof ("Adding related objects for %v" , name )
256
+ namespace := openshiftNamespace // hard-coded to constant
257
+
252
258
switch name {
253
259
case clusterOperatorOLM :
254
- objectReferences = []configv1.ObjectReference {
255
- {
256
- Group : olmv1 .GroupName ,
257
- Resource : olmv1 .OperatorGroupKind ,
258
- Namespace : namespace ,
259
- Name : clusterOperatorOLM ,
260
- },
261
- {
260
+ csvList , err := crClient .OperatorsV1alpha1 ().ClusterServiceVersions (namespace ).List (metav1.ListOptions {})
261
+ if err != nil {
262
+ return nil , err
263
+ }
264
+
265
+ for _ , csv := range csvList .Items {
266
+ if csv .IsCopied () {
267
+ continue
268
+ }
269
+ objectReferences = append (objectReferences , configv1.ObjectReference {
262
270
Group : olmv1alpha1 .GroupName ,
263
271
Resource : olmv1alpha1 .ClusterServiceVersionKind ,
264
- Namespace : namespace ,
265
- Name : clusterOperatorOLM ,
266
- },
272
+ Namespace : csv . GetNamespace () ,
273
+ Name : csv . GetName () ,
274
+ })
267
275
}
268
276
case clusterOperatorCatalogSource :
269
- objectReferences = []configv1.ObjectReference {
270
- {
277
+ subList , err := crClient .OperatorsV1alpha1 ().Subscriptions (namespace ).List (metav1.ListOptions {})
278
+ if err != nil {
279
+ return nil , err
280
+ }
281
+
282
+ installPlanList , err := crClient .OperatorsV1alpha1 ().InstallPlans (namespace ).List (metav1.ListOptions {})
283
+ if err != nil {
284
+ return nil , err
285
+ }
286
+
287
+ for _ , sub := range subList .Items {
288
+ objectReferences = append (objectReferences , configv1.ObjectReference {
271
289
Group : olmv1alpha1 .GroupName ,
272
290
Resource : olmv1alpha1 .SubscriptionKind ,
273
- Namespace : namespace ,
274
- Name : clusterOperatorCatalogSource ,
275
- },
276
- {
291
+ Namespace : sub .GetNamespace (),
292
+ Name : sub .GetName (),
293
+ })
294
+ }
295
+ for _ , ip := range installPlanList .Items {
296
+ objectReferences = append (objectReferences , configv1.ObjectReference {
277
297
Group : olmv1alpha1 .GroupName ,
278
298
Resource : olmv1alpha1 .InstallPlanKind ,
279
- Namespace : namespace ,
280
- Name : clusterOperatorCatalogSource ,
281
- },
299
+ Namespace : ip . GetNamespace () ,
300
+ Name : ip . GetName () ,
301
+ })
282
302
}
283
303
}
284
304
namespaces := configv1.ObjectReference {
@@ -287,5 +307,5 @@ func relatedObjects(name, namespace string, opClient operatorclient.ClientInterf
287
307
Name : namespace ,
288
308
}
289
309
objectReferences = append (objectReferences , namespaces )
290
- return objectReferences
310
+ return objectReferences , nil
291
311
}
0 commit comments