@@ -8,15 +8,16 @@ import (
8
8
9
9
configv1 "github.com/openshift/api/config/v1"
10
10
configv1client "github.com/openshift/client-go/config/clientset/versioned/typed/config/v1"
11
+ "github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned"
11
12
log "github.com/sirupsen/logrus"
12
13
corev1 "k8s.io/api/core/v1"
13
14
k8serrors "k8s.io/apimachinery/pkg/api/errors"
14
15
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
15
16
"k8s.io/apimachinery/pkg/runtime/schema"
17
+ "k8s.io/apimachinery/pkg/util/diff"
16
18
"k8s.io/apimachinery/pkg/util/wait"
17
19
"k8s.io/client-go/discovery"
18
20
19
- olmv1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1"
20
21
olmv1alpha1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
21
22
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
22
23
olmversion "github.com/operator-framework/operator-lifecycle-manager/pkg/version"
@@ -25,9 +26,10 @@ import (
25
26
const (
26
27
clusterOperatorOLM = "operator-lifecycle-manager"
27
28
clusterOperatorCatalogSource = "operator-lifecycle-manager-catalog"
29
+ openshiftNamespace = "openshift-operator-lifecycle-manager"
28
30
)
29
31
30
- func MonitorClusterStatus (name , namespace string , syncCh <- chan error , stopCh <- chan struct {}, opClient operatorclient.ClientInterface , configClient configv1client.ConfigV1Interface ) {
32
+ func MonitorClusterStatus (name string , syncCh <- chan error , stopCh <- chan struct {}, opClient operatorclient.ClientInterface , configClient configv1client.ConfigV1Interface , crClient versioned. Interface ) {
31
33
var (
32
34
syncs int
33
35
successfulSyncs int
@@ -113,11 +115,14 @@ func MonitorClusterStatus(name, namespace string, syncCh <-chan error, stopCh <-
113
115
},
114
116
},
115
117
})
116
- created .Status .RelatedObjects = relatedObjects (name , namespace )
117
118
if createErr != nil {
118
119
log .Errorf ("Failed to create cluster operator: %v\n " , createErr )
119
120
return
120
121
}
122
+ created .Status .RelatedObjects , err = relatedObjects (name , opClient , crClient )
123
+ if err != nil {
124
+ log .Errorf ("Failed to get related objects: %v" , err )
125
+ }
121
126
existing = created
122
127
err = nil
123
128
}
@@ -198,6 +203,16 @@ func MonitorClusterStatus(name, namespace string, syncCh <-chan error, stopCh <-
198
203
// TODO: use % errors within a window to report available
199
204
}
200
205
206
+ // always update the related objects in case changes have occurred
207
+ existing .Status .RelatedObjects , err = relatedObjects (name , opClient , crClient )
208
+ if err != nil {
209
+ log .Errorf ("Failed to get related objects: %v" , err )
210
+ }
211
+ if ! reflect .DeepEqual (previousStatus .RelatedObjects , existing .Status .RelatedObjects ) {
212
+ diffString := diff .ObjectDiff (previousStatus .RelatedObjects , existing .Status .RelatedObjects )
213
+ log .Debugf ("Update required for related objects: %v" , diffString )
214
+ }
215
+
201
216
// update the status
202
217
if ! reflect .DeepEqual (previousStatus , & existing .Status ) {
203
218
if _ , err := configClient .ClusterOperators ().UpdateStatus (existing ); err != nil {
@@ -246,38 +261,55 @@ func findOperatorStatusCondition(conditions []configv1.ClusterOperatorStatusCond
246
261
247
262
// relatedObjects returns RelatedObjects in the ClusterOperator.Status.
248
263
// RelatedObjects are consumed by https://github.com/openshift/must-gather
249
- func relatedObjects (name , namespace string ) []configv1.ObjectReference {
264
+ func relatedObjects (name string , opClient operatorclient. ClientInterface , crClient versioned. Interface ) ( []configv1.ObjectReference , error ) {
250
265
var objectReferences []configv1.ObjectReference
266
+ log .Infof ("Adding related objects for %v" , name )
267
+ namespace := openshiftNamespace // hard-coded to constant
268
+
251
269
switch name {
252
270
case clusterOperatorOLM :
253
- objectReferences = []configv1.ObjectReference {
254
- {
255
- Group : olmv1 .GroupName ,
256
- Resource : olmv1 .OperatorGroupKind ,
257
- Namespace : namespace ,
258
- Name : clusterOperatorOLM ,
259
- },
260
- {
271
+ csvList , err := crClient .OperatorsV1alpha1 ().ClusterServiceVersions (namespace ).List (metav1.ListOptions {})
272
+ if err != nil {
273
+ return nil , err
274
+ }
275
+
276
+ for _ , csv := range csvList .Items {
277
+ if csv .IsCopied () {
278
+ continue
279
+ }
280
+ objectReferences = append (objectReferences , configv1.ObjectReference {
261
281
Group : olmv1alpha1 .GroupName ,
262
282
Resource : olmv1alpha1 .ClusterServiceVersionKind ,
263
- Namespace : namespace ,
264
- Name : clusterOperatorOLM ,
265
- },
283
+ Namespace : csv . GetNamespace () ,
284
+ Name : csv . GetName () ,
285
+ })
266
286
}
267
287
case clusterOperatorCatalogSource :
268
- objectReferences = []configv1.ObjectReference {
269
- {
288
+ subList , err := crClient .OperatorsV1alpha1 ().Subscriptions (namespace ).List (metav1.ListOptions {})
289
+ if err != nil {
290
+ return nil , err
291
+ }
292
+
293
+ installPlanList , err := crClient .OperatorsV1alpha1 ().InstallPlans (namespace ).List (metav1.ListOptions {})
294
+ if err != nil {
295
+ return nil , err
296
+ }
297
+
298
+ for _ , sub := range subList .Items {
299
+ objectReferences = append (objectReferences , configv1.ObjectReference {
270
300
Group : olmv1alpha1 .GroupName ,
271
301
Resource : olmv1alpha1 .SubscriptionKind ,
272
- Namespace : namespace ,
273
- Name : clusterOperatorCatalogSource ,
274
- },
275
- {
302
+ Namespace : sub .GetNamespace (),
303
+ Name : sub .GetName (),
304
+ })
305
+ }
306
+ for _ , ip := range installPlanList .Items {
307
+ objectReferences = append (objectReferences , configv1.ObjectReference {
276
308
Group : olmv1alpha1 .GroupName ,
277
309
Resource : olmv1alpha1 .InstallPlanKind ,
278
- Namespace : namespace ,
279
- Name : clusterOperatorCatalogSource ,
280
- },
310
+ Namespace : ip . GetNamespace () ,
311
+ Name : ip . GetName () ,
312
+ })
281
313
}
282
314
}
283
315
namespaces := configv1.ObjectReference {
@@ -286,5 +318,5 @@ func relatedObjects(name, namespace string) []configv1.ObjectReference {
286
318
Name : namespace ,
287
319
}
288
320
objectReferences = append (objectReferences , namespaces )
289
- return objectReferences
321
+ return objectReferences , nil
290
322
}
0 commit comments