Skip to content

Commit ba9049b

Browse files
author
Jeff Peeler
committed
fix(clusteroperator): fix naming of related objects
1 parent 8d9967e commit ba9049b

File tree

3 files changed

+47
-27
lines changed

3 files changed

+47
-27
lines changed

cmd/catalog/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func main() {
171171
<-op.Ready()
172172

173173
if *writeStatusName != "" {
174-
operatorstatus.MonitorClusterStatus(*writeStatusName, *catalogNamespace, op.AtLevel(), op.Done(), opClient, configClient, crClient)
174+
operatorstatus.MonitorClusterStatus(*writeStatusName, op.AtLevel(), op.Done(), opClient, configClient, crClient)
175175
}
176176

177177
<-op.Done()

cmd/olm/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ func main() {
196196
<-op.Ready()
197197

198198
if *writeStatusName != "" {
199-
operatorstatus.MonitorClusterStatus(*writeStatusName, *namespace, op.AtLevel(), ctx.Done(), opClient, configClient, crClient)
199+
operatorstatus.MonitorClusterStatus(*writeStatusName, op.AtLevel(), ctx.Done(), opClient, configClient, crClient)
200200
}
201201

202202
if *writePackageServerStatusName != "" {

pkg/lib/operatorstatus/status.go

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"k8s.io/apimachinery/pkg/util/wait"
1818
"k8s.io/client-go/discovery"
1919

20-
olmv1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1"
2120
olmv1alpha1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
2221
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
2322
olmversion "github.com/operator-framework/operator-lifecycle-manager/pkg/version"
@@ -26,9 +25,10 @@ import (
2625
const (
2726
clusterOperatorOLM = "operator-lifecycle-manager"
2827
clusterOperatorCatalogSource = "operator-lifecycle-manager-catalog"
28+
openshiftNamespace = "openshift-operator-lifecycle-manager"
2929
)
3030

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) {
3232
var (
3333
syncs int
3434
successfulSyncs int
@@ -114,11 +114,14 @@ func MonitorClusterStatus(name, namespace string, syncCh <-chan error, stopCh <-
114114
},
115115
},
116116
})
117-
created.Status.RelatedObjects = relatedObjects(name, namespace, opClient, crClient)
118117
if createErr != nil {
119118
log.Errorf("Failed to create cluster operator: %v\n", createErr)
120119
return
121120
}
121+
created.Status.RelatedObjects, err = relatedObjects(name, opClient, crClient)
122+
if err != nil {
123+
log.Errorf("Failed to get related objects: %v", err)
124+
}
122125
existing = created
123126
err = nil
124127
}
@@ -247,38 +250,55 @@ func findOperatorStatusCondition(conditions []configv1.ClusterOperatorStatusCond
247250

248251
// relatedObjects returns RelatedObjects in the ClusterOperator.Status.
249252
// 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) {
251254
var objectReferences []configv1.ObjectReference
255+
log.Infof("Adding related objects for %v", name)
256+
namespace := openshiftNamespace // hard-coded to constant
257+
252258
switch name {
253259
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{
262270
Group: olmv1alpha1.GroupName,
263271
Resource: olmv1alpha1.ClusterServiceVersionKind,
264-
Namespace: namespace,
265-
Name: clusterOperatorOLM,
266-
},
272+
Namespace: csv.GetNamespace(),
273+
Name: csv.GetName(),
274+
})
267275
}
268276
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{
271289
Group: olmv1alpha1.GroupName,
272290
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{
277297
Group: olmv1alpha1.GroupName,
278298
Resource: olmv1alpha1.InstallPlanKind,
279-
Namespace: namespace,
280-
Name: clusterOperatorCatalogSource,
281-
},
299+
Namespace: ip.GetNamespace(),
300+
Name: ip.GetName(),
301+
})
282302
}
283303
}
284304
namespaces := configv1.ObjectReference{
@@ -287,5 +307,5 @@ func relatedObjects(name, namespace string, opClient operatorclient.ClientInterf
287307
Name: namespace,
288308
}
289309
objectReferences = append(objectReferences, namespaces)
290-
return objectReferences
310+
return objectReferences, nil
291311
}

0 commit comments

Comments
 (0)